""" Dialog box for configuring various directories. """ import wx import Config from Global import Log class DirConfigDialog(wx.Dialog): def __init__(self, AppConfig, parent, ID, title, size = wx.DefaultSize, pos = wx.DefaultPosition, style = wx.DEFAULT_DIALOG_STYLE, useMetal = False): self.Directories = AppConfig.Directories.copy() # Instead of calling wx.Dialog.__init__ we pre-create the dialog # so we can set an extra style that must be set before # creation, and then we create the GUI object using the Create # method. PreDialog = wx.PreDialog() PreDialog.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) PreDialog.Create(parent, ID, title, pos, size, style) # This next step is the most important, it turns this Python # object into the real wrapper of the dialog (instead of pre) # as far as the wxPython extension is concerned. self.PostCreate(PreDialog) # This extra style can be set after the UI object has been created. if 'wxMac' in wx.PlatformInfo and useMetal: self.SetExtraStyle(wx.DIALOG_EX_METAL) # Now continue with the normal construction of the dialog # contents self.BuildWidgets() def BuildWidgets(self): self.MasterSizer = wx.BoxSizer(wx.VERTICAL) Label = wx.StaticText(self, -1, "Directory configuration") self.MasterSizer.Add(Label, 0, wx.ALIGN_CENTRE | wx.ALL, 5) self.DirectoryTextControls = [] self.DirectoryDotButtons = [] for Index in range(Config.DirectoryConfig.DirCount): self.AddDirConfigWidgets(Index, Config.DirectoryConfig.Names[Index]) # Lower section: OK and Cancel buttons: StaticLine = wx.StaticLine(self, -1, size = (20, -1), style = wx.LI_HORIZONTAL) self.MasterSizer.Add(StaticLine, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5) ButtonSizer = wx.StdDialogButtonSizer() OKButton = wx.Button(self, wx.ID_OK) OKButton.SetDefault() ButtonSizer.AddButton(OKButton) CancelButton = wx.Button(self, wx.ID_CANCEL) ButtonSizer.AddButton(CancelButton) ButtonSizer.Realize() self.MasterSizer.Add(ButtonSizer, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) self.SetSizer(self.MasterSizer) self.MasterSizer.Fit(self) def AddDirConfigWidgets(self, Index, Name): """ Add label, text with dir, and button to search for dir. """ BoxSizer = wx.BoxSizer(wx.HORIZONTAL) Label = wx.StaticText(self, -1, Name) Directory = self.Directories.get(Index, "") TextControl = wx.TextCtrl(self, -1, Directory) self.DirectoryTextControls.append(TextControl) Button = wx.Button(self, -1, "...") self.DirectoryDotButtons.append(Button) self.Bind(wx.EVT_BUTTON, self.OnClick, Button) BoxSizer.Add(Label, 1, wx.ALIGN_CENTRE | wx.ALL, 5) BoxSizer.Add(TextControl, 2, wx.ALIGN_CENTRE | wx.ALL, 5) BoxSizer.Add(Button, 0, wx.ALIGN_CENTRE, 5) self.MasterSizer.Add(BoxSizer, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) def OnClick(self, Event): Button = Event.GetEventObject() ButtonIndex = self.DirectoryDotButtons.index(Button) Log("button %s"%ButtonIndex) Label = "Choose directory for %s"%Config.DirectoryConfig.Names[ButtonIndex] Dialog = wx.DirDialog(self, Label, style = wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) if Dialog.ShowModal() == wx.ID_OK: Path = Dialog.GetPath() self.Directories[ButtonIndex] = Path self.DirectoryTextControls[ButtonIndex].SetValue(Path) Dialog.Destroy() # Destroy AFTER getting the path