mailr22229 - /trunk/gui/input_elements/file.py


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

Header


Content

Posted by edward on February 21, 2014 - 10:00:
Author: bugman
Date: Fri Feb 21 10:00:01 2014
New Revision: 22229

URL: http://svn.gna.org/viewcvs/relax?rev=22229&view=rev
Log:
Improved the behaviour of the multiple file selection GUI window.

The RelaxFileDialog GUI element is now initialised when the file selection 
button is clicked rather
than in the __init__() method.  The result of this change is that the current 
working directory is
dynamically changed in the RelaxFileDialog, hence if the directory is changed 
in one file selection
element, it will look like it is changed in all.


Modified:
    trunk/gui/input_elements/file.py

Modified: trunk/gui/input_elements/file.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/gui/input_elements/file.py?rev=22229&r1=22228&r2=22229&view=diff
==============================================================================
--- trunk/gui/input_elements/file.py (original)
+++ trunk/gui/input_elements/file.py Fri Feb 21 10:00:01 2014
@@ -65,6 +65,12 @@
         @type preview:              bool
         """
 
+        # Store the arguments.
+        self.default = default
+        self.parent = parent
+        self.wildcard = wildcard
+        self.style = style
+
         # A vertical sizer for the two elements of the file selection GUI 
elements and a spacer element.
         self.sizer = wx.BoxSizer(wx.VERTICAL)
 
@@ -76,7 +82,7 @@
 
         # The file index.
         desc = str_to_gui("%i:  " % (index+1))
-        text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
+        text = wx.StaticText(self.parent, -1, desc, style=wx.ALIGN_LEFT)
         text.SetFont(font.normal_bold)
         text.SetMinSize((35, -1))
         sub_sizer.Add(text, 0, 
wx.LEFT|wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
@@ -85,7 +91,7 @@
         sub_sizer.AddSpacer(width_spacer)
 
         # The input field.
-        self.field = wx.TextCtrl(parent, -1, default)
+        self.field = wx.TextCtrl(self.parent, -1, self.default)
         self.field.SetMinSize((-1, height_element))
         self.field.SetFont(font.normal)
         sub_sizer.Add(self.field, 1, 
wx.EXPAND|wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
@@ -93,15 +99,12 @@
         # A little spacing.
         sub_sizer.AddSpacer(width_spacer)
 
-        # The file selection object.
-        obj = RelaxFileDialog(parent, field=self.field, message="File 
selection", defaultFile=default, wildcard=wildcard, style=style)
-
         # The file selection button.
-        button = wx.BitmapButton(parent, -1, 
wx.Bitmap(fetch_icon('oxygen.actions.document-open', "16x16"), 
wx.BITMAP_TYPE_ANY))
+        button = wx.BitmapButton(self.parent, -1, 
wx.Bitmap(fetch_icon('oxygen.actions.document-open', "16x16"), 
wx.BITMAP_TYPE_ANY))
         button.SetMinSize((height_element, height_element))
         button.SetToolTipString("Select the file.")
         sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 
0)
-        parent.Bind(wx.EVT_BUTTON, obj.select_event, button)
+        self.parent.Bind(wx.EVT_BUTTON, self.select_file, button)
 
         # File preview.
         if preview:
@@ -109,11 +112,11 @@
             sub_sizer.AddSpacer(width_spacer)
 
             # The preview button.
-            button = wx.BitmapButton(parent, -1, 
wx.Bitmap(fetch_icon('oxygen.actions.document-preview', "16x16"), 
wx.BITMAP_TYPE_ANY))
+            button = wx.BitmapButton(self.parent, -1, 
wx.Bitmap(fetch_icon('oxygen.actions.document-preview', "16x16"), 
wx.BITMAP_TYPE_ANY))
             button.SetMinSize((height_element, height_element))
             button.SetToolTipString("Preview")
             sub_sizer.Add(button, 0, 
wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
-            parent.Bind(wx.EVT_BUTTON, self.preview_file, button)
+            self.parent.Bind(wx.EVT_BUTTON, self.preview_file, button)
 
         # Right padding.
         sub_sizer.AddSpacer(padding)
@@ -163,6 +166,22 @@
 
         # Open the file as text.
         open_file(file, force_text=True)
+
+
+    def select_file(self, event=None):
+        """Select a file.
+
+        @keyword event: The wx event.
+        @type event:    wx event
+        """
+
+        # The file selection object (initialised in this function and not 
__init__() so that the working directory is more logical).
+        dialog = RelaxFileDialog(self.parent, field=self.field, 
message="File selection", defaultFile=self.default, wildcard=self.wildcard, 
style=self.style)
+
+        # Show the dialog and catch if no file has been selected.
+        if status.show_gui:
+            dialog.select_event(event)
+
 
 
 




Related Messages


Powered by MHonArc, Updated Fri Feb 21 10:20:03 2014