commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r7623 - in grc/branches/grc_reloaded/src/grc/gui: . el


From: jblum
Subject: [Commit-gnuradio] r7623 - in grc/branches/grc_reloaded/src/grc/gui: . elements
Date: Sat, 9 Feb 2008 16:38:19 -0700 (MST)

Author: jblum
Date: 2008-02-09 16:38:18 -0700 (Sat, 09 Feb 2008)
New Revision: 7623

Added:
   grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Colors.py
   grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Platform.py
Removed:
   grc/branches/grc_reloaded/src/grc/gui/FlowGraph.py
   grc/branches/grc_reloaded/src/grc/gui/VariableModificationWindow.py
Modified:
   grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Element.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
   grc/branches/grc_reloaded/src/grc/gui/elements/Port.py
   grc/branches/grc_reloaded/src/grc/gui/elements/__init__.py
Log:
more work on graphics

Added: grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py                        
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc/gui/DrawingArea.py        2008-02-09 
23:38:18 UTC (rev 7623)
@@ -0,0 +1,106 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.gui.DrawingArea
+#Drawing area for graphical elements.
address@hidden Josh Blum
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+class DrawingArea(gtk.DrawingArea):
+       """
+       DrawingArea is the gtk pixel map that graphical elements may draw 
themselves on.
+       The drawing area also responds to mouse and key events.
+       """     
+               
+       def __init__(self, platform):
+               """!
+               DrawingArea contructor.
+               Connect event handlers.
+               @param platform the platform containing all flow graphs
+               """     
+               self._platform = platform
+               #inject drawing area into platform
+               self._platform.drawing_area = self
+               gtk.DrawingArea.__init__(self)
+               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)      
+               #pixmap for drawing to
+               self._pixmap = None
+               self.gc = None
+
+       
##########################################################################
+       ##      Handlers
+       
##########################################################################      
+       
+       def _handle_focus_event(self, widget, event, focus_flag):
+               """Record the focus state of the flow graph window."""
+               self._focus_flag = focus_flag
+               
+       def _handle_mouse_button_press(self, widget, event):
+               """!
+               Forward button click information to the flow graph.
+               """     
+               self._platform.get_flow_graph().handle_mouse_button_click(
+                       left_click=(event.button == 1),
+                       double_click=(event.type == gtk.gdk._2BUTTON_PRESS),
+               ) 
+               return True
+               
+       def _handle_mouse_button_release(self, widget, event):
+               """!
+               Forward button release information to the flow graph.
+               """
+               self._platform.get_flow_graph().handle_mouse_button_release(
+                       left_click=(event.button == 1),
+               ) 
+               return True
+               
+       def _handle_mouse_motion(self, widget, event):          
+               """!
+               Forward mouse motion information to the flow graph.
+               """
+               self._platform.get_flow_graph().handle_mouse_motion(
+                       coordinate=(event.x, event.y),
+               ) 
+               return True
+                                       
+       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)
+               self._platform.get_flow_graph().draw()
+

Deleted: grc/branches/grc_reloaded/src/grc/gui/FlowGraph.py

Deleted: grc/branches/grc_reloaded/src/grc/gui/VariableModificationWindow.py

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-02-09 
01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Block.py     2008-02-09 
23:38:18 UTC (rev 7623)
@@ -20,37 +20,29 @@
 #The graphical signal block.
 address@hidden Josh Blum
 
-import SignalBlock
-import Utils
+from Element import Element
+import Element
 import Colors
-from GraphicalParam import GraphicalParam
-import GraphicalElement
-from GraphicalSocket import GraphicalInputSocket,GraphicalOutputSocket
 from Constants import *
-from DataTypes import Enum,Int
 import pygtk
 pygtk.require('2.0')
 import gtk
 import pango
 
-class GraphicalSignalBlock(SignalBlock.SignalBlock, 
GraphicalElement.GraphicalElement):
+class Block(Element):
        """The graphical signal block."""               
        
-       param_constructor = GraphicalParam
-       input_socket_constructor = GraphicalInputSocket
-       output_socket_constructor = GraphicalOutputSocket
-       
        def update(self):
-               """Update the block, parameters, and sockets when a change 
occurs."""
+               """Update the block, parameters, and ports when a change 
occurs."""
                self.clear()
-               self._adjust_sockets()          
+               self._adjust_ports()            
                self._create_labels()                           
                self.W = self.label_width + 2*LABEL_PADDING_WIDTH
-               max_sockets = max(self.get_num_input_sockets(), 
self.get_num_output_sockets(), 1)
-               self.H = max(self.label_height+2*LABEL_PADDING_HEIGHT, 
2*SOCKET_BORDER_SEPARATION + max_sockets*SOCKET_HEIGHT + 
(max_sockets-1)*SOCKET_SEPARATION)              
-               if Utils.is_horizontal(self.get_rotation()): 
self.add_area((0,0),(self.W,self.H))
-               elif Utils.is_vertical(self.get_rotation()): 
self.add_area((0,0),(self.H,self.W))                                       
-               for socket in self.get_sockets(): socket.update()               
        
