Author: bugman Date: Thu Jun 9 15:28:44 2011 New Revision: 12928 URL: http://svn.gna.org/viewcvs/relax?rev=12928&view=rev Log: Added the add_text_sel_element() base class method for creating one of the basic frame elements. This element consists of text, a text control, and an optional button. Modified: 1.3/gui/analyses/base.py Modified: 1.3/gui/analyses/base.py URL: http://svn.gna.org/viewcvs/relax/1.3/gui/analyses/base.py?rev=12928&r1=12927&r2=12928&view=diff ============================================================================== --- 1.3/gui/analyses/base.py (original) +++ 1.3/gui/analyses/base.py Thu Jun 9 15:28:44 2011 @@ -144,6 +144,8 @@ @type height: int @keyword editable: A flag specifying if the control is editable or not. @type editable: bool + @return: The text control object. + @rtype: control object """ # The control. @@ -161,6 +163,64 @@ return field + def add_text_sel_element(self, box, parent, text="", default="", control=wx.TextCtrl, width_text=-1, width_control=-1, width_button=-1, height=-1, fn=None, editable=True, button=False): + """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. + + @param box: The box element to pack the structure file selection GUI element into. + @type box: wx.BoxSizer instance + @param parent: The parent GUI element. + @type parent: wx object + @keyword text: The static text. + @type text: str + @keyword default: The default text of the control. + @type default: str + @keyword control: The control class to use. + @type control: wx.TextCtrl derived class + @keyword width_text: The minimum width of the static text. + @type width_text: int + @keyword width_control: The minimum width of the text control. + @type width_control: int + @keyword width_button: The minimum width of the button. + @type width_button: int + @keyword height: The minimum height of the entire element. + @type height: int + @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 + @return: The text control object. + @rtype: control object + """ + + # Horizontal packing for this element. + sizer = wx.BoxSizer(wx.HORIZONTAL) + + # The label. + self.add_static_text(sizer, parent, text=text, width=width_text) + + # The text input field. + field = self.add_text_control(sizer, parent, text=default, control=control, width=width_control, editable=editable) + size = field.GetSize() + + # The button. + if button: + # Function is in the control class. + if type(fn) == str: + # The function. + fn = getattr(field, fn) + + # Add the button. + self.add_button_open(sizer, parent, fn=fn, width=width_button, height=size[1]) + + # Add the element to the box. + box.Add(sizer, 1, wx.EXPAND, 0) + + # Return the text control object. + return field + + def add_title(self, box, text): """Create and add the frame title.