[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 03/05: grc: new param type 'multiline' for
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 03/05: grc: new param type 'multiline' for comment entry box |
Date: |
Sat, 4 Apr 2015 17:45:40 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 63e66a352e773557258fd6159363eb08c1fd1355
Author: Sebastian Koslowski <address@hidden>
Date: Tue Mar 24 15:51:33 2015 +0100
grc: new param type 'multiline' for comment entry box
---
grc/base/Block.py | 2 +-
grc/gui/Param.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++----
grc/gui/PropsDialog.py | 8 ++++++--
grc/python/Param.py | 22 ++++++++++-----------
4 files changed, 66 insertions(+), 19 deletions(-)
diff --git a/grc/base/Block.py b/grc/base/Block.py
index 5670d11..cadff12 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -189,7 +189,7 @@ class Block(Element):
block=self,
n=odict({'name': 'Comment',
'key': 'comment',
- 'type': 'string',
+ 'type': 'multiline',
'hide': 'part',
'value': '',
'tab': ADVANCED_PARAM_TAB
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 3ea1e4d..7933973 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -26,8 +26,10 @@ import gtk
import Colors
import os
+
class InputParam(gtk.HBox):
"""The base class for an input parameter inside the input parameters
dialog."""
+ expand = False
def __init__(self, param, changed_callback=None, editing_callback=None):
gtk.HBox.__init__(self)
@@ -123,6 +125,42 @@ class EntryParam(InputParam):
except AttributeError:
pass # no tooltips for old GTK
+
+class MultiLineEntryParam(InputParam):
+ """Provide an multi-line box for strings."""
+ expand = True
+
+ def __init__(self, *args, **kwargs):
+ InputParam.__init__(self, *args, **kwargs)
+ self._buffer = gtk.TextBuffer()
+ self._buffer.set_text(self.param.get_value())
+ self._buffer.connect('changed', self._mark_changed)
+
+ self._view = gtk.TextView(self._buffer)
+ self._view.connect('focus-out-event', self._apply_change)
+ self._view.connect('key-press-event', self._handle_key_press)
+
+ self._sw = gtk.ScrolledWindow()
+ self._sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ self._sw.add_with_viewport(self._view)
+
+ self.pack_start(self._sw, True)
+
+ def get_text(self):
+ return self._buffer.get_text(self._buffer.get_start_iter(),
+ self._buffer.get_end_iter()).strip()
+
+ def set_color(self, color):
+ self._view.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
+ self._view.modify_text(gtk.STATE_NORMAL, Colors.PARAM_ENTRY_TEXT_COLOR)
+
+ def set_tooltip_text(self, text):
+ try:
+ self._view.set_tooltip_text(text)
+ except AttributeError:
+ pass # no tooltips for old GTK
+
+
class EnumParam(InputParam):
"""Provide an entry box for Enum types with a drop down menu."""
@@ -248,6 +286,7 @@ Error:
#end for
#end if"""
+
class Param(Element):
"""The graphical parameter."""
@@ -264,15 +303,21 @@ class Param(Element):
gtk input class
"""
if self.get_type() in ('file_open', 'file_save'):
- return FileParam(self, *args, **kwargs)
+ input_widget = FileParam(self, *args, **kwargs)
elif self.is_enum():
- return EnumParam(self, *args, **kwargs)
+ input_widget = EnumParam(self, *args, **kwargs)
elif self.get_options():
- return EnumEntryParam(self, *args, **kwargs)
+ input_widget = EnumEntryParam(self, *args, **kwargs)
+
+ elif self.get_type() == 'multiline':
+ input_widget = MultiLineEntryParam(self, *args, **kwargs)
+
+ else:
+ input_widget = EntryParam(self, *args, **kwargs)
- return EntryParam(self, *args, **kwargs)
+ return input_widget
def get_markup(self):
"""
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index 1045cfb..083e42d 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -169,7 +169,8 @@ class PropsDialog(gtk.Dialog):
if param.get_hide() == 'all':
continue
box_all_valid = box_all_valid and param.is_valid()
- vbox.pack_start(param.get_input(self._handle_changed,
self._activate_apply), False)
+ input_widget = param.get_input(self._handle_changed,
self._activate_apply)
+ vbox.pack_start(input_widget, input_widget.expand)
label.set_markup(Utils.parse_template(TAB_LABEL_MARKUP_TMPL,
valid=box_all_valid, tab=tab))
#show params box with new params
vbox.show_all()
@@ -191,7 +192,10 @@ class PropsDialog(gtk.Dialog):
Returns:
false to forward the keypress
"""
- if event.keyval == gtk.keysyms.Return and event.state &
gtk.gdk.CONTROL_MASK == 0:
+ if (event.keyval == gtk.keysyms.Return and
+ event.state & gtk.gdk.CONTROL_MASK == 0 and
+ not isinstance(widget.get_focus(), gtk.TextView)
+ ):
self.response(gtk.RESPONSE_ACCEPT)
return True # handled here
return False # forward the keypress
diff --git a/grc/python/Param.py b/grc/python/Param.py
index 827355d..0e72fcb 100644
--- a/grc/python/Param.py
+++ b/grc/python/Param.py
@@ -57,7 +57,7 @@ class Param(_Param, _GUIParam):
'complex', 'real', 'float', 'int',
'complex_vector', 'real_vector', 'float_vector', 'int_vector',
'hex', 'string', 'bool',
- 'file_open', 'file_save',
+ 'file_open', 'file_save', 'multiline',
'id', 'stream_id',
'grid_pos', 'notebook', 'gui_hint',
'import',
@@ -206,14 +206,6 @@ class Param(_Param, _GUIParam):
self._lisitify_flag = False
self._stringify_flag = False
self._hostage_cells = list()
- def eval_string(v):
- try:
- e = self.get_parent().get_parent().evaluate(v)
- if isinstance(e, str): return e
- raise Exception #want to stringify
- except:
- self._stringify_flag = True
- return v
t = self.get_type()
v = self.get_value()
#########################
@@ -280,9 +272,15 @@ class Param(_Param, _GUIParam):
#########################
# String Types
#########################
- elif t in ('string', 'file_open', 'file_save'):
+ elif t in ('string', 'file_open', 'file_save', 'multiline'):
#do not check if file/directory exists, that is a runtime issue
- e = eval_string(v)
+ try:
+ e = self.get_parent().get_parent().evaluate(v)
+ if not isinstance(e, str):
+ raise Exception()
+ except:
+ self._stringify_flag = True
+ e = v
return str(e)
#########################
# Unique ID Type
@@ -413,7 +411,7 @@ class Param(_Param, _GUIParam):
"""
v = self.get_value()
t = self.get_type()
- if t in ('string', 'file_open', 'file_save'): #string types
+ if t in ('string', 'file_open', 'file_save', 'multiline'): #string
types
if not self._init: self.evaluate()
if self._stringify_flag: return '"%s"'%v.replace('"', '\"')
else: return v