def _create_parent_chooser(self, sizer, default_dir): browser = DirBrowseButton(self, labelText="Parent Directory", dialogTitle="Choose Parent Directory", startDirectory=default_dir, size=(600, -1), newDirectory=True, changeCallback=self.OnPathChanged) browser.SetValue(default_dir) sizer.Add(browser, 1, wx.EXPAND) return browser
def _create_parent_chooser(self, sizer, default_dir): browser = DirBrowseButton(self, labelText="Parent Directory", dialogTitle="Choose Parent Directory", startDirectory=default_dir, size=(600, -1), newDirectory=True, changeCallback=self.OnPathChanged) browser.SetBackgroundColour(Colour(self.color_background)) browser.SetForegroundColour(Colour(self.color_foreground)) # TODO: Change colors on buttons and text field # browser.SetOwnBackgroundColour(Colour(self.color_secondary_background)) # browser.SetOwnForegroundColour(Colour(self.color_secondary_foreground)) browser.SetValue(default_dir) sizer.Add(browser, 1, wx.EXPAND) return browser
class MainFrame(wx.Frame): def _init_ctrls(self, parent): self.DecYear = wx.Button(self, -1, '<<', size=(48, 36)) self.DecYear.Bind(wx.EVT_BUTTON, self.OnDecYear) self.DecMonth = wx.Button(self, -1, ' < ', size=(48, 36)) self.DecMonth.Bind(wx.EVT_BUTTON, self.OnDecMonth) self.Current = wx.Button(self, -1, 'Today') self.Current.Bind(wx.EVT_BUTTON, self.OnCurrent) self.IncMonth = wx.Button(self, -1, ' > ', size=(48, 36)) self.IncMonth.Bind(wx.EVT_BUTTON, self.OnIncMonth) self.IncYear = wx.Button(self, -1, '>>', size=(48, 36)) self.IncYear.Bind(wx.EVT_BUTTON, self.OnIncYear) bsizer = wx.BoxSizer(wx.HORIZONTAL) bsizer.Add(self.DecYear, 0, wx.ALL, 2) bsizer.Add(self.DecMonth, 0, wx.ALL, 2) bsizer.Add(self.Current, 1, wx.ALL | wx.EXPAND, 2) bsizer.Add(self.IncMonth, 0, wx.ALL, 2) bsizer.Add(self.IncYear, 0, wx.ALL, 2) self.Calendar = Calendar(self, -1, size=(200, 300)) self.Calendar.Bind(wx.lib.calendar.EVT_CALENDAR, self.OnCalendarChange) self.Calendar.SetCurrentDay() self.Calendar.grid_color = 'BLUE' self.Calendar.SetBusType() self.FBB = FileBrowseButton(self, size=(450, -1), changeCallback=self.OnFBBChange) self.FBB.SetLabel('Symbols File:') self.DBB = DirBrowseButton(self, size=(450, -1), changeCallback=self.OnDBBChange) self.DBB.SetLabel('Prices Folder:') self.ListBox = gizmos.EditableListBox( self, -1, # style=gizmos.EL_DEFAULT_STYLE | gizmos.EL_NO_REORDER ) self.ListBox.GetUpButton().Show(False) self.ListBox.GetDownButton().Show(False) self.ListBox.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnSymbolListChange) self.ListBox.Bind(wx.EVT_LIST_INSERT_ITEM, self.OnSymbolListChange) self.Download = wx.Button(self, wx.OK, 'Download Prices') self.Download.Bind(wx.EVT_BUTTON, self.OnDownload) sizer = wx.BoxSizer(wx.VERTICAL) sizer.AddSizer(bsizer, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 5) sizer.AddWindow(self.Calendar, 0, wx.LEFT | wx.RIGHT | wx.EXPAND, 5) sizer.AddWindow(self.FBB, 0, wx.ALL | wx.EXPAND, 5) sizer.AddWindow(self.DBB, 0, wx.ALL | wx.EXPAND, 5) sizer.AddWindow(self.ListBox, 1, wx.ALL | wx.EXPAND, 5) sizer.AddWindow(self.Download, 0, wx.ALL | wx.ALIGN_RIGHT, 5) self.SetSizer(sizer) def __init__(self, parent=None): wx.Frame.__init__(self, parent=parent, size=(800, 600)) self._init_ctrls(self) self._blocking = Blocker() self._clean = True # Get download directory and symbol filename download_dir = '' symbol_file = '' if os.path.exists('settings.ini'): with file('settings.ini', 'r') as settings: symbol_file = settings.readline().strip() download_dir = settings.readline().strip() if not os.path.exists(symbol_file): symbol_file = '' if not os.path.exists(download_dir): download_dir = '' download_dir = download_dir or os.path.realpath('.') symbol_file = symbol_file or os.path.join(download_dir, 'symbols.txt') self.SetDownloadDir(download_dir) if os.path.exists(symbol_file): self.SetSymbolFile(symbol_file) # Update the calendar self.Download.SetFocus() self.OnCalendarChange(None) def OnCalendarChange(self, event): self.day = self.Calendar.day self.month = self.Calendar.month self.year = self.Calendar.year def OnCurrent(self, event): self.Calendar.SetCurrentDay() self.ResetDisplay() def OnDBBChange(self, event): if self._blocking: return self.SetDownloadDir(event.GetString()) def OnDecMonth(self, event): self.Calendar.DecMonth() self.ResetDisplay() def OnDecYear(self, event): self.Calendar.DecYear() self.ResetDisplay() def OnDownload(self, event): if not self._clean: with file(self.symbol_file, 'w') as symbols: symbols.write('\n'.join(self.ListBox.GetStrings())) self._clean = True dt = datetime.date(self.year, self.month, self.day) pricer.download_date(self.ListBox.GetStrings(), dt, self.download_dir) with file('settings.ini', 'w') as settings: settings.write(self.symbol_file + '\n') settings.write(self.download_dir + '\n') def OnFBBChange(self, event): if self._blocking: return self.ListBox.SetStrings([]) self.SetSymbolFile(event.GetString()) def OnIncMonth(self, event): self.Calendar.IncMonth() self.ResetDisplay() def OnIncYear(self, event): self.Calendar.IncYear() self.ResetDisplay() def OnSymbolListChange(self, event): self._clean = False self.Download.Enable(len(self.ListBox.GetStrings()) > 0) def ResetDisplay(self): self.Calendar.Refresh() def SetDownloadDir(self, download_dir): with self._blocking: self.download_dir = download_dir self.DBB.SetValue(self.download_dir) def SetSymbolFile(self, symbol_file): self.Download.Enable(False) with self._blocking: if not os.path.exists(symbol_file): return self.symbol_file = symbol_file with file(self.symbol_file, 'r') as symbols: l = [] for symbol in symbols: s = symbol.strip().upper() if len(s) and not s.startswith('#'): l.append(s) l.sort() self.ListBox.SetStrings(l) self._clean = True self.FBB.SetValue(self.symbol_file)
class PreferencesDialog(wx.Dialog): __doc__ = globals()['__doc__'] def __init__(self,parent,prefs=None,tablist=None): if not prefs: prefs = neveredit.util.Preferences.getPreferences() self.preferences = prefs if not tablist: tablist = ["GeneralPanel","ScriptEditorPanel","TextPanel", "UserControlsPanel"] # tablist list all tabs that will be activated, the other ones do # not show self.tablist = tablist resourceText = PreferencesDialog_xrc.data # resource = wx.xrc.EmptyXmlResource() resource = wx.xrc.XmlResource() # resource.LoadFromString(resourceText) resource.LoadFromBuffer(resourceText) dialog = resource.LoadDialog(parent,"PrefDialog") notebook = wx.xrc.XRCCTRL(dialog,"PrefNotebook") generalPanel = wx.xrc.XRCCTRL(dialog,"GeneralPanel") if "GeneralPanel" in self.tablist: self.appDirButton = DirBrowseButton(generalPanel,-1,(500,30), labelText=_('NWN Directory'), buttonText=_('Select...'), startDirectory= prefs['NWNAppDir']) self.appDirButton.SetValue(prefs['NWNAppDir']) resource.AttachUnknownControl('AppDir', self.appDirButton, generalPanel) else: index = self.__getPanelIndex(notebook,generalPanel) notebook.DeletePage(index) if "ScriptEditorPanel" in self.tablist: self.scriptAntiAlias = wx.xrc.XRCCTRL(dialog,"ScriptAntiAlias") self.scriptAntiAlias.SetValue(prefs['ScriptAntiAlias']) self.scriptAutoCompile = wx.xrc.XRCCTRL(dialog,"ScriptAutoCompile") self.scriptAutoCompile.SetValue(prefs['ScriptAutoCompile']) else: index = self.__getPanelIndex(notebook, wx.xrc.XRCCTRL(dialog, "ScriptEditorPanel")) notebook.DeletePage(index) if "TextPanel" in self.tablist : self.DefaultLocStringLang = wx.xrc.XRCCTRL( dialog,"DefaultLocStringLang") self.DefaultLocStringLang.SetSelection(neveredit.file.Language.\ convertFromBIOCode(prefs["DefaultLocStringLang"])) else: index = self.__getPanelIndex(notebook, wx.xrc.XRCCTRL(dialog, "TextPanel")) notebook.DeletePage(index) # Set up the User Controls Panel # Create Controls # Fix length # Set value if "UserControlsPanel" in self.tablist : self.mwUpKey = wx.xrc.XRCCTRL(dialog,"mwUpKey") self.mwUpKey.SetMaxLength(1) self.mwUpKey.SetValue(prefs['GLW_UP']) self.mwDownKey = wx.xrc.XRCCTRL(dialog,"mwDownKey") self.mwDownKey.SetMaxLength(1) self.mwDownKey.SetValue(prefs['GLW_DOWN']) self.mwLeftKey = wx.xrc.XRCCTRL(dialog,"mwLeftKey") self.mwLeftKey.SetMaxLength(1) self.mwLeftKey.SetValue(prefs['GLW_LEFT']) self.mwRightKey = wx.xrc.XRCCTRL(dialog,"mwRightKey") self.mwRightKey.SetMaxLength(1) self.mwRightKey.SetValue(prefs['GLW_RIGHT']) else: index = self.__getPanelIndex(notebook, wx.xrc.XRCCTRL(dialog, "UserControlsPanel")) notebook.DeletePage(index) dialog.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.xrc.XRCID("ID_OK")) dialog.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.xrc.XRCID("ID_CANCEL")) # self.PostCreate(dialog) def __getPanelIndex(self,notebook,panel): index = [notebook.GetPage(i).GetId() for i in range(notebook.GetPageCount())]\ .index(panel.GetId()) return index def getValues(self): values = {} if "GeneralPanel" in self.tablist: values.update({'NWNAppDir':self.appDirButton.GetValue()}) if "ScriptEditorPanel" in self.tablist: values.update({'ScriptAntiAlias': self.scriptAntiAlias.GetValue(), 'ScriptAutoCompile': self.scriptAutoCompile.GetValue()}) if "TextPanel" in self.tablist: values.update({"DefaultLocStringLang":neveredit.file.Language.\ convertToBIOCode(self.DefaultLocStringLang.GetSelection())}) # Update value of direction keys for Model/GLWindow if "UserControlsPanel" in self.tablist: values.update({'GLW_UP': self.mwUpKey.GetValue(), 'GLW_DOWN': self.mwDownKey.GetValue(), 'GLW_LEFT': self.mwLeftKey.GetValue(), 'GLW_RIGHT': self.mwRightKey.GetValue()}) return values def ShowAndInterpret(self): self.CentreOnParent() if self.ShowModal() == wx.ID_OK: result = self.getValues() self.preferences.values.update(result) self.preferences.save() return True else: return False def OnCancel(self, event): self.EndModal(wx.ID_CANCEL) def OnOk(self, event): self.EndModal(wx.ID_OK)