[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8934 - in grc/trunk: notes src/grc_gnuradio src/grc_g
From: |
jblum |
Subject: |
[Commit-gnuradio] r8934 - in grc/trunk: notes src/grc_gnuradio src/grc_gnuradio/blocks/variables src/grc_gnuradio/data src/grc_gnuradio/wxgui |
Date: |
Fri, 18 Jul 2008 00:49:04 -0600 (MDT) |
Author: jblum
Date: 2008-07-18 00:49:02 -0600 (Fri, 18 Jul 2008)
New Revision: 8934
Added:
grc/trunk/src/grc_gnuradio/blocks/variables/variable_text_box.xml
Modified:
grc/trunk/notes/todo.txt
grc/trunk/src/grc_gnuradio/FlowGraph.py
grc/trunk/src/grc_gnuradio/blocks/variables/variable_chooser.xml
grc/trunk/src/grc_gnuradio/blocks/variables/variable_slider.xml
grc/trunk/src/grc_gnuradio/data/block_tree.xml
grc/trunk/src/grc_gnuradio/wxgui/__init__.py
grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py
Log:
text box variable control
Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt 2008-07-18 00:51:21 UTC (rev 8933)
+++ grc/trunk/notes/todo.txt 2008-07-18 06:49:02 UTC (rev 8934)
@@ -14,7 +14,10 @@
-block tree class
-dtd for external blocks
-hotkeys in action descriptions
--switch to generation of top_block and hier_block2 classes
+-variables dependent on variables that change
+-text box gui control
+-log slider gui control
+-remove dtd from all block wrappers, setup dtd in platform
############ Suggestions: ####################
-simple usrp
Modified: grc/trunk/src/grc_gnuradio/FlowGraph.py
===================================================================
--- grc/trunk/src/grc_gnuradio/FlowGraph.py 2008-07-18 00:51:21 UTC (rev
8933)
+++ grc/trunk/src/grc_gnuradio/FlowGraph.py 2008-07-18 06:49:02 UTC (rev
8934)
@@ -80,7 +80,7 @@
Get a list of all variables in this flow graph namespace.
@return a sorted list of variable blocks
"""
- variables = filter(lambda b: b.get_key() in ('variable',
'variable_slider', 'variable_chooser'), self.get_blocks())
+ variables = filter(lambda b: b.get_key() in ('variable',
'variable_slider', 'variable_chooser', 'variable_text_box'), self.get_blocks())
#map var id to variable block
id2var = dict([(var.get_id(), var) for var in variables])
#map var id to variable code
Modified: grc/trunk/src/grc_gnuradio/blocks/variables/variable_chooser.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/variables/variable_chooser.xml
2008-07-18 00:51:21 UTC (rev 8933)
+++ grc/trunk/src/grc_gnuradio/blocks/variables/variable_chooser.xml
2008-07-18 06:49:02 UTC (rev 8934)
@@ -15,7 +15,7 @@
#if $label.eval
label=$label,
#else
- label="$id",
+ label="$id",
#end if
index=$value_index,
choices=$choices,
Modified: grc/trunk/src/grc_gnuradio/blocks/variables/variable_slider.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/variables/variable_slider.xml
2008-07-18 00:51:21 UTC (rev 8933)
+++ grc/trunk/src/grc_gnuradio/blocks/variables/variable_slider.xml
2008-07-18 06:49:02 UTC (rev 8934)
@@ -2,7 +2,7 @@
<!DOCTYPE block SYSTEM "../block.dtd">
<!--
###################################################
-##Variable block: a grc variable with key, value, min, max, step
+##Variable Slider: a grc variable with key, value, min, max, step
###################################################
-->
<block>
@@ -15,7 +15,7 @@
#if $label.eval
label=$label,
#else
- label="$id",
+ label="$id",
#end if
value=$id,
min=$min,
Copied: grc/trunk/src/grc_gnuradio/blocks/variables/variable_text_box.xml (from
rev 8924, grc/trunk/src/grc_gnuradio/blocks/variables/variable_slider.xml)
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/variables/variable_text_box.xml
(rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/variables/variable_text_box.xml
2008-07-18 06:49:02 UTC (rev 8934)
@@ -0,0 +1,52 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Variable Text Box: a grc variable with key, value
+###################################################
+ -->
+<block>
+ <name>Variable Text Box</name>
+ <key>variable_text_box</key>
+ <make>$value
+_$(id)_control = grc_wxgui.text_box_control(
+ window=self.GetWin(),
+ callback=self.set_$(id),
+ #if $label.eval
+ label=$label,
+ #else
+ label="$id",
+ #end if
+ value=$id,
+)
+#set $grid_pos = $grid_pos.eval
+#if not grid_pos
+self.Add(_$(id)_control)
+#else
+self.GridAdd(_$(id)_control, $grid_pos[0], $grid_pos[1], $grid_pos[2],
$grid_pos[3])
+#end if</make>
+ <param>
+ <name>Label</name>
+ <key>label</key>
+ <value></value>
+ <type>string</type>
+ </param>
+ <param>
+ <name>Default Value</name>
+ <key>value</key>
+ <value>0</value>
+ <type>raw</type>
+ </param>
+ <param>
+ <name>Grid Position</name>
+ <key>grid_pos</key>
+ <value></value>
+ <type>grid_pos</type>
+ </param>
+ <doc>
+This block creates a variable with a text box. \
+Leave the label blank to use the variable id as the label.
+
+Use the Grid Position (row, column, row span, column span) to position the
graphical element in the window.
+ </doc>
+</block>
Modified: grc/trunk/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-07-18 00:51:21 UTC
(rev 8933)
+++ grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-07-18 06:49:02 UTC
(rev 8934)
@@ -239,6 +239,7 @@
<block>variable</block>
<block>variable_slider</block>
<block>variable_chooser</block>
+ <block>variable_text_box</block>
<block>variable_sink</block>
</cat>
<cat>
Modified: grc/trunk/src/grc_gnuradio/wxgui/__init__.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/__init__.py 2008-07-18 00:51:21 UTC
(rev 8933)
+++ grc/trunk/src/grc_gnuradio/wxgui/__init__.py 2008-07-18 06:49:02 UTC
(rev 8934)
@@ -24,6 +24,7 @@
radio_buttons_horizontal_control, \
radio_buttons_vertical_control, \
slider_horizontal_control, \
- slider_vertical_control
+ slider_vertical_control, \
+ text_box_control
from top_block_gui import top_block_gui
Modified: grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py 2008-07-18
00:51:21 UTC (rev 8933)
+++ grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py 2008-07-18
06:49:02 UTC (rev 8934)
@@ -1,49 +1,49 @@
# Copyright 2008 Free Software Foundation, Inc.
-#
+#
# This file is part of GNU Radio
-#
+#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
-#
+#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-#
+#
import wx
import sys
class LabelText(wx.StaticText):
"""Label text class for uniform labels among all controls."""
-
+
def __init__(self, window, label):
wx.StaticText.__init__(self, window, -1, str(label))
font = self.GetFont()
font.SetWeight(wx.FONTWEIGHT_BOLD)
- self.SetFont(font)
+ self.SetFont(font)
class _control_base(wx.BoxSizer):
"""Control base class"""
-
+
def __init__(self, window, callback):
self.window = window
self.callback = callback
- wx.BoxSizer.__init__(self, wx.VERTICAL)
-
+ wx.BoxSizer.__init__(self, wx.VERTICAL)
+
def get_window(self): return self.window
-
+
def call(self): return self.callback(self.get_value())
-
+
def get_value(self): raise NotImplementedError
-
+
class _chooser_control_base(_control_base):
"""House a drop down or radio buttons for variable control."""
@@ -65,14 +65,14 @@
self.index = index
self.choices = choices
self.labels = map(str, labels or choices)
- self._init()
-
+ self._init()
+
def _handle_changed(self, event=None):
"""!
A change is detected. Call the callback.
"""
try: self.call()
- except Exception, e: print >> sys.stderr, 'Error in exec
callback from handle changed.\n', e
+ except Exception, e: print >> sys.stderr, 'Error in exec
callback from handle changed.\n', e
def get_value(self):
"""!
@@ -80,7 +80,7 @@
@return one of the possible choices
"""
self._update()
- return self.choices[self.index]
+ return self.choices[self.index]
##############################################################################################
# Button Control
@@ -92,7 +92,7 @@
self.button = wx.Button(self.get_window(), -1,
self.labels[self.index])
self.button.Bind(wx.EVT_BUTTON, self._handle_changed)
self.Add(self.button, 0, wx.ALIGN_CENTER)
-
+
def _update(self):
self.index = (self.index + 1)%len(self.choices) #circularly
increment index
self.button.SetLabel(self.labels[self.index])
@@ -106,9 +106,9 @@
def _init(self):
self.drop_down = wx.Choice(self.get_window(), -1,
choices=self.labels)
self.Add(self.drop_down, 0, wx.ALIGN_CENTER)
- self.drop_down.Bind(wx.EVT_CHOICE, self._handle_changed)
+ self.drop_down.Bind(wx.EVT_CHOICE, self._handle_changed)
self.drop_down.SetSelection(self.index)
-
+
def _update(self):
self.index = self.drop_down.GetSelection()
@@ -134,9 +134,9 @@
radio_button.Bind(wx.EVT_RADIOBUTTON,
self._handle_changed)
#set one radio button active
self.radio_buttons[self.index].SetValue(True)
-
+
def _update(self):
- selected_radio_button = filter(lambda rb: rb.GetValue(),
self.radio_buttons)[0]
+ selected_radio_button = filter(lambda rb: rb.GetValue(),
self.radio_buttons)[0]
self.index = self.radio_buttons.index(selected_radio_button)
class radio_buttons_horizontal_control(_radio_buttons_control_base):
@@ -151,7 +151,7 @@
##############################################################################################
class _slider_control_base(_control_base):
"""House a Slider and a Text Box for variable control."""
-
+
def __init__(self, window, callback, label='Label', value=50, min=0,
max=100, num_steps=100):
"""!
Slider contructor.
@@ -170,70 +170,112 @@
self.max = float(max)
self.num_steps = int(num_steps)
#create gui elements
- label_text_sizer = wx.BoxSizer(self.label_text_orientation)
#label and text box container
- label_text = LabelText(self.get_window(), '%s%s'%(str(label),
self.ptr))
+ label_text_sizer = wx.BoxSizer(self.label_text_orientation)
#label and text box container
+ label_text = LabelText(self.get_window(), '%s: '%str(label))
self.text_box = text_box = wx.TextCtrl(self.get_window(), -1,
str(value), style=wx.TE_PROCESS_ENTER)
- text_box.Bind(wx.EVT_TEXT_ENTER, self._handle_enter) #bind
this special enter hotkey event
- for obj in (label_text, text_box): #fill the container
with label and text entry box
+ text_box.Bind(wx.EVT_TEXT_ENTER, self._handle_enter) #bind this
special enter hotkey event
+ for obj in (label_text, text_box): #fill the container with
label and text entry box
label_text_sizer.Add(obj, 0,
wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
self.Add(label_text_sizer, 0, wx.ALIGN_CENTER)
#make the slider
- self.slider = slider = wx.Slider(self.get_window(), -1,
size=wx.Size(*self.slider_size), style=self.slider_style)
+ self.slider = slider = wx.Slider(self.get_window(), -1,
size=wx.Size(*self.slider_size), style=self.slider_style)
try: slider.SetRange(0, num_steps)
except Exception, e:
print >> sys.stderr, 'Error in set slider range:
"%s".'%e
sys.exit(-1)
- slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the
scrolling event
+ slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the
scrolling event
self.Add(slider, 0, wx.ALIGN_CENTER)
#init slider and text box
self._value = value
- self._set_slider_value(self._value)#sets the slider's value
+ self._set_slider_value(self._value) #sets the slider's value
self.text_box.SetValue(str(self._value))
-
+
def get_value(self):
"""!
Get the current set value.
@return the value (float)
"""
return self._value
-
+
def _set_slider_value(self, real_value):
"""!
- Translate the real numerical value into a slider value and,
+ Translate the real numerical value into a slider value and,
write the value to the slider.
@param real_value the numeric value the slider should represent
- """
+ """
slider_value = (float(real_value) -
self.min)*self.num_steps/(self.max - self.min)
self.slider.SetValue(slider_value)
-
+
def _handle_scroll(self, event=None):
"""!
A scroll event is detected. Read the slider, call the callback.
"""
- slider_value = self.slider.GetValue()
+ slider_value = self.slider.GetValue()
new_value = slider_value*(self.max - self.min)/self.num_steps +
self.min
self.text_box.SetValue(str(new_value))
self._value = new_value
try: self.call()
except Exception, e: print >> sys.stderr, 'Error in exec
callback from handle scroll.\n', e
-
+
def _handle_enter(self, event=None):
"""!
An enter key was pressed. Read the text box, call the callback.
- """
+ """
new_value = float(self.text_box.GetValue())
self._set_slider_value(new_value)
self._value = new_value
try: self.call()
except Exception, e: print >> sys.stderr, 'Error in exec
callback from handle enter.\n', e
-
+
class slider_horizontal_control(_slider_control_base):
label_text_orientation = wx.HORIZONTAL
slider_style = wx.SL_HORIZONTAL
slider_size = 200, 20
- ptr = ' -> '
class slider_vertical_control(_slider_control_base):
label_text_orientation = wx.VERTICAL
slider_style = wx.SL_VERTICAL
slider_size = 20, 200
- ptr = ''
+
+##############################################################################################
+# Text Box Control
+##############################################################################################
+class text_box_control(_control_base):
+ """House a Text Box for variable control."""
+
+ def __init__(self, window, callback, label='Label', value=50):
+ """!
+ Text box contructor.
+ Create the text box, and label.
+ @param window the wx parent window
+ @param callback call the callback on changes
+ @param label the label title
+ @param value the default value
+ """
+ #initialize
+ _control_base.__init__(self, window, callback)
+ #create gui elements
+ label_text_sizer = wx.BoxSizer(wx.HORIZONTAL) #label and text
box container
+ label_text = LabelText(self.get_window(), '%s: '%str(label))
+ self.text_box = text_box = wx.TextCtrl(self.get_window(), -1,
str(value), style=wx.TE_PROCESS_ENTER)
+ text_box.Bind(wx.EVT_TEXT_ENTER, self._handle_enter) #bind this
special enter hotkey event
+ for obj in (label_text, text_box): #fill the container with
label and text entry box
+ label_text_sizer.Add(obj, 0,
wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
+ self.Add(label_text_sizer, 0, wx.ALIGN_CENTER)
+ self.text_box.SetValue(str(value))
+
+ def get_value(self):
+ """!
+ Get the current set value.
+ @return the value (float)
+ """
+ return self._value
+
+ def _handle_enter(self, event=None):
+ """!
+ An enter key was pressed. Read the text box, call the callback.
+ If the text cannot be evaluated, do not try callback.
+ """
+ try: self._value = eval(self.text_box.GetValue())
+ except: return
+ try: self.call()
+ except Exception, e: print >> sys.stderr, 'Error in exec
callback from handle enter.\n', e
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8934 - in grc/trunk: notes src/grc_gnuradio src/grc_gnuradio/blocks/variables src/grc_gnuradio/data src/grc_gnuradio/wxgui,
jblum <=