Package gui :: Module settings
[hide private]
[frames] | no frames]

Source Code for Module gui.settings

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2009 Michael Bieri                                            # 
  4  # Copyright (C) 2010-2011 Edward d'Auvergne                                   # 
  5  #                                                                             # 
  6  # This file is part of the program relax.                                     # 
  7  #                                                                             # 
  8  # relax is free software; you can redistribute it and/or modify               # 
  9  # it under the terms of the GNU General Public License as published by        # 
 10  # the Free Software Foundation; either version 2 of the License, or           # 
 11  # (at your option) any later version.                                         # 
 12  #                                                                             # 
 13  # relax is distributed in the hope that it will be useful,                    # 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 16  # GNU General Public License for more details.                                # 
 17  #                                                                             # 
 18  # You should have received a copy of the GNU General Public License           # 
 19  # along with relax; if not, write to the Free Software                        # 
 20  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Python module imports. 
 25  from os import F_OK, access, path, sep 
 26  import sys 
 27  import wx 
 28   
 29  # relax module imports. 
 30  from data import Relax_data_store; ds = Relax_data_store() 
 31  from status import Status; status = Status() 
 32   
 33  # relax GUI module imports. 
 34  from gui.filedialog import RelaxFileDialog 
 35  from gui.fonts import font 
 36  from gui.icons import relax_icons 
 37  from gui.message import error_message 
 38  from gui.misc import gui_to_int, int_to_gui 
 39  from gui import paths 
 40  from gui.wizard import Wiz_page 
 41   
 42   
