summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grc/gui/Param.py50
-rw-r--r--grc/python/Param.py44
2 files changed, 48 insertions, 46 deletions
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index f0e5a2fcb2..7d59708abb 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 3daa37f637..3d9e52e25f 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.