+               max_ports = max(self.get_num_input_ports(), 
self.get_num_output_ports(), 1)
+               self.H = max(self.label_height+2*LABEL_PADDING_HEIGHT, 
2*SOCKET_BORDER_SEPARATION + max_ports*SOCKET_HEIGHT + 
(max_ports-1)*SOCKET_SEPARATION)          
+               if Element.is_horizontal(self.get_rotation()): 
self.add_area((0,0),(self.W,self.H))
+               elif Element.is_vertical(self.get_rotation()): 
self.add_area((0,0),(self.H,self.W))                                     
+               for port in self.get_ports(): port.update()                     
        
        def _create_labels(self):
                """Create the labels for the signal block."""
@@ -87,7 +79,7 @@
                        h_off = h + h_off + LABEL_SEPARATION
                #       create vertical and horizontal images   #               
        
                self.horizontal_label = image = pixmap.get_image(0, 0, width, 
height)
-               if Utils.is_vertical(self.get_rotation()):
+               if Element.is_vertical(self.get_rotation()):
                        self.vertical_label = vimage = 
gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), height, width)
                        for i in range(width):
                                for j in range(height): vimage.put_pixel(j, 
width-i-1, image.get_pixel(i, j))
@@ -97,29 +89,29 @@
                Draw the signal block with label and inputs/outputs.
                @param window the gtk window to draw on
                """
-               GraphicalElement.GraphicalElement.draw(self, window)            
+               Element.draw(self, window)              
                gc = self.gc            
                gc.foreground = Colors.TXT_COLOR
                X,Y = self.get_coordinate()             
-               if Utils.is_horizontal(self.get_rotation()):
+               if Element.is_horizontal(self.get_rotation()):
                        window.draw_image(gc, self.horizontal_label, 0, 0, 
X+LABEL_PADDING_WIDTH, Y+(self.H-self.label_height)/2, -1, -1)
-               elif Utils.is_vertical(self.get_rotation()):
+               elif Element.is_vertical(self.get_rotation()):
                        window.draw_image(gc, self.vertical_label, 0, 0, 
X+(self.H-self.label_height)/2, Y+LABEL_PADDING_WIDTH, -1, -1)
-               for socket in self.get_sockets(): socket.draw(window)
+               for port in self.get_ports(): port.draw(window)
                
        def is_valid(self):             
                """!
-               Is this block is valid/are all the params valid and all sockets 
connected?
+               Is this block is valid/are all the params valid and all ports 
connected?
                User preferences can override certain validity checks.
                @return true if valid
                """
-               import Preferences
-               if Preferences.check_params():  #preferences
-                       for param in self.params:
-                               if not param.get_data_type().is_valid(): return 
False
-               if Preferences.check_sockets(): #preferences
-                       for socket in self.get_sockets():
-                               if not socket.is_valid(): return False
+               #import Preferences
+               #if Preferences.check_params(): #preferences
+               for param in self.params:
+                       if not param.get_data_type().is_valid(): return False
+               #if Preferences.check_ports():  #preferences
+               for port in self.get_ports():
+                       if not port.is_valid(): return False
                return True
                
        def modify_type_controller(self, direction):
@@ -127,6 +119,7 @@
                If a type controller was set, increment/decrement its index by 
1, use a % to stay in bounds.    
                @param direction +1 or -1
                """
+               #TODO find this automatic style
                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())
@@ -135,23 +128,24 @@
                        return True
                return False
                
