# buttons2.py # # buttons for truespace python # # OK, Cancel # Check Box # 3 State (checked, not checked, grayed) # # by Clinton Reese # June 21, 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 doc = trueSpace.GetActiveDocument() doc.ClearOutTxt() # # PyC style can be found at http://aspn.activestate.com/ASPN/ # http://aspn.activestate.com/ASPN/Reference/Products/ActivePython/PythonWin/objectmodmethods.html # # 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 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, 140), 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 # 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]) # Password label and text box # edit style of password dlg.append([dlgStatic, "Password:", -1, (7, 22, 69, 9), cs | win32con.SS_LEFT]) # 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]) dlg.append([dlgButton, "Cancel", win32con.IDCANCEL, (124, 20, 50, 14), s | win32con.BS_PUSHBUTTON]) dlg.append([dlgButton, None, win32ui.IDC_BUTTON1, (70, 40, 50, 14), s | win32con.BS_AUTOCHECKBOX]) dlg.append([dlgButton, None, win32ui.IDC_BUTTON2, (70, 60, 50, 14), s | win32con.BS_AUTO3STATE]) dlg.append([dlgButton, "My Group", win32ui.IDC_BUTTON3, (70, 80, 90, 40), cs | win32con.BS_GROUPBOX]) return dlg # subclass of dialog - title variable passes through to the init portion of class class LoginDlg(dialog.Dialog): Cancel = 0 def __init__(self): dialog.Dialog.__init__(self, MakeDlgTemplate("dummy title") ) # associate resources with variables self.AddDDX(win32ui.IDC_BUTTON1,'DLGbutton1') self.AddDDX(win32ui.IDC_BUTTON2,'DLGbutton2') self.DoModal() def OnInitDialog(self): self.SetWindowText(title) cancel=self.GetDlgItem(win32con.IDCANCEL) # the cancel button cancel.SetWindowText("Kill me") def OnCancel(self): self.Cancel = 1 self._obj_.OnCancel() def GetLogin(): # define a dialog window with program variables associated to resources(edit text, buttons ...) d = LoginDlg() if d.Cancel: return (None, None) else: return (d['DLGbutton1'], d['DLGbutton2']) # script starts here title = "Buttons" def_user = "fred" b1, b2 = GetLogin() if b1 == b2 == None: print "User pressed Cancel" else: print "Check Box : ", b1,"\n" print "3 State Check: ", b2,"\n" print "\n" print "trueSpace version: ", trueSpace.GetVersion(), "\n" trueSpace.Stop()