''' Created on May 24, 2011 @author: daniel ''' import wx, os, gettext from res.util.odict import OrderedDict # This installs gettext as _() for translation catalogs. gettext.install('Demo', unicode = 1) class FormDialog(wx.Dialog): def __init__(self, parent, id = -1, panel = None, title = _("Unnamed Dialog"), modal = False, sizes = (400, -1), refid = None): wx.Dialog.__init__(self, parent, id, _(title), style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) if panel is not None: self._panel = panel(self, refid) self._panel.SetSizeHints(*sizes) ds = wx.GridBagSizer(self._panel._gap, self._panel._gap) ds.Add(self._panel, (0, 0), (1, 1), wx.EXPAND | wx.ALL, self._panel._gap) ds.Add(wx.StaticLine(self), (1, 0), (1, 1), wx.EXPAND | wx.RIGHT | wx.LEFT, self._panel._gap) self.bs = self.CreateButtonSizer(self._panel._form.get('Buttons', wx.OK | wx.CANCEL)) ds.Add(self.bs, (2, 0), (1, 1), wx.ALIGN_RIGHT | wx.ALL, self._panel._gap) ds.AddGrowableCol(0) ds.AddGrowableRow(0) self.SetSizerAndFit(ds) self.Center() self.Bind(wx.EVT_BUTTON, self._panel.onOk, id = wx.ID_OK) self.Bind(wx.EVT_BUTTON, self._panel.onClose, id = wx.ID_CANCEL) # self.Bind(wx.EVT_CLOSE, self._panel.onClose) if modal: self.ShowModal() else: self.Show() class Form(wx.Panel): def __init__(self, parent = None, refid = None, id = -1, gap = 3, sizes = (-1, -1)): wx.Panel.__init__(self, parent, id) self.SetSizeHints(*sizes) self._gap = gap self.itemMap = {} if not hasattr(self, 'q'): self.q = getattr(self.GrandParent, 'q', None) if hasattr(self, '_form'): # Before building verify that several required elements exist in the form # definition object. self.loadDefaults() self._build() self._bind() def _build(self): """ The Build Method automates sizer creation and element placement by parsing a properly constructed object. """ # The Main Sizer for the Panel. panelSizer = wx.BoxSizer(wx.VERTICAL) # Parts is an Ordered Dictionary of regions for the form. for container, blocks in self._form['Parts'].iteritems(): flags, sep, display = container.rpartition('-') #@UnusedVariable if 'NC' in flags: for block in blocks: element, proportion = self._parseBlock(block) panelSizer.Add(element, proportion, flag = wx.EXPAND | wx.ALL, border = self._gap) else: box = wx.StaticBox(self, -1, _(display)) sizer = wx.StaticBoxSizer(box, wx.VERTICAL) for block in blocks: element, proportion = self._parseBlock(block) sizer.Add(element, proportion, flag = wx.EXPAND | wx.ALL) if 'G' in flags: sizerProportion = 1 else: sizerProportion = 0 panelSizer.Add(sizer, sizerProportion, flag = wx.EXPAND | wx.ALL, border = self._gap) self.SetSizerAndFit(panelSizer) def _bind(self): pass def _parseBlock(self, block): """ The form structure is a list of rows (blocks) in the form. Each row consists of a single element, a row of elements, or a sub-grid of elements. These are represented by dictionaries, tuples, or lists, respectively and are each processed differently. """ proportion = 0 if isinstance(block, list): item = self.makeGrid(block) elif isinstance(block, tuple): item = self.makeRow(block) elif isinstance(block, dict): proportion = block.pop('proportion', 0) item = self.makeElement(block) return item, proportion def makeElement(self, object): """ In the form structure a dictionary signifies a single element. A single element is automatically assumed to expand to fill available horizontal space in the form. """ sizer = wx.BoxSizer(wx.HORIZONTAL) flags = object.pop('flags', wx.ALL) element = self._makeWidget(object) sizer.Add(element, 1, border = self._gap, flag = wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | flags) return sizer def makeRow(self, fields): """ In the form structure a tuple signifies a row of elements. These items will be arranged horizontally without dependency on other rows. Each item may provide a proportion property which can cause that element to expand horizontally to fill space. """ sizer = wx.BoxSizer(wx.HORIZONTAL) for field in fields: proportion = field.pop('proportion', 0) sizer.Add(self.makeElement(field), proportion, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALL) return sizer def makeGrid(self, rows): """ In the form structure a list signifies a grid of elements (equal width columns, rows with similar numbers of elements, etc). """ sizer = wx.GridBagSizer(0, 0) for row, fields in enumerate(rows): for col, field in enumerate(fields): flags = field.pop('flags', wx.ALL) # Each item may specify that its row or column 'grow' or expand to fill # the available space in the form. rowGrowable, colGrowable = (field.pop('rowGrowable', False), field.pop('colGrowable', False)) if rowGrowable: sizer.AddGrowableRow(row) if colGrowable: sizer.AddGrowableCol(col) span = field.pop('span', (1, 1)) colpos = field.pop('colpos', col) rowpos = field.pop('rowpos', row) element = self._makeWidget(field) sizer.Add(element, (rowpos, colpos), span, border = self._gap, flag = wx.ALIGN_CENTER_VERTICAL | flags) return sizer def _makeWidget(self, params): """ This function actually creates the widgets that make up the form. In most cases these will be items from the wx libraries, though they may be 'custom' elements which require delayed instantiation by leveraging lambdas. """ type = params.pop('type') if type == 'Custom': lookup = params.pop('lookup') element = self._form[lookup](self) self.itemMap[lookup] = element else: # StaticText items may carry a bold attribute - retrieve it for use later. if type == 'StaticText': bold = params.pop('bold', False) # ComboBoxes need to have choices. if type == 'ComboBox': params['choices'] = self._form['Options'].get(params['name'], []) element = getattr(wx, type)(self, -1, **params) if type == 'ComboTreeBox': choices = self._form['Options'].get(params['name'], []) for category, options in choices: id = element.Append(category) for option in options: element.Append(option, parent = id) element.GetTree().Expand(id) # Require the user to use the browse buttons for File / Folder browsing. if type in ('DirPickerCtrl', 'FilePickerCtrl'): element.GetTextCtrl().SetEditable(False) if params.has_key('name'): # Populate the itemMap - facilitates element retrieval / event bindings. self.itemMap[params['name']] = element # Default value assignment. Must unfortunately do a dance to check # element type - some require ints / floats, while others are ok with # strings. There is also a check against the Translations member - # this facilitates the Human Readable <-> Database Value conversion. value = self._form['Defaults'].get(params['name'], '') if self._form.has_key('Translations'): if self._form['Translations'].has_key(params['name']): value = self._form['Translations'][params['name']][0].get(value, value) if hasattr(element, 'SetValue'): if type == 'SpinCtrl': if value == '': value = 0 element.SetValue(int(value)) elif type in ('CheckBox', 'RadioButton'): element.SetValue(bool(value)) else: element.SetValue(unicode(value)) elif hasattr(element, 'SetPath'): element.SetPath(value) elif type != 'Button': print element # Check for elements we should disable at load time. if params['name'] in self._form['Disabled']: element.Enable(False) # Check for a Validator and add it if required. try: validator = self._form['Validators'][params['name']]() element.SetValidator(validator) except KeyError: pass # No Validator Specified. # Take the bold attribute into account for StaticText elements. if type == 'StaticText' and bold: font = element.GetFont() font.SetWeight(wx.BOLD) element.SetFont(font) return element def loadDefaults(self): if not self._form.has_key('Defaults'): self._form['Defaults'] = {} if not self._form.has_key('Disabled'): self._form['Disabled'] = [] if not self._form.has_key('Validators'): self._form['Validators'] = {} self.loadOptions() def loadOptions(self): if not self._form.has_key('Options'): self._form['Options'] = {} def onOk(self, evt): self.onClose(evt) def onClose(self, evt): self.GetParent().Destroy() class ActionForm(Form): def __init__(self, parent, refid = None): self.refid = refid Form.__init__(self, parent) def onOk(self, evt = None): params = {} for name, field in self.itemMap.iteritems(): try: value = field.GetValue() if self._form.has_key('Translations'): if self._form['Translations'].has_key(name): value = self._form['Translations'][name][1].get(value, value) if hasattr(value, 'isdecimal'): try: f = float(value) i = int(f) if i == f: value = i else: value = f except ValueError: pass # No conversion to int / float - string value. params[name] = value except AttributeError, e: print e try: params[name] = field.GetPath() except AttributeError: print name continue # Something here to store in the database. evt.Skip() class TransformForm(Form): def __init__(self, parent, refid = None): self.refid = refid Form.__init__(self, parent) def addByte(self, f, b): p, s = f.GetInsertionPoint(), f.GetSelection() f.Remove(*s) v = f.GetValue() f.SetValue(v[0:p] + b + v[p:]) f.SetInsertionPoint(p + len(b)) f.SetFocus() def addESC(self, f): self.addByte(f, r'\x1B') def addCR(self, f): self.addByte(f, r'\r') def addLF(self, f): self.addByte(f, r'\n') def addFF(self, f): self.addByte(f, r'\f') def addTAB(self, f): self.addByte(f, r'\t') def onOk(self, evt = None): params = {} for name, field in self.itemMap.iteritems(): try: value = field.GetValue() if self._form.has_key('Translations'): if self._form['Translations'].has_key(name): value = self._form['Translations'][name][1].get(value, value) if hasattr(value, 'isdecimal'): try: f = float(value) i = int(f) if i == f: value = i else: value = f except ValueError: pass # No conversion to int / float - string value. params[name] = value except AttributeError: try: params[name] = field.GetPath() except AttributeError: print name continue # Something here to store in the database / config file. evt.Skip() class Archive(ActionForm): def __init__(self, parent, refid = None): self._form = { 'Title': 'Archive to Folder', 'Parts': OrderedDict([ ('Credentials', [ ({'type': 'ComboBox', 'name': 'Credentials', 'proportion': 1, 'style': wx.CB_READONLY}, {'type': 'Button', 'name': 'AddCredential', 'label': 'Add User'}), ]), ('Location', [ {'type': 'DirPickerCtrl', 'name': 'device', 'proportion': 1} ]), ('File Name Formatting', [ [({'type': 'StaticText', 'label': 'Variables'}, {'type': 'ComboBox', 'name': 'Variables', 'colGrowable': True, 'flags': wx.EXPAND | wx.ALL, 'style': wx.CB_READONLY}, {'type': 'Button', 'name': 'Insert', 'label': 'Insert'}), ({'type': 'StaticText', 'label': 'Template (Mask)'}, {'type': 'TextCtrl', 'name': 'JobFileStr', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2)}), ({'type': 'StaticText', 'label': 'Example'}, {'type': 'StaticText', 'label': 'dfa30.txt', 'name': 'Example', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2), 'bold': True})] ]), ('File Creation', [ ({'type': 'RadioButton', 'label': 'Create New File', 'name': 'Create'}, {'type': 'RadioButton', 'label': 'Append to Existing File', 'proportion': 1, 'name': 'Append'}, {'type': 'RadioButton', 'label': 'Overwrite Existing File', 'proportion': 1, 'name': 'Overwrite'}) ]) ]) } ActionForm.__init__(self, parent, refid) def _bind(self): self.Bind(wx.EVT_BUTTON, self.onInsert, self.itemMap['Insert']) self.Bind(wx.EVT_TEXT, self.onTemplate, self.itemMap['JobFileStr']) self.onTemplate() def onInsert(self, evt = None): self.addTag(self.itemMap['Variables'], self.itemMap['JobFileStr']) def onTemplate(self, evt = None): pass class Filter(ActionForm): def __init__(self, parent, refid = None): self._form = { 'Parts': OrderedDict([ ('Credentials', [ ({'type': 'ComboBox', 'name': 'Credentials', 'proportion': 1}, {'type': 'Button', 'name': 'AddCredential', 'label': 'Add User'}), ({'type': 'CheckBox', 'label': 'Interact with Desktop', 'name': 'interactive'}) ]), ('Program Setup', [ [({'type': 'StaticText', 'label': 'Executable'}, {'type': 'FilePickerCtrl', 'name': 'device', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 3), 'wildcard': 'Executable Files (*.exe, *.bat)|*.exe; *.bat|All Files|*.*'}), ({'type': 'StaticText', 'label': 'Arguments'}, {'type': 'TextCtrl', 'name': 'FilterArgs', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 3)}), ({'type': 'StaticText', 'label': 'Working Directory'}, {'type': 'DirPickerCtrl', 'name': 'WorkDir', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 3)}), ({'type': 'StaticText', 'label': ''}, {'type': 'CheckBox', 'name': 'IdleTerminate', 'label': 'Terminate idle process after'}, {'type': 'TextCtrl', 'name': 'IdleSeconds', 'flags': wx.EXPAND | wx.ALL, 'size': (34, -1)}, {'type': 'StaticText', 'label': 'seconds.', 'colGrowable': True})] ]), #container 'Program Setup' ('Program Input (%s)', [ {'type': 'CheckBox', 'name': 'UseStdin', 'label': 'Transfer file to filter using standard input'}, [({'type': 'StaticText', 'label': 'Variables'}, {'type': 'ComboBox', 'name': 'iVariables', 'colGrowable': True, 'flags': wx.EXPAND | wx.ALL}, {'type': 'Button', 'name': 'iInsert', 'label': 'Insert'}), ({'type': 'StaticText', 'label': 'Template (Mask)'}, {'type': 'TextCtrl', 'name': 'JobFileStr', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2)}), ({'type': 'StaticText', 'label': 'Example'}, {'type': 'StaticText', 'label': 'dfa30.txt', 'name': 'iExample', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2), 'bold': True})] ]), ('Program Output', [ {'type': 'CheckBox', 'name': 'UseStdout', 'label': 'Save standard output (stdout) in working directory'}, [({'type': 'StaticText', 'label': 'Variables'}, {'type': 'ComboBox', 'name': 'oVariables', 'colGrowable': True, 'flags': wx.EXPAND | wx.ALL}, {'type': 'Button', 'name': 'oInsert', 'label': 'Insert'}), ({'type': 'StaticText', 'label': 'Template (Mask)'}, {'type': 'TextCtrl', 'name': 'StdoutPath', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2)}), ({'type': 'StaticText', 'label': 'Example'}, {'type': 'StaticText', 'name': 'oExample', 'flags': wx.EXPAND | wx.ALL, 'span': (1, 2), 'bold': True})] ]), ('Error Handling', [ {'type': 'CheckBox', 'name': 'StdErrLog', 'label': 'Save standard error (stderr) in working directory'} ]) ]), 'Title': 'Filter Action', } ActionForm.__init__(self, parent, refid) def _bind(self): self.Bind(wx.EVT_COMBOBOX, self.onCredentials, self.itemMap['Credentials']) self.Bind(wx.EVT_BUTTON, self.iInsert, self.itemMap['iInsert']) self.Bind(wx.EVT_BUTTON, self.oInsert, self.itemMap['oInsert']) self.Bind(wx.EVT_TEXT, self.iTemplate, self.itemMap['JobFileStr']) self.Bind(wx.EVT_TEXT, self.oTemplate, self.itemMap['StdoutPath']) self.Bind(wx.EVT_CHECKBOX, self.onTerminate, self.itemMap['IdleTerminate']) self.Bind(wx.EVT_CHECKBOX, self.onStdin, self.itemMap['UseStdin']) self.Bind(wx.EVT_CHECKBOX, self.onStdout, self.itemMap['UseStdout']) self.Bind(wx.EVT_FILEPICKER_CHANGED, self.onChooseProgram, self.itemMap['device']) self.iTemplate() self.oTemplate() self.onTerminate() self.onStdin() self.onStdout() self.onCredentials() def onCredentials(self, evt = None): chkState = self.itemMap['Credentials'].GetValue() == r'.\No Credentials' self.itemMap['interactive'].Enable(not chkState) if chkState: self.itemMap['interactive'].SetValue(False) def onChooseProgram(self, evt = None): if self.itemMap['WorkDir'].GetPath() == '': wd = os.path.dirname(self.itemMap['device'].GetPath()) self.itemMap['WorkDir'].SetPath(wd) def iInsert(self, evt = None): self.addTag(self.itemMap['iVariables'], self.itemMap['JobFileStr']) def oInsert(self, evt = None): self.addTag(self.itemMap['oVariables'], self.itemMap['StdoutPath']) def iTemplate(self, evt = None): pass def oTemplate(self, evt = None): pass def onTerminate(self, evt = None): self.itemMap['IdleSeconds'].Enable(self.itemMap['IdleTerminate'].IsChecked()) def onStdin(self, evt = None): chkState = self.itemMap['UseStdin'].IsChecked() fields = ['iVariables', 'iInsert', 'JobFileStr'] for f in fields: self.itemMap[f].Enable(not chkState) def onStdout(self, evt = None): chkState = self.itemMap['UseStdout'].IsChecked() fields = ['oVariables', 'oInsert', 'StdoutPath'] for f in fields: self.itemMap[f].Enable(chkState) class GeneralSettings(Form): def __init__(self, parent, refid = None): self._form = { 'Parts': OrderedDict([ ('Log Settings', [ ({'type': 'StaticText', 'label': 'Remove log messages older than:'}, {'type': 'SpinCtrl', 'name': 'interval', 'min': 1, 'max': 10, 'size': (55, -1), 'flags': wx.LEFT | wx.RIGHT}, {'type': 'ComboBox', 'name': 'unit', 'flags': wx.LEFT | wx.RIGHT, 'proportion': 1}) ]), ('Folder Settings', [ [({'type': 'StaticText', 'label': 'Spool Folder Location:'}, {'type': 'DirPickerCtrl', 'name': 'dir', 'colGrowable': True, 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Temp Folder Location:'}, {'type': 'DirPickerCtrl', 'name': 'temp', 'flags': wx.EXPAND | wx.ALL})] ]), ('Email Notifications', [ [({'type': 'StaticText', 'label': 'Alert Email To:'}, {'type': 'TextCtrl', 'name': 'alert-to', 'colGrowable': True, 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Alert Email From:'}, {'type': 'TextCtrl', 'name': 'alert-from', 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Status Email From:'}, {'type': 'TextCtrl', 'name': 'status-from', 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Alert Email Server:'}, {'type': 'TextCtrl', 'name': 'alert-host', 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Login:'}, {'type': 'TextCtrl', 'name': 'alert-login', 'flags': wx.EXPAND | wx.ALL}), ({'type': 'StaticText', 'label': 'Password:'}, {'type': 'TextCtrl', 'name': 'alert-password', 'style': wx.TE_PASSWORD, 'flags': wx.EXPAND | wx.ALL})] ]), ('Admin User', [ {'type': 'CheckBox', 'name': 'req-admin', 'label': 'Require Admin Rights to make changes.'} ]), ('Miscellaneous', [ ({'type': 'StaticText', 'label': 'Print Worker Tasks'}, {'type': 'SpinCtrl', 'name': 'printtasks', 'min': 1, 'max': 256, 'size': (55, -1), 'flags': wx.LEFT | wx.RIGHT}, {'type': 'StaticText', 'label': 'Job Drag Options'}, {'type': 'ComboBox', 'name': 'jobdrop', 'flags': wx.LEFT | wx.RIGHT | wx.EXPAND, 'proportion': 1}) ]) ]), 'Options': { 'unit': ['Hours', 'Days', 'Months'], 'jobdrop': ['Copy Job to Queue', 'Move Job to Queue'] }, 'Defaults': { 'interval': 3, 'unit': 'Days', 'printtasks': 5, 'jobdrop': 'Copy Job to Queue' } } Form.__init__(self, parent) def onOk(self, evt): print self.itemMap self.onClose(evt) class PCL2PDF(TransformForm): def __init__(self, parent, refid = None): self._form = { 'Parts': OrderedDict([ ('File Settings', [ [({'type': 'CheckBox', 'name': 'UsePageSize', 'label': 'Specify Page Size'}, {'type': 'StaticText', 'label': 'Paper Type'}, {'type': 'ComboBox', 'name': 'PaperType', 'flags': wx.EXPAND | wx.ALL, 'colGrowable': True}), ({'type': 'CheckBox', 'name': 'UseLandscape', 'label': 'Default to Landscape'}, {'type': 'CheckBox', 'name': 'UseRotate', 'label': 'Rotate'}, {'type': 'ComboBox', 'name': 'Rotate', 'flags': wx.EXPAND | wx.ALL})], [({'type': 'StaticText', 'label': 'Keywords'}, {'type': 'TextCtrl', 'name': 'Keywords', 'colGrowable': True, 'size': (35, -1), 'flags': wx.EXPAND | wx.ALL}, {'type': 'StaticText', 'label': 'Author'}, {'type': 'TextCtrl', 'name': 'Author', 'colGrowable': True, 'size': (35, -1), 'flags': wx.EXPAND | wx.ALL}, {'type': 'CheckBox', 'name': 'UseJobOwner', 'label': 'Use Job Owner'}), ({'type': 'StaticText', 'label': 'Subject'}, {'type': 'TextCtrl', 'name': 'Subject', 'size': (35, -1), 'flags': wx.EXPAND | wx.ALL}, {'type': 'StaticText', 'label': 'Title'}, {'type': 'TextCtrl', 'name': 'Title', 'size': (35, -1), 'flags': wx.EXPAND | wx.ALL}, {'type': 'CheckBox', 'name': 'UseJobTitle', 'label': 'Use Job Title'})] ]), ('Overlay', [ {'type': 'CheckBox', 'name': 'UseOverlay', 'label': 'Overlay Existing PDF File'}, ({'type': 'StaticText', 'label': 'Where to use file'}, {'type': 'ComboBox', 'name': 'OverlayMethod', 'flags': wx.EXPAND | wx.ALL, 'proportion': 1}, {'type': 'CheckBox', 'name': 'AtBottom', 'label': 'Move Overlay to Bottom'}), ({'type': 'StaticText', 'label': 'File Path'}, {'type': 'FilePickerCtrl', 'name': 'OverlayPath', 'wildcard': 'PDF Documents (*.pdf)|*.pdf', 'proportion': 1}) ]), ('Permissions', [ ({'type': 'StaticText', 'label': 'Owner Password'}, {'type': 'TextCtrl', 'name': 'OwnerPwd', 'style': wx.TE_PASSWORD, 'proportion': 1}, {'type': 'StaticText', 'label': 'User Password'}, {'type': 'TextCtrl', 'name': 'UserPwd', 'style': wx.TE_PASSWORD, 'proportion': 1}), ({'type': 'CheckBox', 'name': 'PermRead', 'label': 'Allow Read', 'flags': wx.ALL}, {'type': 'CheckBox', 'name': 'PermPrint', 'label': 'Allow Print', 'flags': wx.ALL}, {'type': 'CheckBox', 'name': 'PermCopy', 'label': 'Allow Copy', 'flags': wx.ALL}), ({'type': 'CheckBox', 'name': 'PermEditAll', 'label': 'Allow Editing Content', 'flags': wx.ALL}, {'type': 'CheckBox', 'name': 'PermEditNotes', 'label': 'Allow Editing Notes and Annotations', 'flags': wx.ALL}) ]), ('Miscellaneous', [ ({'type': 'CheckBox', 'name': 'UseRaster', 'label': 'Use Raster Processing', 'flags': wx.ALL}, {'type': 'CheckBox', 'name': 'SuppressBlankPages', 'label': 'Suppress Blank Pages', 'flags': wx.ALL}) ]) ]), 'Title': 'PCL to PDF', 'Options': { 'Rotate': ['90', '180', '270'], 'PaperType': ['11x17', 'A3', 'A4', 'A5', 'B4', 'B5', 'Ledger', 'Legal', 'Letter', 'Note'], 'OverlayMethod': ['First Page', 'Even Pages', 'Every Page', 'All But First Page', 'Odd Pages'] } } TransformForm.__init__(self, parent, refid) def _bind(self): self.Bind(wx.EVT_CHECKBOX, self.onUseOverlay, self.itemMap['UseOverlay']) self.Bind(wx.EVT_TEXT, self.onPasswords, self.itemMap['OwnerPwd']) self.Bind(wx.EVT_TEXT, self.onPasswords, self.itemMap['UserPwd']) self.Bind(wx.EVT_CHECKBOX, self.onUseJobOwner, self.itemMap['UseJobOwner']) self.Bind(wx.EVT_CHECKBOX, self.onUseJobTitle, self.itemMap['UseJobTitle']) self.Bind(wx.EVT_CHECKBOX, self.onSpecifyPageSize, self.itemMap['UsePageSize']) self.Bind(wx.EVT_CHECKBOX, self.onRotate, self.itemMap['UseRotate']) self.onSpecifyPageSize() self.onRotate() self.onUseJobOwner() self.onUseJobTitle() self.onUseOverlay() self.onPasswords() def onUseOverlay(self, evt = None): chkState = self.itemMap['UseOverlay'].IsChecked() keys = ['OverlayPath', 'AtBottom', 'OverlayMethod'] for key in keys: self.itemMap[key].Enable(chkState) def onPasswords(self, evt = None): fldState = (self.itemMap['OwnerPwd'].GetValue() == '' and self.itemMap['UserPwd'].GetValue() == '') keys = ['PermRead', 'PermPrint', 'PermCopy', 'PermEditAll', 'PermEditNotes'] for key in keys: self.itemMap[key].Enable(not fldState) def onUseJobOwner(self, evt = None): self.itemMap['Author'].Enable(not self.itemMap['UseJobOwner'].IsChecked()) def onUseJobTitle(self, evt = None): self.itemMap['Title'].Enable(not self.itemMap['UseJobTitle'].IsChecked()) def onSpecifyPageSize(self, evt = None): self.itemMap['PaperType'].Enable(self.itemMap['UsePageSize'].IsChecked()) def onRotate(self, evt = None): self.itemMap['Rotate'].Enable(self.itemMap['UseRotate'].IsChecked()) if __name__ == "__main__": app = wx.PySimpleApp() frame = wx.Frame(None, -1, "Forms Demo") frame.Show() frame.Center() FormDialog(frame, panel = GeneralSettings, title = 'General Settings', sizes = (400, -1)) FormDialog(frame, panel = Filter, title = 'Filter') FormDialog(frame, panel = PCL2PDF, title = 'PCL to PDF') FormDialog(frame, panel = Archive, title = 'Archive to Folder') app.MainLoop()