mailr14574 - in /1.3/gui: ./ analyses/ components/


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

Header


Content

Posted by edward on September 02, 2011 - 12:19:
Author: bugman
Date: Fri Sep  2 12:19:21 2011
New Revision: 14574

URL: http://svn.gna.org/viewcvs/relax?rev=14574&view=rev
Log:
Deleted the old gui.filedialog.opendir fn and replaced it with a specialised 
RelaxDirDialog class.

This class is more advanced in that it changes the Python working directory 
so that the user does
not have to always navigate back to the same place if relax is launched from 
a different directory.


Modified:
    1.3/gui/analyses/auto_model_free.py
    1.3/gui/analyses/auto_noe.py
    1.3/gui/analyses/auto_rx_base.py
    1.3/gui/components/grid.py
    1.3/gui/filedialog.py
    1.3/gui/relax_gui.py

Modified: 1.3/gui/analyses/auto_model_free.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/analyses/auto_model_free.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/analyses/auto_model_free.py (original)
+++ 1.3/gui/analyses/auto_model_free.py Fri Sep  2 12:19:21 2011
@@ -46,7 +46,7 @@
 from gui.analyses.execute import Execute
 from gui.base_classes import Container
 from gui.components.relax_data import Relax_data_list
-from gui.filedialog import opendir
+from gui.filedialog import RelaxDirDialog
 from gui.fonts import font
 from gui.message import error_message, Question, Missing_data
 from gui.misc import add_border, gui_to_int, gui_to_str, list_to_gui, 
protected_exec, str_to_gui
@@ -622,18 +622,24 @@
         @type event:    wx event
         """
 
-        # Store the original directory.
-        backup = self.field_results_dir.GetValue()
-
-        # Select the file.
-        self.data.save_dir = opendir('Select results directory', 
default=self.field_results_dir.GetValue())
-
-        # Restore the backup file if no file was chosen.
-        if not self.data.save_dir:
-            self.data.save_dir = backup
+        # The dialog.
+        dialog = RelaxDirDialog(parent=self, message='Select the results 
directory', defaultPath=self.field_results_dir.GetValue())
+
+        # Show the dialog and catch if no file has been selected.
+        if dialog.ShowModal() != wx.ID_OK:
+            # Don't do anything.
+            return
+
+        # The path (don't do anything if not set).
+        path = gui_to_str(dialog.get_path())
+        if not path:
+            return
+
+        # Store the path.
+        self.data.save_dir = path
 
         # Place the path in the text box.
-        self.field_results_dir.SetValue(str_to_gui(self.data.save_dir))
+        self.field_results_dir.SetValue(str_to_gui(path))
 
 
     def sync_ds(self, upload=False):

Modified: 1.3/gui/analyses/auto_noe.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/analyses/auto_noe.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/analyses/auto_noe.py (original)
+++ 1.3/gui/analyses/auto_noe.py Fri Sep  2 12:19:21 2011
@@ -43,7 +43,7 @@
 from gui.analyses.results_analysis import color_code_noe
 from gui.base_classes import Container
 from gui.components.spectrum import Spectra_list
-from gui.filedialog import opendir
+from gui.filedialog import RelaxDirDialog
 from gui.message import error_message, Missing_data
 from gui.misc import gui_to_str, protected_exec, str_to_gui
 from gui import paths
@@ -331,18 +331,24 @@
         @type event:    wx event
         """
 
