[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5772 - grc/branches/jblum_work/src/Elements
From: |
jblum |
Subject: |
[Commit-gnuradio] r5772 - grc/branches/jblum_work/src/Elements |
Date: |
Tue, 12 Jun 2007 21:37:13 -0600 (MDT) |
Author: jblum
Date: 2007-06-12 21:37:12 -0600 (Tue, 12 Jun 2007)
New Revision: 5772
Modified:
grc/branches/jblum_work/src/Elements/Connection.py
grc/branches/jblum_work/src/Elements/Element.py
grc/branches/jblum_work/src/Elements/GraphicalConnection.py
grc/branches/jblum_work/src/Elements/GraphicalElement.py
grc/branches/jblum_work/src/Elements/GraphicalParam.py
grc/branches/jblum_work/src/Elements/GraphicalSignalBlock.py
grc/branches/jblum_work/src/Elements/GraphicalSocket.py
grc/branches/jblum_work/src/Elements/Param.py
grc/branches/jblum_work/src/Elements/SignalBlock.py
grc/branches/jblum_work/src/Elements/Socket.py
grc/branches/jblum_work/src/Elements/Utils.py
Log:
added doxygen comments to Elements package
Modified: grc/branches/jblum_work/src/Elements/Connection.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Connection.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/Connection.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -20,7 +20,7 @@
#The elemental connection of input and output sockets.
address@hidden Josh Blum
-from Element import Element
+import Element
import Utils
class InvalidConnectionException(Exception):
@@ -29,18 +29,24 @@
class TooManyConnectionsException(Exception):
def __str__(self): return 'An input socket may only have one
connection!'
-class Connection(Element):
- """ Connection provides elemental interfaces for a connection of
sockets. """
+class Connection(Element.Element):
+ """Connection provides elemental interfaces for a connection of
sockets."""
type = 'connection'
def __init__(self, parent, socket1, socket2):
- """ Initialize the Element and set the parent, coor, and
rotation.
- Try to connect a pair of sockets. The sockets must be an input
and an output.
- Also the input must have no existing connections.
- If an input socket that is already connected is passed to the
constructor,
- the logic will use the output socket that it is connected to.
- This way, a user could try to connect an unconnected input
socket to a signal on another input.
- Then, the program will translate this to the cooresponding
output socket on that signal. """
- Element.__init__(self, parent, (0,0), 0)
+ """!
+ Connection constructor.
+ Initialize the Element with the given parent and a rotation and
coordinate of zeros.
+ Connect a pair of sockets. The sockets must be an input and an
output. The input must have no existing connections.
+ @param parent the flow graph
+ @param socket1 an input/output socket
+ @param socket2 another input/output socket
+ @throw InvalidConnectionException cant connect
+ """
+ Element.Element.__init__(self, parent, (0,0), 0)
+ #If an input socket that is already connected is passed to the
constructor,
+ #the logic will use the output socket that it is connected to.
+ #This way, a user could try to connect an unconnected input
socket to a signal on another input.
+ #Then, the program will translate this to the cooresponding
output socket on that signal.
#>>>I dont like this functionality, uncomment it to pick the
output socket
#if is_input_socket(socket1) and socket1.is_connected():
#socket1 is input and connected
# socket1 =
socket1.get_connections()[0].get_output_socket() #so we use its output
socket
@@ -57,23 +63,35 @@
else: raise InvalidConnectionException()
def get_coordinate(self):
- ''' always get the 0,0 coordinate '''
+ """!Get the 0,0 coordinate.
+ Coordinates are irrelevant in connection.
+ @return 0,0
+ """
return (0,0)
def get_rotation(self):
- ''' always get the 0 degree rotation '''
+ """!Get the 0 degree rotation.
+ Rotations are irrelevant in connection.
+ @return 0
+ """
return 0
def get_input_socket(self):
- """get the input socket"""
+ """!
+ Get the input socket.
+ @return input socket
+ """
return self.sockets[0]
def get_output_socket(self):
- """get the output socket"""
+ """!
+ Get the output socket.
+ @return output socket
+ """
return self.sockets[1]
def disconnect(self):
- """ delete this connection by calling the socket's disconnect
methods. """
+ """Disconnect the sockets by calling each socket's disconnect
methods and removing the sockets from the parent."""
print "disconnecting"
for socket in self.sockets: socket.disconnect(self)
self.get_parent().remove_element(self)
Modified: grc/branches/jblum_work/src/Elements/Element.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Element.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/Element.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -24,26 +24,33 @@
from Constants import POSSIBLE_ROTATIONS,DIR_LEFT,DIR_RIGHT
class Element:
- """ Element is the base class for all elements. It contains an X,Y
coordinate, a list
- of rectangular areas that the element occupies and methods to detect
selection. """
-
- def rotate(self, direction):
- """ rotate all of the areas by 90 degrees, direction is
"left"/"right" """
- if direction == DIR_LEFT: delta_rotation = 90
- elif direction == DIR_RIGHT: delta_rotation = 270
- self.set_rotation((self.get_rotation() + delta_rotation)%360)
- self.update()
-
+ """Element is the base class for all elements. It contains an X,Y
coordinate, a list
+ of rectangular areas (and lines) that the element occupies and methods
to detect selection."""
def __init__(self, parent, coor, rotation):
- """ make a new list of rectangular areas and lines, and set
the coordinate and the rotation """
+ """!
+ Make a new list of rectangular areas and lines, and set the
coordinate and the rotation.
+ @param parent the parent of this element
+ @param coor the coordinate tuple (x,y)
+ @param rotation an angle in degrees 0, 90, 180, 270
+ """
self.parent = parent
self.set_rotation(rotation)
self.set_coordinate(coor)
self.clear()
- self.highlighted = False
+ self.highlighted = False
+
+ def rotate(self, direction):
+ """!
+ Rotate all of the areas by 90 degrees.
+ @param direction DIR_RIGHT or DIR_LEFT
+ """
+ if direction == DIR_LEFT: delta_rotation = 90
+ elif direction == DIR_RIGHT: delta_rotation = 270
+ self.set_rotation((self.get_rotation() + delta_rotation)%360)
+ self.update()
def clear(self):
- ''' make the lines and areas empty. '''
+ """Empty the lines and areas."""
self.areas_dict = dict()
self.lines_dict = dict()
for rotation in POSSIBLE_ROTATIONS:
@@ -51,48 +58,78 @@
self.lines_dict[rotation] = list()
def set_coordinate(self, coor):
- ''' set the reference coordinate. '''
+ """!
+ Set the reference coordinate.
+ @param coor the coordinate tuple (x,y)
+ """
self.coor = coor
def get_parent(self):
- ''' get the parent '''
+ """!
+ Get the parent of this element.
+ @return the parent
+ """
return self.parent
def set_highlighted(self, highlighted):
- """ set the highlight status """
+ """!
+ Set the highlight status.
+ @param highlighted true to enable highlighting
+ """
self.highlighted = highlighted
def is_highlighted(self):
- """ get the highlight status """
+ """!
+ Get the highlight status.
+ @return true if highlighted
+ """
return self.highlighted
def get_coordinate(self):
- """ get the coordinate (X,Y) pair """
+ """!Get the coordinate.
+ @return the coordinate tuple (x,y)
+ """
return self.coor
def move(self, delta_coor):
- """ we move the element by adding the X and Y values of
deltaCoor to this coordinate """
+ """!
+ Move the element by adding the delta_coor to the current
coordinate.
+ @param delta_coor (delta_x,delta_y) tuple
+ """
deltaX,deltaY = delta_coor
X,Y = self.get_coordinate()
self.coor = (X+deltaX, Y+deltaY)
def add_area(self, rel_coor, area, rotation=None):
- """ add an area to the area list, an area is actually a
coordinate relative to the main coordinate
- with a width/height pair relative to the area coordinate. A
positive width is to the right of the
- coordinate. A positive height is above the coordinate """
+ """!
+ Add an area to the area list.
+ An area is actually a coordinate relative to the main
coordinate with a width/height pair relative to the area coordinate.
+ A positive width is to the right of the coordinate. A positive
height is above the coordinate.
+ The area is associated with a rotation. If rotation is not
specified, the element's current rotation is used.
+ @param rel_coor (x,y) offset from this element's coordinate
+ @param area (width,height) tuple
+ @param rotation rotation in degrees
+ """
if rotation == None: rotation = self.get_rotation()
self.areas_dict[rotation].append((rel_coor, area))
def add_line(self, rel_coor1, rel_coor2, rotation=None):
- """ add a line to the line list. A line is defined by 2
relative coordinates.
- Lines must be horizontal or vertical! """
+ """!
+ Add a line to the line list.
+ A line is defined by 2 relative coordinates. Lines must be
horizontal or vertical.
+ The line is associated with a rotation. If rotation is not
specified, the element's current rotation is used.
+ @param rel_coor1 relative (x1,y1) tuple
+ @param rel_coor2 relative (x2,y2) tuple
+ @param rotation rotation in degrees
+ """
if rotation == None: rotation = self.get_rotation()
self.lines_dict[rotation].append((rel_coor1, rel_coor2))
def what_is_selected(self, coor):
- """ is this Element selected at given coor? Or is coor
encompassed by one of the areas or lines.
- We determine the absolute coordinate of each area and
coordinate on the other diagonal of the area.
- return self if one of the areas/lines encompasses the coor, or
None. """
+ """!
+ Is this Element selected at given coordinate/is the coordinate
encompassed by one of the areas or lines?
+ @return self if one of the areas/lines encompasses coor, else
None.
+ """
in_between = lambda A, B, point: point >= min(A,B) and point <=
max(A,B)
X,Y = self.get_coordinate()
x,y = coor
@@ -114,17 +151,22 @@
return None
def get_rotation(self):
- """ get the rotation """
+ """!
+ Get the rotation in degrees.
+ @return the rotation
+ """
return self.rotation
def set_rotation(self, rotation):
- """ set the rotation """
+ """!
+ Set the rotation in degrees.
+ @param rotation the rotation"""
if rotation not in POSSIBLE_ROTATIONS:
raise Exception('"%s" is not one of the possible
rotations: (%s)'%(rotation,POSSIBLE_ROTATIONS))
self.rotation = rotation
def update(self):
- """ Do nothing for the update. """
+ """Do nothing for the update. Dummy method."""
pass
\ No newline at end of file
Modified: grc/branches/jblum_work/src/Elements/GraphicalConnection.py
===================================================================
--- grc/branches/jblum_work/src/Elements/GraphicalConnection.py 2007-06-12
19:19:15 UTC (rev 5771)
+++ grc/branches/jblum_work/src/Elements/GraphicalConnection.py 2007-06-13
03:37:12 UTC (rev 5772)
@@ -22,15 +22,15 @@
import DataTypes
import Utils
-from Connection import Connection
-from GraphicalElement import GraphicalElement
+import Connection
+import GraphicalElement
import Colors
-class GraphicalConnection(Connection, GraphicalElement):
- """ Connection is a graphical connection for sockets """
+class GraphicalConnection(Connection.Connection,
GraphicalElement.GraphicalElement):
+ """A graphical connection for sockets."""
def update(self):
- """ add the horizontal and vertical lines that will connect
the two parameters """
+ """Add the horizontal and vertical lines that will connect the
two parameters."""
self.clear()
input_socket = self.get_input_socket()
output_socket = self.get_output_socket()
@@ -68,9 +68,12 @@
self.add_line((x2,y2),p)
def draw(self, window):
- """ draw the Connection """
+ """!
+ Draw the connection.
+ @param window the gtk window to draw on
+ """
self.update()
- GraphicalElement.draw(self, window)
+ GraphicalElement.GraphicalElement.draw(self, window)
gc = self.gc
''' draw error lines around the existing lines when data
types do not match '''
if not self.is_valid():
@@ -84,9 +87,12 @@
window.draw_line(gc, x1, y1+1, x2, y2+1)
def is_valid(self):
- """ is this connection valid, ie: do the input and output data
types match? """
+ """!
+ Is this connection valid, ie: do the input and output data
types match?
+ User preferences can override this validity check.
+ @return true if the data types match or if check connections is
off
+ """
import Preferences #preferences
return not Preferences.check_connections() or\
- DataTypes.can_connect(self.sockets[0].get_data_type(),
self.sockets[1].get_data_type())
-
+ DataTypes.can_connect(self.sockets[0].get_data_type(),
self.sockets[1].get_data_type())
Modified: grc/branches/jblum_work/src/Elements/GraphicalElement.py
===================================================================
--- grc/branches/jblum_work/src/Elements/GraphicalElement.py 2007-06-12
19:19:15 UTC (rev 5771)
+++ grc/branches/jblum_work/src/Elements/GraphicalElement.py 2007-06-13
03:37:12 UTC (rev 5772)
@@ -22,19 +22,24 @@
address@hidden Josh Blum
from Constants import *
-from Element import Element
+import Element
import Colors
import pygtk
pygtk.require('2.0')
import gtk
import pango
-class GraphicalElement(Element):
+class GraphicalElement(Element.Element):
""" Element is the base class for all graphical elements. It
contains an X,Y coordinate, a list
of rectangular areas that the element occupies and methods to detect
selection. """
def draw(self, window, BG_color=Colors.BG_COLOR,
FG_color=Colors.FG_COLOR):
- """ draw in the given window. """
+ """!
+ Draw in the given window.
+ @param window the gtk window to draw on
+ @param BG_color the background color
+ @param FG_color the foreground color
+ """
gc = self.get_parent().gc
self.gc = gc
X,Y = self.get_coordinate()
@@ -50,7 +55,5 @@
if self.is_highlighted(): gc.foreground = Colors.H_COLOR
else: gc.foreground = FG_color
window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
-
-
\ No newline at end of file
Modified: grc/branches/jblum_work/src/Elements/GraphicalParam.py
===================================================================
--- grc/branches/jblum_work/src/Elements/GraphicalParam.py 2007-06-12
19:19:15 UTC (rev 5771)
+++ grc/branches/jblum_work/src/Elements/GraphicalParam.py 2007-06-13
03:37:12 UTC (rev 5772)
@@ -20,7 +20,7 @@
#GTK objects for handling input and the signal block parameter class.
address@hidden Josh Blum
-from Param import Param
+import Param
from DataTypes import *
import pygtk
pygtk.require('2.0')
@@ -114,11 +114,14 @@
# A Parameter, hold a data type and a cname
######################################################################################################
-class GraphicalParam(Param):
-
+class GraphicalParam(Param.Param):
+ """The graphical parameter."""
def get_input_object(self):
- """ Get the graphical gtk class to represent this parameter.
- Create the input object with this data type and the handle
changed method."""
+ """!
+ Get the graphical gtk class to represent this parameter.
+ Create the input object with this data type and the handle
changed method.
+ @return gtk input object
+ """
if self.get_data_type().get_base_type() ==
Enum().get_base_type(): input = EnumParam
elif self.get_data_type().get_base_type() ==
File().get_base_type(): input = FileParam
else: input = EntryParam
@@ -127,7 +130,7 @@
return self.input
def handle_changed(self, widget=None):
- ''' if the input changed, write the inputs to the param.
'''
+ """When the input changes, write the inputs to the data type."""
data_type = self.get_data_type()
new_data = self.input.get_text()
old_data = data_type.get_data()
@@ -142,10 +145,13 @@
if self.input.tp:
self.input.tp.set_tip(self.input.entry, str(data_type.parse()))
def get_markup(self):
- """ Create a markup to display the Param as a label on the
SignalBlock.
+ """!
+ Create a markup to display the Param as a label on the
SignalBlock.
If the data type is an Enum type, use the cname of the Enum's
current choice.
Otherwise, use parsed the data type and use its string
representation.
- If the data type is not valid, use a red foreground color.
"""
+ If the data type is not valid, use a red foreground color.
+ @return pango markup string
+ """
###########################################################################
# display logic for numbers
###########################################################################
@@ -195,7 +201,10 @@
else: return '<span foreground="red"><b>%s:</b>
error</span>'%self.cname
def get_layout(self):
- """ Create a layout based on the current Param's Markup.
"""
+ """!
+ Create a layout based on the current markup.
+ @return the pango layout
+ """
layout = gtk.DrawingArea().create_pango_layout('')
layout.set_markup(self.get_markup())
desc = pango.FontDescription(PARAM_FONT)
Modified: grc/branches/jblum_work/src/Elements/GraphicalSignalBlock.py
===================================================================
--- grc/branches/jblum_work/src/Elements/GraphicalSignalBlock.py
2007-06-12 19:19:15 UTC (rev 5771)
+++ grc/branches/jblum_work/src/Elements/GraphicalSignalBlock.py
2007-06-13 03:37:12 UTC (rev 5772)
@@ -20,11 +20,11 @@
#The graphical signal block.
address@hidden Josh Blum
-from SignalBlock import SignalBlock
+import SignalBlock
import Utils
import Colors
from GraphicalParam import GraphicalParam
-from GraphicalElement import GraphicalElement
+import GraphicalElement
from GraphicalSocket import GraphicalInputSocket,GraphicalOutputSocket
from Constants import *
from DataTypes import Enum,Int
@@ -33,15 +33,14 @@
import gtk
import pango
-class GraphicalSignalBlock(SignalBlock, GraphicalElement):
- """ SignalBlock is a graphical signal block. It is a Element with
an index from the list of
- possible signal blocks and graphical input/output elements. """
+class GraphicalSignalBlock(SignalBlock.SignalBlock,
GraphicalElement.GraphicalElement):
+ """The graphical signal block."""
param_constructor = GraphicalParam
input_socket_constructor = GraphicalInputSocket
output_socket_constructor = GraphicalOutputSocket
def update(self):
- """ update the block and parameters and sockets when a change
occurs """
+ """Update the block, parameters, and sockets when a change
occurs."""
self.clear()
self._adjust_sockets()
self._create_labels()
@@ -53,7 +52,7 @@
for socket in self.get_sockets(): socket.update()
def _create_labels(self):
- ''' Create the labels for the signal block. '''
+ """Create the labels for the signal block."""
layouts = list()
# create the main layout #
layout = gtk.DrawingArea().create_pango_layout(self.cname)
@@ -93,8 +92,11 @@
for j in range(height): vimage.put_pixel(j,
width-i-1, image.get_pixel(i, j))
def draw(self, window):
- """ draw the signal block with label and inputs/outputs
"""
- GraphicalElement.draw(self, window)
+ """!
+ Draw the signal block with label and inputs/outputs.
+ @param window the gtk window to draw on
+ """
+ GraphicalElement.GraphicalElement.draw(self, window)
gc = self.gc
gc.foreground = Colors.TXT_COLOR
X,Y = self.get_coordinate()
@@ -105,7 +107,11 @@
for socket in self.get_sockets(): socket.draw(window)
def is_valid(self):
- ''' This block is valid if all the params are valid and all
sockets connected. '''
+ """!
+ Is this block is valid/are all the params valid and all sockets
connected?
+ User preferences can override certain validity checks.
+ @return true if valid
+ """
import Preferences
if Preferences.check_params(): #preferences
for param in self.params:
@@ -116,8 +122,10 @@
return True
def modify_type_controller(self, direction):
- """ If a type controller was set, increment/decrement its index
by 1, use a % to stay in bounds.
- Direction may be +1 or -1"""
+ """!
+ If a type controller was set, increment/decrement its index by
1, use a % to stay in bounds.
+ @param direction +1 or -1
+ """
if self.type_controller != None and
self.type_controller.get_type() == Enum().get_type():
num_choices =
len(self.type_controller.get_cnames_list())
index = int(self.type_controller.get_data())
@@ -127,10 +135,12 @@
return False
def modify_socket_controller(self, direction):
- """ If a socket controller was set, increment/decrement its
data type by 1, DO NOT go out of bounds.
- Return True if operation was done. Return False if
operation could not be completed.
- If there is a controller on input and outputs, show
preference to the output controller.
- Direction may be +1 or -1. """
+ """!
+ If a socket controller was set, increment/decrement its data
type by 1, DO NOT go out of bounds.
+ If there is a controller on input and outputs, show preference
to the output controller.
+ @param direction +1 or -1
+ @return true if operation was done, false if operation could
not be completed.
+ """
# Get the socket controller, if there is an input and output
controller, use output #
socket_controller = None
if self.input_sockets_controller != None: socket_controller =
self.input_sockets_controller
Modified: grc/branches/jblum_work/src/Elements/GraphicalSocket.py
===================================================================
--- grc/branches/jblum_work/src/Elements/GraphicalSocket.py 2007-06-12
19:19:15 UTC (rev 5771)
+++ grc/branches/jblum_work/src/Elements/GraphicalSocket.py 2007-06-13
03:37:12 UTC (rev 5772)
@@ -21,8 +21,8 @@
address@hidden Josh Blum
import Utils
-from Socket import Socket
-from GraphicalElement import GraphicalElement
+import Socket
+import GraphicalElement
from DataTypes import *
from Constants import *
import Colors
@@ -31,12 +31,11 @@
import gtk
import pango
-class GraphicalSocket(Socket, GraphicalElement):
- """ Socket is a graphical signal block input/output parameter.
- It has an index, input/output setting, and a data type. """
+class GraphicalSocket(Socket.Socket, GraphicalElement.GraphicalElement):
+ """The graphical socket."""
def update(self):
- """ update the coloring, a change may have occured in the
block params """
+ """Create new areas and labels for the socket."""
self.clear()
self.BG_color = {
Complex().get_type():Colors.COMPLEX_COLOR,
@@ -84,7 +83,7 @@
if self.is_connected():
self.__set_connector_coordinates((x+conOff, y+1+SOCKET_WIDTH),(x+conOff,
y+SOCKET_WIDTH+conExtInitLen+conExtLen*index))
def _create_labels(self):
- ''' Create the labels for the socket. '''
+ """Create the labels for the socket."""
# create the layout #
layout = gtk.DrawingArea().create_pango_layout(self.cname)
desc = pango.FontDescription(SOCKET_FONT)
@@ -105,8 +104,11 @@
for j in range(h): vimage.put_pixel(j, w-i-1,
image.get_pixel(i, j))
def draw(self, window):
- """ draw the paramter with labels """
- GraphicalElement.draw(self, window, BG_color=self.BG_color)
+ """!
+ Draw the socket with a label.
+ @param window the gtk window to draw on
+ """
+ GraphicalElement.GraphicalElement.draw(self, window,
BG_color=self.BG_color)
gc = self.gc
gc.foreground = Colors.TXT_COLOR
X,Y = self.get_coordinate()
@@ -115,29 +117,42 @@
elif Utils.is_vertical(self.get_rotation()):
window.draw_image(gc, self.vertical_label, 0, 0, x+X+(SOCKET_HEIGHT-self.h)/2,
y+Y+(SOCKET_WIDTH-self.w)/2, -1, -1)
def __set_connector_coordinates(self, coor_inner, coor_outer,
rotation=None):
- """ Set the coordinates that connectors may attach to. """
+ """!
+ Set the coordinates that connectors may attach to.
+ The connector coordinates are associated with a rotation. If
rotation is not specified, the element's current rotation is used.
+ @param coor_inner the corrdinate on the socket
+ @param coor_outer the coordinate out of the socket
+ @param rotation rotation in degrees
+ """
if rotation == None: rotation = self.get_rotation()
self.connector_coordinates[rotation] = coor_inner, coor_outer
def get_connector_coordinates(self, rotation=None):
- """ Get the coordinates that Connections may attach to.
"""
+ """!
+ Get the coordinates that Connections may attach to.
+ @param rotation rotation in degrees
+ @return the connector coordinates ((xin, yin), (xout, yout))
tuple
+ """
if rotation == None: rotation = self.get_rotation()
X,Y = self.get_coordinate()
(x1,y1),(x2,y2)= self.connector_coordinates[rotation]
return (x1+X, y1+Y), (x2+X, y2+Y)
def get_connector_direction(self):
- """ the direction that the socket points in 0,90,180,270
- this is the rotation degree if the socket is an output or
- the rotation degree + 180 if the socket is an input """
+ """!
+ Get the direction that the socket points: 0,90,180,270.
+ This is the rotation degree if the socket is an output or
+ the rotation degree + 180 if the socket is an input.
+ @return the direction in degrees
+ """
if Utils.is_output_socket(self): return self.get_rotation()
elif Utils.is_input_socket(self): return (self.get_rotation() +
180)%360
class GraphicalInputSocket(GraphicalSocket):
- ''' The socket for input '''
- type = 'input socket'
+ """ The socket for input """
+ type = Socket.InputSocket.type
class GraphicalOutputSocket(GraphicalSocket):
- ''' The socket for output '''
- type = 'output socket'
+ """ The socket for output """
+ type = Socket.OutputSocket.type
\ No newline at end of file
Modified: grc/branches/jblum_work/src/Elements/Param.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Param.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/Param.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -21,19 +21,28 @@
address@hidden Josh Blum
class Param:
- """ This class holds a single signal block parameter,
- a data type and a cname. """
+ """A param holds a single signal block parameter: a data type and a
canonical name."""
def __init__(self, cname, data_type):
- """ Initialize by setting the data type and cname. """
+ """!
+ Param constructor. Set the data type and cname.
+ @param cname the canonical name
+ @param data_type the data type
+ """
self.cname = cname
self.data_type = data_type
self.input = None
def get_cname(self):
- """ Get the cname. """
+ """!
+ Get the cname.
+ @return the canonical name
+ """
return self.cname
def get_data_type(self):
- """ Get the data type. """
+ """!
+ Get the data type.
+ @return the data type
+ """
return self.data_type
Modified: grc/branches/jblum_work/src/Elements/SignalBlock.py
===================================================================
--- grc/branches/jblum_work/src/Elements/SignalBlock.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/SignalBlock.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -20,28 +20,34 @@
#The elemental signal block.
address@hidden Josh Blum
-from Element import Element
+import Element
import Utils
from Socket import OutputSocket,InputSocket
from Param import Param
from DataTypes import Enum,Int,Vector
-class SignalBlock(Element):
- """ SignalBlock is an Element with an index from the list of
- possible signal blocks and graphical input/output elements. """
+class SignalBlock(Element.Element):
+ """A SignalBlock is an Element with an index from the list of possible
signal blocks and input/output sockets."""
type = 'signal block'
param_constructor = Param
input_socket_constructor = InputSocket
output_socket_constructor = OutputSocket
def __init__(self, parent, coor, rotation, tag, id):
- """ initialize the signalblock, adding lists for sockets,
params """
- Element.__init__(self, parent, coor, rotation)
+ """!
+ SignalBlock constructor.
+ @param parent the flow graph
+ @param coordinate the (x,y) tuple
+ @param rotation the rotation in degrees
+ @param tag a string unique to signal blocks of this type
+ @param id a string unique to this signal block
+ """
+ Element.Element.__init__(self, parent, coor, rotation)
self.tag = tag
self.input_sockets = list()
self.output_sockets = list()
self.params = list()
self.displayed_params = list()
- self.cname = tag #this may change
+ self.cname = tag
self.id = id
self.input_sockets_controller = self.output_sockets_controller
= None
self.type_controller = None
@@ -49,69 +55,118 @@
self.docs = None
def get_docs(self):
- ''' Get a string with helpful hints, suggestions, and
documentation on using this block. '''
+ """!
+ Get a string with helpful hints, suggestions, and documentation
on using this block.
+ @return the documentation string
+ """
return self.docs
def set_docs(self, docs):
- ''' Set the documentation for this block. '''
+ """!
+ Set the documentation for this block.
+ @param docs the documentation string
+ """
self.docs = docs
def get_sockets(self):
- ''' Get a list of all sockets. '''
+ """!
+ Get all sockets for this signal block.
+ @return a list of sockets
+ """
return self.input_sockets + self.output_sockets
def get_input_socket(self, index):
- ''' Get the input socket at index. '''
+ """!
+ Get the input socket at index.
+ @param index the input socket index
+ @return an input socket
+ """
self._adjust_sockets() #a parameter change may have altered the
sockets
for socket in filter(Utils.is_input_socket, self.get_sockets()):
if socket.get_index() == index: return socket
return None
def get_output_socket(self, index):
- ''' Get the output socket at index. '''
+ """!
+ Get the output socket at index.
+ @param index the output socket index
+ @return an output socket
+ """
self._adjust_sockets() #a parameter change may have altered the
sockets
for socket in filter(Utils.is_output_socket,
self.get_sockets()):
if socket.get_index() == index: return socket
return None
def get_id(self):
- ''' Get the id. '''
+ """!
+ Get the id.
+ @return the id string
+ """
return self.id
def get_tag(self):
- ''' Get the tag. '''
+ """!
+ Get the tag.
+ @return the tag string
+ """
return self.tag
def get_cname(self):
- ''' Get the cname. '''
+ """!
+ Get the canonical name.
+ @return the cname string
+ """
return self.cname
def get_params(self):
- ''' Get the params list. '''
+ """!
+ Get all of the parameters for this signal block.
+ @return a list of parameters
+ """
return self.params
def get_num_input_sockets(self):
- ''' Get the number of sockets of input type. '''
+ """!
+ Get the number of sockets of input type.
+ @return an integer number of sockets
+ """
return len(self.input_sockets)
def get_num_output_sockets(self):
- ''' Get the number of sockets of output type. '''
+ """!
+ Get the number of sockets of output type.
+ @return an integer number of sockets
+ """
return len(self.output_sockets)
def add_input_socket(self, cname, data_type, optional=False, vlen=None):
- ''' Append an input socket with its cname and data type.
'''
+ """!
+ Add an input socket with its cname and data type.
+ @param cname the canonical name
+ @param data_type the data type
+ @param optional true if connections are optional
+ @param vlen the width of each sample (how many numbers are in
each sample?)
+ """
self.input_sockets.append(self.input_socket_constructor(self,
cname, self.get_num_input_sockets(), data_type, optional, vlen))
def add_output_socket(self, cname, data_type, optional=False,
vlen=None):
- ''' Append an output socket with its cname and data type.
'''
+ """!
+ Add an output socket with its cname and data type.
+ @param cname the canonical name
+ @param data_type the data type
+ @param optional true if connections are optional
+ @param vlen the width of each sample (how many numbers are in
each sample?)
+ """
self.output_sockets.append(self.output_socket_constructor(self,
cname, self.get_num_output_sockets(), data_type, optional, vlen))
def add_param(self, cname, data_type, show_label=True, type=False,
output_sockets_controller=False, input_sockets_controller=False):
- ''' Append a param with its cname and data type.
- The show_label boolean flag tells the signal blocks to
display the parameter in its label.
- The type boolean flag registers this parameter to be
controlled via keypress.
- The output_sockets_controller registers this parameter
to set the number of output sockets.
- The input_sockets_controller registers this parameter
to set the number of input sockets. '''
+ """!
+ Add a parameter with its cname and data type.
+ @param show_label true to display the parameter in the signal
block's label
+ @param type true if this param is an enum to be controlled via
a keypress
+ @param output_sockets_controller register this parameter to set
the number of output sockets
+ @param input_sockets_controller register this parameter to set
the number of input sockets
+ """
param = self.param_constructor(cname, data_type)
if show_label: self.displayed_params.append(param)
if type: self.type_controller = data_type
@@ -120,20 +175,27 @@
self.params.append(param)
def what_is_selected(self, coor):
- """ get the element that is selected, signal block itself or a
socket """
+ """!
+ Get the element that is selected.
+ @param coor the (x,y) tuple
+ @return this signal block, a socket, or None
+ """
for socket in self.get_sockets():
if socket.what_is_selected(coor) != None:
return socket.what_is_selected(coor)
- return Element.what_is_selected(self, coor)
+ return Element.Element.what_is_selected(self, coor)
def get_connections(self):
- ''' Get a set of all connections from every socket. '''
+ """!
+ Get all connections from every socket.
+ @return a set of connections
+ """
connections = list()
for socket in self.get_sockets(): connections = connections +
socket.get_connections()
return set(connections)
def _adjust_sockets(self):
- ''' Use the input/output socket controllers to adjust the
number of sockets. '''
+ """Use the input/output socket controllers to adjust the number
of sockets."""
for sockets_list,controller,constructor in (
(self.input_sockets, self.input_sockets_controller,
self.input_socket_constructor),
(self.output_sockets, self.output_sockets_controller,
self.output_socket_constructor)
@@ -158,11 +220,16 @@
## Import a Signal Block
##########################################################################
def from_nested_data(fg, nested_data, sb_constructor):
- ''' Create a signal block from the nested data.
- Pass the flow graph/parent of the signal block,
- the nested data for a signal block,
- and the contructor for the signal block.
- Return (the signal block, the runnable signal block)
tuple. '''
+ """!
+ Create a signal block from the nested data.
+ Pass the flow graph/parent of the signal block,
+ the nested data for a signal block,
+ and the contructor for the signal block.
+ Return (the signal block, the runnable signal block) tuple.
+ @param fg the flow graph
+ @param nested_data the nested data
+ @param sb_contructor the contructor used to make a new signal
block
+ """
import ParseXML,Messages,SignalBlockDefs
find_data = ParseXML.find_data
signal_block = find_data([nested_data], 'signal_block')
Modified: grc/branches/jblum_work/src/Elements/Socket.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Socket.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/Socket.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -20,17 +20,26 @@
#The elemental input and output sockets of a signal block.
address@hidden Josh Blum
-from Element import Element
+import Element
import Utils,DataTypes
from Connection import TooManyConnectionsException
-class Socket(Element):
- """ Socket is an input/output element of a signal block.
- It has an index, input/output setting, and a data type. """
+class Socket(Element.Element):
+ """
+ A Socket is an input/output element of a signal block.
+ It has an index, input/output setting, and a data type.
+ """
type = 'socket'
def __init__(self, parent, cname, index, data_type, optional=False,
vlen=None):
- """ Initialize the Element and set the parent, coor, and
rotation """
- Element.__init__(self, parent, (0,0), 0) #use zeros since the
parent contains this information
+ """!
+ Socket constructor.
+ @param parent the signal block
+ @param coordinate the (x,y) tuple
+ @param rotation the rotation in degrees
+ @param optional true if connections are optional
+ @param vlen the width of each sample (how many numbers are in
each sample?)
+ """
+ Element.Element.__init__(self, parent, (0,0), 0) #use zeros
since the parent contains this information
self.connections = list()
self.w = self.h = 0
self.index = index
@@ -41,71 +50,113 @@
self.vlen = vlen
def move(self, delta_coor):
- ''' Move the parent rather than self. '''
+ """!
+ Move the parent rather than self.
+ @param delta_corr the (delta_x, delta_y) tuple
+ """
self.get_parent().move(delta_coor)
def rotate(self, direction):
- ''' Rotate the parent rather than self. '''
+ """!
+ Rotate the parent rather than self.
+ @param direction degrees to rotate
+ """
self.get_parent().rotate(direction)
def get_coordinate(self):
- ''' Use the parent's coordinate rather th.an self '''
+ """!
+ Get the parent's coordinate rather than self.
+ @return the parents coordinate
+ """
return self.get_parent().get_coordinate()
def set_highlighted(self, highlight):
- ''' Set the parent highlight rather than self. '''
+ """!
+ Set the parent highlight rather than self.
+ @param highlight true to enable highlighting
+ """
self.get_parent().set_highlighted(highlight)
def is_highlighted(self):
- ''' Use the parent's is highlight rather than self. '''
+ """!
+ Get the parent's is highlight rather than self.
+ @return the parent's highlighting status
+ """
return self.get_parent().is_highlighted()
def is_valid(self):
- ''' True if connected or the optional flag is True. '''
+ """!
+ Is this socket valid?
+ @return true if connected or the optional flag is true
+ """
return self.optional or self.is_connected()
def get_rotation(self):
- ''' use the parent's rotation as our own '''
+ """!
+ Get the parent's rotation rather than self.
+ @return the parent's rotation
+ """
return self.get_parent().get_rotation()
def get_data_type(self):
- ''' Get the data type. If the parsed vlen > 1, then return the
vectorized data type.'''
+ """!
+ Get the data type. If the parsed vlen > 1, then return the
vectorized data type.
+ @return the data type
+ """
if self.vlen != None and self.vlen.is_valid() and
self.vlen.parse() > 1: return DataTypes.vectorize(self.data_type)
return self.data_type
def get_index(self):
- """ get the index 0, 1, 2... """
+ """!
+ Get the index of this socket.
+ @return the index (integer)
+ """
return self.index
def get_cname(self):
- """ get the cname """
+ """!
+ Get the canonical name.
+ @return the cname (string)
+ """
return self.cname
def is_connected(self):
- """ have a Connection (or more)? """
+ """!
+ Have one or more connections?
+ @return true if at least one connection exists
+ """
return len(self.connections) > 0
def connect(self, connection):
- """ Add a Connection to this socket,
- raise exception if this is an input with an existing
connection. """
+ """!
+ Add a connection to this socket.
+ @param connection the connection
+ @throw TooManyConnectionsException input socket with an
existing connection
+ """
if Utils.is_input_socket(self) and self.is_connected(): raise
TooManyConnectionsException()
self.connections.append(connection)
self.update()
def disconnect(self, connection):
- """ Remove a Connection from this socket. """
+ """!
+ Remove a Connection from this socket.
+ @param connection the connection
+ """
self.connections.remove(connection)
self.update()
def get_connections(self):
- ''' Get the list of connections. '''
+ """!
+ Get all connections for this socket.
+ @return a list of connections
+ """
return self.connections
class InputSocket(Socket):
- ''' The socket for input '''
+ """ The socket for input """
type = 'input socket'
class OutputSocket(Socket):
- ''' The socket for output '''
+ """ The socket for output """
type = 'output socket'
\ No newline at end of file
Modified: grc/branches/jblum_work/src/Elements/Utils.py
===================================================================
--- grc/branches/jblum_work/src/Elements/Utils.py 2007-06-12 19:19:15 UTC
(rev 5771)
+++ grc/branches/jblum_work/src/Elements/Utils.py 2007-06-13 03:37:12 UTC
(rev 5772)
@@ -17,22 +17,26 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
address@hidden Elements.Utils
-#Shared fucntions and exceptions for flow graph elements.
+#Shared functions for flow graph elements.
address@hidden Josh Blum
from SignalBlock import SignalBlock
from Socket import OutputSocket,InputSocket
from Connection import Connection
-# True if the rotation is 90 or 270 degrees. #
+## True if the rotation is 90 or 270 degrees.
is_vertical = lambda rot: rot in (90, 270)
-# True if the rotation is 0 or 180 degrees. #
+## True if the rotation is 0 or 180 degrees.
is_horizontal = lambda rot: rot in (0, 180)
def get_angle_from_coordinates((x1,y1), (x2,y2)):
- """ given two points, calculate the vector direction from point1 to
point2,
- directions are multiples of 90 degrees. """
+ """!
+ Given two points, calculate the vector direction from point1 to point2,
directions are multiples of 90 degrees.
+ @param (x1,y1) the coordinate of point 1
+ @param (x2,y2) the coordinate of point 2
+ @return the direction in degrees
+ """
if y1 == y2:#0 or 180
if x2 > x1: return 0
else: return 180
@@ -43,13 +47,14 @@
##################################################################
# Test methods for elements
#################################################################
-# test method for signal blocks #
+## test method for signal blocks
is_signal_block = lambda obj: obj!= None and obj.type == SignalBlock.type
-# test methods for sockets #
+## test methods for sockets @{
is_input_socket = lambda obj: obj!= None and obj.type == InputSocket.type
is_output_socket = lambda obj: obj!= None and obj.type == OutputSocket.type
is_socket = lambda obj: is_input_socket(obj) or is_output_socket(obj)
-# test method for connections #
address@hidden
+## test method for connections
is_connection = lambda obj: obj!= None and obj.type == Connection.type
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5772 - grc/branches/jblum_work/src/Elements,
jblum <=