Author: bugman Date: Mon May 7 15:51:45 2012 New Revision: 16054 URL: http://svn.gna.org/viewcvs/relax?rev=16054&view=rev Log: Added support for the directory selection wizard page element for the auto-generated user functions. This uses the new Selector_dir GUI element. Modified: branches/uf_redesign/gui/filedialog.py branches/uf_redesign/gui/wizard.py branches/uf_redesign/gui/wizard_elements.py Modified: branches/uf_redesign/gui/filedialog.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/filedialog.py?rev=16054&r1=16053&r2=16054&view=diff ============================================================================== --- branches/uf_redesign/gui/filedialog.py (original) +++ branches/uf_redesign/gui/filedialog.py Mon May 7 15:51:45 2012 @@ -38,11 +38,13 @@ class RelaxDirDialog(wx.DirDialog): """relax specific replacement directory dialog for selecting directories.""" - def __init__(self, parent, message=wx.DirSelectorPromptStr, defaultPath=wx.EmptyString, style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON, pos=wx.DefaultPosition, size=wx.DefaultSize, name=wx.DirDialogNameStr): + def __init__(self, parent, field=None, message=wx.DirSelectorPromptStr, defaultPath=wx.EmptyString, style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON, pos=wx.DefaultPosition, size=wx.DefaultSize, name=wx.DirDialogNameStr): """Setup the class and store the field. @param parent: The parent wx window object. @type parent: Window + @keyword field: The field to update with the file selection. + @type field: wx object or None @keyword message: The path selector prompt string. @type message: String @keyword defaultPath: The default directory to open in. @@ -56,6 +58,9 @@ @keyword name: The title for the dialog. @type name: String """ + + # Store the args. + self.field = field # No path supplied, so use the current working directory. if defaultPath == wx.EmptyString: @@ -80,6 +85,27 @@ # Return the path. return path + + + def select_event(self, event): + """The path selector GUI element. + + @param event: The wx event. + @type event: wx event + """ + + # Show the dialog, and return if nothing was selected. + if status.show_gui and self.ShowModal() != wx.ID_OK: + return + + # Get the selected path. + path = self.get_path() + + # Update the field. + self.field.SetValue(str_to_gui(path)) + + # Scroll the text to the end. + self.field.SetInsertionPoint(len(path)) Modified: branches/uf_redesign/gui/wizard.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard.py?rev=16054&r1=16053&r2=16054&view=diff ============================================================================== --- branches/uf_redesign/gui/wizard.py (original) +++ branches/uf_redesign/gui/wizard.py Mon May 7 15:51:45 2012 @@ -41,7 +41,7 @@ from gui.misc import add_border, bool_to_gui, gui_to_int, gui_to_str, int_to_gui, open_file, protected_exec, str_to_gui from gui.message import Question from gui import paths -from gui.wizard_elements import Selector_bool, Selector_file, Sequence, Sequence_2D, Value +from gui.wizard_elements import Selector_dir, Selector_bool, Selector_file, Sequence, Sequence_2D, Value class Wiz_page(wx.Panel): @@ -615,7 +615,7 @@ self._elements[key] = element - def element_dir_sel(self, key=None, sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None, read_only=False): + def element_dir_sel(self, key=None, sizer=None, desc=None, message='Directory selection', tooltip=None, divider=None, padding=0, spacer=None, read_only=False): """Set up the integer element and store it. @keyword key: The dictionary key to store the element with. @@ -624,6 +624,8 @@ @type sizer: wx.Sizer instance @keyword desc: The text description. @type desc: str + @keyword message: The directory selector prompt string. + @type message: String @keyword tooltip: The tooltip which appears on hovering over the text or input field. @type tooltip: str @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. @@ -637,7 +639,7 @@ """ # Create the element. - element = Selector_dir(name=key, parent=self, sizer=sizer, desc=desc, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer, read_only=read_only) + element = Selector_dir(name=key, parent=self, sizer=sizer, desc=desc, message=message, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer, read_only=read_only) # Store it. self._elements[key] = element Modified: branches/uf_redesign/gui/wizard_elements.py URL: http://svn.gna.org/viewcvs/relax/branches/uf_redesign/gui/wizard_elements.py?rev=16054&r1=16053&r2=16054&view=diff ============================================================================== --- branches/uf_redesign/gui/wizard_elements.py (original) +++ branches/uf_redesign/gui/wizard_elements.py Mon May 7 15:51:45 2012 @@ -36,7 +36,7 @@ # relax GUI module imports. from gui.components.combo_list import Combo_list from gui.errors import gui_raise -from gui.filedialog import RelaxFileDialog +from gui.filedialog import RelaxDirDialog, RelaxFileDialog from gui.fonts import font from gui.misc import add_border, bool_to_gui, float_to_gui, gui_to_bool, gui_to_float, gui_to_int, gui_to_list, gui_to_str, gui_to_tuple, int_to_gui, list_to_gui, str_to_gui, tuple_to_gui from gui import paths @@ -382,6 +382,128 @@ # Set the selection. self.combo.SetStringSelection(bool_to_gui(value)) + + + +class Selector_dir: + """Wizard GUI element for selecting directories.""" + + def __init__(self, name=None, parent=None, sizer=None, desc=None, message='File selection', style=wx.FD_DEFAULT_STYLE, tooltip=None, divider=None, padding=0, spacer=None, read_only=False): + """Build the file selection element. + + @keyword name: The name of the element to use in titles, etc. + @type name: str + @keyword parent: The wizard GUI element. + @type parent: wx.Panel instance + @keyword sizer: The sizer to put the input field into. + @type sizer: wx.Sizer instance + @keyword desc: The text description. + @type desc: str + @keyword message: The file selector prompt string. + @type message: String + @keyword style: The dialog style. To open a single file, set to wx.FD_OPEN. To open multiple files, set to wx.FD_OPEN|wx.FD_MULTIPLE. To save a single file, set to wx.FD_SAVE. To save multiple files, set to wx.FD_SAVE|wx.FD_MULTIPLE. + @type style: long + @keyword tooltip: The tooltip which appears on hovering over all the GUI elements. + @type tooltip: str + @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. + @type divider: None or int + @keyword padding: Spacing to the left and right of the widgets. + @type padding: int + @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. + @type spacer: None or int + @keyword read_only: A flag which if True means that the text of the element cannot be edited. + @type read_only: bool + """ + + # Store the args. + self.name = name + + # Init. + sub_sizer = wx.BoxSizer(wx.HORIZONTAL) + + # Left padding. + sub_sizer.AddSpacer(padding) + + # The description. + text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) + text.SetFont(font.normal) + sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) + + # The divider. + if not divider: + divider = parent._div_left + + # Spacing. + x, y = text.GetSize() + sub_sizer.AddSpacer((divider - x, 0)) + + # The input field. + if not hasattr(parent, 'file_selection_field'): + parent.file_selection_field = [] + parent.file_selection_field.append(wx.TextCtrl(parent, -1, '')) + self._field = parent.file_selection_field[-1] + self._field.SetMinSize((-1, parent.height_element)) + self._field.SetFont(font.normal) + sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) + + # The file selection object. + obj = RelaxDirDialog(parent, field=self._field, message=message, style=style) + + # A little spacing. + sub_sizer.AddSpacer(5) + + # The file selection button. + button = wx.BitmapButton(parent, -1, wx.Bitmap(paths.icon_16x16.open, wx.BITMAP_TYPE_ANY)) + button.SetMinSize((parent.height_element, parent.height_element)) + button.SetToolTipString("Select the file.") + sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) + parent.Bind(wx.EVT_BUTTON, obj.select_event, button) + + # Right padding. + sub_sizer.AddSpacer(padding) + + # Add to the main sizer (followed by stretchable spacing). + sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) + + # Spacing below the widget. + if spacer == None: + sizer.AddStretchSpacer() + else: + sizer.AddSpacer(spacer) + + # Tooltip. + if tooltip: + text.SetToolTipString(tooltip) + self._field.SetToolTipString(tooltip) + + + def Clear(self): + """Special method for clearing or resetting the GUI element.""" + + # Clear the value from the TextCtrl. + self._field.Clear() + + + def GetValue(self): + """Special method for returning the value of the GUI element. + + @return: The string value. + @rtype: list of str + """ + + # Convert and return the value from a TextCtrl. + return gui_to_str(self._field.GetValue()) + + + def SetValue(self, value): + """Special method for setting the value of the GUI element. + + @param value: The value to set. + @type value: str + """ + + # Convert and set the value for a TextCtrl. + self._field.SetValue(str_to_gui(value))