mailr13013 - in /1.3/gui: menu.py relax_gui.py settings.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 14, 2011 - 19:30:
Author: bugman
Date: Tue Jun 14 19:30:46 2011
New Revision: 13013

URL: http://svn.gna.org/viewcvs/relax?rev=13013&view=rev
Log:
Complete redesign of the relax global settings window to fix the Mac OS X 
crashing.

This is an attempt at fixing bug #18197 (https://gna.org/bugs/?18197).

The old code has been completely eliminated and replaced with a new set of 
methods in the base
relax_gui class and a new Global_parameters class in gui.settings which is of 
the same design as the
free file format settings window.


Modified:
    1.3/gui/menu.py
    1.3/gui/relax_gui.py
    1.3/gui/settings.py

Modified: 1.3/gui/menu.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/menu.py?rev=13013&r1=13012&r2=13013&view=diff
==============================================================================
--- 1.3/gui/menu.py (original)
+++ 1.3/gui/menu.py Tue Jun 14 19:30:46 2011
@@ -96,7 +96,7 @@
         self.menubar.Append(menu, "&Settings")
 
         # The 'Settings' menu actions.
-        self.gui.Bind(wx.EVT_MENU, self.gui.settings,                  id=20)
+        self.gui.Bind(wx.EVT_MENU, self.gui.global_parameters,         id=20)
         self.gui.Bind(wx.EVT_MENU, self.gui.free_file_format_settings, id=21)
         self.gui.Bind(wx.EVT_MENU, self.gui.reset_setting,             id=22)
 

Modified: 1.3/gui/relax_gui.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/relax_gui.py?rev=13013&r1=13012&r2=13013&view=diff
==============================================================================
--- 1.3/gui/relax_gui.py (original)
+++ 1.3/gui/relax_gui.py Tue Jun 14 19:30:46 2011
@@ -60,7 +60,7 @@
 from gui import paths
 from references import References
 from relax_prompt import Prompt
-from settings import Free_file_format, load_sequence, relax_global_settings
+from settings import Free_file_format, Global_params, load_sequence
 from user_functions import User_functions
 
 
@@ -81,13 +81,8 @@
     def __init__(self, parent=None, id=-1, title="", script=None):
         """Initialise the main relax GUI frame."""
 
-        # The window style.
-        style = wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION 
| wx.CLIP_CHILDREN
-        if status.debug:
-            style = wx.DEFAULT_FRAME_STYLE
-
         # Execute the base class __init__ method.
-        super(Main, self).__init__(parent=parent, id=id, title=title, 
style=style)
+        super(Main, self).__init__(parent=parent, id=id, title=title, 
style=wx.DEFAULT_FRAME_STYLE)
 
         # Set up the frame.
         self.Layout()
@@ -495,6 +490,20 @@
         win.Show()
 
 
+    def global_parameters(self, event):
+        """Open the global parameters window.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Build the window.
+        win = Global_params(self)
+
+        # Show the window.
+        win.Show()
+
+
     def references(self, event):
         """Display the references relevant for relax.
 
@@ -537,17 +546,9 @@
 
 
     def reset_setting(self, event): #reset all settings
-        global global_setting #import global variable
         if question('Do you realy want to change relax settings?'):
             ds.relax_gui.global_setting = ['1.02 * 1e-10', '-172 * 1e-6', 
'N', 'H', '11', 'newton', '500']
             ds.relax_gui.free_file_format.reset()
-
-
-    def settings(self, event): # set up for relax variables
-        tmp_global = relax_global_settings(ds.relax_gui.global_setting)
-        if not tmp_global == None:
-            if question('Do you realy want to change relax settings?'):
-                ds.relax_gui.global_setting = tmp_global
 
 
     def setup_fonts(self):

Modified: 1.3/gui/settings.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/settings.py?rev=13013&r1=13012&r2=13013&view=diff
==============================================================================
--- 1.3/gui/settings.py (original)
+++ 1.3/gui/settings.py Tue Jun 14 19:30:46 2011
@@ -37,16 +37,6 @@
 from gui.user_functions.base import UF_window
 
 
-def relax_global_settings(oldsettings):
-    global settings
-    global old_settings
-    settings = []
-    old_settings = oldsettings
-    set_relax_params = Globalparam(None, -1, "")
-    set_relax_params.ShowModal()
-    return settings
-
-
 def load_sequence():
     """GUI element for loading the sequence file."""
 
@@ -244,106 +234,128 @@
 
 
 