-       def modify_socket_controller(self, direction):
+       def modify_port_controller(self, direction):
                """!
-               If a socket controller was set, increment/decrement its data 
type by 1, DO NOT go out of bounds.
+               If a port 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
-               elif self.output_sockets_controller != None: socket_controller 
= self.output_sockets_controller
-               if socket_controller != None and socket_controller.is_valid() 
and socket_controller.get_type() == Int().get_type():
-                       old_data = socket_controller.get_data()
-                       socket_controller.set_data(socket_controller.parse() + 
direction)
-                       if socket_controller.is_valid(): #modification was 
successful
+               #TODO find this automatic style
+               # Get the port controller, if there is an input and output 
controller, use output       #
+               port_controller = None          
+               if self.input_ports_controller != None: port_controller = 
self.input_ports_controller
+               elif self.output_ports_controller != None: port_controller = 
self.output_ports_controller
+               if port_controller != None and port_controller.is_valid() and 
port_controller.get_type() == Int().get_type():
+                       old_data = port_controller.get_data()
+                       port_controller.set_data(port_controller.parse() + 
direction)
+                       if port_controller.is_valid(): #modification was 
successful
                                self.get_parent().update()
                                return True
-                       else: socket_controller.set_data(old_data)      
#restore previous value
+                       else: port_controller.set_data(old_data)        
#restore previous value
                return False
 

Added: grc/branches/grc_reloaded/src/grc/gui/elements/Colors.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Colors.py                    
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Colors.py    2008-02-09 
23:38:18 UTC (rev 7623)
@@ -0,0 +1,35 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden Colors
+#Global Colors for the gui
address@hidden Josh Blum
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+
+COLORMAP = gtk.gdk.colormap_get_system()       #create all of the colors
+def get_color(color_code): return COLORMAP.alloc_color(color_code, True, True)
+
+BACKGROUND_COLOR = get_color('#FFF9FF')        #main window background
+FG_COLOR = get_color('black')  #normal border color    
+BG_COLOR = get_color('#F1ECFF')        #default background             
+H_COLOR = get_color('#00FFFF') #Highlight border color
+TXT_COLOR = get_color('black') #text color
+ERROR_COLOR = get_color('red') #error color

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-02-09 01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Connection.py        
2008-02-09 23:38:18 UTC (rev 7623)
@@ -20,13 +20,11 @@
 #The graphical connection for input/output sockets.
 address@hidden Josh Blum
 
-import DataTypes
-import Utils
-import Connection
-import GraphicalElement
+import Element
+from Element import Element
 import Colors
 
-class GraphicalConnection(Connection.Connection, 
GraphicalElement.GraphicalElement):
+class Connection(Element):
        """A graphical connection for sockets."""                       
        
        def update(self):
@@ -48,21 +46,21 @@
                        if output_socket.get_connector_direction() == 0: sW = 
sW * -1
                        sH = y1 - y2
                        if output_socket.get_connector_direction() == 270: sH = 
sH * -1
-                       if ((W>H or sW<0) and 
Utils.is_horizontal(output_socket.get_connector_direction())) or\
-                               (W>=H and sH>=0 and 
Utils.is_vertical(output_socket.get_connector_direction())):
+                       if ((W>H or sW<0) and 
Element.is_horizontal(output_socket.get_connector_direction())) or\
+                               (W>=H and sH>=0 and 
Element.is_vertical(output_socket.get_connector_direction())):
                                self.add_line((x1,y1),(x1,midY))
                                self.add_line((x1,midY),(x2,midY))
                                self.add_line((x2,y2),(x2,midY))
-                       elif (H>=W and sW>=0 and 
Utils.is_horizontal(output_socket.get_connector_direction())) or\
-                               ((H>W or sH<0) and 
Utils.is_vertical(output_socket.get_connector_direction())):
+                       elif (H>=W and sW>=0 and 
Element.is_horizontal(output_socket.get_connector_direction())) or\
+                               ((H>W or sH<0) and 
Element.is_vertical(output_socket.get_connector_direction())):
                                self.add_line((x1,y1),(midX,y1))
                                self.add_line((midX,y1),(midX,y2))
                                self.add_line((x2,y2),(midX,y2))
                else:
                        p1 = (x1, y2)
                        p2 = (x2, y1)
-                       if Utils.get_angle_from_coordinates((x1,y1),p1) == 
(output_socket.get_connector_direction()+180)%360 or\
-                               Utils.get_angle_from_coordinates((x2,y2),p1) == 
(input_socket.get_connector_direction()+180)%360: p = p2
+                       if Element.get_angle_from_coordinates((x1,y1),p1) == 
(output_socket.get_connector_direction()+180)%360 or\
+                               Element.get_angle_from_coordinates((x2,y2),p1) 
== (input_socket.get_connector_direction()+180)%360: p = p2
                        else: p = p1
                        self.add_line((x1,y1),p)
                        self.add_line((x2,y2),p)        

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Element.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Element.py   2008-02-09 
01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Element.py   2008-02-09 
23:38:18 UTC (rev 7623)
@@ -21,16 +21,34 @@
 #signal blocks, input sockets, output sockets and connections.
 address@hidden Josh Blum
 
-from Constants import *
-import Element
 import Colors
 import pygtk
 pygtk.require('2.0')
 import gtk
 import pango
 
-class GraphicalElement(Element.Element):
+##     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.
+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.
+       @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                
+       else:#90 or 270
+               if y2 > y1: return 270
+               else: return 90
+
+class Element(object):
+       """
        GraphicalElement 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 of those areas.
@@ -57,4 +75,4 @@
                        gc.foreground = self.is_highlighted() and 
Colors.H_COLOR or FG_color
                        window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
 
-       
\ No newline at end of file
+       