-        # Store the original directory.
-        backup = self.field_results_dir.GetValue()
-
-        # Select the file.
-        self.data.save_dir = opendir('Select results directory', 
default=self.field_results_dir.GetValue())
-
-        # Restore the backup file if no file was chosen.
-        if not self.data.save_dir:
-            self.data.save_dir = backup
+        # The dialog.
+        dialog = RelaxDirDialog(parent=self, message='Select the results 
directory', defaultPath=self.field_results_dir.GetValue())
+
+        # Show the dialog and catch if no file has been selected.
+        if dialog.ShowModal() != wx.ID_OK:
+            # Don't do anything.
+            return
+
+        # The path (don't do anything if not set).
+        path = gui_to_str(dialog.get_path())
+        if not path:
+            return
+
+        # Store the path.
+        self.data.save_dir = path
 
         # Place the path in the text box.
-        self.field_results_dir.SetValue(str_to_gui(self.data.save_dir))
+        self.field_results_dir.SetValue(str_to_gui(path))
 
 
     def sync_ds(self, upload=False):

Modified: 1.3/gui/analyses/auto_rx_base.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/analyses/auto_rx_base.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/analyses/auto_rx_base.py (original)
+++ 1.3/gui/analyses/auto_rx_base.py Fri Sep  2 12:19:21 2011
@@ -43,7 +43,7 @@
 from gui.analyses.execute import Execute
 from gui.base_classes import Container
 from gui.components.spectrum import Spectra_list
-from gui.filedialog import opendir
+from gui.filedialog import RelaxDirDialog
 from gui.message import error_message, Missing_data
 from gui.misc import gui_to_int, gui_to_str, int_to_gui, protected_exec, 
str_to_gui
 from gui import paths
@@ -347,18 +347,24 @@
         @type event:    wx event
         """
 
-        # Store the original directory.
-        backup = self.field_results_dir.GetValue()
-
-        # Select the file.
-        self.data.save_dir = opendir('Select results directory', 
default=self.field_results_dir.GetValue())
-
-        # Restore the backup file if no file was chosen.
-        if not self.data.save_dir:
-            self.data.save_dir = backup
+        # The dialog.
+        dialog = RelaxDirDialog(parent=self, message='Select the results 
directory', defaultPath=self.field_results_dir.GetValue())
+
+        # Show the dialog and catch if no file has been selected.
+        if dialog.ShowModal() != wx.ID_OK:
+            # Don't do anything.
+            return
+
+        # The path (don't do anything if not set).
+        path = gui_to_str(dialog.get_path())
+        if not path:
+            return
+
+        # Store the path.
+        self.data.save_dir = path
 
         # Place the path in the text box.
-        self.field_results_dir.SetValue(str_to_gui(self.data.save_dir))
+        self.field_results_dir.SetValue(str_to_gui(path))
 
 
     def sync_ds(self, upload=False):

Modified: 1.3/gui/components/grid.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/components/grid.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/components/grid.py (original)
+++ 1.3/gui/components/grid.py Fri Sep  2 12:19:21 2011
@@ -35,7 +35,7 @@
 from status import Status; status = Status()
 
 # relax GUI module imports.
-from gui.filedialog import RelaxFileDialog, opendir
+from gui.filedialog import RelaxFileDialog
 from gui.fonts import font
 from gui.message import error_message
 from gui.misc import add_border, str_to_gui

Modified: 1.3/gui/filedialog.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/filedialog.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/filedialog.py (original)
+++ 1.3/gui/filedialog.py Fri Sep  2 12:19:21 2011
@@ -32,15 +32,54 @@
 from status import Status; status = Status()
 
 # relax GUI module imports.
-from gui.misc import str_to_gui
+from gui.misc import gui_to_str, str_to_gui
 
 
-def opendir(msg, default): # select directory, msg is message to display, 
default is starting directory
-    newdir = None
-    dlg = wx.DirDialog(None, message = msg, style=wx.DD_DEFAULT_STYLE | 
wx.DD_NEW_DIR_BUTTON, defaultPath = default)
-    if dlg.ShowModal() == wx.ID_OK:
-        newdir = dlg.GetPath()
-        return newdir
+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):
+        """Setup the class and store the field.
+
+        @param parent:          The parent wx window object.
+        @type parent:           Window
+        @keyword message:       The path selector prompt string.
+        @type message:          String
+        @keyword defaultPath:   The default directory to open in.
+        @type defaultPath:      String
+        @keyword style:         The dialog style.
+        @type style:            long
+        @keyword pos:           The window position.
+        @type pos:              Point
+        @keyword size:          The default window size.
+        @type size:             Size
+        @keyword name:          The title for the dialog.
+        @type name:             String
+        """
+
+        # No path supplied, so use the current working directory.
+        if defaultPath == wx.EmptyString:
+            defaultPath = getcwd()
+
+        # Initialise the base class.
+        super(RelaxDirDialog, self).__init__(parent, message=message, 
defaultPath=defaultPath, style=style, pos=pos, size=size, name=name)
+
+
+    def get_path(self):
+        """Return the selected path.
+
+        @return:        The name of the selected path.
+        @rtype:         str
+        """
+
+        # The path.
+        path = gui_to_str(self.GetPath())
+
+        # Change the current working directory.
+        chdir(path)
+
+        # Return the path.
+        return path
 
 
 

Modified: 1.3/gui/relax_gui.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/relax_gui.py?rev=14574&r1=14573&r2=14574&view=diff
==============================================================================
--- 1.3/gui/relax_gui.py (original)
+++ 1.3/gui/relax_gui.py Fri Sep  2 12:19:21 2011
@@ -53,7 +53,7 @@
 from gui.base_classes import Container
 from gui.spin_viewer.frame import Spin_view_window
 from gui.controller import Controller
-from gui.filedialog import RelaxFileDialog, opendir
+from gui.filedialog import RelaxFileDialog
 from gui.fonts import font
 from gui.icons import Relax_task_bar_icon, relax_icons
 from gui.interpreter import Interpreter




Related Messages


Powered by MHonArc, Updated Fri Sep 02 12:40:02 2011