commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9487 - in gnuradio/branches/developers/jblum/grc_reor


From: jblum
Subject: [Commit-gnuradio] r9487 - in gnuradio/branches/developers/jblum/grc_reorganize/grc: . data data/platforms src src/gui src/platforms src/utils
Date: Tue, 2 Sep 2008 15:43:20 -0600 (MDT)

Author: jblum
Date: 2008-09-02 15:43:20 -0600 (Tue, 02 Sep 2008)
New Revision: 9487

Added:
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/__init__.py
   
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ActionHandler.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Actions.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Constants.py.in
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Messages.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ParseXML.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Preferences.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/StateCache.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Utils.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/converter.py
   
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/__init__.py
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/utils/__init__.py
Removed:
   gnuradio/branches/developers/jblum/grc_reorganize/grc/data/gui/
   gnuradio/branches/developers/jblum/grc_reorganize/grc/data/platforms/gui/
   gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/
Modified:
   gnuradio/branches/developers/jblum/grc_reorganize/grc/Makefile.inc
Log:
moving sources

Modified: gnuradio/branches/developers/jblum/grc_reorganize/grc/Makefile.inc
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/Makefile.inc  
2008-09-02 21:08:59 UTC (rev 9486)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/Makefile.inc  
2008-09-02 21:43:20 UTC (rev 9487)
@@ -21,8 +21,9 @@
 
 include $(top_srcdir)/Makefile.common
 
+grc_src_prefix = $(pythondir)/gnuradio/grc
 grc_data_prefix = @datadir@/${PACKAGE}/grc
 grc_examples_prefix = @datadir@/${PACKAGE}/examples/grc
-grc_data_dir = $(grc_data_prefix)/grc
-grc_gnuradio_data_dir = $(grc_data_prefix)/grc_gnuradio
-grc_gnuradio_blocks_dir = $(grc_data_prefix)/grc_gnuradio/blocks
+grc_base_data_dir = $(grc_data_prefix)/platforms/base
+grc_python_data_dir = $(grc_data_prefix)/platforms/python
+grc_python_blocks_dir = $(grc_data_prefix)/platforms/python/blocks

Added: gnuradio/branches/developers/jblum/grc_reorganize/grc/src/__init__.py
===================================================================

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ActionHandler.py 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/ActionHandler.py)
===================================================================
--- 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ActionHandler.py  
                            (rev 0)
+++ 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ActionHandler.py  
    2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,441 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden ActionHandler