Copied: grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py (from rev 
7608, grc/branches/grc_reloaded/src/grc/gui/FlowGraph.py)
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py                 
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/FlowGraph.py 2008-02-09 
23:38:18 UTC (rev 7623)
@@ -0,0 +1,501 @@
+"""
+Copyright 2007 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden Graphics.FlowGraph
+#A flow graph structure for storing signal blocks and their connections.
address@hidden Josh Blum
+
+from grc.Constants import *
+from grc.Actions import *
+from Colors import BACKGROUND_COLOR, TXT_COLOR
+
+from Elements import Utils
+
+import pygtk
+pygtk.require('2.0')
+import gtk
+import time,socket #for tagging saved files
+
+
+from SignalBlockParamsDialog import SignalBlockParamsDialog
+import random
+import Messages
+import ParseXML
+import Messages
+
+class FlowGraph(gtk.DrawingArea):
+       """
+       FlowGraph is the data structure to store graphical signal blocks, 
+       graphical inputs and outputs, 
+       and the connections between inputs and outputs.
+       """     
+               
+       def __init__(self, handle_states, variable_modification_window):
+               """!
+               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
+               """     
+               #setup
+               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._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)              
+               #       important vars dealing with mouse event tracking        
#       
+               self.has_moved = False
+               self.mouse_pressed = False
+               self.coordinate = (0,0)
+               self.selected_element = None
+               self.is_selected = lambda: self.selected_element != None
+               self.count = 0
+               self.pixmap = None
+               
+###########################################################################
+#      Flow Graph Access Methods
+###########################################################################    
+       
+       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.
+               @param tag the signal block tag
+               """
+               index = 0
+               while True:
+                       id = tag+str(index)
+                       index = index + 1       
+                       if not [
+                               None for element in self.elements if 
Utils.is_signal_block(element) and id == element.get_id()
+                       ]:              #make sure that the id is not used by 
another signal block
+                               rot = 0
+                               vAdj = 
self.get_parent().get_vadjustment().get_value()
+                               hAdj = 
self.get_parent().get_hadjustment().get_value()
+                               x = random.randint(100,400)+int(hAdj)   
+                               y = random.randint(100,400)+int(vAdj)   
+                               self.elements.append(
+                                       SignalBlockDefs.get_signal_block(self, 
(x, y), rot, tag, id, GraphicalSignalBlock)[0]
+                               )
+                               self.handle_states(SIGNAL_BLOCK_CREATE) 
+                               self.update()
+                               return          
+       
+       def type_controller_modify_selected(self, direction):
+               """
+               !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.
+               @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).
+               @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)
+                       changed = signal_block_params_dialog.run()      
+                       self.update()   
+                       return changed #changes were made?
+               return False    
+               
+       def connect_sockets(self, s1, s2):
+               """!
+               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 ConnectionException: 
+                       Messages.send_fail_connection() 
+                       self.handle_states(NOTHING_SELECT)      
+       
+       def move_selected(self, 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. 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()
+                       return True
+               return False    
+       
+       def delete_selected(self):
+               """!
+               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()                                              
+                       if Utils.is_signal_block(self.selected_element):        
# delete a signal block
+                               connections = 
self.selected_element.get_connections()
+                               for connection in connections: 
connection.disconnect()
+                               self.remove_element(self.selected_element)
+                       elif Utils.is_connection(self.selected_element):        
# delete a connection
+                               self.selected_element.disconnect()              
                        
+                       self.selected_element = None                            
+                       self.update()   
+                       return True
+               return False
+               
+       def unselect(self):
+               """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):               
+               """!
+               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.
+               @param coor the coordinate of the mouse click
+               @return the selected element or None
+               """              
+               #       check the elements      #                       
+               for element in reversed(self.elements):
+                       if element.what_is_selected(coor) != None:
+                               self.elements.remove(element)
+                               self.elements.append(element)
+                               return element.what_is_selected(coor)           
+               return None
+               
+       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
+               #return all([element.is_valid() for element in self.elements])  
#python 2.5 and higher
+               
+       def update(self):
+               """Call update on all elements."""      
+               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:
+                       if self.selected_element != None: 
self.selected_element.set_highlighted(False)
+                       self.count = 0
+                       self.mouse_pressed = True
+                       self.coordinate = (event.x, event.y)
+                       old_selection = self.selected_element
+                       self.selected_element = self.what_is_selected((event.x, 
event.y))
+                       #       handle the state change with the new selection  
#
+                       if Utils.is_connection(self.selected_element): 
self.handle_states(CONNECTION_SELECT)    
+                       elif Utils.is_socket(self.selected_element): 
self.handle_states(SOCKET_SELECT)  
+                       elif Utils.is_signal_block(self.selected_element): 
self.handle_states(SIGNAL_BLOCK_SELECT)      
+                       elif self.selected_element == None: 
self.handle_states(NOTHING_SELECT)                                          
+                       #       this selection and the last were Sockets, try 
to connect them   #
+                       if Utils.is_socket(old_selection) and 
Utils.is_socket(self.selected_element) and\
+                               old_selection is not self.selected_element: 
#cannot be the same socket
+                               self.connect_sockets(old_selection, 
self.selected_element)                                              
+                       if self.selected_element != None: 
self.selected_element.set_highlighted(True)                                     
                              
