Switched the python classes to inherit from the base and gui classes.
authorJosh Blum <josh@joshknows.com>
Sun, 30 Aug 2009 17:34:10 +0000 (10:34 -0700)
committerJosh Blum <josh@joshknows.com>
Sun, 30 Aug 2009 17:34:10 +0000 (10:34 -0700)
Use only **kwargs so all contructor parameters must be passed with keys.
Moved gui input forms classes from base to gui param module.

15 files changed:
grc/base/Block.py
grc/base/FlowGraph.py
grc/base/Param.py
grc/base/Platform.py
grc/gui/ActionHandler.py
grc/gui/Block.py
grc/gui/Param.py
grc/gui/Platform.py
grc/python/Block.py
grc/python/Connection.py
grc/python/FlowGraph.py
grc/python/Param.py
grc/python/Platform.py
grc/python/Port.py
grc/todo.txt

index 7370103052664d1ad39ca1b8ffad11ff15076a70..a9dae660a33a44ba9a8ca87b0a0405b89ff33103 100644 (file)
@@ -74,16 +74,16 @@ class Block(Element):
                self._params = list()
                #add the id param
                self.get_params().append(self.get_parent().get_parent().Param(
-                       self,
-                       odict({
+                       block=self,
+                       n=odict({
                                'name': 'ID',
                                'key': 'id',
                                'type': 'id',
                        })
                ))
                self.get_params().append(self.get_parent().get_parent().Param(
-                       self,
-                       odict({
+                       block=self,
+                       n=odict({
                                'name': 'Enabled',
                                'key': '_enabled',
                                'type': 'raw',
index 990baf02935b99b68ea50b99f51169c0c3aa8d79..9252f3668b43a2b303dd03b506f019a4c9cbf8ec 100644 (file)
@@ -117,7 +117,7 @@ class FlowGraph(Element):
                @return the new connection
                """
                self.flag()
-               connection = self.get_parent().Connection(self, porta, portb)
+               connection = self.get_parent().Connection(flow_graph=self, porta=porta, portb=portb)
                self.get_elements().append(connection)
                return connection
 
index 21d306592c9414d0628037e801341ccd63a1ea73..9279e736bbf3623f299e02bc5869bd2adfc5975e 100644 (file)
@@ -19,74 +19,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 from . import odict
 from Element import Element
-import pygtk
-pygtk.require('2.0')
-import gtk
-
-class InputParam(gtk.HBox):
-       """The base class for an input parameter inside the input parameters dialog."""
-
-       def __init__(self, param, _handle_changed):
-               gtk.HBox.__init__(self)
-               self.param = param
-               self._handle_changed = _handle_changed
-               self.label = gtk.Label('') #no label, markup is added by set_markup
-               self.label.set_size_request(150, -1)
-               self.pack_start(self.label, False)
-               self.set_markup = lambda m: self.label.set_markup(m)
-               self.tp = None
-       def set_color(self, color): pass
-
-class EntryParam(InputParam):
-       """Provide an entry box for strings and numbers."""
-
-       def __init__(self, *args, **kwargs):
-               InputParam.__init__(self, *args, **kwargs)
-               self.entry = input = gtk.Entry()
-               input.set_text(self.param.get_value())
-               input.connect('changed', self._handle_changed)
-               self.pack_start(input, True)
-               self.get_text = input.get_text
-               #tool tip
-               self.tp = gtk.Tooltips()
-               self.tp.set_tip(self.entry, '')
-               self.tp.enable()
-       def set_color(self, color): self.entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
-
-class EnumParam(InputParam):
-       """Provide an entry box for Enum types with a drop down menu."""
-
-       def __init__(self, *args, **kwargs):
-               InputParam.__init__(self, *args, **kwargs)
-               self._input = gtk.combo_box_new_text()
-               for option in self.param.get_options(): self._input.append_text(option.get_name())
-               self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
-               self._input.connect('changed', self._handle_changed)
-               self.pack_start(self._input, False)
-       def get_text(self): return self.param.get_option_keys()[self._input.get_active()]
-
-class EnumEntryParam(InputParam):
-       """Provide an entry box and drop down menu for Raw Enum types."""
-
-       def __init__(self, *args, **kwargs):
-               InputParam.__init__(self, *args, **kwargs)
-               self._input = gtk.combo_box_entry_new_text()
-               for option in self.param.get_options(): self._input.append_text(option.get_name())
-               try: self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
-               except:
-                       self._input.set_active(-1)
-                       self._input.get_child().set_text(self.param.get_value())
-               self._input.connect('changed', self._handle_changed)
-               self._input.get_child().connect('changed', self._handle_changed)
-               self.pack_start(self._input, False)
-       def get_text(self):
-               if self._input.get_active() == -1: return self._input.get_child().get_text()
-               return self.param.get_option_keys()[self._input.get_active()]
-       def set_color(self, color):
-               if self._input.get_active() == -1: #custom entry, use color
-                       self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
-               else: #from enum, make white background
-                       self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
 
 def _get_keys(lst): return [elem.get_key() for elem in lst]
 def _get_elem(lst, key):
@@ -231,18 +163,6 @@ class Param(Element):
                if self.is_enum(): return self.get_option(self.get_value()).get_name()
                return self.get_value()
 
-       def get_input_class(self):
-               """
-               Get the graphical gtk class to represent this parameter.
-               An enum requires and combo parameter.
-               A non-enum with options gets a combined entry/combo parameter.
-               All others get a standard entry parameter.
-               @return gtk input class
-               """
-               if self.is_enum(): return EnumParam
-               if self.get_options(): return EnumEntryParam
-               return EntryParam
-
        ##############################################
        # Access Options
        ##############################################
index db7ade9a3a941f097c0873ae0295e106e27e024c..51a3b2f871eb824aea1fee2227201515a06e2dee 100644 (file)
@@ -146,7 +146,7 @@ class Platform(_Element):
 
        def is_platform(self): return True
 
-       def get_new_flow_graph(self): return self.FlowGraph(self)
+       def get_new_flow_graph(self): return self.FlowGraph(platform=self)
 
        def get_generator(self): return self._generator
 
index 0e64aa89d1215de8b57a0b448a8accda0e37e097..8f317d6a8bd769444a597292a6101193517c801e 100644 (file)
@@ -30,7 +30,6 @@ from threading import Thread
 import Messages
 from .. base import ParseXML
 import random
-from Platform import Platform
 from MainWindow import MainWindow
 from ParamsDialog import ParamsDialog
 import Dialogs
@@ -53,7 +52,6 @@ class ActionHandler:
                @param platform platform module
                """
                self.clipboard = None
-               platform = Platform(platform)
                for action in Actions.get_all_actions(): action.connect('activate', self._handle_actions)
                #setup the main window
                self.main_window = MainWindow(self.handle_states, platform)
index 4add3aa195f9db8d34cd46c09104fd7bf78d2467..0f3e511d82e7879594bc098b293cb283fe1a907d 100644 (file)
@@ -44,8 +44,8 @@ class Block(Element):
                """
                #add the position param
                self.get_params().append(self.get_parent().get_parent().Param(
-                       self,
-                       odict({
+                       block=self,
+                       n=odict({
                                'name': 'GUI Coordinate',
                                'key': '_coordinate',
                                'type': 'raw',
@@ -54,8 +54,8 @@ class Block(Element):
                        })
                ))
                self.get_params().append(self.get_parent().get_parent().Param(
-                       self,
-                       odict({
+                       block=self,
+                       n=odict({
                                'name': 'GUI Rotation',
                                'key': '_rotation',
                                'type': 'raw',
index a11fd906591c02870701c8599a2b090bec9f2bea..4955d3336fd1dfbf070d4a4758e520c0bd0d640f 100644 (file)
@@ -23,6 +23,71 @@ import pygtk
 pygtk.require('2.0')
 import gtk
 
+class InputParam(gtk.HBox):
+       """The base class for an input parameter inside the input parameters dialog."""
+
+       def __init__(self, param, _handle_changed):
+               gtk.HBox.__init__(self)
+               self.param = param
+               self._handle_changed = _handle_changed
+               self.label = gtk.Label('') #no label, markup is added by set_markup
+               self.label.set_size_request(150, -1)
+               self.pack_start(self.label, False)
+               self.set_markup = lambda m: self.label.set_markup(m)
+               self.tp = None
+       def set_color(self, color): pass
+
+class EntryParam(InputParam):
+       """Provide an entry box for strings and numbers."""
+
+       def __init__(self, *args, **kwargs):
+               InputParam.__init__(self, *args, **kwargs)
+               self.entry = input = gtk.Entry()
+               input.set_text(self.param.get_value())
+               input.connect('changed', self._handle_changed)
+               self.pack_start(input, True)
+               self.get_text = input.get_text
+               #tool tip
+               self.tp = gtk.Tooltips()
+               self.tp.set_tip(self.entry, '')
+               self.tp.enable()
+       def set_color(self, color): self.entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
+
+class EnumParam(InputParam):
+       """Provide an entry box for Enum types with a drop down menu."""
+
+       def __init__(self, *args, **kwargs):
+               InputParam.__init__(self, *args, **kwargs)
+               self._input = gtk.combo_box_new_text()
+               for option in self.param.get_options(): self._input.append_text(option.get_name())
+               self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
+               self._input.connect('changed', self._handle_changed)
+               self.pack_start(self._input, False)
+       def get_text(self): return self.param.get_option_keys()[self._input.get_active()]
+
+class EnumEntryParam(InputParam):
+       """Provide an entry box and drop down menu for Raw Enum types."""
+
+       def __init__(self, *args, **kwargs):
+               InputParam.__init__(self, *args, **kwargs)
+               self._input = gtk.combo_box_entry_new_text()
+               for option in self.param.get_options(): self._input.append_text(option.get_name())
+               try: self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
+               except:
+                       self._input.set_active(-1)
+                       self._input.get_child().set_text(self.param.get_value())
+               self._input.connect('changed', self._handle_changed)
+               self._input.get_child().connect('changed', self._handle_changed)
+               self.pack_start(self._input, False)
+       def get_text(self):
+               if self._input.get_active() == -1: return self._input.get_child().get_text()
+               return self.param.get_option_keys()[self._input.get_active()]
+       def set_color(self, color):
+               if self._input.get_active() == -1: #custom entry, use color
+                       self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
+               else: #from enum, make white background
+                       self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
+
 PARAM_MARKUP_TMPL="""\
 #set $foreground = $param.is_valid() and 'black' or 'red'
 <span foreground="$foreground" font_desc="Sans 7.5"><b>$encode($param.get_name()): </b>$encode(repr($param))</span>"""
@@ -49,6 +114,18 @@ Error:
 class Param(Element):
        """The graphical parameter."""
 
+       def get_input_class(self):
+               """
+               Get the graphical gtk class to represent this parameter.
+               An enum requires and combo parameter.
+               A non-enum with options gets a combined entry/combo parameter.
+               All others get a standard entry parameter.
+               @return gtk input class
+               """
+               if self.is_enum(): return EnumParam
+               if self.get_options(): return EnumEntryParam
+               return EntryParam
+
        def update(self):
                """
                Called when an external change occurs.
index 1530a69d63f11cbe7d74eb8d92836a946337e4bc..8f0aa533d47d33ac48ba7836934cebb18e13c097 100644 (file)
@@ -17,31 +17,6 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from FlowGraph import FlowGraph
-from Connection import Connection
-from Block import Block
-from Port import Port
-from Param import Param
+from Element import Element
 
-def conjoin_classes(name, c1, c2):
-       exec("""
-class %s(c1, c2):
-       def __init__(self, *args, **kwargs):
-               c1.__init__(self, *args, **kwargs)
-               c2.__init__(self, *args, **kwargs)
-"""%name, locals())
-       return locals()[name]
-
-def Platform(platform):
-       #combine with gui class
-       for attr, value in (
-               ('FlowGraph', FlowGraph),
-               ('Connection', Connection),
-               ('Block', Block),
-               ('Port', Port),
-               ('Param', Param),
-       ):
-               old_value = getattr(platform, attr)
-               c = conjoin_classes(attr, old_value, value)
-               setattr(platform, attr, c)
-       return platform
+class Platform(Element): pass
index 2df2049a4d9b8bfa24dac854148cdcd4e6a02691..dd39b095de5a0c14920ee1db2bed655c43e5ae1a 100644 (file)
@@ -18,10 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 from .. base.Block import Block as _Block
+from .. gui.Block import Block as _GUIBlock
 import extract_docs
 import extract_category
 
-class Block(_Block):
+class Block(_Block, _GUIBlock):
 
        def is_virtual_sink(self): return self.get_key() == 'virtual_sink'
        def is_virtual_source(self): return self.get_key() == 'virtual_source'
@@ -51,6 +52,7 @@ class Block(_Block):
                        flow_graph=flow_graph,
                        n=n,
                )
+               _GUIBlock.__init__(self)
 
        def validate(self):
                """
index 85b5b2c525ea3ca5d8758c37d678fd2c03e4058b..edc18841a00b7844d6c203bf6af1ca19263115d4 100644 (file)
@@ -18,8 +18,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 from .. base.Connection import Connection as _Connection
+from .. gui.Connection import Connection as _GUIConnection
 
-class Connection(_Connection):
+class Connection(_Connection, _GUIConnection):
+
+       def __init__(self, **kwargs):
+               _Connection.__init__(self, **kwargs)
+               _GUIConnection.__init__(self)
 
        def is_msg(self):
                return self.get_source().get_type() == self.get_sink().get_type() == 'msg'
index 8cad8be492216d46c86884750f0badfb9e6b83fa..96188b8160ffac2dff3d05477d9c399fdfcba529 100644 (file)
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 import expr_utils
 from .. base.FlowGraph import FlowGraph as _FlowGraph
+from .. gui.FlowGraph import FlowGraph as _GUIFlowGraph
 from Block import Block
 from Connection import Connection
 import re
@@ -26,7 +27,11 @@ import re
 _variable_matcher = re.compile('^(variable\w*)$')
 _parameter_matcher = re.compile('^(parameter)$')
 
-class FlowGraph(_FlowGraph):
+class FlowGraph(_FlowGraph, _GUIFlowGraph):
+
+       def __init__(self, **kwargs):
+               _FlowGraph.__init__(self, **kwargs)
+               _GUIFlowGraph.__init__(self)
 
        _eval_cache = dict()
        def _eval(self, code, namespace, namespace_hash):
index d574b513e111d121d537bccd417c6fc1a51ea670..17cfad05123240823235fb0cca2faa0867bfcb97 100644 (file)
@@ -18,7 +18,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 import expr_utils
-from .. base.Param import Param as _Param, EntryParam
+from .. base.Param import Param as _Param
+from .. gui.Param import Param as _GUIParam
+from .. gui.Param import EntryParam
 import Constants
 import numpy
 import os
@@ -83,14 +85,11 @@ COMPLEX_TYPES = tuple(COMPLEX_TYPES + REAL_TYPES + INT_TYPES)
 REAL_TYPES = tuple(REAL_TYPES + INT_TYPES)
 INT_TYPES = tuple(INT_TYPES)
 
-class Param(_Param):
+class Param(_Param, _GUIParam):
 
-       def __init__(self, block, n):
-               _Param.__init__(
-                       self,
-                       block=block,
-                       n=n,
-               )
+       def __init__(self, **kwargs):
+               _Param.__init__(self, **kwargs)
+               _GUIParam.__init__(self)
                self._init = False
                self._hostage_cells = list()
 
@@ -156,7 +155,7 @@ class Param(_Param):
 
        def get_input_class(self):
                if self.get_type() in ('file_open', 'file_save'): return FileParam
-               return _Param.get_input_class(self)
+               return _GUIParam.get_input_class(self)
 
        def get_color(self):
                """
@@ -178,6 +177,7 @@ class Param(_Param):
                                'hex': Constants.INT_COLOR_SPEC,
                                'string': Constants.BYTE_VECTOR_COLOR_SPEC,
                                'id': Constants.ID_COLOR_SPEC,
+                               'stream_id': Constants.ID_COLOR_SPEC,
                                'grid_pos': Constants.INT_VECTOR_COLOR_SPEC,
                                'notebook': Constants.INT_VECTOR_COLOR_SPEC,
                                'raw': Constants.WILDCARD_COLOR_SPEC,
index cab25d348fd3d29665095c77bc3ba2eb33f8f729..bb56d361b5296406c9186086b05f4f6c39a32837 100644 (file)
@@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 import os
 from gnuradio import gr
 from .. base.Platform import Platform as _Platform
+from .. gui.Platform import Platform as _GUIPlatform
 from FlowGraph import FlowGraph as _FlowGraph
 from Connection import Connection as _Connection
 from Block import Block as _Block
@@ -46,7 +47,7 @@ COLORS = (#title, #color spec
        ('Message', Constants.MSG_COLOR_SPEC),
 )
 
-class Platform(_Platform):
+class Platform(_Platform, _GUIPlatform):
 
        def __init__(self):
                """
@@ -70,6 +71,7 @@ class Platform(_Platform):
                        generator=Generator,
                        colors=COLORS,
                )
+               _GUIPlatform.__init__(self)
 
        ##############################################
        # Constructors
index a714844efb99db7761ec16146e05fc7557ca8c5d..33426d905bda81866862d7d49614646d0c1a6af7 100644 (file)
@@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 from .. base.Port import Port as _Port
+from .. gui.Port import Port as _GUIPort
 import Constants
 
 def _get_source_from_virtual_sink_port(vsp):
@@ -49,7 +50,7 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]):
        )
        except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp
 
-class Port(_Port):
+class Port(_Port, _GUIPort):
 
        def __init__(self, block, n, dir):
                """
@@ -73,6 +74,7 @@ class Port(_Port):
                        n=n,
                        dir=dir,
                )
+               _GUIPort.__init__(self)
                self._nports = n.find('nports') or ''
                self._vlen = n.find('vlen') or ''
                self._optional = bool(n.find('optional'))
index dbf526551cb61c26641b44ab096ffb9955a7666e..ffc9d64dba84c64a16c1d18dad116782840ad9eb 100644 (file)
@@ -67,7 +67,6 @@
 * dont generate py files in saved flowgraph dir
 * save/restore cwd
 * threads dont die on exit in probe and variable sink
-* overloaded gui classes for each platform, move param input objects into overloaded
 * align param titles in paramsdialog
 * better error for blank string params
 * weird grid params misbehaving