# copied from dlgpassw.py # some variable name changes and comments added for clarity # # changes by Clinton Reese # June 19, 2003 # import trueSpace import win32ui import win32api import dialog import win32con # from win32dlgdyn.h of pythonwin source code #const BYTE dlgButton = 0x80 ; == 128 #const BYTE dlgEdit = 0x81 ; == 129 == 'EDIT' #const BYTE dlgStatic = 0x82 ; == 130 #const BYTE dlgListbox = 0x83 ; == 131 #const BYTE dlgScrollbar = 0x84 ; == 132 #const BYTE dlgCombobox = 0x85 ; == 133 dlgButton = 128 dlgEdit = 129 dlgStatic = 130 # go to http://msdn.microsoft.com/library/default.asp and choose the following # # this sequence gets to the mfc styles # visual tools and languages # visual studio 6.0 # visual c and c++ 6.0 # product documentation # microsoft foundation class and libraries # class library reference # structures styles callbacks message maps # styles used by mfc # # this sequence gets to the dialog box styles # user interface # windows management # windows user interface # windowing # dialog boxes # dialog box overview # about dialog boxes # define DLGTEMPLATE data structures def MakeDlgTemplate(title): # Dialog Style is modal(cannot switch to another window) # window style popup window, can be seen, has a title bar, has control menu in title bar # dialog style font info included in template style = win32con.DS_MODALFRAME | win32con.WS_POPUP | win32con.WS_VISIBLE | win32con.WS_CAPTION | win32con.WS_SYSMENU | win32con.DS_SETFONT # window style child window, is visible # everything that appears in the window is a child window # buttons, text, text boxes etc are all child windows cs = win32con.WS_CHILD | win32con.WS_VISIBLE # window sizes are defined by (xstart, ystart, width, height) # Window frame and title dlg = [ [title, (0, 0, 184, 40), style, None, (8, "MS Sans Serif")], ] # controls have a format of # [type of control, label, resource id, (x, y, width, height), window and control styles] # pythonwin source code file reswin32ui.h has a list of default resource id's # it has up to IDC_EDIT4 but the max is IDC_EDIT7 # ID label and text box # static text starting at the left of the control child window dlg.append([dlgStatic, "User ID:", -1, (7, 9, 69, 9), cs | win32con.SS_LEFT]) # child control can navigate with Tab and has a border, text entry assigned to IDC_EDIT1 resource s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER dlg.append([dlgEdit, None, win32ui.IDC_EDIT1, (50, 7, 60, 12), s]) # Password label and text box # edit style of password dlg.append([dlgStatic, "Password:", -1, (7, 22, 69, 9), cs | win32con.SS_LEFT]) s = cs | win32con.WS_TABSTOP | win32con.WS_BORDER dlg.append([dlgEdit, None, win32ui.IDC_EDIT2, (50, 20, 60, 12), s | win32con.ES_PASSWORD]) # OK/Cancel Buttons # set OK as default when press Enter key s = cs | win32con.WS_TABSTOP dlg.append([dlgButton, "OK", win32con.IDOK, (124, 5, 50, 14), s | win32con.BS_DEFPUSHBUTTON]) s = win32con.BS_PUSHBUTTON | s dlg.append([dlgButton, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14), s]) return dlg # subclass of dialog - title variable passes through to the init portion of class class LoginDlg(dialog.Dialog): Cancel = 0 def __init__(self, title): dialog.Dialog.__init__(self, MakeDlgTemplate(title) ) # associate resources with variables self.AddDDX(win32ui.IDC_EDIT1,'DLGuserid') self.AddDDX(win32ui.IDC_EDIT2,'DLGpassword') def OnCancel(self): self.Cancel = 1 self._obj_.OnCancel() def GetLogin(title='Login', Defuserid=''): # define a dialog window with program variables associated to resources(edit text, buttons ...) d = LoginDlg(title) # set default value for user id d['DLGuserid'] = Defuserid # invoke the modal dialog box and return the dialog-box result when finished d.DoModal() if d.Cancel: return (None, None) else: return (d['DLGuserid'], d['DLGpassword']) # script starts here title = "FTP Login" def_user = "fred" userid, password = GetLogin(title, def_user) if userid == password == None: print "User pressed Cancel" else: print "User ID: ", userid print ", Password: ", password print "\n" print "trueSpace version: ", trueSpace.GetVersion(), "\n"