+                       #       double click detected, bring up params dialog 
if possible       #
+                       if event.type == gtk.gdk._2BUTTON_PRESS and 
Utils.is_signal_block(self.selected_element):
+                               self.mouse_pressed = False
+                               self.handle_states(SIGNAL_BLOCK_PARAM_MODIFY)   
                        
+                       self.draw()
+               return True
+               
+       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:
+                               if Preferences.snap_to_grid():
+                                       grid_size = Preferences.get_grid_size()
+                                       X,Y = 
self.selected_element.get_coordinate()
+                                       deltaX = X%grid_size
+                                       if deltaX < grid_size/2: deltaX = -1 * 
deltaX
+                                       else: deltaX = grid_size - deltaX
+                                       deltaY = Y%grid_size
+                                       if deltaY < grid_size/2: deltaY = -1 * 
deltaY
+                                       else: deltaY = grid_size - deltaY
+                                       self.move_selected((deltaX,deltaY))
+                               self.handle_states(SIGNAL_BLOCK_MOVE)
+                               self.has_moved = False
+               return True
+               
+       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.   #
+               if self.mouse_pressed and\
+                       self.count == 0 and\
+                       self.selected_element != None:
+                       #       The event coordinates must be within 10 pixels 
away from the bounds of the flow graph.  #
+                       x = event.x
+                       if x <= BORDER_PROXIMITY_SENSITIVITY:
+                               x = BORDER_PROXIMITY_SENSITIVITY
+                       if      x >= fgW - BORDER_PROXIMITY_SENSITIVITY:
+                               x = fgW - BORDER_PROXIMITY_SENSITIVITY          
                        
+                       y = event.y
+                       if y <= BORDER_PROXIMITY_SENSITIVITY:
+                               y = BORDER_PROXIMITY_SENSITIVITY
+                       if      y >= fgH - BORDER_PROXIMITY_SENSITIVITY:        
+                               y = fgH - BORDER_PROXIMITY_SENSITIVITY  
+                       #       get the change in coordinates   #               
+                       X,Y = self.coordinate
+                       deltaX = int(x - X)
+                       deltaY = int(y - Y)                                     
                                                
+                       vAdj = self.get_parent().get_vadjustment().get_value()
+                       hAdj = self.get_parent().get_hadjustment().get_value()
+                       width = self.get_parent().get_hadjustment().page_size
+                       height = self.get_parent().get_vadjustment().page_size
+                       # scroll horizontal if we moved near the border #
+                       if x-hAdj > width-SCROLL_PROXIMITY_SENSITIVITY and\
+                               hAdj+SCROLL_DISTANCE < fgW - width:
+                               
self.get_parent().get_hadjustment().set_value(hAdj+SCROLL_DISTANCE)
+                       elif x-hAdj < SCROLL_PROXIMITY_SENSITIVITY:
+                               
self.get_parent().get_hadjustment().set_value(hAdj-SCROLL_DISTANCE)
+                       # scroll vertical if we moved near the border   #
+                       if y-vAdj > height-SCROLL_PROXIMITY_SENSITIVITY and\
+                               vAdj+SCROLL_DISTANCE < fgH - height:
+                               
self.get_parent().get_vadjustment().set_value(vAdj+SCROLL_DISTANCE)
+                       elif y-vAdj < SCROLL_PROXIMITY_SENSITIVITY:
+                               
self.get_parent().get_vadjustment().set_value(vAdj-SCROLL_DISTANCE)
+                       # move the selected element and record the new 
coordinate       #                       
+                       self.move_selected((deltaX, deltaY))    
+                       self.coordinate = (x, y)        
+                                       
+       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)
+               self.draw()
+
+##########################################################################
+##
+##                     Export the Flow Graph
+##
+##########################################################################     
                                        