+#ActionHandler builds the interface and handles most of the user inputs.
+
+import os
+import signal
+from Constants import *
+from Actions import *
+import pygtk
+pygtk.require('2.0')
+import gtk
+import gui
+import Preferences
+from threading import Thread
+import Messages
+import ParseXML
+import random
+from grc.gui.elements.Platform import Platform
+
+class ActionHandler:
+       """
+       The action handler will setup all the major window components,
+       and handle button presses and flow graph operations from the GUI.
+       """
+
+       def __init__(self, file_paths, platform):
+               """!
+               ActionHandler constructor.
+               Create the main window, setup the message handler, import the 
preferences,
+               and connect all of the action handlers. Finally, enter the gtk 
main loop and block.
+               @param file_paths a list of flow graph file passed from command 
line
+               @param platform platform module
+               """
+               self.clipboard = None
+               platform = Platform(platform)
+               if PY_GTK_ICON: 
gtk.window_set_default_icon_from_file(PY_GTK_ICON)
+               for action in ACTIONS_LIST: action.connect('activate', 
self._handle_actions)
+               #setup the main window
+               self.main_window = gui.MainWindow(self.handle_states, platform)
+               self.main_window.connect('delete_event', self._quit)
+               self.main_window.connect('key_press_event', 
self._handle_key_press)
+               self.get_page = self.main_window.get_page
+               self.get_flow_graph = self.main_window.get_flow_graph
+               self.get_focus_flag = 
self.main_window.drawing_area.get_focus_flag
+               #setup the messages
+               Messages.register_messenger(self.main_window.add_report_line)
+               Messages.send_init()
+               #initialize
+               self.init_file_paths = file_paths
+               self.handle_states(APPLICATION_INITIALIZE)
+               #enter the mainloop
+               gtk.gdk.threads_init()
+               gtk.main()
+
+       def _handle_key_press(self, widget, event):
+               """
+               Handle key presses from the keyboard.
+               Translate key combos into actions.
+               Key combinations that do not include special keys, such as ctrl 
or Fcn*,
+               Also, require that the flow graph has mouse focus when choosing 
to handle keys.
+               @return true if the flow graph is in active use
+               """
+               keyname = gtk.gdk.keyval_name(event.keyval)
+               ctrl = event.state & gtk.gdk.CONTROL_MASK
+               alt = event.state & gtk.gdk.MOD1_MASK
+               shift = event.state & gtk.gdk.SHIFT_MASK
+               #################### save/open/new/close 
###############################
+               if ctrl and keyname == 's':
+                       self.handle_states(FLOW_GRAPH_SAVE)
+               elif ctrl and keyname == 'o':
+                       self.handle_states(FLOW_GRAPH_OPEN)
+               elif ctrl and keyname == 'n':
+                       self.handle_states(FLOW_GRAPH_NEW)
+               elif ctrl and keyname == 'q':
+                       self.handle_states(FLOW_GRAPH_CLOSE)
+               #################### Cut/Copy/Paste 
###############################
+               elif self.get_focus_flag() and ctrl and keyname == 'x': #mouse 
focus
+                       self.handle_states(BLOCK_CUT)
+               elif self.get_focus_flag() and ctrl and keyname == 'c': #mouse 
focus
+                       self.handle_states(BLOCK_COPY)
+               elif self.get_focus_flag() and ctrl and keyname == 'v': #mouse 
focus
+                       self.handle_states(BLOCK_PASTE)
+               #################### Undo/Redo ###############################
+               elif ctrl and keyname == 'z':
+                       self.handle_states(FLOW_GRAPH_UNDO)
+               elif ctrl and keyname == 'y':
+                       self.handle_states(FLOW_GRAPH_REDO)
+               #################### Delete ###############################
+               elif self.get_focus_flag() and keyname == 'Delete':     #mouse 
focus
+                       self.handle_states(ELEMENT_DELETE)
+               #################### Params     ###############################
+               elif self.get_focus_flag() and keyname == 'Return':     #mouse 
focus
+                       self.handle_states(BLOCK_PARAM_MODIFY)
+               #################### Rotate ###############################
+               elif self.get_focus_flag() and keyname == 'Right': #mouse focus
+                       self.handle_states(BLOCK_ROTATE_RIGHT)
+               elif self.get_focus_flag() and keyname == 'Left': #mouse focus
+                       self.handle_states(BLOCK_ROTATE_LEFT)
+               #################### Enable/Disable 
###############################
+               elif self.get_focus_flag() and keyname == 'e': #mouse focus
+                       self.handle_states(BLOCK_ENABLE)
+               elif self.get_focus_flag() and keyname == 'd': #mouse focus
+                       self.handle_states(BLOCK_DISABLE)
+               #################### Data Type ###############################
+               elif self.get_focus_flag() and keyname == 'Down': #mouse focus
+                       self.handle_states(BLOCK_INC_TYPE)
+               elif self.get_focus_flag() and keyname == 'Up': #mouse focus
+                       self.handle_states(BLOCK_DEC_TYPE)
+               #################### Port Controllers 
###############################
+               elif self.get_focus_flag() and keyname in ('equal','plus', 
'KP_Add'): #mouse focus
+                       self.handle_states(PORT_CONTROLLER_INC)
+               elif self.get_focus_flag() and keyname in ('minus', 
'KP_Subtract'): #mouse focus
+                       self.handle_states(PORT_CONTROLLER_DEC)
+               #################### Gen/Exec/Stop/Print 
###############################
+               elif keyname == 'F5':
+                       self.handle_states(FLOW_GRAPH_GEN)
+               elif keyname == 'F6':
+                       self.handle_states(FLOW_GRAPH_EXEC)
+               elif keyname == 'F7':
+                       self.handle_states(FLOW_GRAPH_KILL)
+               elif keyname == 'Print':
+                       self.handle_states(FLOW_GRAPH_SCREEN_CAPTURE)
+               #propagate this if the fg is not in focus or nothing is selected
+               return self.get_focus_flag() and 
self.get_flow_graph().is_selected()
+
+       def _quit(self, window, event):
+               """!
+               Handle the delete event from the main window.
+               Generated by pressing X to close, alt+f4, or right click+close.
+               This method in turns calls the state handler to quit.
+               @return true
+               """
+               self.handle_states(APPLICATION_QUIT)
+               return True
+
+       def _handle_actions(self, event):
+               """
+               Handle all of the activate signals from the gtk actions.
+               The action signals derive from clicking on a toolbar or menu 
bar button.
+               Forward the action to the state handler.
+               """
+               self.handle_states(event.get_name())
+
+       def handle_states(self, state=''):
+               """!
+               Handle the state changes in the GUI.
+               Handle all of the state changes that arise from the action 
handler or other gui and
+               inputs in the application. The state passed to the 
handle_states method is a string descriping
+               the change. A series of if/elif statements handle the state by 
greying out action buttons, causing
+               changes in the flow graph, saving/opening files... The 
handle_states method is passed to the
+               contructors of many of the classes used in this application 
enabling them to report any state change.
+               @param state a string describing the state change
+               """
+               #print state
+               
##############################################################################################
+               # Initalize/Quit
+               
##############################################################################################
+               if state == APPLICATION_INITIALIZE:
+                       for action in ACTIONS_LIST: action.set_sensitive(False) 
#set all actions disabled
+                       # enable a select few actions
+                       for action in (
+                               APPLICATION_QUIT, FLOW_GRAPH_NEW, 
FLOW_GRAPH_OPEN, FLOW_GRAPH_SAVE_AS, FLOW_GRAPH_CLOSE,
+                               ABOUT_WINDOW_DISPLAY, HOTKEYS_WINDOW_DISPLAY,
+                               PREFS_WINDOW_DISPLAY, FLOW_GRAPH_SCREEN_CAPTURE,
+                       ): get_action_from_name(action).set_sensitive(True)
+                       if not self.init_file_paths and 
Preferences.restore_files(): self.init_file_paths = Preferences.files_open()
+                       if not self.init_file_paths: self.init_file_paths = ['']
+                       for file_path in self.init_file_paths:
+                               if file_path: 
self.main_window.new_page(file_path) #load pages from file paths
+                       if Preferences.file_open() in self.init_file_paths: 
self.main_window.new_page(Preferences.file_open(), show=True)
+                       if not self.get_page(): self.main_window.new_page() 
#ensure that at least a blank page exists
+               elif state == APPLICATION_QUIT:
+                       if self.main_window.close_pages():
+                               gtk.main_quit()
+                               exit(0)
+               
##############################################################################################
+               # Selections
+               
##############################################################################################
+               elif state == ELEMENT_SELECT:
+                       self.get_flow_graph().update()
+               elif state == NOTHING_SELECT:
+                       self.get_flow_graph().unselect()
+                       self.get_flow_graph().update()
+               
##############################################################################################
+               # Enable/Disable
+               
##############################################################################################
+               elif state == BLOCK_ENABLE:
+                       if self.get_flow_graph().enable_selected(True):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == BLOCK_DISABLE:
+                       if self.get_flow_graph().enable_selected(False):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               
##############################################################################################
+               # Cut/Copy/Paste
+               
##############################################################################################
+               elif state == BLOCK_CUT:
+                       self.handle_states(BLOCK_COPY)
+                       self.handle_states(ELEMENT_DELETE)
+               elif state == BLOCK_COPY:
+                       self.clipboard = 
self.get_flow_graph().copy_to_clipboard()
+               elif state == BLOCK_PASTE:
+                       if self.clipboard:
+                               
self.get_flow_graph().paste_from_clipboard(self.clipboard)
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               
##############################################################################################
+               # Move/Rotate/Delete/Create
+               
##############################################################################################
+               elif state == BLOCK_MOVE:
+                       
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                       self.get_page().set_saved(False)
+               elif state == BLOCK_ROTATE_LEFT:
+                       if self.get_flow_graph().rotate_selected(DIR_LEFT):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == BLOCK_ROTATE_RIGHT:
+                       if self.get_flow_graph().rotate_selected(DIR_RIGHT):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == ELEMENT_DELETE:
+                       if self.get_flow_graph().remove_selected():
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.handle_states(NOTHING_SELECT)
+                               self.get_page().set_saved(False)
+               elif state == ELEMENT_CREATE:
+                       
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                       self.handle_states(NOTHING_SELECT)
+                       self.get_page().set_saved(False)
+               elif state == BLOCK_INC_TYPE:
+                       if 
self.get_flow_graph().type_controller_modify_selected(1):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == BLOCK_DEC_TYPE:
+                       if 
self.get_flow_graph().type_controller_modify_selected(-1):
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == PORT_CONTROLLER_INC:
+                       if 
self.get_flow_graph().port_controller_modify_selected(1):
+                               self.get_flow_graph().update()
+                               self.get_flow_graph().update() #2 times
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               elif state == PORT_CONTROLLER_DEC:
+                       if 
self.get_flow_graph().port_controller_modify_selected(-1):
+                               self.get_flow_graph().update()
+                               self.get_flow_graph().update() #2 times
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               
##############################################################################################
+               # Window stuff
+               
##############################################################################################
+               elif state == PREFS_WINDOW_DISPLAY:
+                       gui.PreferencesDialog()
+                       self.get_flow_graph().update()
+               elif state == ABOUT_WINDOW_DISPLAY:
+                       gui.AboutDialog()
+               elif state == HOTKEYS_WINDOW_DISPLAY:
+                       gui.HotKeysDialog()
+               
##############################################################################################
+               # Param Modifications
+               
##############################################################################################
+               elif state == BLOCK_PARAM_MODIFY:
+                       if self.get_flow_graph().param_modify_selected():
+                               self.get_flow_graph().update()
+                               
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
+                               self.get_page().set_saved(False)
+               
##############################################################################################
+               # Undo/Redo
+               
##############################################################################################
+               elif state == FLOW_GRAPH_UNDO:
+                       n = self.get_page().get_state_cache().get_prev_state()
+                       if n:
+                               self.get_flow_graph().unselect()
+                               self.get_flow_graph().import_data(n)
+                               self.get_flow_graph().update()
+                               self.get_page().set_saved(False)
+               elif state == FLOW_GRAPH_REDO:
+                       n = self.get_page().get_state_cache().get_next_state()
+                       if n:
+                               self.get_flow_graph().unselect()
+                               self.get_flow_graph().import_data(n)
+                               self.get_flow_graph().update()
+                               self.get_page().set_saved(False)
+               
##############################################################################################
+               # New/Open/Save/Close
+               
##############################################################################################
+               elif state == FLOW_GRAPH_NEW:
+                       self.main_window.new_page()
+               elif state == FLOW_GRAPH_OPEN:
+                       file_paths = 
gui.OpenFlowGraphFileDialog(self.get_page().get_file_path()).run()
+                       if file_paths: #open a new page for each file, show 
only the first
+                               for i,file_path in enumerate(file_paths):
+                                       self.main_window.new_page(file_path, 
show=(i==0))
+               elif state == FLOW_GRAPH_CLOSE:
+                       self.main_window.close_page()
+               elif state == FLOW_GRAPH_SAVE:
+                       if not self.get_page().get_file_path(): 
self.handle_states(FLOW_GRAPH_SAVE_AS)
+                       else:
+                               try:
+                                       
ParseXML.to_file(self.get_flow_graph().export_data(), 
self.get_page().get_file_path())
+                                       self.get_page().set_saved(True)
+                               except IOError:
+                                       
Messages.send_fail_save(self.get_page().get_file_path())
+                                       self.get_page().set_saved(False)
+               elif state == FLOW_GRAPH_SAVE_AS:
+                       file_path = 
gui.SaveFlowGraphFileDialog(self.get_page().get_file_path()).run()
+                       if file_path != None:
+                               self.get_page().set_file_path(file_path)
+                               self.handle_states(FLOW_GRAPH_SAVE)
+               elif state == FLOW_GRAPH_SCREEN_CAPTURE:
+                       file_path = 
gui.SaveImageFileDialog(self.get_page().get_file_path()).run()
+                       if file_path != None:
+                               pixmap = 
self.get_flow_graph().get_drawing_area().pixmap
+                               width, height = pixmap.get_size()
+                               pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 
0, 8, width, height)
+                               pixbuf.get_from_drawable(pixmap, 
pixmap.get_colormap(), 0, 0, 0, 0, width, height)
+                               pixbuf.save(file_path, IMAGE_FILE_EXTENSION[1:])
+               
##############################################################################################
+               # Gen/Exec/Stop
+               
##############################################################################################
+               elif state == FLOW_GRAPH_GEN:
+                       if not self.get_page().get_pid():
+                               if not self.get_page().get_saved() or not 
self.get_page().get_file_path():
+                                       self.handle_states(FLOW_GRAPH_SAVE) 
#only save if file path missing or not saved
+                               if self.get_page().get_saved() and 
self.get_page().get_file_path():
+                                       generator = 
self.get_page().get_generator()
+                                       try:
+                                               
Messages.send_start_gen(generator.get_file_path())
+                                               generator.write()
+                                       except Exception,e: 
Messages.send_fail_gen(e)
+                               else: self.generator = None
+               elif state == FLOW_GRAPH_EXEC:
+                       if not self.get_page().get_pid():
+                               self.handle_states(FLOW_GRAPH_GEN)
+                               if self.get_page().get_saved() and 
self.get_page().get_file_path():
+                                       ExecFlowGraphThread(self)
+               elif state == FLOW_GRAPH_KILL:
+                       if self.get_page().get_pid():
+                               try: os.kill(self.get_page().get_pid(), 
signal.SIGKILL)
+                               except: print "could not kill pid: 
%s"%self.get_page().get_pid()
+               elif state == '': #pass and run the global actions
+                       pass
+               else: print '!!! State "%s" not handled !!!'%state
+               
##############################################################################################
+               # Global Actions for all States
+               
##############################################################################################
+               #update general buttons
+               
get_action_from_name(ELEMENT_DELETE).set_sensitive(bool(self.get_flow_graph().get_selected_elements()))
+               
get_action_from_name(BLOCK_PARAM_MODIFY).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
+               
get_action_from_name(BLOCK_ROTATE_RIGHT).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               
get_action_from_name(BLOCK_ROTATE_LEFT).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               #update cut/copy/paste
+               
get_action_from_name(BLOCK_CUT).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               
get_action_from_name(BLOCK_COPY).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               
get_action_from_name(BLOCK_PASTE).set_sensitive(bool(self.clipboard))
+               #update enable/disable
+               
get_action_from_name(BLOCK_ENABLE).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               
get_action_from_name(BLOCK_DISABLE).set_sensitive(bool(self.get_flow_graph().get_selected_blocks()))
+               #set the exec and stop buttons
+               self.update_exec_stop()
+               #saved status
+               get_action_from_name(FLOW_GRAPH_SAVE).set_sensitive(not 
self.get_page().get_saved())
+               self.main_window.update()
+               #draw the flow graph
+               self.get_flow_graph().draw()
+
+       def update_exec_stop(self):
+               """
+               Update the exec and stop buttons.
+               Lock and unlock the mutex for race conditions with exec flow 
graph threads.
+               """
+               sensitive = self.get_flow_graph().is_valid() and not 
self.get_page().get_pid()
+               get_action_from_name(FLOW_GRAPH_GEN).set_sensitive(sensitive)
+               get_action_from_name(FLOW_GRAPH_EXEC).set_sensitive(sensitive)
+               
get_action_from_name(FLOW_GRAPH_KILL).set_sensitive(self.get_page().get_pid() 
!= None)
+
+class ExecFlowGraphThread(Thread):
+       """Execute the flow graph as a new process and wait on it to finish."""
+       def __init__ (self, action_handler):
+               """!
+               ExecFlowGraphThread constructor.
+               @param action_handler an instance of an ActionHandler
+               """
+               Thread.__init__(self)
+               self.update_exec_stop = action_handler.update_exec_stop
+               self.flow_graph = action_handler.get_flow_graph()
+               #store page and dont use main window calls in run
+               self.page = action_handler.get_page()
+               
Messages.send_start_exec(self.page.get_generator().get_file_path())
+               #get the popen
+               try:
+                       self.p = self.page.get_generator().get_popen()
+                       self.page.set_pid(self.p.pid)
+                       #update
+                       self.update_exec_stop()
+                       self.start()
+               except Exception, e:
+                       Messages.send_verbose_exec(str(e))
+                       Messages.send_end_exec()
+
+       def run(self):
+               """Wait on the flow graph."""
+               #handle completion
+               r = "\n"
+               while(r):
+                       gtk.gdk.threads_enter()
+                       Messages.send_verbose_exec(r)
+                       gtk.gdk.threads_leave()
+                       r = os.read(self.p.stdout.fileno(), 1024)
+               gtk.gdk.threads_enter()
+               Messages.send_end_exec()
+               self.page.set_pid(None)
+               self.update_exec_stop()
+               gtk.gdk.threads_leave()
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Actions.py (from 
rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/Actions.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Actions.py    
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Actions.py    
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,107 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden Actions
+#Global actions for gui elements to communicate state changes to the action 
handler.
+#Use gtk.stock_list_ids() to get a list of possible stock ids (for 
toolbar/menu icons)
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+######################################################################################################
+# States
+######################################################################################################
+APPLICATION_INITIALIZE = 'app init'
+APPLICATION_QUIT = 'app quit'
+PARAM_MODIFY = 'param modify'
+BLOCK_MOVE = 'block move'
+BLOCK_ROTATE_LEFT = 'block rotate left'
+BLOCK_ROTATE_RIGHT = 'block rotate right'
+BLOCK_PARAM_MODIFY = 'block param modify'
+BLOCK_INC_TYPE = 'block increment type'
+BLOCK_DEC_TYPE = 'block decrement type'
+BLOCK_ENABLE = 'block enable'
+BLOCK_DISABLE = 'block disable'
+BLOCK_CUT = 'block cut'
+BLOCK_COPY = 'block copy'
+BLOCK_PASTE = 'block paste'
+PORT_CONTROLLER_INC = 'port controller increment'
+PORT_CONTROLLER_DEC = 'port controller decrement'
+ELEMENT_CREATE = 'element create'
+ELEMENT_DELETE = 'element delete'
+ELEMENT_SELECT = 'element select'
+NOTHING_SELECT = 'nothing select'
+FLOW_GRAPH_OPEN = 'flow graph open'
+FLOW_GRAPH_UNDO = 'flow graph undo'
+FLOW_GRAPH_REDO = 'flow graph redo'
+FLOW_GRAPH_SAVE = 'flow graph save'
+FLOW_GRAPH_SAVE_AS = 'flow graph save as'
+FLOW_GRAPH_CLOSE = 'flow graph close'
+FLOW_GRAPH_NEW = 'flow graph new'
+FLOW_GRAPH_GEN = 'flow graph gen'
+FLOW_GRAPH_EXEC = 'flow graph exec'
+FLOW_GRAPH_KILL = 'flow graph kill'
+FLOW_GRAPH_SCREEN_CAPTURE = 'flow graph screen capture'
+ABOUT_WINDOW_DISPLAY = 'about window display'
+HOTKEYS_WINDOW_DISPLAY = 'hotkeys window display'
+PREFS_WINDOW_DISPLAY = 'prefs window display'
+
+######################################################################################################
+# Actions
+######################################################################################################
+ACTIONS_LIST = (
+       gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', 
'gtk-new'),
+       gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', 
'gtk-open'),
+       gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', 
'gtk-save'),
+       gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph 
as...', 'gtk-save-as'),
+       gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', 
'gtk-close'),
+       gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', 'gtk-quit'),
+       gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', 
'gtk-undo'),
+       gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', 
'gtk-redo'),
+       gtk.Action(ELEMENT_DELETE, '_Delete', 'Delete the selected blocks', 
'gtk-delete'),
+       gtk.Action(BLOCK_ROTATE_LEFT, 'Rotate _Left', 'Rotate the selected 
blocks 90 degrees', 'gtk-go-back'),
+       gtk.Action(BLOCK_ROTATE_RIGHT, 'Rotate _Right', 'Rotate the selected 
blocks -90 degrees', 'gtk-go-forward'),
+       gtk.Action(BLOCK_PARAM_MODIFY, '_Properties', 'Modify params for the 
selected block', 'gtk-properties'),
+       gtk.Action(BLOCK_ENABLE, 'E_nable', 'Enable the selected blocks', 
'gtk-connect'),
+       gtk.Action(BLOCK_DISABLE, 'D_isable', 'Disable the selected blocks', 
'gtk-disconnect'),
+       gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', 'gtk-cut'),
+       gtk.Action(BLOCK_COPY, '_Copy', 'Copy', 'gtk-copy'),
+       gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', 'gtk-paste'),
+       gtk.Action(PREFS_WINDOW_DISPLAY, '_Preferences', 'Configure 
Preferences', 'gtk-preferences'),
+       gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', 
'gtk-about'),
+       gtk.Action(HOTKEYS_WINDOW_DISPLAY, '_HotKeys', 'Hot Keys', 'gtk-info'),
+       gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', 
'gtk-convert'),
+       gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', 
'gtk-execute'),
+       gtk.Action(FLOW_GRAPH_KILL, '_Kill', 'Kill the flow graph', 'gtk-stop'),
+       gtk.Action(FLOW_GRAPH_SCREEN_CAPTURE, 'S_creen Capture', 'Create a 
screen capture of the flow graph', 'gtk-print'),
+)
+
+ACTIONS_DICT = dict((action.get_name(), action) for action in ACTIONS_LIST)
+
+def get_action_from_name(action_name):
+       """!
+       Retrieve the action from the action list.
+       Search the list and find an action with said name.
+       @param action_name the action name(string)
+       @throw KeyError bad action name
+       @return a gtk action object
+       """
+       if ACTIONS_DICT.has_key(action_name): return ACTIONS_DICT[action_name]
+       raise KeyError('Action Name: "%s" does not exist'%action_name)
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Constants.py.in 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/Constants.py.in)
===================================================================
--- 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Constants.py.in   
                            (rev 0)
