[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9021 - in grc/trunk: notes src/grc src/grc/data src/g
From: |
jblum |
Subject: |
[Commit-gnuradio] r9021 - in grc/trunk: notes src/grc src/grc/data src/grc/elements src/grc/gui src/grc_gnuradio src/grc_gnuradio/data src/grc_gnuradio/utils |
Date: |
Fri, 25 Jul 2008 16:30:15 -0600 (MDT) |
Author: jblum
Date: 2008-07-25 16:30:14 -0600 (Fri, 25 Jul 2008)
New Revision: 9021
Removed:
grc/trunk/src/grc/BlockTree.py
Modified:
grc/trunk/notes/todo.txt
grc/trunk/src/grc/data/block_tree.dtd
grc/trunk/src/grc/elements/Platform.py
grc/trunk/src/grc/gui/BlockTreeWindow.py
grc/trunk/src/grc_gnuradio/Generator.py
grc/trunk/src/grc_gnuradio/data/block_tree.xml
grc/trunk/src/grc_gnuradio/utils/convert_hier.py
Log:
multi-level categories and blocks
Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt 2008-07-25 22:23:46 UTC (rev 9020)
+++ grc/trunk/notes/todo.txt 2008-07-25 22:30:14 UTC (rev 9021)
@@ -11,7 +11,6 @@
-command line option for additional block wrappers
-hotkeys in action descriptions
-log slider gui control
--recursive/nested categories
-multi block selection
############ Maybe: ####################
Deleted: grc/trunk/src/grc/BlockTree.py
Modified: grc/trunk/src/grc/data/block_tree.dtd
===================================================================
--- grc/trunk/src/grc/data/block_tree.dtd 2008-07-25 22:23:46 UTC (rev
9020)
+++ grc/trunk/src/grc/data/block_tree.dtd 2008-07-25 22:30:14 UTC (rev
9021)
@@ -21,7 +21,6 @@
Josh Blum
The document type definition for a block tree category listing.
-->
-<!ELEMENT block_tree (cat*)>
-<!ELEMENT cat (name, block*)>
+<!ELEMENT cat (name, cat*, block*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT block (#PCDATA)>
Modified: grc/trunk/src/grc/elements/Platform.py
===================================================================
--- grc/trunk/src/grc/elements/Platform.py 2008-07-25 22:23:46 UTC (rev
9020)
+++ grc/trunk/src/grc/elements/Platform.py 2008-07-25 22:30:14 UTC (rev
9021)
@@ -66,6 +66,12 @@
self._load_block(os.path.join(dirpath, filename))
def _load_block(self, f):
+ """!
+ Load the block wrapper from the file path.
+ The block wrapper must pass validation, and have a unique block
key.
+ If any of the checks fail, exit with error.
+ @param f the file path
+ """
try: ParseXML.validate_dtd(f, self._block_dtd)
except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block
definition "%s" failed: \n\t%s'%(f, e))
n = ParseXML.from_file(f)['block']
@@ -85,22 +91,28 @@
Step 2: Load blocks with builtin category specifications.
@param block_tree the block tree object
"""
+ #recursive function to load categories and blocks
+ def load_category(cat_n, parent=''):
+ #add this category
+ parent = '%s/%s'%(parent, cat_n['name'])
+ block_tree.add_block(parent)
+ #recursive call to load sub categories
+ map(lambda c: load_category(c, parent),
Utils.listify(cat_n, 'cat'))
+ #add blocks in this category
+ for block_key in Utils.listify(cat_n, 'block'):
+ block_tree.add_block(parent,
self.get_block(block_key))
#load the block tree
f = self._block_tree
try: ParseXML.validate_dtd(f, os.path.join(DATA_DIR,
'block_tree.dtd'))
except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block
tree "%s" failed: \n\t%s'%(f, e))
- n = ParseXML.from_file(f)['block_tree']
#add all blocks in the tree
- for category, block_keys in [(c['name'], Utils.listify(c,
'block')) for c in Utils.listify(n, 'cat')]:
- block_tree.add_category(category)
- for block_key in block_keys:
block_tree.add_block(self.get_block(block_key), category)
+ load_category(ParseXML.from_file(f)['cat'])
#add all other blocks, use the catgory
for block in self.get_blocks():
#blocks with empty categories are in the xml block tree
or hidden
- if block.get_category() and not
block_tree.has_block(block):
- block_tree.add_block(block,
block.get_category())
+ if block.get_category():
block_tree.add_block(block.get_category(), block)
- def __str__(self): return 'Platform - %s(%s)'%(self.get_name(),
self.get_key())
+ def __str__(self): return 'Platform - %s(%s)'%(self.get_key(),
self.get_name())
def is_platform(self): return True
Modified: grc/trunk/src/grc/gui/BlockTreeWindow.py
===================================================================
--- grc/trunk/src/grc/gui/BlockTreeWindow.py 2008-07-25 22:23:46 UTC (rev
9020)
+++ grc/trunk/src/grc/gui/BlockTreeWindow.py 2008-07-25 22:30:14 UTC (rev
9021)
@@ -20,7 +20,6 @@
#The block selection panel gives the user a tree selection to choose a block.
address@hidden Josh Blum
-from grc.BlockTree import BlockTree as _BlockTree
from grc.Constants import *
import pygtk
pygtk.require('2.0')
@@ -30,7 +29,7 @@
NAME_INDEX = 0
KEY_INDEX = 1
-class BlockTreeWindow(gtk.VBox, _BlockTree):
+class BlockTreeWindow(gtk.VBox):
"""The block selection panel."""
def __init__(self, platform, get_flow_graph):
@@ -43,7 +42,6 @@
@param get_flow_graph get the selected flow graph
"""
gtk.VBox.__init__(self)
- _BlockTree.__init__(self)
self.platform = platform
self.get_flow_graph = get_flow_graph
#make the tree model for holding blocks
@@ -70,6 +68,7 @@
self.pack_start(self.add_button, False)
#map categories to iters
self.categories = dict()
+ self.categories[tuple()] = None
#add blocks and categories
self.platform.load_block_tree(self)
#initialize
@@ -78,30 +77,29 @@
############################################################
## Block Tree Methods
############################################################
- def add_block(self, block, category):
+ def add_block(self, category, block=None):
"""!
Add a block with category to this selection window.
- Call base class add block, then add to the tree store.
- @param block the block object
+ Add only the category when block is None.
@param category the category string
+ @param block the block object or None
"""
- _BlockTree.add_block(self, block, category)
- new_iter =
self.treestore.insert_before(self.categories[category], None)
- self.treestore.set_value(new_iter, NAME_INDEX, block.get_name())
- self.treestore.set_value(new_iter, KEY_INDEX, block.get_key())
+ #rectify category
+ category = filter(lambda x: x, category.split('/'))
+ #add category and all sub categories
+ for i in range(len(category)):
+ sub_category = tuple(category[:i+1])
+ if sub_category not in self.categories.keys():
+ iter =
self.treestore.insert_before(self.categories[tuple(category[:i])], None)
+ self.treestore.set_value(iter, NAME_INDEX, '[
%s ]'%category[i])
+ self.treestore.set_value(iter, KEY_INDEX, '')
+ self.categories[sub_category] = iter
+ #add block
+ if block is None: return
+ iter =
self.treestore.insert_before(self.categories[tuple(category)], None)
+ self.treestore.set_value(iter, NAME_INDEX, block.get_name())
+ self.treestore.set_value(iter, KEY_INDEX, block.get_key())
- def add_category(self, category):
- """!
- Add a category to this selection window.
- Call base class add category, then add to the tree store.
- @param category the category string
- """
- _BlockTree.add_category(self, category)
- iter = self.treestore.insert_before(None, None)
- self.treestore.set_value(iter, NAME_INDEX, category)
- self.treestore.set_value(iter, KEY_INDEX, '')
- self.categories[category] = iter
-
############################################################
## Helper Methods
############################################################
Modified: grc/trunk/src/grc_gnuradio/Generator.py
===================================================================
--- grc/trunk/src/grc_gnuradio/Generator.py 2008-07-25 22:23:46 UTC (rev
9020)
+++ grc/trunk/src/grc_gnuradio/Generator.py 2008-07-25 22:30:14 UTC (rev
9021)
@@ -25,6 +25,7 @@
from Cheetah.Template import Template
from utils import expr_utils
from Constants import *
+from utils import convert_hier
class Generator(object):
@@ -53,7 +54,6 @@
open(self.get_file_path(), 'w').write(str(self))
if self._generate_options == 'hb':
#convert hier block to xml wrapper
- from utils import convert_hier
convert_hier.convert_hier(self._flow_graph,
self.get_file_path())
os.chmod(self.get_file_path(), self._mode)
Modified: grc/trunk/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-07-25 22:23:46 UTC
(rev 9020)
+++ grc/trunk/src/grc_gnuradio/data/block_tree.xml 2008-07-25 22:30:14 UTC
(rev 9021)
@@ -4,7 +4,8 @@
##Block Tree for platform gnuradio python.
###################################################
-->
-<block_tree>
+<cat>
+ <name></name> <!-- Blank for Root Name -->
<cat>
<name>Sources</name>
<block>gr_sig_source_x</block>
@@ -267,4 +268,4 @@
<block>xmlrpc_server</block>
<block>xmlrpc_client</block>
</cat>
-</block_tree>
+</cat>
Modified: grc/trunk/src/grc_gnuradio/utils/convert_hier.py
===================================================================
--- grc/trunk/src/grc_gnuradio/utils/convert_hier.py 2008-07-25 22:23:46 UTC
(rev 9020)
+++ grc/trunk/src/grc_gnuradio/utils/convert_hier.py 2008-07-25 22:30:14 UTC
(rev 9021)
@@ -20,7 +20,7 @@
#Utility functions to convert a grc hier block to an xml wrapper
address@hidden Josh Blum
-from grc_gnuradio.Platform import BLOCK_DTD
+from grc_gnuradio.Constants import BLOCK_DTD
from grc import ParseXML
from grc.Utils import odict
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9021 - in grc/trunk: notes src/grc src/grc/data src/grc/elements src/grc/gui src/grc_gnuradio src/grc_gnuradio/data src/grc_gnuradio/utils,
jblum <=