+       def to_nested_data(self):
+               """!
+               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()
+               W,H = self.get_size_request()
+               nested_data = ('flow_graph', [
+                       ('timestamp', str(time.time())),
+                       ('hostname', socket.gethostname()),
+                       ('version', VERSION),
+                       ('valid', str(self.is_valid())),
+                       ('window_width', str(W)),
+                       ('window_height', str(H)),
+                       ('vars', vars_list),
+                       ('signal_blocks', signal_blocks_list),
+                       ('connections', connections_list)
+               ])      
+       
##########################################################################
+       ##      Export the Variables
+       
##########################################################################      
+               for key in self.variable_modification_window.to_key_list():
+                       row = (key,) + Variables.get_values(key)
+                       vars_list.append(('var', [
+                               ('key', row[0]), 
+                               ('value', row[1]),
+                               ('min', row[2]),
+                               ('max', row[3]),
+                               ('step', row[4]),
+                       ]))
+       
##########################################################################
+       ##      Export the Signal Blocks
+       
##########################################################################
+               for element in filter(Utils.is_signal_block, self.elements):
+                       params_list = list()
+                       signal_blocks_list.append(('signal_block', [
+                               ('tag', element.get_tag()), 
+                               ('id', element.get_id()),
+                               ('x_coordinate', 
str(element.get_coordinate()[0])),
+                               ('y_coordinate', 
str(element.get_coordinate()[1])),
+                               ('rotation', str(element.get_rotation())),
+                               ('params', params_list)
+                       ]))
+                       for param in element.get_params():
+                               params_list.append(('param', 
str(param.get_data_type().get_data()))     )       
+       
##########################################################################
+       ##      Export the Connections
+       
##########################################################################
+               for element in filter(Utils.is_connection, self.elements):
+                       connections_list.append(('connection', [
+                               ('input_signal_block_id', 
str(element.get_input_socket().get_parent().get_id())), 
+                               ('input_socket_index', 
str(element.get_input_socket().get_index())),
+                               ('output_signal_block_id', 
str(element.get_output_socket().get_parent().get_id())), 
+                               ('output_socket_index', 
str(element.get_output_socket().get_index()))
+                       ]))
+               #print 'To',nested_data
+               return nested_data
+
+##########################################################################
+##     
+##                     Import the Flow Graph
+##
+##########################################################################     
        
+       def from_nested_data(self, nested_data):
+               """!
+               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 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')
+               #       window width and height are optional    #
+               window_width = find_data(flow_graph, 'window_width')
+               if window_width == None: window_width = MAX_WINDOW_WIDTH
+               window_height = find_data(flow_graph, 'window_height')
+               if window_height == None: window_height = MAX_WINDOW_HEIGHT
+               self.set_size_request(int(window_width),int(window_height))
+               vars = find_data(flow_graph, 'vars')
+               signal_blocks = find_data(flow_graph, 'signal_blocks')
+               connections = find_data(flow_graph, 'connections')
+       
##########################################################################
+       ##      Import the Variables
+       
##########################################################################
+               keys = Variables.from_nested_data(vars)
+               self.variable_modification_window.from_key_list(keys)
+       
##########################################################################
+       ##      Import the Signal Blocks
+       
##########################################################################
+               for signal_block in signal_blocks:
+                       signal_block = 
GraphicalSignalBlock.from_nested_data(self, signal_block, 
GraphicalSignalBlock)[0]       #index 0 for just signal block  
+                       if signal_block: self.elements.append(signal_block)     
                
+       
##########################################################################
+       ##      Import the Connections
+       
##########################################################################
+               for connection in connections:
+                       connection = find_data([connection], 'connection')
+                       input_signal_block_id = find_data(connection, 
'input_signal_block_id')
+                       input_socket_index = int(find_data(connection, 
'input_socket_index'))
+                       output_signal_block_id = find_data(connection, 
'output_signal_block_id')
+                       output_socket_index = int(find_data(connection, 
'output_socket_index'))
+                       input_socket = output_socket = None                     
                                                        
+                       for element in filter(Utils.is_signal_block, 
self.elements):
+                               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 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            
+               self.update()
+               # done importing the flow graph #
+

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-09 
01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Param.py     2008-02-09 
23:38:18 UTC (rev 7623)
@@ -20,8 +20,7 @@
 #GTK objects for handling input and the signal block parameter class.
 address@hidden Josh Blum
 
-import Param
-from DataTypes import *
+from Element import Element
 import pygtk
 pygtk.require('2.0')
 import gtk
@@ -113,7 +112,7 @@
 #      A Parameter, hold a data type and a cname
 
######################################################################################################
 
-class GraphicalParam(Param.Param):
+class Param(Element):
        """The graphical parameter."""  
 
        def update(self):

Added: grc/branches/grc_reloaded/src/grc/gui/elements/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Platform.py                  
        (rev 0)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Platform.py  2008-02-09 
