<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import os , sys <EOL> import datetime <EOL> import functools <EOL> import marshal <EOL> import operator <EOL> import pythoncom <EOL> import winxpgui as win32gui <EOL> import pythoncom <EOL> import win32com . server . policy <EOL> import win32api <EOL> import win32con <EOL> import win32cred <EOL> import win32event <EOL> from win32com . shell import shell , shellcon <EOL> import win32ui <EOL> import struct <EOL> import threading <EOL> import traceback <EOL> import uuid <EOL> from winsys . _compat import * <EOL> from winsys import core , constants , exc , utils <EOL> BIF = constants . Constants . from_dict ( dict ( <EOL> BIF_RETURNONLYFSDIRS = <NUM_LIT> , <EOL> BIF_DONTGOBELOWDOMAIN = <NUM_LIT> , <EOL> BIF_STATUSTEXT = <NUM_LIT> , <EOL> BIF_RETURNFSANCESTORS = <NUM_LIT> , <EOL> BIF_EDITBOX = <NUM_LIT> , <EOL> BIF_VALIDATE = <NUM_LIT> , <EOL> BIF_NEWDIALOGSTYLE = <NUM_LIT> , <EOL> BIF_BROWSEINCLUDEURLS = <NUM_LIT> , <EOL> BIF_UAHINT = <NUM_LIT> , <EOL> BIF_NONEWFOLDERBUTTON = <NUM_LIT> , <EOL> BIF_NOTRANSLATETARGETS = <NUM_LIT> , <EOL> BIF_BROWSEFORCOMPUTER = <NUM_LIT> , <EOL> BIF_BROWSEFORPRINTER = <NUM_LIT> , <EOL> BIF_BROWSEINCLUDEFILES = <NUM_LIT> , <EOL> BIF_SHAREABLE = <NUM_LIT> <EOL> ) , pattern = "<STR_LIT>" ) <EOL> BIF . update ( dict ( USENEWUI = BIF . NEWDIALOGSTYLE | BIF . EDITBOX ) ) <EOL> BIF . doc ( "<STR_LIT>" ) <EOL> BFFM = constants . Constants . from_pattern ( "<STR_LIT>" , namespace = shellcon ) <EOL> BFFM . doc ( "<STR_LIT>" ) <EOL> CREDUI_FLAGS = constants . Constants . from_pattern ( "<STR_LIT>" , namespace = win32cred ) <EOL> CREDUI_FLAGS . doc ( "<STR_LIT>" ) <EOL> CRED_FLAGS = constants . Constants . from_pattern ( "<STR_LIT>" , namespace = win32cred ) <EOL> CRED_TYPE = constants . Constants . from_pattern ( "<STR_LIT>" , namespace = win32cred ) <EOL> CRED_TI = constants . Constants . from_pattern ( "<STR_LIT>" , namespace = win32cred ) <EOL> class x_dialogs ( exc . x_winsys ) : <EOL> "<STR_LIT>" <EOL> WINERROR_MAP = { <EOL> } <EOL> wrapped = exc . wrapper ( WINERROR_MAP , x_dialogs ) <EOL> DESKTOP = wrapped ( win32gui . GetDesktopWindow ) <EOL> ENCODING = "<STR_LIT>" <EOL> class _DropTarget ( win32com . server . policy . DesignatedWrapPolicy ) : <EOL> """<STR_LIT>""" <EOL> _reg_clsid_ = '<STR_LIT>' <EOL> _reg_progid_ = "<STR_LIT>" <EOL> _reg_desc_ = "<STR_LIT>" <EOL> _public_methods_ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> _com_interfaces_ = [ pythoncom . IID_IDropTarget ] <EOL> _data_format = ( <EOL> win32con . CF_HDROP , <EOL> None , <EOL> pythoncom . DVASPECT_CONTENT , <EOL> - <NUM_LIT:1> , <EOL> pythoncom . TYMED_HGLOBAL <EOL> ) <EOL> def __init__ ( self , hwnd ) : <EOL> self . _wrap_ ( self ) <EOL> self . hwnd = hwnd <EOL> def DragEnter ( self , data_object , key_state , point , effect ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> data_object . QueryGetData ( self . _data_format ) <EOL> except pywintypes . error : <EOL> return shellcon . DROPEFFECT_NONE <EOL> else : <EOL> return shellcon . DROPEFFECT_COPY <EOL> def Drop ( self , data_object , key_state , point , effect ) : <EOL> child_point = wrapped ( win32gui . ScreenToClient , self . hwnd , point ) <EOL> child_hwnd = wrapped ( win32gui . ChildWindowFromPoint , self . hwnd , child_point ) <EOL> data = data_object . GetData ( self . _data_format ) <EOL> n_files = shell . DragQueryFileW ( data . data_handle , - <NUM_LIT:1> ) <EOL> if n_files : <EOL> files_string = shell . DragQueryFileW ( data . data_handle , <NUM_LIT:0> ) <EOL> print ( type ( files_string ) , files_string ) <EOL> address , _ = win32gui . PyGetBufferAddressAndLen ( files_string . encode ( "<STR_LIT>" ) ) <EOL> SendMessage ( <EOL> child_hwnd , win32con . WM_SETTEXT , None , <EOL> win32gui . PyGetBufferAddressAndLen ( memoryview ( files_string . encode ( "<STR_LIT>" ) ) ) [ <NUM_LIT:0> ] <EOL> ) <EOL> def DragOver ( self , key_state , point , effect ) : <EOL> """<STR_LIT>""" <EOL> child_point = wrapped ( win32gui . ScreenToClient , self . hwnd , point ) <EOL> child_hwnd = wrapped ( win32gui . ChildWindowFromPoint , self . hwnd , child_point ) <EOL> if child_hwnd == <NUM_LIT:0> : <EOL> return shellcon . DROPEFFECT_NONE <EOL> else : <EOL> if wrapped ( win32gui . GetClassName , child_hwnd ) == "<STR_LIT>" : <EOL> return shellcon . DROPEFFECT_COPY <EOL> else : <EOL> return shellcon . DROPEFFECT_NONE <EOL> def DragLeave ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def as_code ( text ) : <EOL> return text . lower ( ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) <EOL> def _register_wndclass ( ) : <EOL> """<STR_LIT>""" <EOL> class_name = str ( uuid . uuid1 ( ) ) <EOL> wc = wrapped ( win32gui . WNDCLASS ) <EOL> wc . SetDialogProc ( ) <EOL> wc . hInstance = win32gui . dllhandle <EOL> wc . lpszClassName = class_name <EOL> wc . style = win32con . CS_VREDRAW | win32con . CS_HREDRAW <EOL> wc . hCursor = wrapped ( win32gui . LoadCursor , <NUM_LIT:0> , win32con . IDC_ARROW ) <EOL> wc . hbrBackground = win32con . COLOR_WINDOW + <NUM_LIT:1> <EOL> wc . lpfnWndProc = { } <EOL> wc . cbWndExtra = win32con . DLGWINDOWEXTRA + struct . calcsize ( b"<STR_LIT>" ) <EOL> icon_flags = win32con . LR_LOADFROMFILE | win32con . LR_DEFAULTSIZE <EOL> python_exe = wrapped ( win32api . GetModuleHandle , None ) <EOL> if not hasattr ( sys , "<STR_LIT>" ) : <EOL> wc . hIcon = wrapped ( win32gui . LoadIcon , python_exe , <NUM_LIT:1> ) <EOL> class_atom = wrapped ( win32gui . RegisterClass , wc ) <EOL> return class_name <EOL> _class_name = _register_wndclass ( ) <EOL> def SendMessage ( * args , ** kwargs ) : <EOL> return wrapped ( win32gui . SendMessage , * args , ** kwargs ) <EOL> def PostMessage ( * args , ** kwargs ) : <EOL> return wrapped ( win32gui . PostMessage , * args , ** kwargs ) <EOL> def MoveWindow ( * args , ** kwargs ) : <EOL> return wrapped ( win32gui . MoveWindow , * args , ** kwargs ) <EOL> class BaseDialog ( object ) : <EOL> """<STR_LIT>""" <EOL> WM_PROGRESS_MESSAGE = win32con . WM_USER + <NUM_LIT:1> <EOL> WM_PROGRESS_COMPLETE = win32con . WM_USER + <NUM_LIT:2> <EOL> IDC_LABEL_BASE = <NUM_LIT> <EOL> IDC_FIELD_BASE = IDC_LABEL_BASE + <NUM_LIT:1000> <EOL> IDC_CALLBACK_BASE = IDC_FIELD_BASE + <NUM_LIT:1000> <EOL> W = <NUM_LIT> <EOL> GUTTER_W = <NUM_LIT:5> <EOL> GUTTER_H = <NUM_LIT:5> <EOL> CONTROL_H = <NUM_LIT:12> <EOL> LABEL_W = <NUM_LIT> <EOL> FIELD_W = W - GUTTER_W - LABEL_W - GUTTER_W - GUTTER_W <EOL> BUTTON_W = <NUM_LIT> <EOL> CALLBACK_W = CONTROL_H <EOL> MAX_W = <NUM_LIT> <EOL> MAX_H = <NUM_LIT> <EOL> BUTTONS = [ ( "<STR_LIT>" , win32con . IDCANCEL ) , ( "<STR_LIT>" , win32con . IDOK ) ] <EOL> def __init__ ( self , title , parent_hwnd = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> wrapped ( win32gui . InitCommonControls ) <EOL> wrapped ( pythoncom . OleInitialize ) <EOL> self . hinst = win32gui . dllhandle <EOL> self . title = title <EOL> self . parent_hwnd = parent_hwnd <EOL> self . fields = [ ] <EOL> self . _progress_id = None <EOL> def _get_dialog_template ( self ) : <EOL> """<STR_LIT>""" <EOL> dlg_class_name = _register_wndclass ( ) <EOL> style = reduce ( operator . or_ , ( <EOL> win32con . WS_THICKFRAME , <EOL> win32con . WS_POPUP , <EOL> win32con . WS_VISIBLE , <EOL> win32con . WS_CAPTION , <EOL> win32con . WS_SYSMENU , <EOL> win32con . DS_SETFONT , <EOL> win32con . WS_MINIMIZEBOX <EOL> ) ) <EOL> cs = win32con . WS_CHILD | win32con . WS_VISIBLE <EOL> n_fields = len ( self . fields ) + ( <NUM_LIT:1> if self . progress_callback else <NUM_LIT:0> ) <EOL> dlg = [ ] <EOL> control_t = self . GUTTER_H <EOL> for i , ( field , default_value , callback ) in enumerate ( self . fields ) : <EOL> label_l = self . GUTTER_W <EOL> label_t = control_t <EOL> field_l = label_l + self . LABEL_W + self . GUTTER_W <EOL> field_t = label_t <EOL> display_h = field_h = self . CONTROL_H <EOL> if field is None : <EOL> field_type , sub_type = "<STR_LIT>" , "<STR_LIT>" <EOL> elif isinstance ( default_value , bool ) : <EOL> field_type , sub_type = "<STR_LIT>" , "<STR_LIT>" <EOL> elif isinstance ( default_value , tuple ) : <EOL> field_type , sub_type = "<STR_LIT>" , "<STR_LIT>" <EOL> elif isinstance ( default_value , list ) : <EOL> field_type , sub_type = "<STR_LIT>" , None <EOL> elif field . upper ( ) == "<STR_LIT>" : <EOL> field_type , sub_type = "<STR_LIT>" , "<STR_LIT>" <EOL> else : <EOL> field_type , sub_type = "<STR_LIT>" , None <EOL> dlg . append ( [ "<STR_LIT>" , field , self . IDC_LABEL_BASE + i , ( label_l , label_t , self . LABEL_W , self . CONTROL_H ) , cs | win32con . SS_LEFT ] ) <EOL> if field_type != "<STR_LIT>" : <EOL> field_styles = win32con . WS_TABSTOP <EOL> else : <EOL> field_styles = <NUM_LIT:0> <EOL> if ( field_type , sub_type ) == ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> field_styles |= win32con . BS_AUTOCHECKBOX <EOL> field_w = self . CONTROL_H <EOL> elif ( field_type , sub_type ) == ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> field_styles |= win32con . BS_AUTORADIOBUTTON <EOL> field_w = self . CONTROL_H <EOL> elif field_type == "<STR_LIT>" : <EOL> if callback is not None : <EOL> raise x_dialogs ( "<STR_LIT>" ) <EOL> field_styles |= win32con . CBS_DROPDOWNLIST | win32con . WS_VSCROLL <EOL> field_w = self . FIELD_W <EOL> field_h = <NUM_LIT:8> * self . CONTROL_H <EOL> display_h = self . CONTROL_H <EOL> elif field_type == "<STR_LIT>" : <EOL> field_styles |= win32con . WS_BORDER | win32con . ES_AUTOHSCROLL | win32con . ES_AUTOVSCROLL <EOL> field_w = self . FIELD_W - ( ( self . CALLBACK_W ) if callback else <NUM_LIT:0> ) <EOL> if "<STR_LIT:\r\n>" in unicode ( default_value ) : <EOL> field_styles |= win32con . ES_MULTILINE <EOL> display_h = field_h = self . CONTROL_H * min ( default_value . count ( "<STR_LIT:\r\n>" ) , <NUM_LIT:10> ) <EOL> if sub_type == "<STR_LIT>" : <EOL> field_styles |= win32con . ES_READONLY <EOL> if sub_type == "<STR_LIT>" : <EOL> field_styles |= win32con . ES_PASSWORD <EOL> else : <EOL> raise x_dialogs ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> ) <EOL> dlg . append ( [ field_type , None , self . IDC_FIELD_BASE + i , ( field_l , field_t , field_w , field_h ) , cs | field_styles ] ) <EOL> if callback : <EOL> dlg . append ( [ "<STR_LIT>" , "<STR_LIT>" , self . IDC_CALLBACK_BASE + i , ( field_l + field_w + self . GUTTER_W , field_t , self . CALLBACK_W , self . CONTROL_H ) , cs | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON ] ) <EOL> control_t += display_h + self . GUTTER_H <EOL> i += <NUM_LIT:1> <EOL> if self . progress_callback : <EOL> self . _progress_id = self . IDC_FIELD_BASE + i <EOL> field_t = control_t <EOL> field_w = self . W - ( <NUM_LIT:2> * self . GUTTER_W ) <EOL> field_l = self . GUTTER_W <EOL> field_h = self . CONTROL_H <EOL> field_styles = win32con . SS_LEFT <EOL> dlg . append ( [ "<STR_LIT>" , None , self . IDC_FIELD_BASE + i , ( field_l , field_t , field_w , field_h ) , cs | field_styles ] ) <EOL> control_t += field_h + self . GUTTER_H <EOL> cs = win32con . WS_CHILD | win32con . WS_VISIBLE | win32con . WS_TABSTOP | win32con . BS_PUSHBUTTON <EOL> button_t = control_t <EOL> for i , ( caption , id ) in enumerate ( reversed ( self . BUTTONS ) ) : <EOL> field_h = self . CONTROL_H <EOL> dlg . append ( [ "<STR_LIT>" , caption , id , ( self . W - ( ( i + <NUM_LIT:1> ) * ( self . GUTTER_W + self . BUTTON_W ) ) , button_t , self . BUTTON_W , field_h ) , cs ] ) <EOL> control_t += field_h + self . GUTTER_H <EOL> dlg . insert ( <NUM_LIT:0> , [ self . title , ( <NUM_LIT:0> , <NUM_LIT:0> , self . W , control_t ) , style , None , ( <NUM_LIT:9> , "<STR_LIT>" ) , None , dlg_class_name ] ) <EOL> return dlg <EOL> class Dialog ( BaseDialog ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , title , fields , progress_callback = core . UNSET , parent_hwnd = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> BaseDialog . __init__ ( self , title , parent_hwnd ) <EOL> self . progress_callback = progress_callback <EOL> self . fields = list ( fields ) <EOL> if not self . fields : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> self . results = [ ] <EOL> self . progress_thread = core . UNSET <EOL> self . progress_cancelled = win32event . CreateEvent ( None , <NUM_LIT:1> , <NUM_LIT:0> , None ) <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> message_map = { <EOL> win32con . WM_COMMAND : self . OnCommand , <EOL> win32con . WM_INITDIALOG : self . OnInitDialog , <EOL> win32con . WM_SIZE : self . OnSize , <EOL> win32con . WM_GETMINMAXINFO : self . OnMinMaxInfo , <EOL> self . WM_PROGRESS_MESSAGE : self . OnProgressMessage , <EOL> self . WM_PROGRESS_COMPLETE : self . OnProgressComplete <EOL> } <EOL> return wrapped ( <EOL> win32gui . DialogBoxIndirect , <EOL> self . hinst , <EOL> self . _get_dialog_template ( ) , <EOL> self . parent_hwnd , <EOL> message_map <EOL> ) <EOL> def corners ( self , l , t , r , b ) : <EOL> """<STR_LIT>""" <EOL> return l , t , r , b <EOL> def OnInitDialog ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> self . hwnd = hwnd <EOL> if False : <EOL> wrapped ( <EOL> win32gui . SetWindowLong , <EOL> self . hwnd , <EOL> win32con . GWL_EXSTYLE , <EOL> win32con . WS_EX_LAYERED | wrapped ( <EOL> win32gui . GetWindowLong , <EOL> self . hwnd , <EOL> win32con . GWL_EXSTYLE <EOL> ) <EOL> ) <EOL> wrapped ( <EOL> win32gui . SetLayeredWindowAttributes , <EOL> self . hwnd , <EOL> <NUM_LIT:255> , <EOL> ( <NUM_LIT:255> * <NUM_LIT> ) / <NUM_LIT:100> , <EOL> win32con . LWA_ALPHA <EOL> ) <EOL> pythoncom . RegisterDragDrop ( <EOL> hwnd , <EOL> pythoncom . WrapObject ( <EOL> _DropTarget ( hwnd ) , <EOL> pythoncom . IID_IDropTarget , <EOL> pythoncom . IID_IDropTarget <EOL> ) <EOL> ) <EOL> for i , ( field , default , callback ) in enumerate ( self . fields ) : <EOL> id = self . IDC_FIELD_BASE + i <EOL> self . _set_item ( id , default ) <EOL> parent = self . parent_hwnd or DESKTOP <EOL> l , t , r , b = self . corners ( * wrapped ( win32gui . GetWindowRect , self . hwnd ) ) <EOL> r = min ( r , l + self . MAX_W ) <EOL> dt_l , dt_t , dt_r , dt_b = wrapped ( win32gui . GetWindowRect , parent ) <EOL> cx = int ( round ( ( dt_r - dt_l ) / <NUM_LIT:2> ) ) <EOL> cy = int ( round ( ( dt_b - dt_t ) / <NUM_LIT:2> ) ) <EOL> centre_x , centre_y = wrapped ( win32gui . ClientToScreen , parent , ( cx , cy ) ) <EOL> dx = int ( round ( centre_x - ( r / <NUM_LIT:2> ) ) ) <EOL> dy = int ( round ( centre_y - ( b / <NUM_LIT:2> ) ) ) <EOL> wrapped ( win32gui . MoveWindow , self . hwnd , dx , dy , r - l , b - t , <NUM_LIT:0> ) <EOL> l , t , r , b = wrapped ( win32gui . GetClientRect , self . hwnd ) <EOL> self . _resize ( r - l , b - t , <NUM_LIT:0> ) <EOL> return True <EOL> def _resize ( self , dialog_w , dialog_h , repaint = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> def coords ( hwnd , id ) : <EOL> ctrl = wrapped ( win32gui . GetDlgItem , hwnd , id ) <EOL> l , t , r , b = wrapped ( win32gui . GetWindowRect , ctrl ) <EOL> l , t = wrapped ( win32gui . ScreenToClient , hwnd , ( l , t ) ) <EOL> r , b = wrapped ( win32gui . ScreenToClient , hwnd , ( r , b ) ) <EOL> return ctrl , l , t , r , b <EOL> hDC = wrapped ( win32gui . GetDC , self . hwnd ) <EOL> try : <EOL> label_w , label_h = max ( wrapped ( win32gui . GetTextExtentPoint32 , hDC , label or "<STR_LIT>" ) for label , _ , _ in self . fields ) <EOL> finally : <EOL> wrapped ( win32gui . ReleaseDC , self . hwnd , hDC ) <EOL> for i , ( field , default , callback ) in enumerate ( self . fields ) : <EOL> if field is not None : <EOL> label , l , t , r , b = coords ( self . hwnd , self . IDC_LABEL_BASE + i ) <EOL> wrapped ( win32gui . MoveWindow , label , self . GUTTER_W , t , label_w , b - t , repaint ) <EOL> label_r = self . GUTTER_W + label_w <EOL> if callback : <EOL> callback_button , l , t , r , b = coords ( self . hwnd , self . IDC_CALLBACK_BASE + i ) <EOL> callback_w = r - l <EOL> callback_l = dialog_w - self . GUTTER_W - callback_w <EOL> MoveWindow ( callback_button , callback_l , t , r - l , b - t , repaint ) <EOL> else : <EOL> callback_w = <NUM_LIT:0> <EOL> else : <EOL> label_r = callback_w = <NUM_LIT:0> <EOL> field , l , t , r , b = coords ( self . hwnd , self . IDC_FIELD_BASE + i ) <EOL> field_l = label_r + self . GUTTER_W <EOL> field_w = dialog_w - self . GUTTER_W - field_l - ( callback_w + self . GUTTER_W if callback_w else <NUM_LIT:0> ) <EOL> MoveWindow ( field , field_l , t , field_w , b - t , repaint ) <EOL> if self . _progress_id : <EOL> field , l , t , r , b = coords ( self . hwnd , self . _progress_id ) <EOL> field_w = dialog_w - <NUM_LIT:2> * self . GUTTER_W <EOL> MoveWindow ( field , l , t , field_w , b - t , repaint ) <EOL> for i , ( caption , id ) in enumerate ( reversed ( self . BUTTONS ) ) : <EOL> button , l , t , r , b = coords ( self . hwnd , id ) <EOL> MoveWindow ( button , dialog_w - ( ( i + <NUM_LIT:1> ) * ( self . GUTTER_W + ( r - l ) ) ) , t , r - l , b - t , repaint ) <EOL> def _get_item ( self , item_id ) : <EOL> """<STR_LIT>""" <EOL> hwnd = wrapped ( win32gui . GetDlgItem , self . hwnd , item_id ) <EOL> class_name = wrapped ( win32gui . GetClassName , hwnd ) <EOL> if class_name == "<STR_LIT>" : <EOL> value = wrapped ( win32gui . GetDlgItemText , self . hwnd , item_id ) <EOL> if isinstance ( value , unicode ) : <EOL> return value <EOL> else : <EOL> return value . decode ( "<STR_LIT>" ) <EOL> elif class_name == "<STR_LIT>" : <EOL> return bool ( SendMessage ( hwnd , win32con . BM_GETCHECK , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> elif class_name == "<STR_LIT>" : <EOL> field , default , callback = self . fields [ item_id - self . IDC_FIELD_BASE ] <EOL> return default [ SendMessage ( hwnd , win32con . CB_GETCURSEL , <NUM_LIT:0> , <NUM_LIT:0> ) ] <EOL> elif class_name == "<STR_LIT>" : <EOL> return None <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" % class_name ) <EOL> def _set_item ( self , item_id , value ) : <EOL> """<STR_LIT>""" <EOL> item_hwnd = wrapped ( win32gui . GetDlgItem , self . hwnd , item_id ) <EOL> class_name = wrapped ( win32gui . GetClassName , item_hwnd ) <EOL> styles = wrapped ( win32gui . GetWindowLong , self . hwnd , win32con . GWL_STYLE ) <EOL> if class_name == "<STR_LIT>" : <EOL> if isinstance ( value , datetime . date ) : <EOL> value = value . strftime ( "<STR_LIT>" ) <EOL> value = unicode ( value ) . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) <EOL> wrapped ( win32gui . SetDlgItemText , self . hwnd , item_id , value ) <EOL> elif class_name == "<STR_LIT>" : <EOL> SendMessage ( item_hwnd , win32con . BM_SETCHECK , int ( value ) , <NUM_LIT:0> ) <EOL> elif class_name == "<STR_LIT>" : <EOL> for item in value : <EOL> if isinstance ( item , tuple ) : <EOL> item = item [ <NUM_LIT:0> ] <EOL> SendMessage ( item_hwnd , win32con . CB_ADDSTRING , <NUM_LIT:0> , utils . string_as_pointer ( str ( item ) ) ) <EOL> SendMessage ( item_hwnd , win32con . CB_SETCURSEL , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> elif class_name == "<STR_LIT>" : <EOL> wrapped ( win32gui . SetDlgItemText , self . hwnd , item_id , unicode ( value ) ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" % class_name ) <EOL> def OnSize ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> w = win32api . LOWORD ( lparam ) <EOL> h = win32api . HIWORD ( lparam ) <EOL> self . _resize ( w , h ) <EOL> return <NUM_LIT:0> <EOL> def OnMinMaxInfo ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> dlg_l , dlg_t , dlg_r , dlg_b = wrapped ( win32gui . GetWindowRect , hwnd ) <EOL> if wrapped ( win32gui . GetClientRect , hwnd ) == ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) : <EOL> return <NUM_LIT:0> <EOL> POINT_FORMAT = b"<STR_LIT>" <EOL> MINMAXINO_FORMAT = <NUM_LIT:5> * POINT_FORMAT <EOL> data = win32gui . PyGetMemory ( lparam , struct . calcsize ( MINMAXINO_FORMAT ) ) <EOL> minmaxinfo = list ( struct . unpack ( MINMAXINO_FORMAT , data ) ) <EOL> minmaxinfo [ <NUM_LIT:9> ] = minmaxinfo [ <NUM_LIT:7> ] = dlg_b - dlg_t <EOL> win32gui . PySetMemory ( lparam , struct . pack ( MINMAXINO_FORMAT , * minmaxinfo ) ) <EOL> return <NUM_LIT:0> <EOL> def _enable ( self , id , allow = True ) : <EOL> """<STR_LIT>""" <EOL> wrapped ( <EOL> win32gui . EnableWindow , <EOL> wrapped ( win32gui . GetDlgItem , self . hwnd , id ) , <EOL> allow <EOL> ) <EOL> def OnProgressMessage ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> message = marshal . loads ( win32gui . PyGetString ( lparam , wparam ) ) <EOL> self . _set_item ( self . _progress_id , message ) <EOL> def OnProgressComplete ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> message = marshal . loads ( win32gui . PyGetString ( lparam , wparam ) ) <EOL> except ValueError : <EOL> message = "<STR_LIT>" <EOL> self . _set_item ( self . _progress_id , message ) <EOL> self . _enable ( win32con . IDCANCEL , False ) <EOL> self . _enable ( win32con . IDOK , True ) <EOL> PostMessage ( self . hwnd , win32con . WM_QUIT , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> def _progress_complete ( self , message ) : <EOL> """<STR_LIT>""" <EOL> _message = buffer ( marshal . dumps ( message ) ) <EOL> address , length = win32gui . PyGetBufferAddressAndLen ( _message ) <EOL> PostMessage ( self . hwnd , self . WM_PROGRESS_COMPLETE , length , address ) <EOL> def _progress_message ( self , message ) : <EOL> """<STR_LIT>""" <EOL> _message = buffer ( marshal . dumps ( message ) ) <EOL> address , length = win32gui . PyGetBufferAddressAndLen ( _message ) <EOL> SendMessage ( self . hwnd , self . WM_PROGRESS_MESSAGE , length , address ) <EOL> def OnOk ( self , hwnd ) : <EOL> """<STR_LIT>""" <EOL> def progress_thread ( iterator , cancelled ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> for message in iterator : <EOL> if wrapped ( win32event . WaitForSingleObject , cancelled , <NUM_LIT:0> ) != win32event . WAIT_TIMEOUT : <EOL> self . _progress_complete ( "<STR_LIT>" ) <EOL> break <EOL> else : <EOL> self . _progress_message ( message ) <EOL> except : <EOL> info_dialog ( <EOL> "<STR_LIT>" , <EOL> traceback . format_exc ( ) , <EOL> hwnd <EOL> ) <EOL> self . _progress_complete ( "<STR_LIT>" ) <EOL> else : <EOL> self . _progress_complete ( "<STR_LIT>" ) <EOL> self . results = [ ] <EOL> for i , ( field , default_value , callback ) in enumerate ( self . fields ) : <EOL> value = self . _get_item ( self . IDC_FIELD_BASE + i ) <EOL> if isinstance ( default_value , datetime . date ) : <EOL> try : <EOL> if value : <EOL> value = datetime . datetime . strptime ( value , "<STR_LIT>" ) . date ( ) <EOL> else : <EOL> value = None <EOL> except ValueError : <EOL> win32api . MessageBox ( <EOL> hwnd , <EOL> "<STR_LIT>" % datetime . date . today ( ) . strftime ( "<STR_LIT>" ) . lstrip ( "<STR_LIT:0>" ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> return <EOL> self . results . append ( value ) <EOL> if self . progress_callback : <EOL> self . _set_item ( self . _progress_id , "<STR_LIT>" ) <EOL> for i in range ( len ( self . fields ) ) : <EOL> self . _enable ( self . IDC_FIELD_BASE + i , False ) <EOL> self . _enable ( win32con . IDOK , False ) <EOL> wrapped ( win32gui . SetFocus , wrapped ( win32gui . GetDlgItem , hwnd , win32con . IDCANCEL ) ) <EOL> progress_iterator = self . progress_callback ( * self . results ) <EOL> self . progress_callback = None <EOL> self . progress_thread = threading . Thread ( <EOL> target = progress_thread , <EOL> args = ( progress_iterator , self . progress_cancelled ) <EOL> ) <EOL> self . progress_thread . setDaemon ( True ) <EOL> self . progress_thread . start ( ) <EOL> else : <EOL> wrapped ( win32gui . EndDialog , hwnd , win32con . IDOK ) <EOL> def OnCancel ( self , hwnd ) : <EOL> """<STR_LIT>""" <EOL> self . results = [ ] <EOL> if self . progress_thread : <EOL> win32event . SetEvent ( self . progress_cancelled ) , <EOL> self . _set_item ( self . _progress_id , "<STR_LIT>" ) <EOL> self . progress_thread . join ( ) <EOL> wrapped ( win32gui . EndDialog , hwnd , win32con . IDCANCEL ) <EOL> def OnCallback ( self , hwnd , field_id ) : <EOL> """<STR_LIT>""" <EOL> field , default , callback = self . fields [ field_id - self . IDC_FIELD_BASE ] <EOL> result = callback ( hwnd , self . _get_item ( field_id ) ) <EOL> if result : <EOL> self . _set_item ( field_id , result ) <EOL> def OnCommand ( self , hwnd , msg , wparam , lparam ) : <EOL> """<STR_LIT>""" <EOL> id = win32api . LOWORD ( wparam ) <EOL> if id == win32con . IDOK : <EOL> self . OnOk ( hwnd ) <EOL> elif id == win32con . IDCANCEL : <EOL> self . OnCancel ( hwnd ) <EOL> elif self . IDC_CALLBACK_BASE <= id < ( self . IDC_CALLBACK_BASE + len ( self . fields ) ) : <EOL> self . OnCallback ( hwnd , self . IDC_FIELD_BASE + id - self . IDC_CALLBACK_BASE ) <EOL> def _fields_to_fields ( fields ) : <EOL> """<STR_LIT>""" <EOL> _fields = [ ] <EOL> for field in fields : <EOL> if len ( field ) < <NUM_LIT:3> : <EOL> _fields . append ( tuple ( field ) + ( None , ) ) <EOL> else : <EOL> _fields . append ( tuple ( field ) ) <EOL> return _fields <EOL> def dialog ( title , * fields ) : <EOL> """<STR_LIT>""" <EOL> d = Dialog ( title , _fields_to_fields ( fields ) ) <EOL> d . run ( ) <EOL> return d . results <EOL> def progress_dialog ( title , progress_callback , * fields ) : <EOL> """<STR_LIT>""" <EOL> d = Dialog ( title , _fields_to_fields ( fields ) , progress_callback = progress_callback ) <EOL> d . run ( ) <EOL> return d . results <EOL> def info_dialog ( title , text , hwnd = core . UNSET ) : <EOL> """<STR_LIT>""" <EOL> InfoDialog ( title , text , hwnd ) . run ( ) <EOL> def get_folder ( hwnd = None , start_folder = None ) : <EOL> """<STR_LIT>""" <EOL> def _set_start_folder ( hwnd , msg , lp , data ) : <EOL> if msg == BFFM . INITIALIZED and data : <EOL> SendMessage ( hwnd , BFFM . SETSELECTION , <NUM_LIT:1> , utils . string_as_pointer ( data ) ) <EOL> pythoncom . CoInitialize ( ) <EOL> try : <EOL> pidl , display_name , image_list = wrapped ( <EOL> shell . SHBrowseForFolder , <EOL> hwnd or DESKTOP , <EOL> None , <EOL> "<STR_LIT>" , <EOL> BIF . USENEWUI | BIF . SHAREABLE , <EOL> _set_start_folder , <EOL> start_folder <EOL> ) <EOL> finally : <EOL> pythoncom . CoUninitialize ( ) <EOL> if ( pidl , display_name , image_list ) == ( None , None , None ) : <EOL> return None <EOL> else : <EOL> return wrapped ( shell . SHGetPathFromIDList , pidl ) <EOL> def get_filename ( hwnd = None , start_folder = None ) : <EOL> """<STR_LIT>""" <EOL> def _set_start_folder ( hwnd , msg , lp , data ) : <EOL> if msg == BFFM . INITIALIZED and data : <EOL> SendMessage ( hwnd , BFFM . SETSELECTION , <NUM_LIT:1> , utils . string_as_pointer ( data ) ) <EOL> pythoncom . CoInitialize ( ) <EOL> try : <EOL> pidl , display_name , image_list = wrapped ( <EOL> shell . SHBrowseForFolder , <EOL> hwnd , <EOL> None , <EOL> "<STR_LIT>" , <EOL> BIF . BROWSEINCLUDEFILES | BIF . USENEWUI | BIF . SHAREABLE , <EOL> _set_start_folder if start_folder else None , <EOL> start_folder <EOL> ) <EOL> finally : <EOL> pythoncom . CoUninitialize ( ) <EOL> if ( pidl , display_name , image_list ) == ( None , None , None ) : <EOL> return None <EOL> else : <EOL> return wrapped ( shell . SHGetPathFromIDList , pidl ) <EOL> class InfoDialog ( Dialog ) : <EOL> def __init__ ( self , title , info , parent_hwnd = core . UNSET ) : <EOL> if parent_hwnd is core . UNSET : <EOL> parent_hwnd = DESKTOP <EOL> self . info = str ( info ) . replace ( "<STR_LIT:\r\n>" , "<STR_LIT:\n>" ) . replace ( "<STR_LIT:\n>" , "<STR_LIT:\r\n>" ) <EOL> Dialog . __init__ ( self , title , [ ( None , self . info , None ) ] , parent_hwnd = parent_hwnd ) <EOL> self . BUTTONS = [ ( "<STR_LIT>" , win32con . IDOK ) ] <EOL> def OnOk ( self , hwnd ) : <EOL> wrapped ( win32gui . EndDialog , hwnd , win32con . IDOK ) <EOL> def corners ( self , l , t , r , b ) : <EOL> """<STR_LIT>""" <EOL> hDC = wrapped ( win32gui . GetDC , self . hwnd ) <EOL> try : <EOL> w , h = max ( wrapped ( win32gui . GetTextExtentPoint32 , hDC , line ) for line in self . info . split ( "<STR_LIT:\r\n>" ) ) <EOL> return l , t , l + w + <NUM_LIT:2> * self . GUTTER_W , b <EOL> finally : <EOL> wrapped ( win32gui . ReleaseDC , self . hwnd , hDC ) <EOL> def get_password ( name = "<STR_LIT>" , domain = "<STR_LIT>" ) : <EOL> flags = <NUM_LIT:0> <EOL> flags |= CREDUI_FLAGS . GENERIC_CREDENTIALS <EOL> flags |= CREDUI_FLAGS . DO_NOT_PERSIST <EOL> _ , password , _ = wrapped ( <EOL> win32cred . CredUIPromptForCredentials , <EOL> domain , <EOL> <NUM_LIT:0> , <EOL> name , <EOL> None , <EOL> True , <EOL> flags , <EOL> { } <EOL> ) <EOL> return password </s>