43 -def load_sequence():
44 """GUI element for loading the sequence file.""" 45 46 # The dialog. 47 dialog = RelaxFileDialog(parent=self, message='Select a sequence file', style=wx.FD_OPEN) 48 49 # Show the dialog and catch if no file has been selected. 50 if status.show_gui and dialog.ShowModal() != wx.ID_OK: 51 # Don't do anything. 52 return 53 54 # The file. 55 seqfile = dialog.get_file() 56 57 # Does not exist. 58 if not access(seqfile, F_OK): 59 error_message("The file '%s' does not exist." % seqfile) 60 return None 61 62 # Not a file. 63 if path.isdir(seqfile): 64 error_message("The selection '%s' is a directory, not a file." % seqfile) 65 return None 66 67 # Return the file. 68 return seqfile
69 70 71
72 -class Base_window(wx.Dialog):
73 """Base class for the settings windows.""" 74 75 # The window size. 76 SIZE = (600, 600) 77 78 # A border. 79 BORDER = 10 80 81 # Sizes. 82 SIZE_BUTTON = (100, 33) 83
84 - def __init__(self, parent=None, id=-1, title='', heading='', style=wx.DEFAULT_FRAME_STYLE):
85 """Set up the window.""" 86 87 # Execute the base __init__() method. 88 wx.Dialog.__init__(self, parent, id=id, title=title, style=style) 89 90 # Set up the window icon. 91 self.SetIcons(relax_icons) 92 93 # The main sizer. 94 self.main_sizer = self.build_frame() 95 96 # The heading. 97 text = wx.StaticText(self, -1, heading) 98 text.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, "")) 99 self.main_sizer.Add(text, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) 100 self.main_sizer.AddStretchSpacer() 101 102 # The relax logo. 103 bmp = wx.StaticBitmap(self, -1, wx.Bitmap(paths.IMAGE_PATH+'relax.gif', wx.BITMAP_TYPE_ANY)) 104 self.main_sizer.Add(bmp, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) 105 self.main_sizer.AddStretchSpacer() 106 107 # The centre section. 108 self.add_centre(self.main_sizer) 109 110 # The bottom buttons. 111 self.add_buttons(self.main_sizer) 112 113 # Set the window size. 114 self.SetSize(self.SIZE) 115 self.SetMinSize(self.SIZE) 116 117 # Centre the window. 118 self.Center()
119 120
121 - def add_buttons(self, sizer):
122 """Add the buttons to the sizer. 123 124 @param sizer: A sizer object. 125 @type sizer: wx.Sizer instance 126 """ 127 128 # Create a horizontal layout for the buttons. 129 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 130 sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0) 131 132 # The save button. 133 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Save") 134 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.save, wx.BITMAP_TYPE_ANY)) 135 button.SetFont(font.normal) 136 button.SetToolTipString("Save the free file format settings within the relax data store.") 137 button.SetMinSize(self.SIZE_BUTTON) 138 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 139 self.Bind(wx.EVT_BUTTON, self.save, button) 140 141 # Spacer. 142 button_sizer.AddSpacer(20) 143 144 # The reset button. 145 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Reset") 146 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.edit_delete, wx.BITMAP_TYPE_ANY)) 147 button.SetFont(font.normal) 148 button.SetToolTipString("Reset the free file format settings to the original values.") 149 button.SetMinSize(self.SIZE_BUTTON) 150 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 151 self.Bind(wx.EVT_BUTTON, self.reset, button) 152 153 # Spacer. 154 button_sizer.AddSpacer(20) 155 156 # The cancel button. 157 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Cancel") 158 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.dialog_cancel, wx.BITMAP_TYPE_ANY)) 159 button.SetFont(font.normal) 160 button.SetMinSize(self.SIZE_BUTTON) 161 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 162 self.Bind(wx.EVT_BUTTON, self.cancel, button)
163 164
165 - def add_centre(self, sizer):
166 """Dummy base class method for adding the centre of the settings window. 167 168 @param sizer: A sizer object. 169 @type sizer: wx.Sizer instance 170 """
171 172
173 - def build_frame(self):
174 """Create the main part of the frame, returning the central sizer.""" 175 176 # The sizers. 177 sizer1 = wx.BoxSizer(wx.HORIZONTAL) 178 sizer2 = wx.BoxSizer(wx.VERTICAL) 179 central_sizer = wx.BoxSizer(wx.VERTICAL) 180 181 # Left and right borders. 182 sizer1.AddSpacer(self.BORDER) 183 sizer1.Add(sizer2, 1, wx.EXPAND|wx.ALL, 0) 184 sizer1.AddSpacer(self.BORDER) 185 186 # Top and bottom borders. 187 sizer2.AddSpacer(self.BORDER) 188 sizer2.Add(central_sizer, 1, wx.EXPAND|wx.ALL, 0) 189 sizer2.AddSpacer(self.BORDER) 190 191 # Set the sizer for the frame. 192 self.SetSizer(sizer1) 193 194 # Return the central sizer. 195 return central_sizer
196 197
198 - def save(self, event):
199 """Dummy base class save method. 200 201 @param event: The wx event. 202 @type event: wx event 203 """ 204 205 # Destroy the window. 206 self.Destroy()
207 208
209 - def cancel(self, event):
210 """Close the window. 211 212 @param event: The wx event. 213 @type event: wx event 214 """ 215 216 # Destroy the window. 217 self.Destroy()
218 219 220
221 -class Free_file_format(Base_window, Wiz_page):
222 """The free file format setting window.""" 223 224 # The window size. 225 SIZE = (500, 550) 226
227 - def __init__(self, parent=None):
228 """Set up the window.""" 229 230 # The sizes. 231 self._main_size = self.SIZE[0] - 2*self.BORDER 232 self._div_left = self._main_size / 2 233 234 # Execute the base __init__() method. 235 super(Free_file_format, self).__init__(parent=parent, id=-1, title="Free file format", heading="Settings for the free file format")
236 237
238 - def add_centre(self, sizer):
239 """Add the centre of the free file format settings window. 240 241 @param sizer: A sizer object. 242 @type sizer: wx.Sizer instance 243 """ 244 245 # The widget. 246 self.free_file_format(sizer, data_cols=True, save=False, reset=False) 247 248 # Spacing. 249 self.main_sizer.AddStretchSpacer()
250 251
252 - def reset(self, event):
253 """Reset the free file format settings. 254 255 @param event: The wx event. 256 @type event: wx event 257 """ 258 259 # Execute the base class method. 260 self._free_file_format_reset(event)
261 262
263 - def save(self, event):
264 """Save the free file format widget contents into the relax data store. 265 266 @param event: The wx event. 267 @type event: wx event 268 """ 269 270 # Execute the base class method. 271 self._free_file_format_save(event) 272 273 # Destroy the window. 274 self.Destroy()
275