Author: bugman Date: Thu Jul 18 20:08:05 2013 New Revision: 20397 URL: http://svn.gna.org/viewcvs/relax?rev=20397&view=rev Log: Created a boolean input element for the auto-analyses of the GUI. This simply turns on and off. Added: trunk/gui/analyses/elements/bool_element.py - copied, changed from r20324, trunk/gui/analyses/elements/text_element.py Modified: trunk/gui/analyses/elements/__init__.py Modified: trunk/gui/analyses/elements/__init__.py URL: http://svn.gna.org/viewcvs/relax/trunk/gui/analyses/elements/__init__.py?rev=20397&r1=20396&r2=20397&view=diff ============================================================================== --- trunk/gui/analyses/elements/__init__.py (original) +++ trunk/gui/analyses/elements/__init__.py Thu Jul 18 20:08:05 2013 @@ -24,6 +24,7 @@ # The package contents. __all__ = [ + 'bool_element', 'model_list', 'spin_element', 'text_element' Copied: trunk/gui/analyses/elements/bool_element.py (from r20324, trunk/gui/analyses/elements/text_element.py) URL: http://svn.gna.org/viewcvs/relax/trunk/gui/analyses/elements/bool_element.py?p2=trunk/gui/analyses/elements/bool_element.py&p1=trunk/gui/analyses/elements/text_element.py&r1=20324&r2=20397&rev=20397&view=diff ============================================================================== --- trunk/gui/analyses/elements/text_element.py (original) +++ trunk/gui/analyses/elements/bool_element.py Thu Jul 18 20:08:05 2013 @@ -28,18 +28,18 @@ import wx.lib.buttons # relax module imports. +from graphics import fetch_icon from gui.fonts import font -from gui.paths import icon_16x16 from gui.string_conv import str_to_gui -class Text_ctrl: +class Boolean_ctrl: """The analysis specific text control. This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button. """ - def __init__(self, box, parent, text="", default="", tooltip=None, tooltip_button=None, button_text=" Change", control=wx.TextCtrl, icon=icon_16x16.open, fn=None, editable=True, button=False, width_text=200, width_button=80, spacer=0): + def __init__(self, box, parent, text="", default=True, tooltip=None, tooltip_button=None, button_text=" Toggle", control=wx.TextCtrl, width_text=200, width_button=80, spacer=0): """Create a text selection element for the frame. This consists of a horizontal layout with a static text element, a text control, and an optional button. @@ -50,8 +50,8 @@ @type parent: wx object @keyword text: The static text. @type text: str - @keyword default: The default text of the control. - @type default: str + @keyword default: The default value of the control. + @type default: bool @keyword tooltip: The tooltip which appears on hovering over the text or input field. @type tooltip: str @keyword tooltip_button: The separate tooltip for the button. @@ -60,14 +60,6 @@ @type button_text: str @keyword control: The control class to use. @type control: wx.TextCtrl derived class - @keyword icon: The path of the icon to use for the button. - @type icon: str - @keyword fn: The function or method to execute when clicking on the button. If this is a string, then an equivalent function will be searched for in the control object. - @type fn: func or str - @keyword editable: A flag specifying if the control is editable or not. - @type editable: bool - @keyword button: A flag which if True will cause a button to appear. - @type button: bool @keyword width_text: The width of the text element. @type width_text: int @keyword width_button: The width of the button. @@ -75,6 +67,9 @@ @keyword spacer: The horizontal spacing between the elements. @type spacer: int """ + + # Store the state. + self.state = default # Horizontal packing for this element. sizer = wx.BoxSizer(wx.HORIZONTAL) @@ -96,33 +91,23 @@ self.field = control(parent, -1, str_to_gui(default)) self.field.SetMinSize((-1, size_horizontal)) self.field.SetFont(font.normal) - self.field.SetEditable(editable) - if not editable: - colour = parent.GetBackgroundColour() - self.field.SetOwnBackgroundColour(colour) + colour = parent.GetBackgroundColour() + self.field.SetOwnBackgroundColour(colour) sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) # Spacer. sizer.AddSpacer((spacer, -1)) - # The button. - if button: - # Function is in the control class. - if isinstance(fn, str): - # The function. - fn = getattr(field, fn) - - # Add the button. - self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text)) - self.button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY)) - self.button.SetMinSize((width_button, size_horizontal)) - self.button.SetFont(font.normal) - parent.Bind(wx.EVT_BUTTON, fn, self.button) - sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) - - # No button, so add a spacer. + # Add the button. + self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text)) + if default == True: + self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY)) else: - sizer.AddSpacer((width_button, -1)) + self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY)) + self.button.SetMinSize((width_button, size_horizontal)) + self.button.SetFont(font.normal) + parent.Bind(wx.EVT_BUTTON, self.toggle, self.button) + sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0) # Add the element to the box. box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0) @@ -131,7 +116,7 @@ if tooltip: self.label.SetToolTipString(tooltip) self.field.SetToolTipString(tooltip) - if button and tooltip_button: + if tooltip_button: self.button.SetToolTipString(tooltip_button) @@ -142,10 +127,8 @@ @type enable: bool """ - # Call the control and button methods. - self.field.Enable(enable) - if hasattr(self, 'button'): - self.button.Enable(enable) + # Call the button method. + self.button.Enable(enable) def GetValue(self): @@ -155,16 +138,22 @@ @rtype: int """ - # Get the value from the text control. - return self.field.GetValue() + # Return the state. + return self.state - def SetValue(self, value): - """Set the value of the control. + def toggle(self, event=None): + """Switch the state.""" - @param value: The value to set the text control to. - @type value: text - """ + # From False to True. + if self.state == False: + self.field.SetValue('True') + self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY)) + self.state = True - # Set the value of the text control. - return self.field.SetValue(value) + # From True to False. + else: + self.field.SetValue('False') + self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY)) + self.state = False + self.button