def __init__( self, option_parser, #The OptionParser object parent=None, ID=0, title='Optparse Dialog', pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE, name='OptparseDialog', ): TabbedDialog.__init__(self, parent, option_parser.tab_names, title='Tab Test') provider = wx.SimpleHelpProvider() wx.HelpProvider_Set(provider) pre = wx.PreDialog() pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) pre.Create(parent, ID, title, pos, size, style) self.PostCreate(pre) sizer = self.sizer(option_parser.tab_names[0]) tab = self.panel(option_parser.tab_names[0]) panel1 = tab panel1_sizer = sizer text = wx.TextCtrl(panel1, -1, "Hi!", size=(400, 90), style=wx.TE_MULTILINE) button1 = wx.Button(panel1, -1, "I only resize horizontally...") panel1_sizer.Add(text, 1, wx.EXPAND | wx.ALL, 10) panel1_sizer.Add(button1, 0, wx.EXPAND | wx.ALL, 10) self.option_controls = {} top_label_text = '%s %s' % (option_parser.get_prog_name(), option_parser.get_version()) label = wx.StaticText(tab, -1, top_label_text) sizer.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) self.browse_option_map = {} # Add controls for all the options for option in option_parser.option_list: if option.dest is None: continue if option.help is None: option.help = u'' print('tab_name=%s' % option.tab_name) sizer = self.sizer(option.tab_name) tab = self.panel(option.tab_name) box = wx.BoxSizer(wx.HORIZONTAL) if 'store' == option.action: label = wx.StaticText(tab, -1, option.dest) label.SetHelpText(option.help) box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) if 'choice' == option.type: if optparse.NO_DEFAULT == option.default: option.default = option.choices[0] ctrl = wx.ComboBox(tab, -1, choices=option.choices, value=option.default, style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT) else: if 'MULTILINE' in option.help: ctrl = wx.TextCtrl(tab, -1, "", size=(300, 100), style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER) else: ctrl = wx.TextCtrl(tab, -1, "", size=(300, -1)) if ( option.default != optparse.NO_DEFAULT ) and \ ( option.default is not None ): ctrl.Value = unicode(option.default) box.Add(ctrl, 1, wx.ALIGN_CENTRE | wx.ALL, 5) if option.type in ['file', 'directory']: browse = wx.Button(tab, label='...') browse.SetHelpText('Click to open %s browser' % (option.type)) self.browse_option_map[browse.GetId()] = option, ctrl wx.EVT_BUTTON(tab, browse.GetId(), self.OnSelectPath) box.Add(browse, 0, wx.ALIGN_CENTRE | wx.ALL, 5) elif option.action in ('store_true', 'store_false'): ctrl = wx.CheckBox(tab, -1, option.dest, size=(300, -1)) box.Add(ctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5) else: raise NotImplementedError('Unknown option action: %s' % repr(option.action)) ctrl.SetHelpText(option.help) sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.option_controls[option] = ctrl # Add a text control for entering args box = wx.BoxSizer(wx.HORIZONTAL) label = wx.StaticText(tab, -1, 'args') label.SetHelpText('This is the place to enter the args') self.args_ctrl = wx.TextCtrl(tab, -1, '', size=(-1, 100), style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER) self.args_ctrl.SetHelpText( '''Args can either be separated by a space or a newline Args the contain spaces must be entered like so: "arg with sapce" ''') box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) box.Add(self.args_ctrl, 1, wx.ALIGN_CENTRE | wx.ALL, 5) sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) line = wx.StaticLine(tab, -1, size=(20, -1), style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) btnsizer = wx.StdDialogButtonSizer() if wx.Platform != "__WXMSW__": btn = wx.ContextHelpButton(tab) btnsizer.AddButton(btn) btn = wx.Button(tab, wx.ID_OK) btn.SetHelpText("The OK button completes the dialog") btn.SetDefault() btnsizer.AddButton(btn) btn = wx.Button(tab, wx.ID_CANCEL) btn.SetHelpText("The Cancel button cancels the dialog. (Cool, huh?)") btnsizer.AddButton(btn) btnsizer.Realize() sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) sizer.Fit(tab) self.ReFit()
if val == wx.ID_YES: self.DeleteAllItems() self.currentItem = -1 dlg.Destroy() return True dlg.Destroy() return False return True #--------------------------------------------------------------------------- # Create and set a help provider. Normally you would do this in # the app's OnInit as it must be done before any SetHelpText calls. provider = wx.SimpleHelpProvider() wx.HelpProvider.Set(provider) #--------------------------------------------------------------------------- class FindTimeDlg(wx.Dialog): LON = 0 RETR = 1 MIN = 0 SEC = 1 RET = 2 USEAPPROX = 0
def __init__(self, optParser, title, parent=None, ID=0, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.DEFAULT_DIALOG_STYLE|wx.THICK_FRAME): """Function for initialization""" # TODO fix icon # modis_icon = wx.Icon('/home/lucadelu/github/pyModis/pyModis.ico', # wx.BITMAP_TYPE_ICO) # self.SetIcon(modis_icon) provider = wx.SimpleHelpProvider() wx.HelpProvider_Set(provider) pre = wx.PreDialog() pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) pre.Create(parent, ID, title, pos, size, style) self.PostCreate(pre) self.CenterOnScreen() sizer = wx.BoxSizer(wx.VERTICAL) self.args_ctrl = [] self.option_controls = dict() # IN THE TOP OF GUI THERE WAS THE NAME OF THE SCRIPT, BUT NOW IT IS IN # THE TITLE # top_label_text = '%s %s' % (optParser.get_prog_name(), # optParser.get_version()) # label = wx.StaticText(self, -1, top_label_text) # sizer.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) # Add a text control for entering args arg = self._checkArg(optParser.get_prog_name()) sizer.Add(arg, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) self.browse_option_map = dict() # Add controls for all the options for option in optParser.list_of_option: if option.dest is None: continue if option.help is None: option.help = '' if checkLabel(option) == 'Formats': continue box = wx.BoxSizer(wx.HORIZONTAL) if 'store' == option.action: label = wx.StaticText(self, -1, checkLabel(option)) label.SetHelpText(option.help.replace(' [default=%default]', '')) box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) if 'choice' == option.type: choices = list(set(option.choices)) if optparse.NO_DEFAULT == option.default: option.default = choices[0] ctrl = wx.ComboBox(self, -1, choices=choices, value=option.default, size=TEXTCTRL_SIZE, style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT) elif option.type in ['file', 'output']: if option.type == 'file': fmode = wx.OPEN elif option.type == 'output': fmode = wx.SAVE ctrl = filebrowse.FileBrowseButton(self, id=wx.ID_ANY, fileMask='*', labelText='', dialogTitle='Choose output file', buttonText='Browse', startDirectory=os.getcwd(), fileMode=fmode, size=TEXTCTRL_SIZE) elif option.type == 'directory': ctrl = filebrowse.DirBrowseButton(self, id=wx.ID_ANY, labelText='', dialogTitle='Choose output file', buttonText='Browse', startDirectory=os.getcwd(), size=TEXTCTRL_SIZE) else: if 'MULTILINE' in option.help: ctrl = wx.TextCtrl(self, -1, "", size=(400, 100), style=wx.TE_MULTILINE | wx.TE_PROCESS_ENTER) else: ctrl = wx.TextCtrl(self, -1, "", size=TEXTCTRL_SIZE) if (option.default != optparse.NO_DEFAULT) and \ (option.default is not None): ctrl.Value = str(option.default) box.Add(ctrl, 1, wx.ALIGN_RIGHT | wx.ALL, 5) elif option.action in ('store_true', 'store_false'): ctrl = wx.CheckBox(self, -1, checkLabel(option), size=(300, -1)) box.Add(ctrl, 0, wx.ALIGN_CENTRE | wx.ALL, 5) elif option.action == 'group_name': label = wx.StaticText(self, -1, checkLabel(option)) font = wx.Font(12, wx.DECORATIVE, wx.NORMAL, wx.BOLD) label.SetFont(font) box.Add(label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) ctrl = None else: raise NotImplementedError('Unknown option action: ' '{act}'.format(act=repr(option.action))) if ctrl: ctrl.SetHelpText(option.help.replace(' [default=%default]', '')) self.option_controls[option] = ctrl sizer.Add(box, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) line = wx.StaticLine(self, -1, size=(20, -1), style=wx.LI_HORIZONTAL) sizer.Add(line, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) btnsizer = wx.StdDialogButtonSizer() if wx.Platform != "__WXMSW__": btn = wx.ContextHelpButton(self) btnsizer.AddButton(btn) btn = wx.Button(self, wx.ID_OK) btn.SetHelpText("The OK button completes the dialog") btn.SetDefault() btnsizer.AddButton(btn) btn = wx.Button(self, wx.ID_CANCEL) btn.SetHelpText("The Cancel button cancels the dialog. (Cool, huh?)") btnsizer.AddButton(btn) btnsizer.Realize() sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.SetSizer(sizer) sizer.Fit(self)