23:38:18 UTC (rev 7623)
@@ -0,0 +1,40 @@
+"""
+Copyright 2008 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
address@hidden grc.gui.elements.Platform
+#Graphical platform to turn an existing platform into a gui platform.
address@hidden Josh Blum
+
+from FlowGraph import FlowGraph
+from Connection import Connection
+from Block import Block
+from Port import Port
+from Param import Param
+
+from new import classobj
+
+def Platform(platform):
+       #combine with gui class
+       platform.FlowGraph = classobj('FlowGraph', (FlowGraph, 
platform.FlowGraph), {})
+       platform.Connection = classobj('Connection', (Connection, 
platform.Connection), {})
+       platform.Block = classobj('Block', (Block, platform.Block), {})
+       platform.Source = classobj('Source', (Port, platform.Source), {})
+       platform.Sink = classobj('Sink', (Port, platform.Sink), {})
+       platform.Param = classobj('Param', (Param, platform.Param), {}) 
+       return platform
+       

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/Port.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/Port.py      2008-02-09 
01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/Port.py      2008-02-09 
23:38:18 UTC (rev 7623)
@@ -20,10 +20,8 @@
 #The graphical input/output sockets of the signal block.
 address@hidden Josh Blum
 
-import Utils
-import Socket
-import GraphicalElement
-from DataTypes import *
+import Element
+from Element import Element
 from Constants import *
 import Colors
 import pygtk
@@ -31,62 +29,50 @@
 import gtk
 import pango
 
-class GraphicalSocket(Socket.Socket, GraphicalElement.GraphicalElement):
-       """The graphical socket."""     
+class Port(Element):
+       """The graphical port."""       
                                
        def update(self):
-               """Create new areas and labels for the socket."""
+               """Create new areas and labels for the port."""
                self.clear()
-               self.BG_color = {
-                       Complex().get_type():Colors.COMPLEX_COLOR,
-                       Float().get_type():Colors.FLOAT_COLOR,
-                       Int().get_type():Colors.INT_COLOR,
-                       Short().get_type():Colors.SHORT_COLOR,                  
-                       Byte().get_type():Colors.BYTE_COLOR,    
-                       # and for the vectors   #       
-                       ComplexVector().get_type():Colors.COMPLEX_VECTOR_COLOR,
-                       FloatVector().get_type():Colors.FLOAT_VECTOR_COLOR,
-                       IntVector().get_type():Colors.INT_VECTOR_COLOR,
-                       ShortVector().get_type():Colors.SHORT_VECTOR_COLOR,     
                
-                       ByteVector().get_type():Colors.BYTE_VECTOR_COLOR,
-               }[self.get_data_type().get_type()]
+               self.BG_color = Colors.get_color(self.get_color())
                self._create_labels()           
                #       add the input/output area for each rotation angle       
#       
                rotation = self.get_rotation()          
                conExtLen = CONNECTOR_EXTENSION_LENGTH
                conExtInitLen = CONNECTOR_EXTENSION_INITIAL_LENGTH
-               conOff = SOCKET_HEIGHT/2
+               conOff = PORT_HEIGHT/2
                index = self.get_index()
-               if Utils.is_input_socket(self): length = 
self.get_parent().get_num_input_sockets()
-               elif Utils.is_output_socket(self): length = 
self.get_parent().get_num_output_sockets()
-               offset = (self.get_parent().H - length*SOCKET_HEIGHT - 
(length-1)*SOCKET_SEPARATION)/2                  
+               if self.is_sink(): length = 
self.get_parent().get_num_input_sockets()
+               elif self.is_source(): length = 
self.get_parent().get_num_output_sockets()
+               offset = (self.get_parent().H - length*PORT_HEIGHT - 
(length-1)*PORT_SEPARATION)/2                      
                if rotation == 180 or rotation == 270: index = length-index-1   
#reverse the order                              
-               if (Utils.is_input_socket(self) and rotation == 0) or 
(Utils.is_output_socket(self) and rotation == 180):               
-                       x = -1*SOCKET_WIDTH
-                       y = (SOCKET_SEPARATION+SOCKET_HEIGHT)*index+offset
-                       self.add_area((x, y), (SOCKET_WIDTH, SOCKET_HEIGHT))
+               if (self.is_sink() and rotation == 0) or (self.is_source() and 
rotation == 180):                
+                       x = -1*PORT_WIDTH
+                       y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
+                       self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
                        if self.is_connected(): 
self.__set_connector_coordinates((x-1, 
y+conOff),(x-conExtInitLen-conExtLen*index, y+conOff))
-               elif (Utils.is_output_socket(self) and rotation == 0) or 
(Utils.is_input_socket(self) and rotation == 180):     
+               elif (self.is_source() and rotation == 0) or (self.is_sink() 
and rotation == 180):      
                        x = self.parent.W
-                       y = (SOCKET_SEPARATION+SOCKET_HEIGHT)*index+offset
-                       self.add_area((x, y), (SOCKET_WIDTH, SOCKET_HEIGHT))
-                       if self.is_connected(): 
self.__set_connector_coordinates((x+1+SOCKET_WIDTH, 
y+conOff),(x+conExtInitLen+SOCKET_WIDTH+conExtLen*index, y+conOff))
-               elif (Utils.is_output_socket(self) and rotation == 90) or 
(Utils.is_input_socket(self) and rotation == 270):            
-                       y = -1*SOCKET_WIDTH
-                       x = (SOCKET_SEPARATION+SOCKET_HEIGHT)*index+offset
-                       self.add_area((x, y), (SOCKET_HEIGHT, SOCKET_WIDTH))
+                       y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
+                       self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
+                       if self.is_connected(): 
self.__set_connector_coordinates((x+1+PORT_WIDTH, 
y+conOff),(x+conExtInitLen+PORT_WIDTH+conExtLen*index, y+conOff))
+               elif (self.is_source() and rotation == 90) or (self.is_sink() 
and rotation == 270):             
+                       y = -1*PORT_WIDTH
+                       x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
+                       self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
                        if self.is_connected(): 
self.__set_connector_coordinates((x+conOff, y-1),(x+conOff, 
y-conExtInitLen-conExtLen*index))
-               elif (Utils.is_input_socket(self) and rotation == 90) or 
(Utils.is_output_socket(self) and rotation == 270):    
+               elif (self.is_sink() and rotation == 90) or (self.is_source() 
and rotation == 270):     
                        y = self.parent.W
-                       x = (SOCKET_SEPARATION+SOCKET_HEIGHT)*index+offset
-                       self.add_area((x, y), (SOCKET_HEIGHT, SOCKET_WIDTH))
-                       if self.is_connected(): 
self.__set_connector_coordinates((x+conOff, y+1+SOCKET_WIDTH),(x+conOff, 
y+SOCKET_WIDTH+conExtInitLen+conExtLen*index))
+                       x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
+                       self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
+                       if self.is_connected(): 
self.__set_connector_coordinates((x+conOff, y+1+PORT_WIDTH),(x+conOff, 
y+PORT_WIDTH+conExtInitLen+conExtLen*index))
                        
        def _create_labels(self):
                """Create the labels for the socket."""
                #       create the layout       #
                layout = gtk.DrawingArea().create_pango_layout(self.cname)
-               desc = pango.FontDescription(SOCKET_FONT)
+               desc = pango.FontDescription(PORT_FONT)
                layout.set_font_description(desc) 
                w,h = self.w,self.h = layout.get_pixel_size()   
                #       create the pixmap       #                       
@@ -98,7 +84,7 @@
                pixmap.draw_layout(gc, 0, 0, layout)
                #       create the images       #
                self.horizontal_label = image = pixmap.get_image(0, 0, w, h)    
-               if Utils.is_vertical(self.get_rotation()):      
+               if Element.is_vertical(self.get_rotation()):    
                        self.vertical_label = vimage = 
gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), h, w)
                        for i in range(w):
                                for j in range(h): vimage.put_pixel(j, w-i-1, 
image.get_pixel(i, j))
@@ -113,8 +99,8 @@
                gc.foreground = Colors.TXT_COLOR
                X,Y = self.get_coordinate()
                (x,y),(w,h) = self.areas_dict[self.get_rotation()][0] #use the 
first area's sizes to place the labels
-               if Utils.is_horizontal(self.get_rotation()): 
window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(SOCKET_WIDTH-self.w)/2, 
y+Y+(SOCKET_HEIGHT-self.h)/2, -1, -1)
-               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)
+               if Element.is_horizontal(self.get_rotation()): 
window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(PORT_WIDTH-self.w)/2, 
y+Y+(PORT_HEIGHT-self.h)/2, -1, -1)
+               elif Element.is_vertical(self.get_rotation()): 
window.draw_image(gc, self.vertical_label, 0, 0, x+X+(PORT_HEIGHT-self.h)/2, 
y+Y+(PORT_WIDTH-self.w)/2, -1, -1)
        
        def __set_connector_coordinates(self, coor_inner, coor_outer, 
rotation=None):
                """!
@@ -145,15 +131,8 @@
                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                                
+               if self.is_source(): return self.get_rotation()
+               elif self.is_sink(): return (self.get_rotation() + 180)%360     
                        
        
-class GraphicalInputSocket(GraphicalSocket):
-       """ The socket for input        """
-       type = Socket.InputSocket.type
-
-class GraphicalOutputSocket(GraphicalSocket):
-       """ The socket for output       """
-       type = Socket.OutputSocket.type
+       
                
-               
\ No newline at end of file

Modified: grc/branches/grc_reloaded/src/grc/gui/elements/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/gui/elements/__init__.py  2008-02-09 
01:04:02 UTC (rev 7622)
+++ grc/branches/grc_reloaded/src/grc/gui/elements/__init__.py  2008-02-09 
23:38:18 UTC (rev 7623)
@@ -16,6 +16,8 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
address@hidden grc.elements
-#All elements used in a flow graph.
address@hidden grc.gui.elements
+#All graphical elements used in a flow graph.
 address@hidden Josh Blum
+
+





reply via email to

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