commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 09/15: grc: move FileParam to gui module


From: git
Subject: [Commit-gnuradio] [gnuradio] 09/15: grc: move FileParam to gui module
Date: Thu, 10 Apr 2014 19:38:18 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

trondeau pushed a commit to branch master
in repository gnuradio.

commit 07ffd6eb2f4a47d8bd5088588465f5d54423e4ec
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Apr 9 18:16:43 2014 +0200

    grc: move FileParam to gui module
---
 grc/gui/Param.py    | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 grc/python/Param.py | 44 --------------------------------------------
 2 files changed, 48 insertions(+), 46 deletions(-)

diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index f0e5a2f..7d59708 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -23,6 +23,7 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 import Colors
+import os
 
 class InputParam(gtk.HBox):
     """The base class for an input parameter inside the input parameters 
dialog."""
@@ -130,6 +131,44 @@ class EnumEntryParam(InputParam):
             self._input.get_child().modify_base(gtk.STATE_NORMAL, 
Colors.ENTRYENUM_CUSTOM_COLOR)
             self._input.get_child().modify_text(gtk.STATE_NORMAL, 
Colors.PARAM_ENTRY_TEXT_COLOR)
 
+
+class FileParam(EntryParam):
+    """Provide an entry box for filename and a button to browse for a file."""
+
+    def __init__(self, *args, **kwargs):
+        EntryParam.__init__(self, *args, **kwargs)
+        input = gtk.Button('...')
+        input.connect('clicked', self._handle_clicked)
+        self.pack_start(input, False)
+
+    def _handle_clicked(self, widget=None):
+        """
+        If the button was clicked, open a file dialog in open/save format.
+        Replace the text in the entry with the new filename from the file 
dialog.
+        """
+        #get the paths
+        file_path = self.param.is_valid() and self.param.get_evaluated() or ''
+        (dirname, basename) = os.path.isfile(file_path) and 
os.path.split(file_path) or (file_path, '')
+        if not os.path.exists(dirname): dirname = os.getcwd() #fix bad paths
+        #build the dialog
+        if self.param.get_type() == 'file_open':
+            file_dialog = gtk.FileChooserDialog('Open a Data File...', None,
+                gtk.FILE_CHOOSER_ACTION_OPEN, 
('gtk-cancel',gtk.RESPONSE_CANCEL,'gtk-open',gtk.RESPONSE_OK))
+        elif self.param.get_type() == 'file_save':
+            file_dialog = gtk.FileChooserDialog('Save a Data File...', None,
+                gtk.FILE_CHOOSER_ACTION_SAVE, 
('gtk-cancel',gtk.RESPONSE_CANCEL, 'gtk-save',gtk.RESPONSE_OK))
+            file_dialog.set_do_overwrite_confirmation(True)
+            file_dialog.set_current_name(basename) #show the current filename
+        file_dialog.set_current_folder(dirname) #current directory
+        file_dialog.set_select_multiple(False)
+        file_dialog.set_local_only(True)
+        if gtk.RESPONSE_OK == file_dialog.run(): #run the dialog
+            file_path = file_dialog.get_filename() #get the file path
+            self._input.set_text(file_path)
+            self._handle_changed()
+        file_dialog.destroy() #destroy the dialog
+
+
 PARAM_MARKUP_TMPL="""\
 #set $foreground = $param.is_valid() and 'black' or 'red'
 <span foreground="$foreground" font_desc="Sans 
7.5"><b>$encode($param.get_name()): </b>$encode(repr($param))</span>"""
@@ -179,8 +218,15 @@ class Param(Element):
         Returns:
             gtk input class
         """
-        if self.is_enum(): return EnumParam(self, *args, **kwargs)
-        if self.get_options(): return EnumEntryParam(self, *args, **kwargs)
+        if self.get_type() in ('file_open', 'file_save'):
+            return FileParam(self, *args, **kwargs)
+
+        elif self.is_enum():
+            return EnumParam(self, *args, **kwargs)
+
+        elif self.get_options():
+            return EnumEntryParam(self, *args, **kwargs)
+
         return EntryParam(self, *args, **kwargs)
 
     def get_markup(self):
diff --git a/grc/python/Param.py b/grc/python/Param.py
index 3daa37f..3d9e52e 100644
--- a/grc/python/Param.py
+++ b/grc/python/Param.py
@@ -19,13 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
MA  02110-1301, USA
 
 from .. base.Param import Param as _Param
 from .. gui.Param import Param as _GUIParam
-from .. gui.Param import EntryParam
 import Constants
 import numpy
-import os
-import pygtk
-pygtk.require('2.0')
-import gtk
 from gnuradio import eng_notation
 import re
 from gnuradio import gr
@@ -33,41 +28,6 @@ from gnuradio import gr
 _check_id_matcher = re.compile('^[a-z|A-Z]\w*$')
 _show_id_matcher = re.compile('^(variable\w*|parameter|options|notebook)$')
 
-class FileParam(EntryParam):
-    """Provide an entry box for filename and a button to browse for a file."""
-
-    def __init__(self, *args, **kwargs):
-        EntryParam.__init__(self, *args, **kwargs)
-        input = gtk.Button('...')
-        input.connect('clicked', self._handle_clicked)
-        self.pack_start(input, False)
-
-    def _handle_clicked(self, widget=None):
-        """
-        If the button was clicked, open a file dialog in open/save format.
-        Replace the text in the entry with the new filename from the file 
dialog.
-        """
-        #get the paths
-        file_path = self.param.is_valid() and self.param.get_evaluated() or ''
-        (dirname, basename) = os.path.isfile(file_path) and 
os.path.split(file_path) or (file_path, '')
-        if not os.path.exists(dirname): dirname = os.getcwd() #fix bad paths
-        #build the dialog
-        if self.param.get_type() == 'file_open':
-            file_dialog = gtk.FileChooserDialog('Open a Data File...', None,
-                gtk.FILE_CHOOSER_ACTION_OPEN, 
('gtk-cancel',gtk.RESPONSE_CANCEL,'gtk-open',gtk.RESPONSE_OK))
-        elif self.param.get_type() == 'file_save':
-            file_dialog = gtk.FileChooserDialog('Save a Data File...', None,
-                gtk.FILE_CHOOSER_ACTION_SAVE, 
('gtk-cancel',gtk.RESPONSE_CANCEL, 'gtk-save',gtk.RESPONSE_OK))
-            file_dialog.set_do_overwrite_confirmation(True)
-            file_dialog.set_current_name(basename) #show the current filename
-        file_dialog.set_current_folder(dirname) #current directory
-        file_dialog.set_select_multiple(False)
-        file_dialog.set_local_only(True)
-        if gtk.RESPONSE_OK == file_dialog.run(): #run the dialog
-            file_path = file_dialog.get_filename() #get the file path
-            self._input.set_text(file_path)
-            self._handle_changed()
-        file_dialog.destroy() #destroy the dialog
 
 #blacklist certain ids, its not complete, but should help
 import __builtin__
@@ -162,10 +122,6 @@ class Param(_Param, _GUIParam):
         ##################################################
         return _truncate(dt_str, truncate)
 
-    def get_input(self, *args, **kwargs):
-        if self.get_type() in ('file_open', 'file_save'): return 
FileParam(self, *args, **kwargs)
-        return _GUIParam.get_input(self, *args, **kwargs)
-
     def get_color(self):
         """
         Get the color that represents this param's type.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]