[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5774 - in grc/branches/jblum_work: notes src src/Elem
From: |
jblum |
Subject: |
[Commit-gnuradio] r5774 - in grc/branches/jblum_work: notes src src/Elements src/Graphics src/SignalBlockDefs |
Date: |
Fri, 15 Jun 2007 14:41:28 -0600 (MDT) |
Author: jblum
Date: 2007-06-15 14:41:27 -0600 (Fri, 15 Jun 2007)
New Revision: 5774
Modified:
grc/branches/jblum_work/notes/notes.txt
grc/branches/jblum_work/src/ActionHandler.py
grc/branches/jblum_work/src/Elements/Connection.py
grc/branches/jblum_work/src/Elements/Socket.py
grc/branches/jblum_work/src/ExecFlowGraph.py
grc/branches/jblum_work/src/ExecFlowGraphGUI.py
grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
grc/branches/jblum_work/src/Graphics/Bars.py
grc/branches/jblum_work/src/Graphics/Dialogs.py
grc/branches/jblum_work/src/Graphics/FlowGraph.py
grc/branches/jblum_work/src/Graphics/FlowGraphFileDialog.py
grc/branches/jblum_work/src/Graphics/MainWindow.py
grc/branches/jblum_work/src/Graphics/SignalBlockParamsDialog.py
grc/branches/jblum_work/src/Graphics/SignalBlockSelectionWindow.py
grc/branches/jblum_work/src/Graphics/USRPDiagnostics.py
grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
grc/branches/jblum_work/src/MathExprParser.py
grc/branches/jblum_work/src/SignalBlockDefs/Modulators.py
grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
grc/branches/jblum_work/src/StateCache.py
grc/branches/jblum_work/src/Variables.py
Log:
added QAM, doxygen for Graphics package and some SignalBlockDefs files
Modified: grc/branches/jblum_work/notes/notes.txt
===================================================================
--- grc/branches/jblum_work/notes/notes.txt 2007-06-15 20:01:45 UTC (rev
5773)
+++ grc/branches/jblum_work/notes/notes.txt 2007-06-15 20:41:27 UTC (rev
5774)
@@ -1,7 +1,8 @@
############ Blocks to Add: ####################
--blks.pkt mod/demod? (needs an instance of a mod/demod for a param)
+-ofdm
+-usrp misc settings
-usrp dual and quad souce
--blks blocks, add filesave for message reports
+-blks blocks, add filesave for logging
-combine add/mult with add/mult vector
-selector blocks
@@ -15,6 +16,7 @@
-changing an enum doesnt call update for params with variable datatypes
############ Features to Add: ####################
+-packet framework
-save settings after close (working directory)
-create sub-flow graphs to be used in larger flow graphs
-include dtd in saved flow graphs
Modified: grc/branches/jblum_work/src/ActionHandler.py
===================================================================
--- grc/branches/jblum_work/src/ActionHandler.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/ActionHandler.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -255,7 +255,7 @@
elif state == MATH_EXPR_WINDOW_DISPLAY:
Graphics.MathExprDialog()
elif state == FLOW_GRAPH_WINDOW_RESIZE:
- dimensions =
Graphics.FlowGraphWindowSizeDialog(self.flow_graph).run()
+ dimensions =
Graphics.FlowGraphWindowSizeDialog(self.flow_graph.get_size_request()).run()
if dimensions != None:
self.flow_graph.set_size_request(dimensions[0],
dimensions[1])
self.state_cache.save_new_state(self.flow_graph.to_nested_data())
Modified: grc/branches/jblum_work/src/Elements/Connection.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Connection.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Elements/Connection.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -23,12 +23,8 @@
import Element
import Utils
-class InvalidConnectionException(Exception):
- def __str__(self): return 'A connection requires a valid input and
output socket!'
+class ConnectionException(Exception): pass
-class TooManyConnectionsException(Exception):
- def __str__(self): return 'An input socket may only have one
connection!'
-
class Connection(Element.Element):
"""Connection provides elemental interfaces for a connection of
sockets."""
type = 'connection'
@@ -60,7 +56,7 @@
socket2.connect(self) #order is important, try input
socket first (since input can throw an exception)
socket1.connect(self)
self.sockets = [socket2, socket1]
- else: raise InvalidConnectionException()
+ else: raise ConnectionException, 'A connection requires a valid
input and output socket!'
def get_coordinate(self):
"""!Get the 0,0 coordinate.
Modified: grc/branches/jblum_work/src/Elements/Socket.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Socket.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Elements/Socket.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -22,7 +22,7 @@
import Element
import Utils,DataTypes
-from Connection import TooManyConnectionsException
+from Connection import ConnectionException
class Socket(Element.Element):
"""
@@ -133,7 +133,8 @@
@param connection the connection
@throw TooManyConnectionsException input socket with an
existing connection
"""
- if Utils.is_input_socket(self) and self.is_connected(): raise
TooManyConnectionsException()
+ if Utils.is_input_socket(self) and self.is_connected():
+ raise ConnectionException, 'An input socket may only
have one connection!'
self.connections.append(connection)
self.update()
Modified: grc/branches/jblum_work/src/ExecFlowGraph.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -40,7 +40,7 @@
gr.flow_graph.__init__(self)
self.callbacks = list()
self.var_keys = list()
- self.parse_nested_data(nested_data)
+ self._parse_nested_data(nested_data)
def add_window(self, window, type='', title=''):
''' Empty method for adding a window in the GUI flow graph.
'''
@@ -68,7 +68,7 @@
else: function(data_type_params.parse())
except: print "error parsing a callback -> ignoring..."
- def parse_nested_data(self, nested_data):
+ def _parse_nested_data(self, nested_data):
""" Parse nested data from a flow graph file and build the
graphics.
This code is partially copied from FlowGraph.py, with
unnecessary code removed. """
find_data = ParseXML.find_data
Modified: grc/branches/jblum_work/src/ExecFlowGraphGUI.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -43,7 +43,7 @@
label_text_sizer = wx.BoxSizer(wx.HORIZONTAL) #label and text
box container
label = wx.StaticText(parent, -1, key+' -> ')
self.text_box = text_box = wx.TextCtrl(parent, -1, value,
style=wx.TE_PROCESS_ENTER)
- text_box.Bind(wx.EVT_TEXT_ENTER, self.handle_enter) #bind
this special enter hotkey event
+ text_box.Bind(wx.EVT_TEXT_ENTER, self._handle_enter) #bind
this special enter hotkey event
for obj in (label, text_box): #fill the container with label
and text entry box
label_text_sizer.Add(obj, 0,
wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL)
self.Add(label_text_sizer, 0, wx.ALIGN_CENTER)
@@ -61,34 +61,34 @@
except Exception, e:
sys.stderr.write('Slider, "%s", has too many
steps!\n'%key)
sys.exit(1)
- slider.Bind(wx.EVT_SCROLL, self.handle_scroll) #bind the
scrolling event
+ slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the
scrolling event
self.Add(slider, 0, wx.ALIGN_CENTER)
- self.handle_enter()#sets the slider's value
+ self._handle_enter()#sets the slider's value
def get_slider_width(self):
""" Get the width of the slider in pixels. """
return self.slider_width
- def get_slider_value(self):
+ def _get_slider_value(self):
""" Read the value from the slider slider.
Translate the slider value into a real numerical value. """
slider_value = self.slider.GetValue()
value, min, max, step = Variables.get_values(self.key)
return str(slider_value*(float(max)-float(min))/self.num_steps
+ float(min))
- def set_slider_value(self, real_value):
+ def _set_slider_value(self, real_value):
""" Translate the real numerical value into a slider value.
Write the value to the slider. """
value, min, max, step = Variables.get_values(self.key)
slider_value =
(float(real_value)-float(min))*self.num_steps/(float(max)-float(min))
self.slider.SetValue(slider_value)
- def handle_scroll(self, event=None):
+ def _handle_scroll(self, event=None):
""" A scroll event is detected. Read the slider. Try to
register the new entry:
If the registration passes, update the text box, and parse the
callbacks.
If the registration fails, restore the slider to the previous
registered values. """
key = self.key
- new_value = str(self.get_slider_value()) #the new value
must be a string!
+ new_value = str(self._get_slider_value()) #the new value
must be a string!
value, min, max, step = Variables.get_values(key)
Variables.unregister(key)
try:
@@ -97,9 +97,9 @@
self.parse_callbacks()
except:
Variables.register(key, value, min, max, step)
- self.set_slider_value(value)
+ self._set_slider_value(value)
- def handle_enter(self, event=None):
+ def _handle_enter(self, event=None):
""" An enter key was pressed. Read the text box. Try to
register the new entry:
If the registration passes, move the slider, and parse the
callbacks.
If the registration fails, restore the text box to the
previous registered value. """
@@ -109,7 +109,7 @@
Variables.unregister(key)
try:
Variables.register(key, new_value, min, max, step)
- self.set_slider_value(new_value)
+ self._set_slider_value(new_value)
self.parse_callbacks()
except:
Variables.register(key, value, min, max, step)
@@ -139,17 +139,17 @@
self.sliders_box = wx.BoxSizer(wx.VERTICAL)
main_box.Add(self.sliders_box, 0, wx.ALIGN_CENTER)
main_box.Add(panel, 0, wx.EXPAND)
- self.Bind(wx.EVT_CLOSE, self.Quit)
+ self.Bind(wx.EVT_CLOSE, self._quit)
# fill in all the sliders and graphs #
FlowGraphBuilder.__init__(self, file_path)
- self.create_sliders()
+ self._create_sliders()
graphs_box.SetCols(int(math.sqrt(len(self.sink_windows))))
for key in sorted(self.sink_windows.keys()):
graphs_box.Add(self.sink_windows[key], 0, wx.EXPAND)
self.SetSizerAndFit(main_box)
self.Show()
self.start() #start the flow graph
- def Quit(self, event):
+ def _quit(self, event):
''' Exit the application. '''
self.stop() #stop the flow graph
self.Destroy() #destroy the wx frame
@@ -165,7 +165,7 @@
''' Get the panel that will parent the graphical blocks.
'''
return self.panel
- def create_sliders(self):
+ def _create_sliders(self):
''' Using the list of variable keys imported by the builder,
create sliders for those variables with ranges. '''
len = 0
Modified: grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/ExecFlowGraphXMLRPC.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -64,7 +64,7 @@
self.parse_callbacks()
except Exception, e: #restore variable and raise Error
Variables.register(key, value, min, max, step)
- raise Error(str(e))
+ raise Error, e
return new_value
##############################################################################################
Modified: grc/branches/jblum_work/src/Graphics/Bars.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/Bars.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Graphics/Bars.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -84,10 +84,10 @@
)
class Toolbar(gtk.Toolbar):
- """ Toolbar is a gtk Toolbar with actions added from the toolbar
list """
+ """The gtk toolbar with actions added from the toolbar list."""
def __init__(self):
- """ Parse the list of action names in the toolbar list.
Look up the action for each name
- in the action list and add it to the toolbar """
+ """Parse the list of action names in the toolbar list.
+ Look up the action for each name in the action list and
add it to the toolbar."""
gtk.Toolbar.__init__(self)
self.set_style(gtk.TOOLBAR_ICONS)
for action_name in TOOLBAR_LIST:
@@ -103,11 +103,10 @@
class MenuBar(gtk.MenuBar):
- """ MenuBar is a gtk MenuBar with actions added from the menuBar
list """
+ """The gtk menu bar with actions added from the menu bar list."""
def __init__(self):
- """ Parse the list of submenus from the menubar list. For
each submenu, get a list of action names.
- Look up the action for each name in the action list and add it
to the submenu.
- Add the submenu to the menuBar """
+ """Parse the list of submenus from the menubar list. For each
submenu, get a list of action names.
+ Look up the action for each name in the action list and add it
to the submenu. Add the submenu to the menu bar."""
gtk.MenuBar.__init__(self)
for main_action,action_names in MENU_BAR_LIST:
# Create the MenuItem
Modified: grc/branches/jblum_work/src/Graphics/Dialogs.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/Dialogs.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Graphics/Dialogs.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -30,9 +30,12 @@
import Preferences
class TextDisplay(gtk.TextView):
- """ A non editable gtk text view. """
+ """A non editable gtk text view."""
def __init__(self, text=''):
- """ Create a new TextDisplay with the given text. """
+ """!
+ TextDisplay constructor.
+ @param text the text to display (string)
+ """
text_buffer = gtk.TextBuffer()
text_buffer.set_text(text)
self.set_text = text_buffer.set_text
@@ -45,8 +48,9 @@
######################################################################################################
class PreferencesDialog(gtk.Dialog):
- """ A dialog box to display each preference parameter. """
+ """A dialog box to display the preferences."""
def __init__(self):
+ """PreferencesDialog constructor."""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
self.set_title("Preferences")
self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
@@ -71,29 +75,33 @@
######################################################################################################
class FlowGraphWindowSizeDialog(gtk.Dialog):
- """ A dialog box to set the window size, width and heigh in pixels.
"""
- def __init__(self, flow_graph):
+ """A dialog box to set the window size, width and heigh in pixels."""
+ def __init__(self, dimensions):
+ """!
+ FlowGraphWindowSizeDialog constructor.
+ @param dimensions the (width,height) tuple from the flow graph
+ """
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
- self.flow_graph = flow_graph
self.set_title("Set the Window Size")
# the helpful dimension constraints label #
- windowSizeDesc = '''
+ window_size_label = gtk.Label()
+ window_size_label.set_markup("""<i>
Minimum window (width/height) in pixels is (%d/%d).
Maximum window (width/height) in pixels is (%d/%d).
-'''%(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT, MAX_WINDOW_WIDTH, MAX_WINDOW_HEIGHT)
- windowSizeDescLabel = gtk.Label()
- windowSizeDescLabel.set_markup('<i>'+windowSizeDesc+'</i>')
- windowSizeDescLabel.show()
- self.vbox.pack_end(windowSizeDescLabel, False)
- self.original_dimensions = width,height =
self.flow_graph.get_size_request() # get the window dimensions
+</i>"""%(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT, MAX_WINDOW_WIDTH,
MAX_WINDOW_HEIGHT))
+ window_size_label.show()
+ self.vbox.pack_end(window_size_label, False)
+ self.original_dimensions = width,height = dimensions
self.width = Int(width, min=MIN_WINDOW_WIDTH,
max=MAX_WINDOW_WIDTH)
self.height = Int(height, min=MIN_WINDOW_HEIGHT,
max=MAX_WINDOW_HEIGHT)
self.vbox.pack_start(GraphicalParam('width (pixels)',
self.width).get_input_object(), False)
self.vbox.pack_start(GraphicalParam('height (pixels)',
self.height).get_input_object(), False)
def run(self):
- ''' Return the new dimensions rather than a response.
- If the dimensions were invalid, return None. '''
+ """!
+ Get the new dimensions.
+ @return the new dimensions (width,height) or None if invalid.
+ """
self.dimensions = None
gtk.Dialog.run(self)
if self.width.is_valid() and self.height.is_valid():
@@ -104,14 +112,18 @@
######################################################################################################
class LooseChangesMessage(gtk.MessageDialog):
- """ This message dialog will ask about discarding unsaved changes.
"""
+ """Message dialog to ask about discarding unsaved changes."""
def __init__(self):
+ """LooseChangesMessage constructor."""
gtk.MessageDialog.__init__(self, None, gtk.DIALOG_MODAL,
gtk.MESSAGE_WARNING,
gtk.BUTTONS_OK_CANCEL, "Would you like to discard your
unsaved changes?")
self.set_title('Unsaved Changes!')
def run(self):
- """ call parent class run(), destroy the dialog. Return
True if OK was clicked, or False. """
+ """!
+ Get the user's response.
+ @return true if ok was clicked, otherwise false
+ """
response = gtk.MessageDialog.run(self)
self.destroy()
if response == gtk.RESPONSE_OK: return True
@@ -119,8 +131,9 @@
######################################################################################################
class AboutDialog(gtk.AboutDialog):
- """ cute little about dialog """
+ """A cute little about dialog."""
def __init__(self):
+ """AboutDialog constructor."""
gtk.AboutDialog.__init__(self)
self.set_version(VERSION)
self.set_name(MAIN_WINDOW_PREFIX)
@@ -144,8 +157,9 @@
######################################################################################################
class DataTypeColorsDialog(gtk.Dialog):
- """ Display each data type with its associated color. """
+ """Display each data type with its associated color."""
def __init__(self):
+ """DataTypeColorsDialog constructor."""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
self.set_title('Colors')
self.set_size_request(150, -1)
@@ -169,8 +183,9 @@
######################################################################################################
class HotKeysDialog(gtk.Dialog):
- """ Display each action with the associated hotkey. """
+ """Display each action with the associated hotkey."""
def __init__(self):
+ """HotKeysDialog constructor."""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
self.set_title('Hot Keys')
for action, hotkey in (('New Flow Graph', 'Ctrl + n'),
@@ -199,7 +214,8 @@
######################################################################################################
class MathExprDialog(gtk.Dialog):
- """ A dialog to test math expressions for the parser. """
+ """A dialog to test math expressions for the parser."""
+ ##the help message
HELP_MSG = """\
<b>Operators - Complex <i>(complex arguments)</i></b>
+ - * / ^
@@ -231,7 +247,7 @@
<b>Test Your Expressions Below:</b>\
"""
def __init__(self):
- """ Create a new gtk Dialog with a close button, an extry
box, and an output text box. """
+ """MathExprDialog constrcutor. Create a new gtk Dialog with a
close button, an extry box, and an output text box."""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
# Create the title and label #
self.set_title('Mathematical Expressions')
@@ -243,7 +259,7 @@
# create the entry box and connect it to a new handler #
self.param = GraphicalParam('Expression', RawExpr(''))
self.input_obj = self.param.get_input_object()
- self.input_obj.entry.connect("changed", self.handle_changed)
+ self.input_obj.entry.connect("changed", self._handle_changed)
self.vbox.pack_start(self.input_obj, False)
# create a text box for parser output #
self.text_box = TextDisplay()
@@ -254,13 +270,13 @@
scrolled_window.add_with_viewport(self.text_box)
scrolled_window.show()
self.vbox.pack_start(scrolled_window, True)
- self.handle_changed() #initial display
+ self._handle_changed() #initial display
self.run()
self.destroy()
- def handle_changed(self, widget=None):
- ''' Handle changed in the param's entry box.
- Call the default change handler and then update the
text box. '''
+ def _handle_changed(self, widget=None):
+ """Handle changed in the param's entry box.
+ Call the default change handler and then update the text box."""
self.param.handle_changed()
if self.param.get_data_type().is_valid():
text = str(self.param.get_data_type().parse())
Modified: grc/branches/jblum_work/src/Graphics/FlowGraph.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/FlowGraph.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Graphics/FlowGraph.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -25,7 +25,7 @@
from Colors import BACKGROUND_COLOR, TXT_COLOR
from Elements import GraphicalSignalBlock,GraphicalConnection
from Elements import Utils
-from Elements.Connection import
InvalidConnectionException,TooManyConnectionsException
+from Elements.Connection import ConnectionException
import Variables
import pygtk
pygtk.require('2.0')
@@ -40,29 +40,34 @@
import Messages
class FlowGraph(gtk.DrawingArea):
- """ FlowGraph is the data structure to store graphical signal
blocks, their graphical input/output
- parameters, and the connections between inputs and outputs. """
+ """FlowGraph is the data structure to store graphical signal blocks,
+ their graphical input/output parameters, and the connections between
inputs and outputs."""
signal_block_constructor = GraphicalSignalBlock
connection_contructor = GraphicalConnection
def __init__(self, handle_states, variable_modification_window):
- """ Create a list for signal blocks and connections. Connect
mouse handlers. """
+ """!
+ FlowGraph contructor.
+ Create a list for signal blocks and connections. Connect mouse
handlers.
+ @param handle_states the callback function
+ @param variable_modification_window var mod window also for
callbacks
+ """
self.elements = list()
self.remove_element = lambda e: self.elements.remove(e)
self.gc = None
self.handle_states = handle_states
self.variable_modification_window = variable_modification_window
gtk.DrawingArea.__init__(self)
- self.connect('expose-event', self.__on_expose)
- self.connect('motion-notify-event',
self.__motion_notify_event_cb)
- self.connect('button-press-event',
self.__button_press_event_cb)
- self.connect('button-release-event',
self.__button_release_event_cb)
+ self.connect('expose-event', self._handle_window_expose)
+ self.connect('motion-notify-event', self._handle_mouse_motion)
+ self.connect('button-press-event',
self._handle_mouse_button_press)
+ self.connect('button-release-event',
self._handle_mouse_button_release)
self.set_events(gtk.gdk.BUTTON_PRESS_MASK |
gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.BUTTON_RELEASE_MASK\
| gtk.gdk.LEAVE_NOTIFY_MASK | gtk.gdk.ENTER_NOTIFY_MASK)
# setup the focus flag #
self.focus_flag = False
self.get_focus_flag = lambda: self.focus_flag
- self.connect("leave-notify-event", self.__handle_focus_event,
False)
- self.connect("enter-notify-event", self.__handle_focus_event,
True)
+ self.connect("leave-notify-event", self._handle_focus_event,
False)
+ self.connect("enter-notify-event", self._handle_focus_event,
True)
# important vars dealing with mouse event tracking
#
self.has_moved = False
self.mouse_pressed = False
@@ -73,12 +78,15 @@
self.pixmap = None
self.show()
- def __handle_focus_event(self, widget, event, focus_flag):
- """ Record the focus state of the flow graph window. """
+ def _handle_focus_event(self, widget, event, focus_flag):
+ """Record the focus state of the flow graph window."""
self.focus_flag = focus_flag
def add_signal_block(self, tag):
- ''' Add a signal block of the given tag to this flow graph.
'''
+ """!
+ Add a signal block of the given tag to this flow graph.
+ @param tag the signal block tag
+ """
index = 0
while True:
id = tag+str(index)
@@ -102,21 +110,30 @@
return
def type_controller_modify_selected(self, direction):
- """ Change the registered type controller for the selected
signal block.
- direction may be +1 or -1 """
+ """
+ !Change the registered type controller for the selected signal
block.
+ @param direction +1 or -1
+ @return true for success
+ """
if Utils.is_socket(self.selected_element):
self.selected_element = self.selected_element.get_parent()
if Utils.is_signal_block(self.selected_element): return
self.selected_element.modify_type_controller(direction)
return False
def socket_controller_modify_selected(self, direction):
- """ Change socket controller for the selected signal block.
- direction may be +1 or -1 """
+ """!
+ Change socket controller for the selected signal block.
+ @param direction +1 or -1
+ @return true for success
+ """
if Utils.is_socket(self.selected_element):
self.selected_element = self.selected_element.get_parent()
if Utils.is_signal_block(self.selected_element): return
self.selected_element.modify_socket_controller(direction)
return False
def param_modify_selected(self):
- """ Create and show a param modification dialog for the
selected element (socket and signal block only) """
+ """!
+ Create and show a param modification dialog for the selected
element (socket and signal block only).
+ @return true if parameters were changed
+ """
if Utils.is_socket(self.selected_element):
self.selected_element = self.selected_element.get_parent()
if Utils.is_signal_block(self.selected_element):
signal_block_params_dialog =
SignalBlockParamsDialog(self.selected_element)
@@ -126,27 +143,37 @@
return False
def connect_sockets(self, s1, s2):
- """ Connect input and output sockets. Ignore state change
if creation of connection fails. """
+ """!
+ Connect input and output sockets. Ignore state change if
creation of connection fails.
+ @param s1 a socket
+ @param s2 another socket
+ """
try:
connection = GraphicalConnection(self, s1, s2)
self.elements.append(connection)
self.selected_element = None
self.handle_states(CONNECTION_CREATE)
self.update()
- except (InvalidConnectionException,
TooManyConnectionsException), e:
+ except ConnectionException:
Messages.send_fail_connection()
self.handle_states(NOTHING_SELECT)
def move_selected(self, delta_coordinate):
- """ Move the element and by the change in coordinate
(delta_coordinate) """
+ """!
+ Move the element and by the change in coordinates.
+ @param delta_coordinate the change in coordinates
+ """
if self.selected_element != None:
self.selected_element.move(delta_coordinate)
self.has_moved = True
self.draw()
def rotate_selected(self, direction):
- """ Rotate the selected element by 90 degrees, direction
can be "left"/"right"
- True if rotated, otherwise False. Only rotate
SignalBlocks and Sockets. """
+ """!
+ Rotate the selected element by 90 degrees. Only rotate
SignalBlocks and Sockets.
+ @param direction DIR_LEFT or DIR_RIGHT
+ @return true if rotated, otherwise false.
+ """
if self.selected_element != None and
(Utils.is_signal_block(self.selected_element) or
Utils.is_socket(self.selected_element)):
self.selected_element.rotate(direction)
self.draw()
@@ -154,8 +181,10 @@
return False
def delete_selected(self):
- """ If an element is selected, remove it and its attached
parts from the element list.
- True if the element was deleted, otherwise False.
"""
+ """!
+ If an element is selected, remove it and its attached parts
from the element list.
+ @return true if the element was deleted, otherwise false.
+ """
if self.selected_element != None:
if Utils.is_socket(self.selected_element): # found
a socket, set to parent signal block
self.selected_element =
self.selected_element.get_parent()
@@ -171,17 +200,22 @@
return False
def unselect(self):
- """ If an element is selected, un-highlight it and set selected
to None. """
+ """If an element is selected, un-highlight it and set selected
to None."""
if self.selected_element != None:
self.selected_element.set_highlighted(False)
self.selected_element = None
self.update()
def what_is_selected(self, coor):
- """ At the given coordinate, return the first element found
to be selected
+ """!
+ What is selected?
+ At the given coordinate, return the first element found to be
selected
- iterate though the elements backwards since top elements are
at the end of the list
- if an element is selected, place it at the end of the list so
that is is drawn last,
- and hence on top. """
+ and hence on top.
+ @param coor the coordinate of the mouse click
+ @return the selected element or None
+ """
# check the elements #
for i,element in enumerate(reversed(self.elements)):
if element.what_is_selected(coor) != None:
@@ -190,9 +224,51 @@
return element.what_is_selected(coor)
return None
- def __button_press_event_cb(self, widget, event):
- """ A mouse button is pressed. Record the state of the
mouse, find the selected element,
- set the Element highlighted, handle the state change, and
redraw the FlowGraph. """
+ def draw(self, drawable=None):
+ """Draw the background and then all of the Elements in this
FlowGraph on the pixmap,
+ then draw the pixmap to the drawable window of this
FlowGraph."""
+ if self.gc != None:
+ # draw the background #
+ W,H = self.get_size_request()
+ self.gc.foreground = BACKGROUND_COLOR
+ self.pixmap.draw_rectangle(self.gc, True, 0, 0, W, H)
+ if Preferences.show_grid():
+ grid_size = Preferences.get_grid_size()
+ points = list()
+ for i in range(W/grid_size):
+ for j in range(H/grid_size):
+
points.append((i*grid_size,j*grid_size))
+ self.gc.foreground = TXT_COLOR
+ self.pixmap.draw_points(self.gc, points)
+ # draw the foreground #
+ for element in filter(Utils.is_signal_block,
self.elements) + filter(Utils.is_connection, self.elements):
+ element.draw(self.pixmap) # draw signal
blocks first, then connections on the top
+ if self.mouse_pressed and self.selected_element != None:
+ self.selected_element.draw(self.pixmap)
+ self.window.draw_drawable(self.gc, self.pixmap, 0, 0,
0, 0, -1, -1)
+
+ def is_valid(self):
+ """!
+ Is the flow graph valid, ie: are all elements valid?
+ @return true if flow graph is valid
+ """
+ for element in self.elements:
+ if not element.is_valid(): return False
+ return True
+
+ def update(self):
+ """Call update on all elements."""
+ print "Updating entire flow graph..."
+ for element in self.elements: element.update()
+ self.draw()
+
+
##########################################################################
+ ## Handlers
+
##########################################################################
+
+ def _handle_mouse_button_press(self, widget, event):
+ """ A mouse button is pressed. Record the state of the mouse,
find the selected element,
+ set the Element highlighted, handle the state change, and
redraw the FlowGraph."""
# unselect anything in the vars mod window #
self.variable_modification_window.unselect_all()
if event.button == 1:
@@ -219,8 +295,8 @@
self.draw()
return True
- def __button_release_event_cb(self, widget, event):
- """ A mouse button is released, record the state. """
+ def _handle_mouse_button_release(self, widget, event):
+ """A mouse button is released, record the state."""
if event.button == 1:
self.mouse_pressed = False
if self.has_moved:
@@ -238,22 +314,9 @@
self.has_moved = False
return True
- def is_valid(self):
- """ is the flow graph valid, ie: are all elements valid?
"""
- for element in self.elements:
- if not element.is_valid(): return False
- return True
-
- def update(self):
- '''call update on all elements'''
- print "Updating entire flow graph..."
- for element in self.elements: element.update()
- self.draw()
-
- def __motion_notify_event_cb(self, widget, event):
- """ The mouse is moved. If mouse_pressed is true, react to the
motions:
- - if an Element is highlighted, this will move the
Element by
- redrawing it at the new position """
+ def _handle_mouse_motion(self, widget, event):
+ """The mouse has moved. If mouse_pressed is true, react to the
motions:
+ - if an Element is highlighted, this will move the
Element by redrawing it at the new position."""
fgW,fgH = self.get_size_request()
self.count = (1 +
self.count)%MOTION_DETECT_REDRAWING_SENSITIVITY
# to perform a movement, the mouse must be pressed, an
element selected, count of zero. #
@@ -295,37 +358,14 @@
self.move_selected((deltaX, deltaY))
self.coordinate = (x, y)
- def __on_expose(self, widget, event):
- """ The window initially appears or is resized, create a
new pixmap, draw the flow graph. """
+ def _handle_window_expose(self, widget, event):
+ """Called when the window initially appears or is resized:
create a new pixmap, draw the flow graph."""
self.gc = self.window.new_gc()
width, height = self.get_size_request()
if self.pixmap == None or (width, height) !=
self.pixmap.get_size():
self.pixmap = gtk.gdk.Pixmap(self.window, width,
height, -1)
print "Main Pixmap Created!"
self.draw()
-
- def draw(self, drawable=None):
- """ draw the background and then all of the Elements in
this FlowGraph on the pixmap,
- then draw the pixmap to the drawable window of this FlowGraph.
"""
- if self.gc != None:
- # draw the background #
- W,H = self.get_size_request()
- self.gc.foreground = BACKGROUND_COLOR
- self.pixmap.draw_rectangle(self.gc, True, 0, 0, W, H)
- if Preferences.show_grid():
- grid_size = Preferences.get_grid_size()
- points = list()
- for i in range(W/grid_size):
- for j in range(H/grid_size):
-
points.append((i*grid_size,j*grid_size))
- self.gc.foreground = TXT_COLOR
- self.pixmap.draw_points(self.gc, points)
- # draw the foreground #
- for element in filter(Utils.is_signal_block,
self.elements) + filter(Utils.is_connection, self.elements):
- element.draw(self.pixmap) # draw signal
blocks first, then connections on the top
- if self.mouse_pressed and self.selected_element != None:
- self.selected_element.draw(self.pixmap)
- self.window.draw_drawable(self.gc, self.pixmap, 0, 0,
0, 0, -1, -1)
##########################################################################
##
@@ -333,7 +373,10 @@
##
##########################################################################
def to_nested_data(self):
- ''' Dump all the values in this flow graph into a nested
data format. '''
+ """!
+ Dump all the values in this flow graph into a nested data
format.
+ @return nested data representing a flow graph
+ """
vars_list = list()
signal_blocks_list = list()
connections_list = list()
@@ -395,10 +438,12 @@
##
##########################################################################
def from_nested_data(self, nested_data):
- ''' Set all the values in this flow graph using the nested
data.
- Return a string of errors, one error per line. '''
+ """!
+ Set all the values in this flow graph using the nested data.
+ @param nested_data nested data representing a flow graph
+ """
#print 'From',nested_data
- #TODO: use a non-destructive methode to clear the elements list
+ #TODO: use a non-destructive method to clear the elements list
self.elements = list() #clear the elements
find_data = ParseXML.find_data
flow_graph = find_data([nested_data], 'flow_graph')
@@ -436,7 +481,7 @@
if element.get_id() == input_signal_block_id:
input_socket = element.get_input_socket(input_socket_index)
if element.get_id() == output_signal_block_id:
output_socket = element.get_output_socket(output_socket_index)
try: self.elements.append(GraphicalConnection(self,
input_socket, output_socket))
- except (InvalidConnectionException,
TooManyConnectionsException):
+ except ConnectionException:
Messages.send_error_load('Could not connect
"%s" input[%d] and "%s" output[%d].'%(
input_signal_block_id,
input_socket_index, output_signal_block_id, output_socket_index))
self.selected_element = None
Modified: grc/branches/jblum_work/src/Graphics/FlowGraphFileDialog.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/FlowGraphFileDialog.py 2007-06-15
20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/Graphics/FlowGraphFileDialog.py 2007-06-15
20:41:27 UTC (rev 5774)
@@ -27,24 +27,32 @@
from os import path
class FlowGraphFileDialog(gtk.FileChooserDialog):
- """ A dialog box to save or open flow graph files. """
+ """A dialog box to save or open flow graph files."""
+ ##the filter for flow graph files
flow_graph_files_filter = gtk.FileFilter()
flow_graph_files_filter.set_name('FG Files')
flow_graph_files_filter.add_pattern('*'+DEFAULT_FILE_EXTENSION)
+ ##the filter for image files
image_files_filter = gtk.FileFilter()
image_files_filter.set_name('Image Files')
image_files_filter.add_pattern('*'+IMAGE_FILE_EXTENSION)
#image_files_filter.add_pixbuf_formats()
+ ##the filter for all files
all_files_filter = gtk.FileFilter()
all_files_filter.set_name('All Files')
all_files_filter.add_pattern('*')
def __init__(self, type, current_file_path):
- """ Create a new gtk.FileChooserDialog, type can be ('open',
'save', or 'save image')
- open and save are for flow graphs, save image is for
screenshots"""
+ """!
+ FlowGraphFileDialog constructor.
+ Create a new gtk.FileChooserDialog, type specifies what filter
to use:
+ open and save are for flow graphs, save image is for
screenshots.
+ @param type 'open', 'save', or 'save image'
+ @param current_file_path the current directory
+ """
if current_file_path == '': current_file_path =
DEFAULT_FILE_PATH+NEW_FLOGRAPH_TITLE+DEFAULT_FILE_EXTENSION
if type == 'open':
gtk.FileChooserDialog.__init__(self, 'Open a Flow Graph
from a File...', None,
@@ -75,7 +83,10 @@
self.set_local_only(True)
def get_filename(self):
- """ retrieve the filename from the dialog, append the extension
if missing. """
+ """!
+ Retrieve the filename from the dialog, append the extension if
missing.
+ @return the filename with extension
+ """
filename = gtk.FileChooserDialog.get_filename(self)
if filename[len(filename)-len(DEFAULT_FILE_EXTENSION):] !=
DEFAULT_FILE_EXTENSION and\
self.flow_graph_files_filter == self.get_filter():
filename = filename + DEFAULT_FILE_EXTENSION
@@ -84,7 +95,10 @@
return filename
def run(self):
- """ retrieve the filename from get_filename, None if a
close/cancel occured, and destroy the dialog. """
+ """!
+ Call run, wait for user response, and destroy the dialog.
+ @return the filename or None if a close/cancel occured.
+ """
response = gtk.FileChooserDialog.run(self)
if response == gtk.RESPONSE_OK: filename = self.get_filename()
else: filename = None
Modified: grc/branches/jblum_work/src/Graphics/MainWindow.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/MainWindow.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/Graphics/MainWindow.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -31,9 +31,12 @@
from Dialogs import TextDisplay
class MainWindow(gtk.Window):
- """ The main topmost window with menus and toolbars and flow graph
"""
+ """The topmost window with menus, the tool bar, and other major
windows."""
def __init__(self, handle_states):
- """ add menu bar, toolbar, and flowgraph """
+ """!
+ MainWindow contructor.
+ @param handle_states the callback function
+ """
self.handle_states = handle_states
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
vbox = gtk.VBox()
@@ -83,19 +86,28 @@
#self.show()
def add_report_line(self, line):
- """ place line plus a newline at the end of the text buffer,
then scroll its window all the way down. """
+ """!
+ Place line plus a newline at the end of the text buffer, then
scroll its window all the way down.
+ @param line the new text
+ """
self.text_display.insert(line)
vadj = self.reports_scrolled_window.get_vadjustment()
vadj.set_value(vadj.upper)
def set_title(self, title):
- """ set the title and prepend the program name """
+ """!
+ Set the title and prepend the program name.
+ @param title the window title
+ """
prepend_str = MAIN_WINDOW_PREFIX + ' - Editing: '
gtk.Window.set_title(self, prepend_str + str(title))
def show_reports_window(self, show):
- """ Show the reports window when show is True.
- Hide the reports window when show is False. """
+ """!
+ Show the reports window when show is True.
+ Hide the reports window when show is False.
+ @param show boolean flag
+ """
if show: self.reports_scrolled_window.show()
else: self.reports_scrolled_window.hide()
\ No newline at end of file
Modified: grc/branches/jblum_work/src/Graphics/SignalBlockParamsDialog.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/SignalBlockParamsDialog.py
2007-06-15 20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/Graphics/SignalBlockParamsDialog.py
2007-06-15 20:41:27 UTC (rev 5774)
@@ -27,8 +27,12 @@
from Constants import MIN_DIALOG_WIDTH,MIN_DIALOG_HEIGHT
class SignalBlockParamsDialog(gtk.Dialog):
- """ A dialog box to set signal block parameters such as sampling
rate and decimation values. """
+ """A dialog box to set signal block parameters."""
def __init__(self, signal_block):
+ """!
+ SignalBlockParamsDialog contructor.
+ @param signal_block the signal block
+ """
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
self.signal_block = signal_block
self.set_title(signal_block.get_id()+' properties')
@@ -62,7 +66,10 @@
self.vbox.pack_start(TextDisplay(self.signal_block.get_docs()), False)
def run(self):
- ''' Call the parent class run and return True if a change
occured. '''
+ """!
+ Call run().
+ @return true if a change occured.
+ """
gtk.Dialog.run(self)
self.destroy()
self.data = list()
Modified: grc/branches/jblum_work/src/Graphics/SignalBlockSelectionWindow.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/SignalBlockSelectionWindow.py
2007-06-15 20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/Graphics/SignalBlockSelectionWindow.py
2007-06-15 20:41:27 UTC (rev 5774)
@@ -28,10 +28,15 @@
from SignalBlockDefs import SB_TREE
class SignalBlockSelectionWindow(gtk.VBox):
- """ The signal block selection window. """
+ """The signal block selection window."""
def __init__(self, flow_graph):
- """ Show all possible signal blocks in this dialog. Each
signal block is represented by a
- gtk label of its CNAME and an add button. The add
button tells the flow graph to add the chosen block. """
+ """!
+ SignalBlockSelectionWindow constructor.
+ Show all possible signal blocks in this dialog.
+ Each signal block is represented by a gtk label of its tag and
an add button.
+ The add button tells the flow graph to create the selected
block. and add it to the flow graph.
+ @param flow_graph the flow graph
+ """
gtk.VBox.__init__(self)
self.flow_graph = flow_graph
#title label
@@ -44,10 +49,10 @@
self.treeview = gtk.TreeView(self.model)
self.treeview.set_enable_search(False) #disable pop up search
box
self.treeview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
- self.treeview.connect('button_press_event',
self.handle_button_press)
+ self.treeview.connect('button_press_event',
self._handle_button_press)
selection = self.treeview.get_selection()
selection.set_mode('single')
- selection.connect('changed', self.handle_selection_change)
+ selection.connect('changed', self._handle_selection_change)
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn("Category", renderer, text=0)
self.treeview.append_column(column)
@@ -62,7 +67,7 @@
self.pack_start(scrolled_window)
# add button #
self.add_button = gtk.Button(None, 'gtk-add')
- self.add_button.connect('clicked', self.handle_add_button)
+ self.add_button.connect('clicked', self._handle_add_button)
self.add_button.show()
self.pack_start(self.add_button, False)
# add blocks and categories #
@@ -72,23 +77,23 @@
for tag in tags:
new_iter = self.model.insert_before(iter, None)
self.model.set_value(new_iter, 0, tag[0])
- self.handle_selection_change(None)
+ self._handle_selection_change(None)
self.show()
- def handle_button_press(self, widget, event):
- ''' If a left double click is detected, let the handler for the
add button decide to add a block. '''
+ def _handle_button_press(self, widget, event):
+ """If a left double click is detected, let the handler for the
add button decide to add a block."""
if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:
- self.handle_add_button(widget)
+ self._handle_add_button(widget)
- def handle_selection_change(self, event):
- ''' If a selection changes, set the add button sensitive.
'''
+ def _handle_selection_change(self, event):
+ """If a selection changes, set the add button sensitive."""
selection = self.treeview.get_selection()
model, iter = selection.get_selected()
if iter != None and not model.iter_has_child(iter):
self.add_button.set_sensitive(True)
else: self.add_button.set_sensitive(False)
- def handle_add_button(self, widget):
- """ add the signal block to the flow graph and redraw the
flow graph """
+ def _handle_add_button(self, widget):
+ """Add the signal block to the flow graph."""
selection = self.treeview.get_selection()
model, iter = selection.get_selected()
if iter != None and not model.iter_has_child(iter):
self.flow_graph.add_signal_block(model.get_value(iter, 0))
Modified: grc/branches/jblum_work/src/Graphics/USRPDiagnostics.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/USRPDiagnostics.py 2007-06-15
20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/Graphics/USRPDiagnostics.py 2007-06-15
20:41:27 UTC (rev 5774)
@@ -29,17 +29,18 @@
from Dialogs import TextDisplay
def enable_usrp_diagnostics():
- """ Only enable the action for USRP diganostics if gnuradio.usrp
can be imported. """
+ """Enable the action for USRP diganostics if gnuradio.usrp can be
imported."""
try:
from gnuradio import usrp
get_action_from_name(USRP_DIAGNOSTICS_DISPLAY).set_sensitive(True)
except ImportError: print "USRP support missing -> USRP diagnostics
disabled..."
class USRPDiagnosticsDialog(gtk.Dialog):
- """ The main dialog window for USRP Dignostics.
- The USRP parameters and feedback will be located inside this dialog.
"""
+ """The main dialog window for USRP Dignostics.
+ The USRP parameters and feedback will be located inside this dialog."""
def __init__(self):
- """ Create a new gtk Dialog with a close button, USRP input
paramaters, and output labels. """
+ """USRPDiagnosticsDialog contructor.
+ Create a new gtk Dialog with a close button, USRP input
paramaters, and output labels."""
gtk.Dialog.__init__(self, buttons=('gtk-close',
gtk.RESPONSE_CLOSE))
# Create the title label #
self.set_title('USRP Diagnostics')
@@ -53,7 +54,7 @@
self.vbox.pack_start(GraphicalParam('Transmit/Receive',
self.USRP_type).get_input_object(), False)
self.vbox.pack_start(GraphicalParam('Side:Subdevice',
self.USRP_subdev).get_input_object(), False)
self.diagnose_button = gtk.Button('Query')
- self.diagnose_button.connect('clicked', self.diagnose_usrp)
+ self.diagnose_button.connect('clicked', self._diagnose_usrp)
self.diagnose_button.show()
self.vbox.pack_start(self.diagnose_button, False)
# Create a text box for USRP queries #
@@ -63,8 +64,8 @@
self.run()
self.destroy()
- def diagnose_usrp(self, widget=None):
- """ Query the USRP device and append the results into the query
text box. """
+ def _diagnose_usrp(self, widget=None):
+ """Query the USRP device and copy the results into the query
text box."""
from gnuradio import usrp
type = self.USRP_type.parse()
if type == 'rx': #for the rx query, use the source and
rx methods
Modified: grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
===================================================================
--- grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
2007-06-15 20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/Graphics/VariableModificationWindow.py
2007-06-15 20:41:27 UTC (rev 5774)
@@ -29,9 +29,12 @@
import Variables
class VariableModificationWindow(gtk.VBox):
- ''' A scrollable window to add/remove variables in the variable
registry '''
+ """A scrollable window to add/remove variables in the variable
registry."""
def __init__(self, handle_states):
- ''' create a scrolled window, and add buttons and lists '''
+ """!
+ VariableModificationWindow constrcutor.Create a scrolled
window, and add buttons and lists.
+ @param handle_states callback function to handle the variable
changes
+ """
gtk.VBox.__init__(self)
self.handle_states = handle_states
#title label
@@ -62,7 +65,7 @@
for i,title in enumerate(['Variable', 'Default', 'Min', 'Max',
'Step']): #create each data column
renderer = gtk.CellRendererText()
renderer.set_property('editable', True)
- renderer.connect('edited',
self.__handle_renderer_edited)
+ renderer.connect('edited', self._handle_renderer_edited)
self.renderers.append(renderer)
tree_view_column = gtk.TreeViewColumn(title, renderer,
text=i)
tree_view_column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) #allow the column to
shrink
@@ -70,7 +73,7 @@
self.treeview.set_reorderable(True)
selection = self.treeview.get_selection()
selection.set_mode('single')
- selection.connect('changed', self.__handle_selection_change)
+ selection.connect('changed', self._handle_selection_change)
self.treeview.show()
scrolled_window.add_with_viewport(self.treeview)
# buttons #
@@ -79,37 +82,42 @@
self.pack_start(buttons_hbox, False)
# add, edit, and remove buttons #
add_button = gtk.Button(None, 'gtk-add')
- add_button.connect('clicked', self.__handle_add_button)
+ add_button.connect('clicked', self._handle_add_button)
add_button.show()
buttons_hbox.pack_start(add_button, False)
self.remove_button = gtk.Button(None, 'gtk-remove')
- self.remove_button.connect('clicked',
self.__handle_remove_button)
+ self.remove_button.connect('clicked',
self._handle_remove_button)
self.remove_button.show()
buttons_hbox.pack_start(self.remove_button, False)
- self.treeview.connect("cursor-changed",
self.__handle_cursor_changed)
- self.__handle_selection_change()
+ self.treeview.connect("cursor-changed",
self._handle_cursor_changed)
+ self._handle_selection_change()
self.show()
def unselect_all(self):
- ''' Stop editing in each renderer and unselect every row in the
tree view. '''
+ """Stop editing in each renderer and unselect every row in the
tree view."""
#TODO: stop editing doesnt work
for renderer in self.renderers: renderer.stop_editing(True)
self.treeview.get_selection().unselect_all()
- def __handle_cursor_changed(self, event=None):
- ''' Called when the cursor is placed on a row or in a cell.
- Unselect any selected element in the flow graph. '''
+ def _handle_cursor_changed(self, event=None):
+ """Called when the cursor is placed on a row or in a cell.
+ Unselect any selected element in the flow graph."""
self.handle_states(NOTHING_SELECT)
- def __handle_selection_change(self, event=None):
- ''' If a selection changes, set the edit and remove buttons
sensitive. '''
+ def _handle_selection_change(self, event=None):
+ """If a selection changes, set the edit and remove buttons
sensitive."""
selection = self.treeview.get_selection()
model, iter = selection.get_selected()
if iter != None: self.remove_button.set_sensitive(True)
else: self.remove_button.set_sensitive(False)
- def __handle_renderer_edited(self, renderer, row_index, new_text):
- ''' A cell was edited, determine what was edited and how to
handle it. '''
+ def _handle_renderer_edited(self, renderer, row_index, new_text):
+ """!
+ A cell was edited, determine what was edited and how to handle
it.
+ @param renderer the renderer
+ @param row_index the index of the row that changes
+ @param new_text the new text in the cell
+ """
column_index = self.renderers.index(renderer)
if new_text == self.liststore[row_index][column_index]: return
#no change
old_list = self.liststore[row_index]
@@ -131,8 +139,8 @@
self.liststore[row_index][i] = value
self.handle_states(VARIABLE_MODIFY)
- def __handle_remove_button(self, widget, data=None):
- ''' Remove the selected element from the list and from the
VarReg. '''
+ def _handle_remove_button(self, widget, data=None):
+ """Remove the selected element from the list and from the
variables registry."""
selection = self.treeview.get_selection()
model, iter = selection.get_selected()
if iter != None:
@@ -140,9 +148,9 @@
model.remove(iter)
self.handle_states(VARIABLE_MODIFY)
- def __handle_add_button(self, widget, data=None):
- ''' Handle the add button by adding a variable with key and
value.
- The key will be unique in the form 'new_var' + index.
'''
+ def _handle_add_button(self, widget, data=None):
+ """Handle the add button by adding a variable with key and
value.
+ The key will be unique in the form 'new_var' + index."""
new_key_index = 0
while True:
new_key_name = 'new_var'+str(new_key_index)
@@ -156,13 +164,19 @@
return #leave the while loop
def to_key_list(self):
- ''' Return a list of the keys in the current order.
'''
+ """!
+ Get a list of the keys in the current order.
+ @return a list of ordered variable keys
+ """
key_list = list()
for row in self.liststore: key_list.append(row[0])
return key_list
def from_key_list(self, key_list):
- ''' Clear the rows and refill the list with keys from the list.
'''
+ """!
+ Clear the rows and refill the list with keys from the key list.
+ @param key_list a list of ordered keys
+ """
self.liststore.clear()
for key in key_list:
self.liststore.append((key,)+Variables.get_values(key))
Modified: grc/branches/jblum_work/src/MathExprParser.py
===================================================================
--- grc/branches/jblum_work/src/MathExprParser.py 2007-06-15 20:01:45 UTC
(rev 5773)
+++ grc/branches/jblum_work/src/MathExprParser.py 2007-06-15 20:41:27 UTC
(rev 5774)
@@ -51,7 +51,7 @@
@return a complex number
"""
try: c_num = complex(num) #ensure that the num can be complex
- except: raise ValueError('"%s" is not a number.'%(num,))
+ except: raise ValueError, '"%s" is not a number.'%(num,)
return c_num
def verify_float(num):
@@ -63,7 +63,7 @@
@return a float number
"""
c_num = verify_complex(num) #ensure that the num can be complex
- if c_num.imag != 0: raise ValueError('Expected a float but found
"%s".'%(c_num,))
+ if c_num.imag != 0: raise ValueError, 'Expected a float but found
"%s".'%(c_num,)
return float(c_num.real)
def verify_int(num):
@@ -76,7 +76,7 @@
@return an integer number
"""
f_num = verify_float(num)
- if f_num - int(f_num) != 0: raise ValueError('Expected an integer but
found "%s".'%(f_num,))
+ if f_num - int(f_num) != 0: raise ValueError, 'Expected an integer but
found "%s".'%(f_num,)
return int(f_num)
def verify_number(num):
@@ -176,7 +176,7 @@
}
arg_lens, floats, ints = filter_props[filter]
# handle the filter arguments #
- if len(filter_args) not in arg_lens: raise SyntaxError('Invalid number
of arguments for "%s".'%filter)
+ if len(filter_args) not in arg_lens: raise SyntaxError, 'Invalid number
of arguments for "%s".'%filter
for i,arg in enumerate(filter_args):
if i in floats: filter_args[i] = verify_float(arg)
if i in ints: filter_args[i] = verify_int(arg)
@@ -297,7 +297,7 @@
@throw ArithmeticError impossible operations
@return the nested data representing the result (numbers and lists)
"""
- if op not in _ORDER_OF_OPS: raise NameError('Unknown operator:
"%s".'%(op))
+ if op not in _ORDER_OF_OPS: raise NameError, 'Unknown operator:
"%s".'%(op)
arg1_is_list = _is_list(arg1)
arg2_is_list = _is_list(arg2)
# addition and subtraction of vectors #
@@ -325,12 +325,12 @@
return verify_number(arg1 * arg2)
elif op == '/':
try: return verify_number(verify_complex(arg1) /
verify_complex(arg2)) #make sure to use non-integer division
- except ZeroDivisionError: raise
ZeroDivisionError('Cannot divide "%s" by 0.'%(arg1,))
+ except ZeroDivisionError: raise ZeroDivisionError,
'Cannot divide "%s" by 0.'%(arg1,)
elif op == '+':
return verify_number(arg1 + arg2)
elif op == '-':
return verify_number(arg1 - arg2)
- raise ArithmeticError('Operation of "%s" cannot be performed on "%s",
"%s".'%(op, arg1, arg2))
+ raise ArithmeticError, 'Operation of "%s" cannot be performed on "%s",
"%s".'%(op, arg1, arg2)
#########################################################
# Evaluate the expression string
@@ -407,11 +407,11 @@
nested_elements.append(_nest_elements(elements,
element))
elif _is_close_bracket(element):
if element != _get_oposing_bracket(open_bracket):
#matching open/close brackets?
- raise SyntaxError('Expected "%s", but found
"%s".'%(_get_oposing_bracket(open_bracket), element))
+ raise SyntaxError, 'Expected "%s", but found
"%s".'%(_get_oposing_bracket(open_bracket), element)
return nested_elements
else: nested_elements.append(element)
if open_bracket: #any unclosed bracket pairs?
- raise SyntaxError('Expected "%s", but found
nothing.'%(_get_oposing_bracket(open_bracket),))
+ raise SyntaxError, 'Expected "%s", but found
nothing.'%(_get_oposing_bracket(open_bracket),)
return nested_elements
def _simplify_nested_elements(nested_elements):
@@ -436,12 +436,12 @@
for function in _FUNCTIONS.keys():
while function in nested_elements:
i = nested_elements.index(function)
- if i+1 == len(nested_elements): raise
SyntaxError('Function "%s" has no arguments.'%(function))
+ if i+1 == len(nested_elements): raise SyntaxError,
'Function "%s" has no arguments.'%(function)
args = nested_elements[i+1]
if not _is_list(args): args = [args]
try: ans = _FUNCTIONS[function](*args)
except Exception, e:
- raise SyntaxError('Function "%s" with arguments
"%s" failed.\n\t%s'%(function, nested_elements[i+1], e))
+ raise SyntaxError, 'Function "%s" with
arguments "%s" failed.\n\t%s'%(function, nested_elements[i+1], e)
if not _is_list(ans): ans = [ans] # ans must be a
list
ans_with_commas = list()
for an in ans: ans_with_commas.extend([an, ','])
@@ -454,7 +454,7 @@
if i > 0: arg1 = nested_elements[i-1]
if i+1 < len(nested_elements): arg2 =
nested_elements[i+1]
#raise error if arg1 or arg2 is None
- if arg1 == None or arg2 == None: raise
SyntaxError('Operator "%s" is missing argument.'%(operator))
+ if arg1 == None or arg2 == None: raise SyntaxError,
'Operator "%s" is missing argument.'%(operator)
ans = _handle_operation(operator, arg1, arg2)
if not _is_list(ans): ans = [ans] # ans must be a
list
ans_with_commas = list()
@@ -466,12 +466,12 @@
for element in nested_elements:
if not _is_comma(element):
if not _is_list(element) and not _is_number(element)
and element not in _CONSTANTS.values():
- raise NameError('Unknown symbol
"%s".'%(element))
+ raise NameError, 'Unknown symbol
"%s".'%(element)
if last_element and not _is_comma(last_element):
- raise SyntaxError('Expected comma, but found
"%s".'%(element))
+ raise SyntaxError, 'Expected comma, but found
"%s".'%(element)
vector.append(element)
elif _is_comma(element) and _is_comma(last_element):
- raise SyntaxError('Commas must be separated by
non-commas.')
+ raise SyntaxError, 'Commas must be separated by
non-commas.'
last_element = element
if len(vector) == 1 and not _is_comma(last_element): return vector[0]
#return single number
return vector #otherwise return vector
Modified: grc/branches/jblum_work/src/SignalBlockDefs/Modulators.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/Modulators.py 2007-06-15
20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/SignalBlockDefs/Modulators.py 2007-06-15
20:41:27 UTC (rev 5774)
@@ -42,8 +42,12 @@
sb.add_input_socket('in', Complex())
sb.add_output_socket('out', Float())
sb.add_param('Gain', Float(1))
- return sb, lambda fg, gain: fcn(gain.parse())
+ return sb, lambda fg, gain: fcn(gain.parse())
+###########################################################################
+# Narrow band and Wide band FM
+###########################################################################
+
def WFMReceive(sb):
from gnuradio import blks
fcn = blks.wfm_rcv
@@ -119,6 +123,10 @@
return fcn(fg, audio_rate, quad_rate, tau.parse(),
max_dev.parse())
return sb, make
+###########################################################################
+# AM and FM demodulation
+###########################################################################
+
def AMDemod(sb):
from gnuradio import blks
fcn = blks.am_demod_cf
@@ -144,29 +152,45 @@
sb.add_param('Tau', Float(75e-6))
return sb, lambda fg, *args: fcn(fg, *map(lambda a: a.parse(), args))
+###########################################################################
+# Phase shift keying
+###########################################################################
+
def PSKMod(sb):
from gnuradio import blks
sb.add_input_socket('in', Byte())
sb.add_output_socket('out', Complex())
- sb.add_param('Type', Enum([('DBPSK', blks.dbpsk_mod), ('DQPSK',
blks.dqpsk_mod)]), type=True)
+ sb.add_param('Type', Enum([
+ ('DBPSK', blks.dbpsk_mod),
+ ('DQPSK', blks.dqpsk_mod),
+ ('D8PSK', blks.d8psk_mod),
+ ]), type=True)
sb.add_param('Samples/Symbol', Int(2, min=1))
sb.add_param('Excess BW', Float(0.35))
- sb.add_param('Use Gray Code', Enum([('Yes', True), ('No', False)]))
+ sb.add_param('Use Gray Code', Bool(true='Yes', false='No',
default=True))
return sb, lambda fg, type, *args: type.parse()(fg, *map(lambda a:
a.parse(), args))
def PSKDemod(sb):
from gnuradio import blks
sb.add_input_socket('in', Complex())
sb.add_output_socket('out', Byte())
- sb.add_param('Type', Enum([('DBPSK', blks.dbpsk_demod), ('DQPSK',
blks.dqpsk_demod)]), type=True)
+ sb.add_param('Type', Enum([
+ ('DBPSK', blks.dbpsk_demod),
+ ('DQPSK', blks.dqpsk_demod),
+ ('D8PSK', blks.d8psk_demod),
+ ]), type=True)
sb.add_param('Samples/Symbol', Int(2, min=1))
sb.add_param('Excess BW', Float(0.35))
sb.add_param('Costas Alpha', Float(0.03))
sb.add_param('Gain Mu', Float(0.05))
sb.add_param('Mu', Float(0.005))
sb.add_param('Omega Relative Limit', Float(0.05))
- sb.add_param('Use Gray Code', Enum([('Yes', True), ('No', False)]))
+ sb.add_param('Use Gray Code', Bool(true='Yes', false='No',
default=True))
return sb, lambda fg, type, *args: type.parse()(fg, *map(lambda a:
a.parse(), args))
+
+###########################################################################
+# Gaussian minimum shift keying
+###########################################################################
def GMSKMod(sb):
from gnuradio import blks
@@ -191,6 +215,42 @@
return sb, lambda fg, *args: fcn(fg, *map(lambda a: a.parse(), args))
###########################################################################
+# Quadrature amplitude modulation
+###########################################################################
+
+def QAMMod(sb):
+ from gnuradio import blks
+ sb.add_input_socket('in', Byte())
+ sb.add_output_socket('out', Complex())
+ sb.add_param('Type', Enum([
+ ('QAM 8', blks.qam8_mod),
+ ('QAM 64', blks.qam64_mod),
+ ('QAM 256', blks.qam256_mod),
+ ]), type=True)
+ sb.add_param('Samples/Symbol', Int(2, min=1))
+ sb.add_param('Excess BW', Float(0.35))
+ sb.add_param('Use Gray Code', Bool(true='Yes', false='No',
default=True))
+ return sb, lambda fg, type, *args: type.parse()(fg, *map(lambda a:
a.parse(), args))
+
+def QAMDemod(sb):
+ from gnuradio import blks
+ sb.add_input_socket('in', Complex())
+ sb.add_output_socket('out', Byte())
+ sb.add_param('Type', Enum([
+ ('QAM 8', blks.qam8_demod),
+ ('QAM 64', blks.qam64_demod),
+ ('QAM 256', blks.qam256_demod),
+ ]), type=True)
+ sb.add_param('Samples/Symbol', Int(2, min=1))
+ sb.add_param('Excess BW', Float(0.35))
+ sb.add_param('Costas Alpha', Float(0.03))
+ sb.add_param('Gain Mu', Float(0.05))
+ sb.add_param('Mu', Float(0.005))
+ sb.add_param('Omega Relative Limit', Float(0.05))
+ sb.add_param('Use Gray Code', Bool(true='Yes', false='No',
default=True))
+ return sb, lambda fg, type, *args: type.parse()(fg, *map(lambda a:
a.parse(), args))
+
+###########################################################################
# Phase Locked Loops
###########################################################################
Modified: grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
2007-06-15 20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockConstants.py
2007-06-15 20:41:27 UTC (rev 5774)
@@ -22,6 +22,7 @@
from DataTypes import *
+##choices for an Enum of regular data types
all_choices = [
('Complex', Complex()),
('Float', Float()),
@@ -30,6 +31,7 @@
('Byte', Byte()),
]
+##choices for an Enum of vector data types
all_vector_choices = [
('Complex Vector', (ComplexVector(), Complex())),
('Float Vector', (FloatVector(), Float())),
@@ -38,8 +40,10 @@
('Byte Vector', (ByteVector(), Byte()))
]
+##default sampling rate
default_samp_rate = '$samp_rate'
+##possible audio rates for audio source/sink
audio_rates = [
('16KHz', int(16e3)),
('22.05KHz', int(22.05e3)),
@@ -48,8 +52,11 @@
('44.1KHz', int(44.1e3)),
('48KHz', int(48e3)),
]
+
+##index of the default audio rate
default_audio_rate_index = 3
+##default udp port for udp source/sink
default_udp_port = 3456
\ No newline at end of file
Modified: grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
2007-06-15 20:01:45 UTC (rev 5773)
+++ grc/branches/jblum_work/src/SignalBlockDefs/SignalBlockTree.py
2007-06-15 20:41:27 UTC (rev 5774)
@@ -33,6 +33,7 @@
import Coders
import Trellis
+##A categorized list of all signal blocks
SB_TREE = [
('Sources', [
('Signal Source', Sources.SignalSource),
@@ -146,6 +147,8 @@
('PSK Demodulation', Modulators.PSKDemod),
('GMSK Modulation', Modulators.GMSKMod),
('GMSK Demodulation', Modulators.GMSKDemod),
+ ('QAM Modulation', Modulators.QAMMod),
+ ('QAM Demodulation', Modulators.QAMDemod),
]),
('Coders', [
('Constellation Decoder',
Coders.ConstellationDecoder),
@@ -174,8 +177,18 @@
]),
]
-def get_signal_block(parent, coor, rot, lookup_tag, id,
signal_block_constructor=SignalBlock):
- """ Create a new signal based on a few input parameters. """
+def get_signal_block(parent=None, coor=(0,0), rot=0, lookup_tag='', id='',
signal_block_constructor=SignalBlock):
+ """!
+ Create a new signal block.
+ @param parent the flow graph
+ @param coor the (x,y) corrdinate
+ @param rot the rotation in degrees
+ @param lookup_tag the tag of the desired signal block
+ @param id the unique id for the new signal block
+ @param signal_block_constructor the contructor for a new signal block
+ @throw TagNotFoundException tag not found
+ @return (the signal block, a gnuradio signal block builder function)
tuple
+ """
sb = signal_block_constructor(parent, coor, rot, lookup_tag, id)
for category, signal_blocks in SB_TREE:
for tag, builder in signal_blocks:
@@ -188,7 +201,7 @@
tags_to_remove = list()
for tag in tags:
try:
- get_signal_block(None, (0,0), 0, tag[0], '')
+ get_signal_block(lookup_tag=tag[0])
if tag[0] in tags_set: # remove redundant tags
#
print 'Removing redundant tag "%s" in category
"%s"...'%(tag[0], category)
tags_to_remove.append(tag)
@@ -211,7 +224,8 @@
def __init__(self, value): self.value = value
def __str__(self): return 'Exception! The tag: %s could not be
found'%repr(self.value)
-def print_tags():
+def print_sb_tree():
+ """Print the signal block tree."""
for category,tags in TAGS:
print category
for tag in tags: print '\t%s'%tag[0]
Modified: grc/branches/jblum_work/src/StateCache.py
===================================================================
--- grc/branches/jblum_work/src/StateCache.py 2007-06-15 20:01:45 UTC (rev
5773)
+++ grc/branches/jblum_work/src/StateCache.py 2007-06-15 20:41:27 UTC (rev
5774)
@@ -34,8 +34,7 @@
StateCache constructor.
@param initial_state the intial state (nested data)
"""
- self.states = list()
- for i in range(STATE_CACHE_SIZE): self.states.append(None)
+ self.states = [None for i in range(STATE_CACHE_SIZE)] #fill
states
self.current_state_index = 0
self.num_prev_states = 0
self.num_next_states = 0
Modified: grc/branches/jblum_work/src/Variables.py
===================================================================
--- grc/branches/jblum_work/src/Variables.py 2007-06-15 20:01:45 UTC (rev
5773)
+++ grc/branches/jblum_work/src/Variables.py 2007-06-15 20:41:27 UTC (rev
5774)
@@ -53,11 +53,11 @@
"""
# make sure that all parameters are strings #
for var in (key, value, min, max, step):
- if type(var) != type(str()): raise TypeError('"%s" var is not
of type string'%var)
+ if type(var) != type(str()): raise TypeError, '"%s" var is not
of type string'%var
# make sure that the key does not already exists #
- if has_key(key): raise KeyError('"%s" already exists!'%key)
+ if has_key(key): raise KeyError, '"%s" already exists!'%key
# make sure that the key name is valid #
- if not is_key_name_valid(key): raise KeyError('"%s" is a invalid key
name!'%key)
+ if not is_key_name_valid(key): raise KeyError, '"%s" is a invalid key
name!'%key
# count the number of blank strings in min, max, and step #
num_blanks = 0
for var in (min, max, step):
@@ -65,26 +65,26 @@
if num_blanks == 3: pass #allow the vars to be registered normally
else: #num_blanks is less than 3
try: float(value) #make sure that value is a float
- except ValueError: raise TypeError('"%s" must be parseable to
type float'%value)
+ except ValueError: raise TypeError, '"%s" must be parseable to
type float'%value
if num_blanks == 2: #do something intelligent to fill the
two blanks
# make sure that the non-blank value is a float
#
for var in (min, max, step):
if var != '': #only try to parse the
non-blank variable
try: float(var) #make sure that value
is a float
- except ValueError: raise
TypeError('"%s" must be parseable to type float'%var)
+ except ValueError: raise TypeError,
'"%s" must be parseable to type float'%var
# determine the non-blank var and generate the
other two vars #
if min != '': max = value
elif max != '': min = value
- elif step != '': raise ValueError('step cannot have a
value when min and max are blank')
+ elif step != '': raise ValueError, 'step cannot have a
value when min and max are blank'
elif num_blanks == 1: #clear all vars for min, max, and step
if step != '': min = max = step = '' #only if step was
not the blank one
elif num_blanks == 0: pass #none were blank, move onto the
validity check
# check the values for validity #
if min != '' and max != '': #only check for validity if min and max are
non blank
if float(value) < float(min) or float(value) > float(max) or
float(min) >= float(max):
- raise ValueError('%s is not greater than or equal to %s
and less than and equal to %s'%(value, min, max))
+ raise ValueError, '%s is not greater than or equal to
%s and less than and equal to %s'%(value, min, max)
if step == '': step = str((float(max) -
float(min))/float(DEFAULT_SLIDER_STEPS))
- if (float(max) - float(min))/float(step) < 1: raise
ValueError('%s step size is too large'%step)
+ if (float(max) - float(min))/float(step) < 1: raise ValueError,
'%s step size is too large'%step
### register the values ###
VARS_DICT[key] = (value, min, max, step)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5774 - in grc/branches/jblum_work: notes src src/Elements src/Graphics src/SignalBlockDefs,
jblum <=