[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7641 - in grc/branches/grc_reloaded/src/grc: elements
From: |
jblum |
Subject: |
[Commit-gnuradio] r7641 - in grc/branches/grc_reloaded/src/grc: elements gui gui/elements platforms/gnuradio_python platforms/gnuradio_python/blocks platforms/gnuradio_python/blocks/operators platforms/gnuradio_python/blocks/variables |
Date: |
Mon, 11 Feb 2008 23:16:50 -0700 (MST) |
Author: jblum
Date: 2008-02-11 23:16:49 -0700 (Mon, 11 Feb 2008)
New Revision: 7641
Modified:
grc/branches/grc_reloaded/src/grc/elements/Block.py
grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
grc/branches/grc_reloaded/src/grc/elements/Param.py
grc/branches/grc_reloaded/src/grc/elements/Platform.py
grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py
grc/branches/grc_reloaded/src/grc/gui/MainWindow.py
grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
grc/branches/grc_reloaded/src/grc/gui/SignalBlockSelectionWindow.py
grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
grc/branches/grc_reloaded/src/grc/gui/elements/Element.py
grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py
grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
Log:
blocks selection window and params dialog
Modified: grc/branches/grc_reloaded/src/grc/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-12 06:15:24 UTC
(rev 7640)
+++ grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-12 06:16:49 UTC
(rev 7641)
@@ -38,7 +38,6 @@
#grab the data
name = n['name']
key = n['key']
- cat = n['cat']
params = Utils.listify(n, 'param')
checks = Utils.listify(n, 'check')
sources = Utils.listify(n, 'source')
@@ -48,7 +47,6 @@
#store the data
self._name = name
self._key = key
- self._cat = cat
#create the param objects
self._params = odict()
#add the id param
@@ -115,6 +113,8 @@
def __str__(self): return 'Block: %s(%s)'%(self.get_name(),
self.get_key())
+ def get_id(self): return self.get_param('id').get_value()
+
def is_block(self): return True
def get_doc(self): return self._doc
@@ -123,8 +123,6 @@
def get_key(self): return self._key
- def get_category(self): return self._cat
-
def get_doc(self): return ''
##############################################
Modified: grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -69,7 +69,7 @@
@param key the block key
@return the new block or None if not found
"""
- #TODO implemnt None for bad key
+ if key not in self.get_parent().get_block_keys(): return None
block = self.get_parent().get_new_block(self, key)
self.get_elements().append(block)
return block
@@ -81,10 +81,13 @@
@param portb another port
@return the new connection or None for bad connection
"""
- #TODO implemnt None for bad connection
- connection = self.get_parent.Connection(self, porta, portb)
- self.get_elements().append(connection)
- return connection
+ try:
+ connection = self.get_parent.Connection(self, porta,
portb)
+ self.get_elements().append(connection)
+ return connection
+ except AssertionError:
+ #TODO messages print bad connection
+ return None
def remove_element(self, element):
"""!
@@ -143,6 +146,8 @@
Any blocks or connections in error will be ignored.
@param n the nested data odict
"""
+ #remove previous elements
+ self._elements = list()
#TODO error checking, also ignore options block
fg_n = n['flow_graph']
blocks_n = Utils.listify(fg_n, 'block')
@@ -150,7 +155,8 @@
#build the blocks
for block_n in blocks_n:
key = block_n['key']
- block = self.get_new_block(key)
+ if key == 'options': block = self._options_block
+ else: block = self.get_new_block(key)
block.import_data(block_n)
#build the connections
for connection_n in connections_n:
@@ -176,6 +182,7 @@
#build the connection
self.connect(source, sink)
except AssertionError: pass #TODO messages print problem
+ return []
Modified: grc/branches/grc_reloaded/src/grc/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-12 06:15:24 UTC
(rev 7640)
+++ grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-12 06:16:49 UTC
(rev 7641)
@@ -81,7 +81,7 @@
class Param(Element):
##possible param types
- TYPES = ['enum']
+ TYPES = ['enum', 'raw']
def __init__(self, block, n):
"""
@@ -171,6 +171,8 @@
def is_enum(self): return self._type == 'enum'
+ def is_type_dependent(self): return '$' in self._type
+
##############################################
# Access Options
##############################################
Modified: grc/branches/grc_reloaded/src/grc/elements/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -70,12 +70,20 @@
def get_new_flow_graph(self):
return self.FlowGraph(self)
+
+ def get_block_tree(self):
+ """
+ Get a tree containing all blocks and their categories.
+ @return the block tree
+ """
+ return self.BLOCK_TREE
##############################################
# Access Blocks
##############################################
def get_block_keys(self): return self._blocks.keys()
def get_block(self, key): return self._blocks[key]
+ def get_blocks(self): return self._blocks.values()
def get_new_block(self, flow_graph, key): return self.Block(flow_graph,
n=self._blocks_n[key])
def get_name(self): return self._name
Modified: grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -108,7 +108,7 @@
def _handle_window_expose(self, widget, event):
"""Called when the window initially appears or is resized:
create a new pixmap, draw the flow graph."""
#TODO remove set size
- self.set_size_request(400, 400)
+ self.set_size_request(800, 600)
self.gc = self.window.new_gc()
width, height = self.get_size_request()
if not self.pixmap or (width, height) !=
self.pixmap.get_size():
Modified: grc/branches/grc_reloaded/src/grc/gui/MainWindow.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/MainWindow.py 2008-02-12 06:15:24 UTC
(rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/MainWindow.py 2008-02-12 06:16:49 UTC
(rev 7641)
@@ -205,8 +205,7 @@
#create the side windows
side_box = gtk.VBox()
hbox.pack_start(side_box, False)
- #TODO side_box.pack_start(self.variable_modification_window,
False) #dont allow resize
- #TODO
side_box.pack_start(SignalBlockSelectionWindow(self.get_flow_graph)) #all
resize, selection window can have more space
+ side_box.pack_start(SignalBlockSelectionWindow(platform,
self.get_flow_graph)) #allow resize, selection window can have more space
#create the reports window
self.text_display = TextDisplay()
#house the reports in a scrolled window
@@ -382,6 +381,7 @@
)
#reports window
#TODO
self._show_reports_window(Preferences.show_reports_window())
+ self._show_reports_window(True)
def get_page(self):
"""!
Modified: grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
2008-02-12 06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/SignalBlockParamsDialog.py
2008-02-12 06:16:49 UTC (rev 7641)
@@ -24,43 +24,43 @@
pygtk.require('2.0')
import gtk
from Dialogs import TextDisplay
-from Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
+from grc.Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
class SignalBlockParamsDialog(gtk.Dialog):
"""A dialog box to set signal block parameters."""
- def __init__(self, signal_block):
+ def __init__(self, block):
"""!
SignalBlockParamsDialog contructor.
- @param signal_block the signal block
+ @param block the signal block
"""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
- self.signal_block = signal_block
- self.set_title('Properties: %s'%signal_block.get_id())
+ self.block = block
+ self.set_title('Properties: %s'%block.get_id())
self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
vbox = gtk.VBox()
- # Create the title label #
+ #Create the title label
label = gtk.Label()
- label.set_markup('\n<b>Parameters:
%s</b>\n'%self.signal_block.get_id())
+ label.set_markup('\n<b>Parameters:
%s</b>\n'%self.block.get_id())
vbox.pack_start(label, False)
- # Create the scrolled window to hold all the parameters #
+ #Create the scrolled window to hold all the parameters
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
gtk.POLICY_AUTOMATIC)
scrolled_window.add_with_viewport(vbox)
self.vbox.pack_start(scrolled_window, True)
self.original_data = list()
- # Add all the parameters #
- for param in self.signal_block.get_params():
-
self.original_data.append(param.get_data_type().get_data())
+ #Add all the parameters
+ for param in filter(lambda p: p.get_key() not in ('position',),
self.block.get_params()):
+ self.original_data.append(param.get_value())
vbox.pack_start(param.get_input_object(self._handle_changed), False)
- # Done adding parameters #
- if self.signal_block.get_docs():
- # Create the title label #
+ #Done adding parameters
+ if self.block.get_doc():
+ #Create the title label
label = gtk.Label()
- label.set_markup('\n\n<b>Documentation:
%s</b>\n'%self.signal_block.get_cname())
+ label.set_markup('\n\n<b>Documentation:
%s</b>\n'%self.block.get_name())
vbox.pack_start(label, False)
- # Create the text box to display notes about the
block #
-
vbox.pack_start(TextDisplay(self.signal_block.get_docs()), False)
+ #Create the text box to display notes about the block
+ vbox.pack_start(TextDisplay(self.block.get_docs()),
False)
self.show_all()
def _handle_changed(self, param):
@@ -70,9 +70,7 @@
the variable param will need an external update.
@param param the graphical parameter that initiated the
callback
"""
- for p in self.signal_block.get_params():
- if hasattr(p.get_data_type(), 'enum_data_type') and \
- param.get_data_type() ==
getattr(p.get_data_type(), 'enum_data_type'): p.update()
+ map(lambda p: p.update(), filter(lambda p:
p.is_type_dependent(), self.block.get_params()))
def run(self):
"""!
@@ -82,7 +80,7 @@
gtk.Dialog.run(self)
self.destroy()
self.data = list()
- for param in self.signal_block.get_params():
- self.data.append(param.get_data_type().get_data())
+ for param in self.block.get_params():
+ self.data.append(param.get_value())
return self.original_data != self.data
-
\ No newline at end of file
+
Modified: grc/branches/grc_reloaded/src/grc/gui/SignalBlockSelectionWindow.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/SignalBlockSelectionWindow.py
2008-02-12 06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/SignalBlockSelectionWindow.py
2008-02-12 06:16:49 UTC (rev 7641)
@@ -29,23 +29,20 @@
class SignalBlockSelectionWindow(gtk.VBox):
"""The signal block selection window."""
- def __init__(self, get_flow_graph):
+ def __init__(self, platform, get_flow_graph):
"""!
SignalBlockSelectionWindow constructor.
Show all possible signal blocks in this dialog.
Each signal block is represented by a gtk label of its tag and
an add button.
The add button tells the flow graph to create the selected
block. and add it to the flow graph.
+ @param platform the particular platform will all block
prototypes
@param get_flow_graph get the selected flow graph
"""
gtk.VBox.__init__(self)
self.get_flow_graph = get_flow_graph
- #title label
- label = gtk.Label()
- label.set_markup('<b>Signal Blocks</b>')
- self.pack_start(label, False)
#make the tree model for holding blocks
- self.model = gtk.TreeStore(gobject.TYPE_STRING)
- self.treeview = gtk.TreeView(self.model)
+ self.treestore = gtk.TreeStore(gobject.TYPE_STRING)
+ self.treeview = gtk.TreeView(self.treestore)
self.treeview.set_enable_search(False) #disable pop up search
box
self.treeview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.treeview.connect('button_press_event',
self._handle_mouse_button_press)
@@ -53,7 +50,7 @@
selection.set_mode('single')
selection.connect('changed', self._handle_selection_change)
renderer = gtk.CellRendererText()
- column = gtk.TreeViewColumn("Category", renderer, text=0)
+ column = gtk.TreeViewColumn("Signal Blocks", renderer, text=0)
self.treeview.append_column(column)
#make the scrolled window to hold the tree view
scrolled_window = gtk.ScrolledWindow()
@@ -68,36 +65,47 @@
self.add_button = gtk.Button(None, 'gtk-add')
self.add_button.connect('clicked', self._handle_add_button)
self.pack_start(self.add_button, False)
- #add blocks and categories
- for category, tags in SB_TREE:
- iter = self.model.insert_before(None, None)
- self.model.set_value(iter, 0, category)
- for tag in tags:
- new_iter = self.model.insert_before(iter, None)
- self.model.set_value(new_iter, 0, tag[0])
+ #map names to keys
+ self.names = dict()
+ #add blocks and categories
+ for category, keys in platform.get_block_tree():
+ iter = self.treestore.insert_before(None, None)
+ self.treestore.set_value(iter, 0, category)
+ for key in keys:
+ name = platform.get_block(key).get_name()
+ self.names[name] = key
+ new_iter = self.treestore.insert_before(iter,
None)
+ self.treestore.set_value(new_iter, 0, name)
#initialize
self._handle_selection_change()
def _handle_mouse_button_press(self, widget, event):
- """Handle the mouse button press.
+ """!
+ Handle the mouse button press.
If a left double click is detected,
- let the handler for the add button decide to add a block."""
+ let the handler for the add button decide to add a block.
+ """
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
self._handle_add_button(widget)
def _handle_selection_change(self, selection=None):
- """Handle a selection change in the tree view.
- If a selection changes, set the add button sensitive."""
+ """!
+ Handle a selection change in the tree view.
+ If a selection changes, set the add button sensitive.
+ """
selection = self.treeview.get_selection()
model, iter = selection.get_selected()
if iter != None and not model.iter_has_child(iter):
self.add_button.set_sensitive(True)
else: self.add_button.set_sensitive(False)
def _handle_add_button(self, widget):
- """Handle the add button clicked signal.
- Add the signal block to the flow graph."""
- if self.get_flow_graph():
- selection = self.treeview.get_selection()
- model, iter = selection.get_selected()
- if iter != None and not model.iter_has_child(iter):
self.get_flow_graph().add_signal_block(model.get_value(iter, 0))
-
-
+ """!
+ Handle the add button clicked signal.
+ Add the signal block to the flow graph.
+ """
+ selection = self.treeview.get_selection()
+ treestore, iter = selection.get_selected()
+ if iter != None and not treestore.iter_has_child(iter):
+ name = treestore.get_value(iter, 0)
+ key = self.names[name]
+ self.get_flow_graph().add_new_block(key)
+
Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Block.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Block.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -30,8 +30,62 @@
import pango
class Block(Element):
- """The graphical signal block."""
+ """The graphical signal block."""
+ def __init__(self, *args, **kwargs):
+ """!
+ Block contructor.
+ Add graphics related params to the block.
+ """
+ #add the position param
+ self._params['position'] = self.get_parent().get_parent().Param(
+ self,
+ {
+ 'name': 'Position',
+ 'key': 'position',
+ 'type': 'raw',
+ }
+ )
+ Element.__init__(self)
+
+ def get_coordinate(self):
+ """!
+ Get the coordinate from the position param.
+ @return the coordinate tuple (x, y) or (0, 0) if failure
+ """
+ try: #should evaluate to dict
+ position = eval(self.get_param('position').get_value())
+ return (int(position['x']), int(position['y']))
+ except: return (0, 0)
+
+ def set_coordinate(self, coor):
+ """!
+ Set the coordinate into the position param.
+ @param coor the coordinate tuple (x, y)
+ """
+ x, y = coor
+ position = {'x': x, 'y': y, 'rot': self.get_rotation()}
+ self.get_param('position').set_value(str(position))
+
+ def get_rotation(self):
+ """!
+ Get the rotation from the position param.
+ @return the rotation in degrees or 0 if failure
+ """
+ try: #should evaluate to dict
+ position = eval(self.get_param('position').get_value())
+ return int(position['rot'])
+ except: return 0
+
+ def set_rotation(self, rot):
+ """!
+ Set the rotation into the position param.
+ @param rot the rotation in degrees
+ """
+ x, y = self.get_coordinate()
+ position = {'x': x, 'y': y, 'rot': rot}
+ self.get_param('position').set_value(str(position))
+
def update(self):
"""Update the block, parameters, and ports when a change
occurs."""
self.clear()
@@ -54,9 +108,8 @@
layouts.append(layout)
if not self.is_valid(): layout.set_markup('<span
foreground="red"><b>'+self.get_name()+'</b></span>')
self.label_width,self.label_height = layout.get_pixel_size()
- # handle each of the displayable params #
- #TODO for param in self.displayed_params:
- if False:
+ #display the params (except for the special params id and
position)
+ for param in filter(lambda p: p.get_key() not in ('id',
'position'), self.get_params()):
layout = param.get_layout()
layouts.append(layout)
w,h = layout.get_pixel_size()
Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Element.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Element.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Element.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -123,7 +123,7 @@
"""
deltaX, deltaY = delta_coor
X, Y = self.get_coordinate()
- self.coor = (X+deltaX, Y+deltaY)
+ self.set_coordinate((X+deltaX, Y+deltaY))
def add_area(self, rel_coor, area, rotation=None):
"""!
Modified: grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -23,7 +23,7 @@
from grc.Constants import *
from grc.Actions import *
from Colors import BACKGROUND_COLOR, TXT_COLOR
-
+from grc.gui.SignalBlockParamsDialog import SignalBlockParamsDialog
from Element import Element
import pygtk
@@ -61,31 +61,32 @@
def get_size(self): return self.drawing_area.get_size_request()
def get_window(self): return self.drawing_area.window
+
+ def get_scroll_pane(self): return self.drawing_area.get_parent()
###########################################################################
# Flow Graph Access Methods
###########################################################################
- def add_signal_block(self, tag):
+ def add_new_block(self, key):
"""!
- Add a signal block of the given tag to this flow graph.
- @param tag the signal block tag
+ Add a block of the given key to this flow graph.
+ @param key the block key
"""
index = 0
while True:
- id = tag+str(index)
+ id = '%s%d'%(key, index)
index = index + 1
- if not [
- None for element in self.elements if
Element.is_signal_block(element) and id == element.get_id()
- ]: #make sure that the id is not used by
another signal block
- rot = 0
- vAdj =
self.get_parent().get_vadjustment().get_value()
- hAdj =
self.get_parent().get_hadjustment().get_value()
+ #make sure that the id is not used by another block
+ if not filter(lambda e: e.is_block() and e.get_id() ==
id, self.get_elements()):
+ vAdj =
self.get_scroll_pane().get_vadjustment().get_value()
+ hAdj =
self.get_scroll_pane().get_hadjustment().get_value()
x = random.randint(100,400)+int(hAdj)
y = random.randint(100,400)+int(vAdj)
- self.elements.append(
- SignalBlockDefs.get_signal_block(self,
(x, y), rot, tag, id, GraphicalSignalBlock)[0]
- )
+ block = self.get_new_block(key)
+ block.set_coordinate((x, y))
+ block.set_rotation(0)
+ block.get_param('id').set_value(id)
self.handle_states(BLOCK_CREATE)
self.update()
return
@@ -115,8 +116,10 @@
Create and show a param modification dialog for the selected
element (port and signal block only).
@return true if parameters were changed
"""
- if Element.is_port(self.selected_element):
self.selected_element = self.selected_element.get_parent()
- if Element.is_signal_block(self.selected_element):
+ if not self.selected_element: return False
+ if self.selected_element.is_source() or
self.selected_element.is_sink():
+ self.selected_element =
self.selected_element.get_parent()
+ if self.selected_element.is_block():
signal_block_params_dialog =
SignalBlockParamsDialog(self.selected_element)
changed = signal_block_params_dialog.run()
self.update()
@@ -128,7 +131,7 @@
Move the element and by the change in coordinates.
@param delta_coordinate the change in coordinates
"""
- if self.selected_element != None:
+ if self.selected_element:
self.selected_element.move(delta_coordinate)
self.has_moved = True
self.draw()
@@ -137,9 +140,10 @@
"""!
Rotate the selected element by 90 degrees. Only rotate
SignalBlocks and Sockets.
@param direction DIR_LEFT or DIR_RIGHT
- @return true if rotated, otherwise false.
+ @return true if rotated, otherwise false.
"""
- if self.selected_element != None and
(Element.is_signal_block(self.selected_element) or
Element.is_port(self.selected_element)):
+ if self.selected_element and self.selected_element.is_block()
or \
+ self.selected_element.is_source() or
self.selected_element.is_sink():
self.selected_element.rotate(direction)
self.draw()
return True
@@ -159,7 +163,7 @@
def unselect(self):
"""If an element is selected, un-highlight it and set selected
to None."""
- if self.selected_element != None:
+ if self.selected_element:
self.selected_element.set_highlighted(False)
self.selected_element = None
self.update()
@@ -199,16 +203,25 @@
points.append((i*grid_size,j*grid_size))
self.get_gc().foreground = TXT_COLOR
self.get_pixmap().draw_points(self.get_gc(),
points)
- #draw the foreground
+ #draw signal blocks first, then connections on the top
for element in self.get_blocks() +
self.get_connections():
- element.draw(self.get_pixmap()) # draw signal
blocks first, then connections on the top
+ element.draw(self.get_pixmap())
+ #draw any selected element as the topmost
if self.mouse_pressed and self.selected_element:
self.selected_element.draw(self.get_pixmap())
self.drawing_area.draw()
def update(self):
- """Call update on all elements."""
+ """Call update on all elements."""
map(lambda e: e.update(), self.get_elements())
+ #set the size of the flow graph area
+ old_x, old_y = self.get_size()
+ try: new_x = int(self.get_option('window_width'))
+ except: new_x = old_x
+ try: new_y = int(self.get_option('window_height'))
+ except: new_y = old_y
+ if new_x != old_x or new_y != old_y:
self.drawing_area.set_size_request(new_x, new_y)
+ #draw the flow graph
self.draw()
##########################################################################
@@ -272,7 +285,7 @@
def handle_mouse_motion(self, coordinate):
"""The mouse has moved. If mouse_pressed is true, react to the
motions:
- if an Element is highlighted, this will move the
Element by redrawing it at the new position."""
- scroll_pane = self.drawing_area.get_parent()
+ get_scroll_pane = self.drawing_area.get_parent()
fgW,fgH = self.get_size()
self.count = (1 +
self.count)%MOTION_DETECT_REDRAWING_SENSITIVITY
# to perform a movement, the mouse must be pressed, an
element selected, count of zero. #
@@ -293,22 +306,22 @@
X,Y = self.get_coordinate()
deltaX = int(x - X)
deltaY = int(y - Y)
- vAdj = scroll_pane.get_vadjustment().get_value()
- hAdj = scroll_pane.get_hadjustment().get_value()
- width = scroll_pane.get_hadjustment().page_size
- height = scroll_pane.get_vadjustment().page_size
+ vAdj = get_scroll_pane.get_vadjustment().get_value()
+ hAdj = get_scroll_pane.get_hadjustment().get_value()
+ width = get_scroll_pane.get_hadjustment().page_size
+ height = get_scroll_pane.get_vadjustment().page_size
# scroll horizontal if we moved near the border #
if x-hAdj > width-SCROLL_PROXIMITY_SENSITIVITY and\
hAdj+SCROLL_DISTANCE < fgW - width:
-
scroll_pane.get_hadjustment().set_value(hAdj+SCROLL_DISTANCE)
+
get_scroll_pane.get_hadjustment().set_value(hAdj+SCROLL_DISTANCE)
elif x-hAdj < SCROLL_PROXIMITY_SENSITIVITY:
-
scroll_pane.get_hadjustment().set_value(hAdj-SCROLL_DISTANCE)
+
get_scroll_pane.get_hadjustment().set_value(hAdj-SCROLL_DISTANCE)
# scroll vertical if we moved near the border #
if y-vAdj > height-SCROLL_PROXIMITY_SENSITIVITY and\
vAdj+SCROLL_DISTANCE < fgH - height:
-
scroll_pane.get_vadjustment().set_value(vAdj+SCROLL_DISTANCE)
+
get_scroll_pane.get_vadjustment().set_value(vAdj+SCROLL_DISTANCE)
elif y-vAdj < SCROLL_PROXIMITY_SENSITIVITY:
-
scroll_pane.get_vadjustment().set_value(vAdj-SCROLL_DISTANCE)
+
get_scroll_pane.get_vadjustment().set_value(vAdj-SCROLL_DISTANCE)
# move the selected element and record the new
coordinate #
self.move_selected((deltaX, deltaY))
self.set_coordinate(coordinate)
Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Param.py 2008-02-12
06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Param.py 2008-02-12
06:16:49 UTC (rev 7641)
@@ -36,9 +36,9 @@
class InputParam(gtk.HBox):
"""The base class for an input parameter inside the input parameters
dialog."""
- def __init__(self, data_type, _handle_changed):
+ def __init__(self, param, _handle_changed):
gtk.HBox.__init__(self)
- self.data_type = data_type
+ self.param = param
self._handle_changed = _handle_changed
self.label = gtk.Label() #no label, markup is added by
set_markup
self.label.set_size_request(140,-1)
@@ -52,11 +52,11 @@
def __init__(self, *args):
InputParam.__init__(self, *args)
self.entry = input = gtk.Entry()
- input.set_text(self.data_type.get_data())
+ input.set_text(self.param.get_value())
input.connect("changed", self._handle_changed)
self.pack_start(input, True)
self.get_text = input.get_text
- # tool tip fun #
+ #tool tip fun
self.tp = gtk.Tooltips()
self.tp.set_tip(self.entry, "")
self.tp.enable()
@@ -73,13 +73,13 @@
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. """
- file_path = self.data_type.parse()
+ file_path = self.param.evaluate()
# bad file paths will be redirected to default #
if not path.exists(path.dirname(file_path)): file_path =
DEFAULT_FILE_PATH
- if self.data_type.get_type() == FileOpen().get_type():
+ if self.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.data_type.get_type() == FileSave().get_type():
+ elif self.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)
@@ -87,11 +87,11 @@
file_dialog.set_current_folder(path.dirname(file_path))
#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
+ if gtk.RESPONSE_OK == file_dialog.run(): #run the dialog
+ file_path = file_dialog.get_filename() #get the file
path
self.entry.set_text(file_path)
self._handle_changed()
- file_dialog.destroy() #destroy the dialog
+ file_dialog.destroy() #destroy the dialog
class EnumParam(InputParam):
"""Provide an entry box for Enum types with a drop down menu."""
@@ -102,8 +102,8 @@
cell = gtk.CellRendererText()
input.pack_start(cell, True)
input.add_attribute(cell, 'text', 0)
- for cname in self.data_type.get_cnames_list():
input.append_text(cname)
- input.set_active(int(self.data_type.get_data()))
+ for option in self.param.get_options():
input.append_text(option.get_name())
+
input.set_active(int(self.param.get_option_keys().index(self.param.get_value())))
input.connect("changed", self._handle_changed)
self.pack_start(input, False)
self.get_text = lambda: str(input.get_active()) #the get text
parses the selected index to a string
@@ -128,27 +128,29 @@
@return gtk input object
"""
self.callback=callback
- if self.get_data_type().get_base_type() ==
Enum().get_base_type(): input = EnumParam
- elif self.get_data_type().get_base_type() ==
File().get_base_type(): input = FileParam
+ if self.is_enum(): input = EnumParam
+ elif self.get_type() in ('file_open', 'file_save'): input =
FileParam
else: input = EntryParam
- self.input = input(self.get_data_type(), self._handle_changed)
+ self.input = input(self, self._handle_changed)
self._handle_changed()
return self.input
def _handle_changed(self, widget=None):
- """When the input changes, write the inputs to the data type.
- Finish by calling the exteral callback."""
- data_type = self.get_data_type()
+ """!
+ When the input changes, write the inputs to the data type.
+ Finish by calling the exteral callback.
+ """
new_data = self.input.get_text()
- old_data = data_type.get_data()
- if old_data != new_data: data_type.set_data(new_data)
+ if self.is_enum(): new_data =
self.get_option_keys()[int(new_data)]
+ old_data = self.get_value()
+ if old_data != new_data: self.set_value(new_data)
#set the markup on the label, red for errors in corresponding
data type.
- cname = self.get_cname()
- if self.variable: cname = '<span
underline="low">%s</span>'%cname #alter format if the param is variable
- if not data_type.is_valid(): self.input.set_markup('<span
foreground="red"><b>%s</b></span>'%cname)
- else: self.input.set_markup(cname)
+ name = self.get_name()
+ #TODO if self.variable: name = '<span
underline="low">%s</span>'%name #alter format if the param is variable
+ if not self.is_valid(): self.input.set_markup('<span
foreground="red"><b>%s</b></span>'%name)
+ else: self.input.set_markup(name)
#set the tooltip
- if self.input.tp: self.input.tp.set_tip(self.input.entry,
str(data_type))
+ if self.input.tp: self.input.tp.set_tip(self.input.entry,
str(self))
#execute the external callback
if self.callback: self.callback(self)
@@ -170,29 +172,28 @@
if var*1000-int(var*1000) == 0: return '%.3f'%var
else: return '%.3g'%var
def to_str(var):
- if type(var) == type(str()): return var
- elif type(var) == type(complex()):
+ if isinstance(var, str): return var
+ elif isinstance(var, complex):
if var.imag == var.real == 0: return '0'
#value is zero
elif var.imag == 0: return
'%s'%float_to_str(var.real) #value is real
elif var.real == 0: return
'%sj'%float_to_str(var.imag) #value is imaginary
elif var.imag < 0: return
'%s-%sj'%(float_to_str(var.real), float_to_str(var.imag*-1))
else: return '%s+%sj'%(float_to_str(var.real),
float_to_str(var.imag))
- elif type(var) == type(float()): return
float_to_str(var)
- elif type(var) == type(int()): return '%d'%var
+ elif isinstance(var, float): return float_to_str(var)
+ elif isinstance(var, int): return '%d'%var
else: return var
###########################################################################
- if self.get_data_type().is_valid():
- data = self.get_data_type().parse()
- if self.get_data_type().get_base_type() ==
Enum().get_base_type(): #enum types
- dt_str = self.get_data_type().get_cname()
- elif self.get_data_type().get_base_type() ==
File().get_base_type(): #file types
+ if self.is_valid():
+ data = self.evaluate()
+ t = self.get_type()
+ if t in ('file_open', 'file_save'): #file types
suggested_length = 30
if len(data) <= suggested_length: dt_str = data
else: #truncate the tail if there is not
enough space
tail,head = path.split(data)
if len(head) >= suggested_length:
dt_str = head
else: dt_str =
tail[0:suggested_length-len(head)] + '...' + head
- elif self.get_data_type().get_base_type() ==
Vector().get_base_type(): #vector types
+ elif isinstance(data, (list, tuple)): #vector types
for i,e in enumerate(data): data[i] = to_str(e)
# only keep the first X elements of the
list:
X = (100/len(str(data))) + 1 #display more
for non complex vectors
@@ -203,10 +204,9 @@
if i < len(data)-1 and (i+1 !=
X or X+1 == len(data)): dt_str = dt_str + ', '
elif i == X: dt_str = dt_str + ' ... '
dt_str = dt_str + ']'
- elif self.get_data_type().get_type() ==
Hex().get_type(): dt_str = hex(data) #hex, base 16
else: dt_str = to_str(data) #other types
- return '<b>%s:</b> %s'%(self.cname, dt_str)
- else: return '<span foreground="red"><b>%s:</b>
error</span>'%self.cname
+ return '<b>%s:</b> %s'%(self.get_name(), dt_str)
+ else: return '<span foreground="red"><b>%s:</b>
error</span>'%self.get_name()
def get_layout(self):
"""!
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-12 06:15:24 UTC (rev 7640)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-12 06:16:49 UTC (rev 7641)
@@ -28,8 +28,25 @@
from Port import Source,Sink
from Param import Param as _Param
+BLOCK_TREE = [
+ ('Operators',[
+ 'add',
+ 'add_const',
+ ]
+ ),
+ ('Variables',[
+ 'variable',
+ 'variable_drop_down',
+ 'variable_button',
+ 'variable_slider',
+ ]
+ ),
+]
+
class Platform(_Platform):
+ BLOCK_TREE = BLOCK_TREE
+
def __init__(self):
"""!
Make a platform from the arguments.
@@ -43,7 +60,7 @@
name='GNURadio Python',
key='gnuradio_python',
path=os.path.dirname(__file__),
- )
+ )
##############################################
# Constructors
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
2008-02-12 06:16:49 UTC (rev 7641)
@@ -26,7 +26,7 @@
Top level element.
A block contains a name, ...parameters list, and list of IO ports.
-->
-<!ELEMENT block (name, key, cat, dep*, fcn, callback*, param*, check*, sink*,
source*, doc?)>
+<!ELEMENT block (name, key, dep*, fcn, callback*, param*, check*, sink*,
source*, doc?)>
<!--
Sub level elements.
-->
@@ -40,7 +40,6 @@
-->
<!ELEMENT dep (#PCDATA)>
<!ELEMENT doc (#PCDATA)>
-<!ELEMENT cat (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT key (#PCDATA)>
<!ELEMENT check (#PCDATA)>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -9,7 +9,6 @@
<block>
<name>Add</name>
<key>add</key>
- <cat>Operators</cat>
<dep>from gnuradio import gr</dep>
<fcn>$type:fcn($vec_len)</fcn>
<param>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -9,7 +9,6 @@
<block>
<name>Add Const</name>
<key>add_const</key>
- <cat>Operators</cat>
<dep>from gnuradio import gr</dep>
<fcn>$type:fcn($const)</fcn>
<callback>set_k($const)</callback>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/options.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -10,7 +10,6 @@
<block>
<name>Options</name>
<key>options</key>
- <cat>Main</cat>
<fcn />
<param>
<name>Name</name>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -8,7 +8,6 @@
<block>
<name>Variable</name>
<key>variable</key>
- <cat>Variables</cat>
<fcn />
<param>
<name>Key</name>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -8,7 +8,6 @@
<block>
<name>Variable Button</name>
<key>variable_button</key>
- <cat>Variables</cat>
<fcn />
<param>
<name>Key</name>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_drop_down.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -8,7 +8,6 @@
<block>
<name>Variable Drop Down</name>
<key>variable_drop_down</key>
- <cat>Variables</cat>
<fcn />
<param>
<name>Key</name>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
2008-02-12 06:15:24 UTC (rev 7640)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
2008-02-12 06:16:49 UTC (rev 7641)
@@ -8,7 +8,6 @@
<block>
<name>Variable Slider</name>
<key>variable_slider</key>
- <cat>Variables</cat>
<fcn />
<param>
<name>Key</name>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7641 - in grc/branches/grc_reloaded/src/grc: elements gui gui/elements platforms/gnuradio_python platforms/gnuradio_python/blocks platforms/gnuradio_python/blocks/operators platforms/gnuradio_python/blocks/variables,
jblum <=