+++ 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Constants.py.in   
    2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,154 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.Constants
+#Global constants
address@hidden Josh Blum
+
+import os
+
+######################################################################################################
+## Global Titles
+######################################################################################################
+
+##The current version of this code
+VERSION = '@VERSION@'
+
+##The name to appear in the main window for a flow graph that has not been 
saved to file.
+NEW_FLOGRAPH_TITLE = 'untitled'
+
+##The prefix title on the main window.
+MAIN_WINDOW_PREFIX = "GRC"
+
+######################################################################################################
+## Signal block connector lengths
+######################################################################################################
+
+##The length that a connection must extend from the port until the length 
depends on the index of the port.
+CONNECTOR_EXTENSION_INITIAL_LENGTH = 11
+
+##The length that a connection must extend from the initial length times the 
index of the port, after this length, the connection may have a bend.
+CONNECTOR_EXTENSION_LENGTH = 11
+
+##The length of the connector arrow base in pixels
+CONNECTOR_ARROW_BASE = 13
+
+##The length of the connector arrow height in pixels
+CONNECTOR_ARROW_HEIGHT = 17
+
+######################################################################################################
+## Signal block rotations
+######################################################################################################
+
+##List of possible angles (in degrees) that a block can be rotated to.
+POSSIBLE_ROTATIONS = (0, 90, 180, 270)
+
+##direction of rotation left.
+DIR_LEFT = 'left'
+
+##direction of rotation right.
+DIR_RIGHT = 'right'
+
+######################################################################################################
+## Dimension constraints for the various windows (in pixels)
+######################################################################################################
+
+##main window constraints
+MIN_WINDOW_WIDTH = 600
+MIN_WINDOW_HEIGHT = 400
+
+##dialog constraints
+MIN_DIALOG_WIDTH = 500
+MIN_DIALOG_HEIGHT = 500
+
+##static height of reports window
+REPORTS_WINDOW_HEIGHT = 100
+
+##static width of block selection window
+BLOCK_SELECTION_WINDOW_WIDTH = 200
+
+######################################################################################################
+## Constraints on displayable labels and ports
+######################################################################################################
+
+LABEL_SEPARATION = 3
+LABEL_PADDING_WIDTH = 9
+LABEL_PADDING_HEIGHT = 9
+
+PORT_SEPARATION = 17
+PORT_HEIGHT = 15
+PORT_WIDTH = 25
+PORT_BORDER_SEPARATION = 9
+MAX_NUM_PORTS = 7
+
+PARAM_LABEL_FONT = 'Sans 9.5'
+PARAM_FONT = 'Sans 7.5'
+BLOCK_FONT = 'Sans 8'
+PORT_FONT = 'Sans 7.5'
+
+######################################################################################################
+## Dragging, scrolling, and redrawing constants for the flow graph window in 
pixels
+######################################################################################################
+
+##How close can the mouse get to the window border before mouse events are 
ignored.
+BORDER_PROXIMITY_SENSITIVITY = 50
+
+##How close the mouse can get to the edge of the visible window before 
scrolling is invoked.
+SCROLL_PROXIMITY_SENSITIVITY = 30
+
+##When the window has to be scrolled, move it this distance in the required 
direction.
+SCROLL_DISTANCE = 15
+
+##The redrawing sensitivity, how many seconds must pass between motion events 
before a redraw?
+MOTION_DETECT_REDRAWING_SENSITIVITY = .02
+
+##How close the mouse click can be to a connection and register a connection 
select.
+CONNECTION_SELECT_SENSITIVITY = 5
+
+######################################################################################################
+# A state is recorded for each change to the flow graph, the size dictates how 
many states we can record
+######################################################################################################
+
+##The size of the state saving cache in the flow graph (for undo/redo 
functionality)
+STATE_CACHE_SIZE = 42
+
+######################################################################################################
+## Constansts dealing with File Paths
+######################################################################################################
+
+##Location of external data files.
+DATA_DIR = '@datadir@'
+
+##DTD validator for saved flow graphs.
+FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
+
+##The default file extension for flow graphs.
+FLOW_GRAPH_FILE_EXTENSION = '.grc'
+
+##The default file extension for saving flow graph snap shots.
+IMAGE_FILE_EXTENSION = '.png'
+
+##The default path for the open/save dialogs.
+DEFAULT_FILE_PATH = os.getcwd()
+
+##The default icon for the gtk windows.
+PY_GTK_ICON = os.path.join(DATA_DIR, 'grc-icon-256.png')
+
+##The users home directory.
+HOME_DIR = os.path.expanduser('~')
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Messages.py (from 
rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/Messages.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Messages.py   
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Messages.py   
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,104 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden Messages
+#Handle all of the system messages and error reports.
+
+from Constants import VERSION
+import traceback
+import sys
+
+##     A list of functions that can receive a message.
+MESSENGERS_LIST = list()
+
+def register_messenger(messenger):
+       """!
+       Append the given messenger to the list of messengers.
+       @param messenger a method thats takes a string
+       """
+       MESSENGERS_LIST.append(messenger)
+
+def send(message):
+       """!
+       Give the message to each of the messengers.
+       @param message a message string
+       """
+       for messenger in MESSENGERS_LIST: messenger(message)
+
+#register stdout by default
+register_messenger(sys.stdout.write)
+
+###########################################################################
+#      Special functions for specific program functionalities
+###########################################################################
+def send_init():
+       send("""<<< Welcome to GRC %s >>>\n"""%VERSION)
+
+def send_page_switch(file_path):
+       send('\nShowing: "%s"\n'%file_path)
+
+#################      functions for loading flow graphs       
########################################
+def send_start_load(file_path):
+       send('\nLoading: "%s"'%file_path + '\n')
+
+def send_error_load(error):
+       send('>>> Error: %s\n'%error)
+       traceback.print_exc()
+
+def send_end_load():
+       send(">>> Done\n")
+
+def send_fail_load(error):
+       send('Parser Error: %s\n'%error)
+       send(">>> Failue\n")
+       traceback.print_exc()
+
+#################      functions for generating flow graphs    
########################################
+def send_start_gen(file_path):
+       send('\nGenerating: "%s"'%file_path + '\n')
+
+def send_fail_gen(error):
+       send('Generate Error: %s\n'%error)
+       send(">>> Failue\n")
+       traceback.print_exc()
+
+#################      functions for executing flow graphs     
########################################
+def send_start_exec(file_path):
+       send('\nExecuting: "%s"'%file_path + '\n')
+
+def send_verbose_exec(verbose):
+       send(verbose)
+
+def send_end_exec():
+       send("\n>>> Done\n")
+
+#################      functions for saving flow graphs        
########################################
+def send_fail_save(file_path):
+       send('>>> Error: Cannot save: %s\n'%file_path)
+
+#################      functions for connections       
########################################
+def send_fail_connection():
+       send('>>> Warning: A connection can only be created between a source 
and an unconnected sink.\n')
+
+#################      functions for preferences       
########################################
+def send_fail_load_preferences(prefs_file_path):
+       send('>>> Error: Cannot load preferences file: "%s"\n'%prefs_file_path)
+
+def send_fail_save_preferences(prefs_file_path):
+       send('>>> Error: Cannot save preferences file: "%s"\n'%prefs_file_path)
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ParseXML.py (from 
rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/ParseXML.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ParseXML.py   
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/ParseXML.py   
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,102 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.gui.ParseXML
+#Parse xml files to nested data and vice-versa.
+
+from lxml import etree
+from Utils import odict
+
+XMLSyntaxError = etree.XMLSyntaxError
+
+def validate_dtd(xml_file, dtd_file=None):
+       """!
+       Validate an xml file against its dtd.
+       @param xml_file the xml file
+       @param dtd_file the optional dtd file
+       @throws Exception validation fails
+       """
+       if dtd_file:
+               dtd = etree.DTD(dtd_file)
+               xml = etree.parse(xml_file)
+               if not dtd.validate(xml.getroot()):
+                       raise XMLSyntaxError, '\n'.join(map(str, 
dtd.error_log.filter_from_errors()))
+       else:
+               parser = etree.XMLParser(dtd_validation=True)
+               xml = etree.parse(xml_file, parser=parser)
+               if parser.error_log:
+                       raise XMLSyntaxError, '\n'.join(map(str, 
parser.error_log.filter_from_errors()))
+
+def from_file(xml_file):
+       """!
+       Create nested data from an xml file using the from xml helper.
+       @param xml_file the xml file path
+       @return the nested data
+       """
+       xml = etree.parse(xml_file).getroot()
+       return _from_file(xml)
+
+def _from_file(xml):
+       """!
+       Recursivly parse the xml tree into nested data format.
+       @param xml the xml tree
+       @return the nested data
+       """
+       tag = xml.tag
+       if not len(xml):
+               return odict({tag: xml.text or ''}) #store empty tags (text is 
None) as empty string
+       nested_data = odict()
+       for elem in xml:
+               key, value = _from_file(elem).items()[0]
+               if nested_data.has_key(key): nested_data[key].append(value)
+               else: nested_data[key] = [value]
+       #delistify if the length of values is 1
+       for key, values in nested_data.iteritems():
+               if len(values) == 1: nested_data[key] = values[0]
+       return odict({tag: nested_data})
+
+def to_file(nested_data, xml_file):
+       """!
+       Write an xml file and use the to xml helper method to load it.
+       @param nested_data the nested data
+       @param xml_file the xml file path
+       """
+       xml = _to_file(nested_data)[0]
+       open(xml_file, 'w').write(etree.tostring(xml, xml_declaration=True, 
pretty_print=True))
+
+def _to_file(nested_data):
+       """!
+       Recursivly parse the nested data into xml tree format.
+       @param nested_data the nested data
+       @return the xml tree filled with child nodes
+       """
+       nodes = list()
+       for key, values in nested_data.iteritems():
+               #listify the values if not a list
+               if not isinstance(values, (list, set, tuple)):
+                       values = [values]
+               for value in values:
+                       node = etree.Element(key)
+                       if isinstance(value, (str, unicode)): node.text = value
+                       else: node.extend(_to_file(value))
+                       nodes.append(node)
+       return nodes
+
+if __name__ == '__main__':
+       """Use the main method to test parse xml's functions."""
+       pass

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Preferences.py 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/Preferences.py)
===================================================================
--- 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Preferences.py    
                            (rev 0)
+++ 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Preferences.py    
    2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,133 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.Preferences
+#Holds global paramerences
+
+from Constants import HOME_DIR, FLOW_GRAPH_DTD
+import ParseXML
+import Messages
+import os
+
+##Access the loaded preferences in this module
+_prefs = list()
+def _set_prefs(prefs): _prefs.append(prefs)
+def _get_prefs(): return _prefs[0]
+def load(platform): _Preferences(platform)
+def save(): _get_prefs().save()
+def get_preferences(): return _get_prefs().get_preferences()
+
+class _Preferences(object):
+
+       def __init__(self, platform):
+               #make self available to module
+               _set_prefs(self)
+               #get prefs block
+               self._prefs_block = platform.get_prefs_block()
+               #prefs file path
+               self._prefs_file_path = os.path.join(HOME_DIR, 
self._prefs_block.get_param('prefs_file').get_value())
+               #load
+               try:
+                       ParseXML.validate_dtd(self._prefs_file_path, 
FLOW_GRAPH_DTD)
+                       n = ParseXML.from_file(self._prefs_file_path)
+                       self._prefs_block.import_data(n['block'])
+               except: 
Messages.send_fail_load_preferences(self._prefs_file_path)
+               ##all params
+               self.snap_to_grid_param = 
self._prefs_block.get_param('snap_to_grid')
+               self.grid_size_param = self._prefs_block.get_param('grid_size')
+               self.show_grid_param = self._prefs_block.get_param('show_grid')
+               self.show_reports_param = 
self._prefs_block.get_param('show_reports')
+               self.restore_files_param = 
self._prefs_block.get_param('restore_files')
+               self.window_size_param = 
self._prefs_block.get_param('window_size')
+               self.file_open_param = self._prefs_block.get_param('file_open')
+               self.files_open_param = 
self._prefs_block.get_param('files_open')
+               self.show_params_param = 
self._prefs_block.get_param('show_params')
+               self.show_id_param = self._prefs_block.get_param('show_id')
+
+       def save(self):
+               try: ParseXML.to_file({'block': 
self._prefs_block.export_data()}, self._prefs_file_path)
+               except IOError: 
Messages.send_fail_save_preferences(self._prefs_file_path)
+
+       def get_preferences(self):
+               ##Preferences: title, notes, params
+               return [
+                       (
+                               'Grid',
+                               '''
+Show grid will draw a square grid onto the flow graph with grid points 
separated by grid size pixels. \
+Snap to Grid forces the upper right corner of the signal block to align with a 
grid point.
+''',
+                               [self.snap_to_grid_param, self.grid_size_param, 
self.show_grid_param],
+                       ),
+                       (
+                               'Appearance',
+                               '''
+Show or hide the reports window at the bottom of the main window.
+Show or hide all paramater labels in the signal blocks.
+Show or hide the ID label in the signal blocks.
+''',
+                               [self.show_reports_param, 
self.show_params_param, self.show_id_param],
+                       ),
+                       (
+                               'Misc',
+                               '''
+Restore previously opened files on start-up.
+''',
+                               [self.restore_files_param],
+                       ),
+               ]
+
+###########################################################################
+#      Special methods for specific program functionalities
+###########################################################################
+
+def window_size(size=None):
+       if size: _get_prefs().window_size_param.set_value(size)
+       else:
+               try: return eval(_get_prefs().window_size_param.get_value())
+               except: return (-1, -1)
+
+def restore_files():
+       return _get_prefs().restore_files_param.get_value() == 'yes'
+
+def file_open(file=None):
+       if file is not None: _get_prefs().file_open_param.set_value(file)
+       else: return _get_prefs().file_open_param.get_value()
+
+def files_open(files=None):
+       if files is not None: 
_get_prefs().files_open_param.set_value('\n'.join(files))
+       else: return _get_prefs().files_open_param.get_value().split('\n')
+
+def show_reports_window():
+       return _get_prefs().show_reports_param.get_value() == 'show'
+
+def get_grid_size():
+       return int(_get_prefs().grid_size_param.get_value())
+
+def snap_to_grid():
+       return _get_prefs().snap_to_grid_param.get_value() == 'on'
+
+def show_grid():
+       return _get_prefs().show_grid_param.get_value() == 'show'
+
+def show_params():
+       return _get_prefs().show_params_param.get_value() == 'show'
+
+def show_id():
+       return _get_prefs().show_id_param.get_value() == 'show'
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/StateCache.py 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/StateCache.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/StateCache.py 
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/StateCache.py 
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,97 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden StateCache
+#Stores the flow graph states to drive the undo/redo and save interface.
+
+from Actions import FLOW_GRAPH_UNDO, FLOW_GRAPH_REDO, get_action_from_name
+
+from Constants import STATE_CACHE_SIZE
+
+class StateCache(object):
+       """
+       The state cache is an interface to a list to record data/states and to 
revert to previous states.
+       States are recorded into the list in a circular fassion by using an 
index for the current state,
+       and counters for the range where states are stored.
+       """     
+       
+       def __init__(self, initial_state):
+               """!
+               StateCache constructor.
+               @param initial_state the intial state (nested data)
+               """
+               self.states = [None] * STATE_CACHE_SIZE #fill states
+               self.current_state_index = 0
+               self.num_prev_states = 0
+               self.num_next_states = 0
+               self.states[0] = initial_state
+               self.update_actions()
+                       
+       def save_new_state(self, state):
+               """!
+               Save a new state.
+               Place the new state at the next index and add one to the number 
of previous states.
+               @param state the new state
+               """
+               self.current_state_index = (self.current_state_index + 
1)%STATE_CACHE_SIZE
+               self.states[self.current_state_index] = state           
+               self.num_prev_states = self.num_prev_states + 1
+               if self.num_prev_states == STATE_CACHE_SIZE: 
self.num_prev_states = STATE_CACHE_SIZE - 1
+               self.num_next_states = 0
+               self.update_actions()
+                       
+       def get_current_state(self):
+               """!
+               Get the state at the current index.
+               @return the current state (nested data)
+               """
+               self.update_actions()
+               return self.states[self.current_state_index]            
+       
+       def get_prev_state(self):
+               """!
+               Get the previous state and decrement the current index.
+               @return the previous state or None
+               """
+               if self.num_prev_states > 0:
+                       self.current_state_index = (self.current_state_index + 
STATE_CACHE_SIZE -1)%STATE_CACHE_SIZE
+                       self.num_next_states = self.num_next_states + 1
+                       self.num_prev_states = self.num_prev_states - 1
+                       return self.get_current_state()
+               return None             
+       
+       def get_next_state(self):
+               """!
+               Get the nest state and increment the current index.
+               @return the next state or None
+               """
+               if self.num_next_states > 0:
+                       self.current_state_index = (self.current_state_index + 
1)%STATE_CACHE_SIZE
+                       self.num_next_states = self.num_next_states - 1
+                       self.num_prev_states = self.num_prev_states + 1
+                       return self.get_current_state()
+               return None
+               
+       def update_actions(self):
+               """
+               Update the undo and redo actions based on the number of next 
and prev states.
+               """
+               
get_action_from_name(FLOW_GRAPH_REDO).set_sensitive(self.num_next_states != 0)
+               
get_action_from_name(FLOW_GRAPH_UNDO).set_sensitive(self.num_prev_states != 0)
+               
+               

Copied: gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Utils.py 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/Utils.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Utils.py      
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/Utils.py      
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,59 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.gui.Utils
+#Utility methods and classes.
+
+from UserDict import DictMixin
+
+class odict(DictMixin):
+
+       def __init__(self, d={}):
+               self._keys = list(d.keys())
+               self._data = dict(d.copy())
+
+       def __setitem__(self, key, value):
+               if key not in self._data:
+                       self._keys.append(key)
+               self._data[key] = value
+
+       def __getitem__(self, key):
+               return self._data[key]
+
+       def __delitem__(self, key):
+               del self._data[key]
+               self._keys.remove(key)
+
+       def keys(self):
+               return list(self._keys)
+
+       def copy(self):
+               copy_dict = odict()
+               copy_dict._data = self._data.copy()
+               copy_dict._keys = list(self._keys)
+               return copy_dict
+
+def exists_or_else(d, key, alt):
+       if d.has_key(key): return d[key]
+       else: return alt
+
+def listify(d, key):
+       obj = exists_or_else(d, key, [])
+       if isinstance(obj, list): return obj
+       return [obj]
+

Copied: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/converter.py 
(from rev 9481, 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/grc/converter.py)
===================================================================
--- gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/converter.py  
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc_reorganize/grc/src/gui/converter.py  
2008-09-02 21:43:20 UTC (rev 9487)
@@ -0,0 +1,250 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion 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 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion 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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.converter
+#convert old flow graph file format to new format
+
+from grc.Constants import FLOW_GRAPH_DTD
+from grc import ParseXML, Utils
+from grc.Utils import odict
+from lxml import etree
+import difflib
+import os
+
+def _make_param(key, value):
+       """!
+       Make a paramater dict from the key/value pair.
+       @param key the key
+       @param value the value
+       @return a dictionary object
+       """
+       param = odict()
+       param['key'] = key
+       param['value'] = value
+       return param
+
+def _get_blocks(blocks, tag):
+       """!
+       Get a list of blocks with the tag.
+       @param blocks the old block list
+       @param tag the tag name
+       @retun a list of matching blocks
+       """
+       return filter(lambda b: b['tag'] == tag, blocks)
+
+def _get_params(block):
+       """!
+       Get a list of params.
+       @param block the old block
+       @retun a list of params
+       """
+       params = Utils.exists_or_else(block, 'params', {}) or {}
+       params = Utils.listify(params, 'param')
+       return params
+
+def _convert_id(id):
+       """!
+       Convert an old id to a new safe id.
+       Replace spaces with underscores.
+       Lower case the odl id.
+       @return the reformatted id
+       """
+       return id.lower().replace(' ', '_')
+
+def convert(file_path, platform):
+       """!
+       Convert the flow graph to the new format.
+       Make a backup of the old file.
+       Save a reformated flow graph to the file path.
+       If this is a new format flow graph, do nothing.
+       @param file_path the path to the saved flow graph
+       @param platform the grc gnuradio platform
+       """
+       try: #return if file passes validation
+               ParseXML.validate_dtd(file_path, FLOW_GRAPH_DTD)
+               try:
+                       changed = False
+                       #convert instances of gui_coordinate and gui_rotation
+                       xml = etree.parse(file_path)
+                       for find, replace in (
+                               ('gui_coordinate', '_coordinate'),
+                               ('gui_rotation', '_rotation'),
+                       ):
+                               keys = 
xml.xpath('/flow_graph/block/param[key="%s"]/key'%find)
+                               for key in keys:
+                                       key.text = replace
+                                       changed = True
+                       if not changed: return
+                       #backup after successful conversion
+                       os.rename(file_path, file_path+'.bak')
+                       #save new flow graph to file path
+                       xml.write(file_path, xml_declaration=True, 
pretty_print=True)
+               except Exception, e: print e
+               return
+       except: pass #convert
+       ############################################################
+       # extract window size, variables, blocks, and connections
+       ############################################################
+       old_n = ParseXML.from_file(file_path)['flow_graph']
+       try: window_width = min(3*int(old_n['window_width'])/2, 2048)
+       except: window_width = 2048
+       try: window_height = min(3*int(old_n['window_height'])/2, 2048)
+       except: window_height = 2048
+       window_size = '%d, %d'%(window_width, window_height)
+       variables = Utils.exists_or_else(old_n, 'vars', {}) or {}
+       variables = Utils.listify(variables, 'var')
+       blocks = Utils.exists_or_else(old_n, 'signal_blocks', {}) or {}
+       blocks = Utils.listify(blocks, 'signal_block')
+       connections = Utils.exists_or_else(old_n, 'connections', {}) or {}
+       connections = Utils.listify(connections, 'connection')
+       #initialize new nested data
+       new_n = odict()
+       new_n['block'] = list()
+       new_n['connection'] = list()
+       ############################################################
+       # conversion - options block
+       ############################################################
+       #get name
+       about_blocks = _get_blocks(blocks, 'About')
+       if about_blocks: title = _get_params(about_blocks[0])[0]
+       else: title = 'Untitled'
+       #get author
+       if about_blocks: author = _get_params(about_blocks[0])[1]
+       else: author = ''
+       #get desc
+       note_blocks = _get_blocks(blocks, 'Note')
+       if note_blocks: desc = _get_params(note_blocks[0])[0]
+       else: desc = ''
+       #create options block
+       options_block = odict()
+       options_block['key'] = 'options'
+       options_block['param'] = [
+               _make_param('id', 'top_block'),
+               _make_param('title', title),
+               _make_param('author', author),
+               _make_param('description', desc),
+               _make_param('window_size', window_size),
+               _make_param('_coordinate', '(10, 10)'),
+       ]
+       #append options block
+       new_n['block'].append(options_block)
+       ############################################################
+       # conversion - variables
+       ############################################################
+       x = 100 
+       for variable in variables:
+               key = variable['key']
+               value = variable['value']
+               minimum = Utils.exists_or_else(variable, 'min', '')
+               maximum = Utils.exists_or_else(variable, 'max', '')
+               step = Utils.exists_or_else(variable, 'step', '')
+               x = x + 150
+               coor = '(%d, %d)'%(x, 10)
+               var_block = odict()
+               if minimum and maximum: #slider varible
+                       #determine num steps
+                       try: num_steps = str(int((float(maximum) - 
float(minimum))/float(step)))
+                       except: num_steps = '100'
+                       var_block['key'] = 'variable_slider'
+                       var_block['param'] = [
+                               _make_param('id', key),
+                               _make_param('value', value),
+                               _make_param('min', minimum),
+                               _make_param('max', maximum),
+                               _make_param('num_steps', num_steps),
+                               _make_param('_coordinate', coor),
+                       ]
+               else: #regular variable
+                       var_block['key'] = 'variable'
+                       var_block['param'] = [
+                               _make_param('id', key),
+                               _make_param('value', value),
+                               _make_param('_coordinate', coor),
+                       ]
+               #append variable block
+               new_n['block'].append(var_block)
+       ############################################################
+       # conversion - blocks
+       ############################################################
+       #create name to key map for all blocks in platform
+       name_to_key = dict((b.get_name(), b.get_key()) for b in 
platform.get_blocks())
+       for block in blocks:
+               #extract info
+               tag = block['tag']
+               #ignore list
+               if tag in ('Note', 'About'): continue
+               id = _convert_id(block['id'])
+               coor = '(%s, %s + 100)'%(
+                       Utils.exists_or_else(block, 'x_coordinate', '0'),
+                       Utils.exists_or_else(block, 'y_coordinate', '0'),
+               )
+               rot = Utils.exists_or_else(block, 'rotation', '0')
+               params = _get_params(block)
+               #new block
+               new_block = odict()
+               matches = difflib.get_close_matches(tag, name_to_key.keys(), 1)
+               if not matches: continue
+               #match found
+               key = name_to_key[matches[0]]
+               new_block['key'] = key
+               new_block['param'] = [
+                       _make_param('id', id),
+                       _make_param('_coordinate', coor),
+                       _make_param('_rotation', rot),
+               ]
+               #handle specific blocks
+               if key == 'wxgui_fftsink2':
+                       params = params[0:3] + ['0'] + params[3:4] + ['8'] + 
params[4:]
+               #append params
+               for i, param in enumerate(params):
+                       platform_block = platform.get_block(key)
+                       try: platform_param = platform_block.get_params()[i+2]
+                       except IndexError: break
+                       if platform_param.is_enum():
+                               try: param_value = 
platform_param.get_option_keys()[int(param)]
+                               except: param_value = 
platform_param.get_option_keys()[0]
+                       else:
+                               param_value = param.replace('$', 
'').replace('^', '**')
+                       
new_block['param'].append(_make_param(platform_param.get_key(), param_value))
+               #append block
+               new_n['block'].append(new_block)
+       ############################################################
+       # conversion - connections
+       ############################################################
+       for connection in connections:
+               #extract info
+               input_signal_block_id = connection['input_signal_block_id']
+               input_socket_index = connection['input_socket_index']
+               output_signal_block_id = connection['output_signal_block_id']
+               output_socket_index = connection['output_socket_index']
+               #new connection
+               new_conn = odict()
+               new_conn['source_block_id'] = 
_convert_id(output_signal_block_id)
+               new_conn['sink_block_id'] = _convert_id(input_signal_block_id)
+               new_conn['source_key'] = output_socket_index
+               new_conn['sink_key'] = input_socket_index
+               #append connection
+               new_n['connection'].append(new_conn)
+       ############################################################
+       # backup and replace
+       ############################################################
+       #backup after successful conversion
+       os.rename(file_path, file_path+'.bak')
+       #save new flow graph to file path
+       ParseXML.to_file({'flow_graph': new_n}, file_path)
+

Added: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/platforms/__init__.py
===================================================================

Added: 
gnuradio/branches/developers/jblum/grc_reorganize/grc/src/utils/__init__.py
===================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]