From a07fe1904412af78b3d70a6225e6efe10c9efbe5 Mon Sep 17 00:00:00 2001
From: Tim O'Shea <tim.oshea753@gmail.com>
Date: Tue, 25 Sep 2012 11:40:10 -0400
Subject: adding GRC Reload Block XML action

---
 grc/base/Platform.py       | 4 ++++
 grc/gui/ActionHandler.py   | 6 ++++++
 grc/gui/Actions.py         | 5 +++++
 grc/gui/Bars.py            | 2 ++
 grc/gui/BlockTreeWindow.py | 5 +++++
 grc/gui/MainWindow.py      | 3 ++-
 6 files changed, 24 insertions(+), 1 deletion(-)

(limited to 'grc')

diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 94d0077ea9..d4b09088b2 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -61,6 +61,10 @@ class Platform(_Element):
 		#create a dummy flow graph for the blocks
 		self._flow_graph = _Element(self)
 		#search for *.xml files in the given search path
+
+		self.loadblocks();
+    
+	def loadblocks(self):
 		xml_files = list()
 		for block_path in self._block_paths:
 			if os.path.isfile(block_path): xml_files.append(block_path)
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 476c82b4f6..5600edc069 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -53,6 +53,7 @@ class ActionHandler:
 		self.clipboard = None
 		for action in Actions.get_all_actions(): action.connect('activate', self._handle_action)
 		#setup the main window
+		self.platform = platform;
 		self.main_window = MainWindow(platform)
 		self.main_window.connect('delete-event', self._quit)
 		self.main_window.connect('key-press-event', self._handle_key_press)
@@ -302,6 +303,10 @@ class ActionHandler:
 				except: print "could not kill process: %d"%self.get_page().get_proc().pid
 		elif action == Actions.PAGE_CHANGE: #pass and run the global actions
 			pass
+		elif action == Actions.RELOAD_BLOCKS:
+			self.platform.loadblocks()
+			self.main_window.btwin.clear();
+			self.platform.load_block_tree(self.main_window.btwin);
 		else: print '!!! Action "%s" not handled !!!'%action
 		##################################################
 		# Global Actions for all States