-class Globalparam(wx.Dialog):
-    def __init__(self, *args, **kwds):
-        # begin globalparam.__init__
-        kwds["style"] = wx.DEFAULT_FRAME_STYLE
-        wx.Dialog.__init__(self, *args, **kwds)
-        self.label_1_copy = wx.StaticText(self, -1, "Set the parameters for 
optimisation")
-        self.bitmap_1_copy = wx.StaticBitmap(self, -1, 
wx.Bitmap(paths.IMAGE_PATH+'relax.gif', wx.BITMAP_TYPE_ANY))
-        self.label_2_copy = wx.StaticText(self, -1, "Bond length")
-        self.bond = wx.TextCtrl(self, -1, old_settings[0])
-        self.label_3_copy = wx.StaticText(self, -1, "Chemical shift 
anisotropy (CSA)")
-        self.csa = wx.TextCtrl(self, -1, old_settings[1])
-        self.label_5_copy = wx.StaticText(self, -1, "Heteronucleus name")
-        self.hetero = wx.TextCtrl(self, -1, old_settings[2])
-        self.label_6_copy = wx.StaticText(self, -1, "Proton name")
-        self.prot = wx.TextCtrl(self, -1, old_settings[3])
-        self.label_9_copy = wx.StaticText(self, -1, "Grid search increments")
-        self.grid = wx.TextCtrl(self, -1, old_settings[4])
-        self.label_7_copy = wx.StaticText(self, -1, "Minimisation algorithm")
-        self.minim = wx.TextCtrl(self, -1, old_settings[5])
-        self.label_8_copy = wx.StaticText(self, -1, "Monte Carlo simulation 
number")
-        self.monte = wx.TextCtrl(self, -1, old_settings[6])
-        self.ok_copy = wx.Button(self, -1, "Ok")
-        self.cancel_copy = wx.Button(self, -1, "Cancel")
-
-        self.__set_properties()
-        self.__do_layout()
-
-        self.Bind(wx.EVT_BUTTON, self.accept_settings, self.ok_copy)
-        self.Bind(wx.EVT_BUTTON, self.cancel_settings, self.cancel_copy)
-        self.Bind(wx.EVT_CLOSE, self.cancel_settings)
-
-
-    def __do_layout(self):
-        # begin  globalparam.__do_layout
-        sizer_1_copy = wx.BoxSizer(wx.VERTICAL)
-        grid_sizer_1_copy = wx.FlexGridSizer(8, 2, 0, 0)
-        sizer_1_copy.Add(self.label_1_copy, 0, 
wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
-        sizer_1_copy.Add(self.bitmap_1_copy, 0, 
wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
-        grid_sizer_1_copy.Add(self.label_2_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.bond, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_3_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.csa, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_5_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.hetero, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_6_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.prot, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_9_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.grid, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_7_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.minim, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.Add(self.label_8_copy, 1, wx.LEFT, 5)
-        grid_sizer_1_copy.Add(self.monte, 1, wx.EXPAND, 0)
-        grid_sizer_1_copy.AddGrowableCol(1)
-        sizer_1_copy.Add(grid_sizer_1_copy, 1, wx.EXPAND|wx.ALL, 5)
-        sizer2 = wx.BoxSizer(wx.HORIZONTAL)
-        sizer2.Add(self.ok_copy, 0, wx.ALL|wx.ALIGN_RIGHT, 5)
-        sizer2.Add(self.cancel_copy, 0, wx.ALL, 5)
-        sizer_1_copy.Add(sizer2, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
-        self.SetSizer(sizer_1_copy)
-        sizer_1_copy.Fit(self)
-        self.Layout()
-
-
-    def __set_properties(self):
-        # begin globalparam.__set_properties
-        self.SetTitle("Global parameters")
-
-        # Disable icon if running on a Mac
-        if not 'darwin' in sys.platform:
-            _icon = wx.EmptyIcon()
-            
_icon.CopyFromBitmap(wx.Bitmap(paths.IMAGE_PATH+'relax_start.gif', 
wx.BITMAP_TYPE_ANY))
-            self.SetIcon(_icon)
-
-        self.label_1_copy.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, 
wx.BOLD, 0, ""))
-        self.bond.SetMinSize((250, 27))
-        self.csa.SetMinSize((250, 27))
-        self.hetero.SetMinSize((250, 27))
-        self.prot.SetMinSize((250, 27))
-        self.grid.SetMinSize((250, 27))
-        self.minim.SetMinSize((250, 27))
-        self.label_8_copy.SetMinSize((250, 17))
-        self.monte.SetMinSize((250, 27))
-
-
-    def accept_settings(self, event): # change settings
-        global settings
-        settings = []
-        settings.append(str(self.bond.GetValue()))
-        settings.append(str(self.csa.GetValue()))
-        settings.append(str(self.hetero.GetValue()))
-        settings.append(str(self.prot.GetValue()))
-        settings.append(str(self.grid.GetValue()))
-        settings.append(str(self.minim.GetValue()))
-        settings.append(str(self.monte.GetValue()))
+class Global_params(Base_window):
+    """The global parameters setting window."""
+
+    # The window size.
+    SIZE = (500, 550)
+
+    def __init__(self, parent=None):
+        """Set up the window."""
+
+        # The sizes.
+        self.main_size = self.SIZE[0] - 2*self.BORDER
+        self.div_left = self.main_size / 2
+
+        # Execute the base __init__() method.
+        super(Global_params, self).__init__(parent=parent, id=-1, 
title="Global settings", heading="Global settings")
+
+
+    def add_centre(self, sizer):
+        """Add the centre of the free file format settings window.
+
+        @param sizer:   A sizer object.
+        @type sizer:    wx.Sizer instance
+        """
+
+        # The widget.
+        self.settings(sizer, save=False)
+
+        # Spacing.
+        self.main_sizer.AddStretchSpacer()
+
+
+    def settings(self, sizer, save=True):
+        """Build the free format file settings widget.
+
+        @param sizer:       The sizer to put the input field into.
+        @type sizer:        wx.Sizer instance
+        @keyword save:      A flag which if True will cause the save button 
to be displayed.
+        @type save:         bool
+        """
+
+        # A static box to hold all the widgets.
+        box = wx.StaticBox(self, -1, "Set the parameters for optimisation")
+
+        # Init.
+        sub_sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+        sub_sizer.AddSpacer(10)
+        divider = self.div_left - 15
+        padding = 10
+        spacer = 3
+
+        # The columns.
+        self.bond = self.input_field(sub_sizer, "Bond length:", 
divider=divider, padding=padding, spacer=spacer)
+        self.csa = self.input_field(sub_sizer, "Chemical shift anisotropy 
(CSA):", divider=divider, padding=padding, spacer=spacer)
+        self.hetero = self.input_field(sub_sizer, "Heteronucleus name:", 
divider=divider, padding=padding, spacer=spacer)
+        self.prot = self.input_field(sub_sizer, "Proton name:", 
divider=divider, padding=padding, spacer=spacer)
+        self.grid = self.input_field(sub_sizer, "Grid search increments:", 
divider=divider, padding=padding, spacer=spacer)
+        self.minim = self.input_field(sub_sizer, "Minimisation algorithm:", 
divider=divider, padding=padding, spacer=spacer)
+        self.monte = self.input_field(sub_sizer, "Monte Carlo simulation 
number:", divider=divider, padding=padding, spacer=spacer)
+
+        # Set the values.
+        self.bond.SetValue(int_to_gui(ds.relax_gui.global_setting[0]))
+        self.csa.SetValue(int_to_gui(ds.relax_gui.global_setting[1]))
+        self.hetero.SetValue(int_to_gui(ds.relax_gui.global_setting[2]))
+        self.prot.SetValue(int_to_gui(ds.relax_gui.global_setting[3]))
+        self.grid.SetValue(int_to_gui(ds.relax_gui.global_setting[4]))
+        self.minim.SetValue(int_to_gui(ds.relax_gui.global_setting[5]))
+        self.monte.SetValue(int_to_gui(ds.relax_gui.global_setting[6]))
+
+        # Add a save button.
+        if save:
+            # A sizer.
+            button_sizer = wx.BoxSizer(wx.HORIZONTAL)
+
+            # Build the button.
+            button = buttons.ThemedGenBitmapTextButton(self, -1, None, "  
Save")
+            button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.save, 
wx.BITMAP_TYPE_ANY))
+            button.SetToolTipString("Save the free file format settings 
within the relax data store")
+
+            # Add the button.
+            button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0)
+
+            # Right padding.
+            button_sizer.AddSpacer(padding)
+
+            # Bind the click event.
+            self.Bind(wx.EVT_BUTTON, self.save, button)
+
+            # Add the button sizer to the widget (with spacing).
+            sub_sizer.AddSpacer(10-spacer)
+            sub_sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT|wx.ALL, 0)
+
+        # Set the size of the widget.
+        sub_sizer.AddSpacer(10)
+        x, y = box.GetSize()
+        box.SetMinSize((self.main_size, y))
+
+        # The border of the widget.
+        border = wx.BoxSizer()
+
+        # Place the box sizer inside the border.
+        border.Add(sub_sizer, 1, wx.ALL|wx.EXPAND, 0)
+
+        # Add to the main sizer (followed by stretchable spacing).
+        sizer.Add(border, 0, wx.EXPAND)
+        sizer.AddStretchSpacer()
+
+
+    def save(self, event):
+        """Save the free file format widget contents into the relax data 
store.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Get the values.
+        ds.relax_gui.global_setting[0] = str(self.bond.GetValue())
+        ds.relax_gui.global_setting[1] = str(self.csa.GetValue())
+        ds.relax_gui.global_setting[2] = str(self.hetero.GetValue())
+        ds.relax_gui.global_setting[3] = str(self.prot.GetValue())
+        ds.relax_gui.global_setting[4] = str(self.grid.GetValue())
+        ds.relax_gui.global_setting[5] = str(self.minim.GetValue())
+        ds.relax_gui.global_setting[6] = str(self.monte.GetValue())
+
+        # Destroy the window.
         self.Destroy()
-        event.Skip()
-
-
-    def cancel_settings(self, event): # do not change settings
-        global settings
-        settings = None
-        self.Destroy()
-        event.Skip()




Related Messages


Powered by MHonArc, Updated Tue Jun 14 19:40:02 2011