@@ -319,6 +324,7 @@ class ActionHandler:
 		#update enable/disable
 		Actions.BLOCK_ENABLE.set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
 		Actions.BLOCK_DISABLE.set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+		Actions.RELOAD_BLOCKS.set_sensitive(True)
 		#set the exec and stop buttons
 		self.update_exec_stop()
 		#saved status
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index 4d196477eb..4185de0486 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -273,3 +273,8 @@ BLOCK_INC_TYPE = Action(
 BLOCK_DEC_TYPE = Action(
 	keypresses=(gtk.keysyms.Up, NO_MODS_MASK),
 )
+RELOAD_BLOCKS = Action(
+	label='Reload _Blocks',
+	tooltip='Reload Blocks',
+	stock_id=gtk.STOCK_REFRESH
+)
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index 8fd1678698..0cdbdbb128 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -49,6 +49,8 @@ TOOLBAR_LIST = (
 	None,
 	Actions.BLOCK_ENABLE,
 	Actions.BLOCK_DISABLE,
+    None,
+    Actions.RELOAD_BLOCKS,
 )
 
 ##The list of actions and categories for the menu bar.
diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index 0175c8becf..62afb62056 100644
--- a/grc/gui/BlockTreeWindow.py
+++ b/grc/gui/BlockTreeWindow.py
@@ -90,6 +90,11 @@ class BlockTreeWindow(gtk.VBox):
 		#initialize
 		self._update_add_button()
 
+	def clear(self):
+		self.treestore.clear();
+		self._categories = {tuple(): None}
+
+
 	############################################################
 	## Block Tree Methods
 	############################################################
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 2f761df1f8..429bd9e860 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -93,7 +93,8 @@ class MainWindow(gtk.Window):
 		#flow_graph_box.pack_start(self.scrolled_window)
 		self.flow_graph_vpaned.pack1(self.notebook)
 		self.hpaned.pack1(self.flow_graph_vpaned)
-		self.hpaned.pack2(BlockTreeWindow(platform, self.get_flow_graph), False) #dont allow resize
+		self.btwin = BlockTreeWindow(platform, self.get_flow_graph);
+		self.hpaned.pack2(self.btwin, False) #dont allow resize
 		#create the reports window
 		self.text_display = TextDisplay()
 		#house the reports in a scrolled window
-- 
cgit v1.2.3


From 515d1b6f91f5dd28997525b1e88006bbfc0f170a Mon Sep 17 00:00:00 2001
From: Tim O'Shea <tim.oshea753@gmail.com>
Date: Wed, 26 Sep 2012 14:18:30 -0400
Subject: added the ability to open custom GRC hier block definitions from
 graphs using an instance of them

---
 grc/base/Block.py          | 1 +
 grc/gui/ActionHandler.py   | 6 ++++++
 grc/gui/Actions.py         | 5 +++++
 grc/gui/Bars.py            | 1 +
 grc/gui/FlowGraph.py       | 1 +
 grc/gui/MainWindow.py      | 2 ++
 grc/python/block.dtd       | 3 ++-
 grc/python/convert_hier.py | 1 +
 8 files changed, 19 insertions(+), 1 deletion(-)

(limited to 'grc')

diff --git a/grc/base/Block.py b/grc/base/Block.py
index fe7ad3c2f3..a20be9db96 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -67,6 +67,7 @@ class Block(Element):
 		self._name = n.find('name')
 		self._key = n.find('key')
 		self._category = n.find('category') or ''
+		self._grc_source = n.find('grc_source') or ''
 		self._block_wrapper_path = n.find('block_wrapper_path')
 		#create the param objects
 		self._params = list()
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 5600edc069..d1491db0b2 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -307,6 +307,11 @@ class ActionHandler:
 			self.platform.loadblocks()
 			self.main_window.btwin.clear();
 			self.platform.load_block_tree(self.main_window.btwin);
+		elif action == Actions.OPEN_HIER:
+			bn = [];
+			for b in self.get_flow_graph().get_selected_blocks():
+				if b._grc_source:
+				    self.main_window.new_page(b._grc_source, show=True);
 		else: print '!!! Action "%s" not handled !!!'%action
 		##################################################
 		# Global Actions for all States
@@ -324,6 +329,7 @@ class ActionHandler:
 		#update enable/disable
 		Actions.BLOCK_ENABLE.set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
 		Actions.BLOCK_DISABLE.set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+		Actions.OPEN_HIER.set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
 		Actions.RELOAD_BLOCKS.set_sensitive(True)
 		#set the exec and stop buttons
 		self.update_exec_stop()
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index 4185de0486..03aa430573 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -278,3 +278,8 @@ RELOAD_BLOCKS = Action(
 	tooltip='Reload Blocks',
 	stock_id=gtk.STOCK_REFRESH
 )
+OPEN_HIER = Action(
+	label='Open H_ier',
+	tooltip='Open the source of the selected hierarchical block',
+	stock_id=gtk.STOCK_JUMP_TO,
+)
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index 0cdbdbb128..d95d23f1fe 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -51,6 +51,7 @@ TOOLBAR_LIST = (
 	Actions.BLOCK_DISABLE,
     None,
     Actions.RELOAD_BLOCKS,
+    Actions.OPEN_HIER,
 )
 
 ##The list of actions and categories for the menu bar.
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 9f3326adaf..0f69d48783 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -63,6 +63,7 @@ class FlowGraph(Element):
 			Actions.BLOCK_ENABLE,
 			Actions.BLOCK_DISABLE,
 			Actions.BLOCK_PARAM_MODIFY,
+			Actions.OPEN_HIER,
 		]: self._context_menu.append(action.create_menu_item())
 
 	###########################################################################
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 429bd9e860..37a100c94f 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -170,6 +170,8 @@ class MainWindow(gtk.Window):
 		try: #try to load from file
 			if file_path: Messages.send_start_load(file_path)
 			flow_graph = self._platform.get_new_flow_graph()
+			flow_graph.grc_file_path = file_path;
+			#print flow_graph
 			page = NotebookPage(
 				self,
 				flow_graph=flow_graph,
diff --git a/grc/python/block.dtd b/grc/python/block.dtd
index 41a744d07a..292ea06cb6 100644
--- a/grc/python/block.dtd
+++ b/grc/python/block.dtd
@@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 	Top level element.
 	A block contains a name, ...parameters list, and list of IO ports.
  -->
-<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, callback*, param*, check*, sink*, source*, doc?)>
+<!ELEMENT block (name, key, category?, throttle?, import*, var_make?, make, callback*, param*, check*, sink*, source*, doc?, grc_source?)>
 <!--
 	Sub level elements.
  -->
@@ -40,6 +40,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 <!ELEMENT category (#PCDATA)>
 <!ELEMENT import (#PCDATA)>
 <!ELEMENT doc (#PCDATA)>
+<!ELEMENT grc_source (#PCDATA)>
 <!ELEMENT name (#PCDATA)>
 <!ELEMENT key (#PCDATA)>
 <!ELEMENT check (#PCDATA)>
diff --git a/grc/python/convert_hier.py b/grc/python/convert_hier.py
index c6ca5b7692..f4d082d596 100644
--- a/grc/python/convert_hier.py
+++ b/grc/python/convert_hier.py
@@ -73,6 +73,7 @@ def convert_hier(flow_graph, python_file):
 		block_n['source'].append(source_n)
 	#doc data
 	block_n['doc'] = "%s\n%s\n%s"%(block_author, block_desc, python_file)
+	block_n['grc_source'] = "%s"%(flow_graph.grc_file_path)
 	#write the block_n to file
 	xml_file = python_file + '.xml'
 	ParseXML.to_file({'block': block_n}, xml_file)
-- 
cgit v1.2.3