summaryrefslogtreecommitdiff
path: root/grc/gui
diff options
context:
space:
mode:
Diffstat (limited to 'grc/gui')
-rw-r--r--grc/gui/ActionHandler.py4
-rw-r--r--grc/gui/Block.py29
-rw-r--r--grc/gui/Connection.py11
-rw-r--r--grc/gui/Element.py53
-rw-r--r--grc/gui/FlowGraph.py9
-rw-r--r--grc/gui/Makefile.am2
-rw-r--r--grc/gui/Param.py95
-rw-r--r--grc/gui/Platform.py3
-rw-r--r--grc/gui/Port.py11
-rw-r--r--grc/gui/PropsDialog.py (renamed from grc/gui/ParamsDialog.py)113
10 files changed, 181 insertions, 149 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 8f317d6a8..f12893579 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -31,7 +31,7 @@ import Messages
from .. base import ParseXML
import random
from MainWindow import MainWindow
-from ParamsDialog import ParamsDialog
+from PropsDialog import PropsDialog
import Dialogs
from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveImageFileDialog
@@ -240,7 +240,7 @@ class ActionHandler:
##################################################
elif state == Actions.BLOCK_PARAM_MODIFY:
selected_block = self.get_flow_graph().get_selected_block()
- if selected_block and ParamsDialog(selected_block).run():
+ if selected_block and PropsDialog(selected_block).run():
self.get_flow_graph().update()
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.get_page().set_saved(False)
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 0f3e511d8..8c65bf06f 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -37,7 +37,7 @@ BLOCK_MARKUP_TMPL="""\
class Block(Element):
"""The graphical signal block."""
- def __init__(self, *args, **kwargs):
+ def __init__(self):
"""
Block contructor.
Add graphics related params to the block.
@@ -113,23 +113,16 @@ class Block(Element):
"""
self.get_param('_rotation').set_value(str(rot))
- def update(self):
+ def create_shapes(self):
"""Update the block, parameters, and ports when a change occurs."""
- self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR
- self.clear()
- self._create_labels()
- self.W = self.label_width + 2*BLOCK_LABEL_PADDING
- self.H = max(*(
- [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \
- sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
- for ports in (self.get_sources(), self.get_sinks())]
- ))
+ Element.create_shapes(self)
if self.is_horizontal(): self.add_area((0, 0), (self.W, self.H))
elif self.is_vertical(): self.add_area((0, 0), (self.H, self.W))
- map(lambda p: p.update(), self.get_ports())
- def _create_labels(self):
+ def create_labels(self):
"""Create the labels for the signal block."""
+ Element.create_labels(self)
+ self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR
layouts = list()
#create the main layout
layout = gtk.DrawingArea().create_pango_layout('')
@@ -142,7 +135,7 @@ class Block(Element):
layouts.append(layout)
w,h = layout.get_pixel_size()
self.label_width = max(w, self.label_width)
- self.label_height = self.label_height + h + LABEL_SEPARATION
+ self.label_height += h + LABEL_SEPARATION
width = self.label_width
height = self.label_height
#setup the pixmap
@@ -164,7 +157,13 @@ class Block(Element):
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))
- map(lambda p: p._create_labels(), self.get_ports())
+ #calculate width and height needed
+ self.W = self.label_width + 2*BLOCK_LABEL_PADDING
+ self.H = max(*(
+ [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \
+ sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
+ for ports in (self.get_sources(), self.get_sinks())]
+ ))
def draw(self, gc, window):
"""
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index 013bcb00f..fabf34ee7 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -1,5 +1,5 @@
"""
-Copyright 2007, 2008 Free Software Foundation, Inc.
+Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -32,6 +32,8 @@ class Connection(Element):
The arrow coloring exposes the enabled and valid states.
"""
+ def __init__(self): Element.__init__(self)
+
def get_coordinate(self):
"""
Get the 0,0 coordinate.
@@ -48,8 +50,9 @@ class Connection(Element):
"""
return 0
- def update(self):
+ def create_shapes(self):
"""Precalculate relative coordinates."""
+ Element.create_shapes(self)
self._sink_rot = None
self._source_rot = None
self._sink_coor = None
@@ -72,7 +75,7 @@ class Connection(Element):
def _update_after_move(self):
"""Calculate coordinates."""
- self.clear()
+ self.clear() #FIXME do i want this here?
#source connector
source = self.get_source()
X, Y = source.get_connector_coordinate()
@@ -123,7 +126,7 @@ class Connection(Element):
sink = self.get_sink()
source = self.get_source()
#check for changes
- if self._sink_rot != sink.get_rotation() or self._source_rot != source.get_rotation(): self.update()
+ if self._sink_rot != sink.get_rotation() or self._source_rot != source.get_rotation(): self.create_shapes()
elif self._sink_coor != sink.get_coordinate() or self._source_coor != source.get_coordinate(): self._update_after_move()
#cache values
self._sink_rot = sink.get_rotation()
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 315191723..f0518ee12 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -1,5 +1,5 @@
"""
-Copyright 2007 Free Software Foundation, Inc.
+Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -17,11 +17,9 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-import Colors
import pygtk
pygtk.require('2.0')
import gtk
-import pango
from Constants import LINE_SELECT_SENSITIVITY
from Constants import POSSIBLE_ROTATIONS
@@ -32,7 +30,7 @@ class Element(object):
and methods to detect selection of those areas.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self):
"""
Make a new list of rectangular areas and lines, and set the coordinate and the rotation.
"""
@@ -61,6 +59,21 @@ class Element(object):
rotation = rotation or self.get_rotation()
return rotation in (90, 270)
+ def create_labels(self):
+ """
+ Create labels (if applicable) and call on all children.
+ Call this base method before creating labels in the element.
+ """
+ for child in self.get_children(): child.create_labels()
+
+ def create_shapes(self):
+ """
+ Create shapes (if applicable) and call on all children.
+ Call this base method before creating shapes in the element.
+ """
+ self.clear()
+ for child in self.get_children(): child.create_shapes()
+
def draw(self, gc, window, border_color, bg_color):
"""
Draw in the given window.
@@ -70,14 +83,14 @@ class Element(object):
@param bg_color the color for the inside of the rectangle
"""
X,Y = self.get_coordinate()
- for (rX,rY),(W,H) in self.areas_dict[self.get_rotation()]:
+ for (rX,rY),(W,H) in self._areas_list:
aX = X + rX
aY = Y + rY
gc.set_foreground(bg_color)
window.draw_rectangle(gc, True, aX, aY, W, H)
gc.set_foreground(border_color)
window.draw_rectangle(gc, False, aX, aY, W, H)
- for (x1, y1),(x2, y2) in self.lines_dict[self.get_rotation()]:
+ for (x1, y1),(x2, y2) in self._lines_list:
gc.set_foreground(border_color)
window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
@@ -90,8 +103,8 @@ class Element(object):
def clear(self):
"""Empty the lines and areas."""
- self.areas_dict = dict((rotation, list()) for rotation in POSSIBLE_ROTATIONS)
- self.lines_dict = dict((rotation, list()) for rotation in POSSIBLE_ROTATIONS)
+ self._areas_list = list()
+ self._lines_list = list()
def set_coordinate(self, coor):
"""
@@ -136,7 +149,7 @@ class Element(object):
X, Y = self.get_coordinate()
self.set_coordinate((X+deltaX, Y+deltaY))
- def add_area(self, rel_coor, area, rotation=None):
+ def add_area(self, rel_coor, area):
"""
Add an area to the area list.
An area is actually a coordinate relative to the main coordinate
@@ -144,25 +157,21 @@ class Element(object):
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
"""
- self.areas_dict[rotation or self.get_rotation()].append((rel_coor, area))
+ self._areas_list.append((rel_coor, area))
- def add_line(self, rel_coor1, rel_coor2, rotation=None):
+ def add_line(self, rel_coor1, rel_coor2):
"""
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
"""
- self.lines_dict[rotation or self.get_rotation()].append((rel_coor1, rel_coor2))
+ self._lines_list.append((rel_coor1, rel_coor2))
def what_is_selected(self, coor, coor_m=None):
"""
@@ -183,24 +192,24 @@ class Element(object):
if coor_m:
x_m, y_m = [a-b for a,b in zip(coor_m, self.get_coordinate())]
#handle rectangular areas
- for (x1,y1), (w,h) in self.areas_dict[self.get_rotation()]:
+ for (x1,y1), (w,h) in self._areas_list:
if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \
in_between(x1+w, x, x_m) and in_between(y1, y, y_m) or \
in_between(x1, x, x_m) and in_between(y1+h, y, y_m) or \
in_between(x1+w, x, x_m) and in_between(y1+h, y, y_m):
return self
#handle horizontal or vertical lines
- for (x1, y1), (x2, y2) in self.lines_dict[self.get_rotation()]:
+ for (x1, y1), (x2, y2) in self._lines_list:
if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \
in_between(x2, x, x_m) and in_between(y2, y, y_m):
return self
return None
else:
#handle rectangular areas
- for (x1,y1), (w,h) in self.areas_dict[self.get_rotation()]:
+ for (x1,y1), (w,h) in self._areas_list:
if in_between(x, x1, x1+w) and in_between(y, y1, y1+h): return self
#handle horizontal or vertical lines
- for (x1, y1), (x2, y2) in self.lines_dict[self.get_rotation()]:
+ for (x1, y1), (x2, y2) in self._lines_list:
if x1 == x2: x1, x2 = x1-LINE_SELECT_SENSITIVITY, x2+LINE_SELECT_SENSITIVITY
if y1 == y2: y1, y2 = y1-LINE_SELECT_SENSITIVITY, y2+LINE_SELECT_SENSITIVITY
if in_between(x, x1, x2) and in_between(y, y1, y2): return self
@@ -220,7 +229,3 @@ class Element(object):
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. Dummy method."""
- pass
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 5e645be72..35ccf5e27 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -39,7 +39,7 @@ class FlowGraph(Element):
and the connections between inputs and outputs.
"""
- def __init__(self, *args, **kwargs):
+ def __init__(self):
"""
FlowGraph contructor.
Create a list for signal blocks and connections. Connect mouse handlers.
@@ -291,12 +291,13 @@ class FlowGraph(Element):
def update(self):
"""
- Do a global rewrite and validate.
- Call update on all elements.
+ Call the top level rewrite and validate.
+ Call the top level create labels and shapes.
"""
self.rewrite()
self.validate()
- for element in self.get_elements(): element.update()
+ self.create_labels()
+ self.create_shapes()
##########################################################################
## Get Selected
diff --git a/grc/gui/Makefile.am b/grc/gui/Makefile.am
index cb45d5359..b14817d04 100644
--- a/grc/gui/Makefile.am
+++ b/grc/gui/Makefile.am
@@ -43,7 +43,7 @@ ourpython_PYTHON = \
MainWindow.py \
Messages.py \
NotebookPage.py \
- ParamsDialog.py \
+ PropsDialog.py \
Preferences.py \
StateCache.py \
__init__.py
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 4955d3336..4464a57ab 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -26,17 +26,52 @@ import gtk
class InputParam(gtk.HBox):
"""The base class for an input parameter inside the input parameters dialog."""
- def __init__(self, param, _handle_changed):
+ def __init__(self, param, callback=None):
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._callback = callback
+ 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
+ #connect events
+ self.connect('show', self._update_gui)
def set_color(self, color): pass
+ def _update_gui(self, *args):
+ """
+ Set the markup, color, tooltip, show/hide.
+ """
+ #set the markup
+ has_cb = \
+ hasattr(self.param.get_parent(), 'get_callbacks') and \
+ filter(lambda c: self.param.get_key() in c, self.param.get_parent()._callbacks)
+ self.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self.param, has_cb=has_cb))
+ #set the color
+ self.set_color(self.param.get_color())
+ #set the tooltip
+ if self.tp: self.tp.set_tip(
+ self.entry,
+ Utils.parse_template(TIP_MARKUP_TMPL, param=self.param).strip(),
+ )
+ #show/hide
+ if self.param.get_hide() == 'all': self.hide_all()
+ else: self.show_all()
+
+ def _handle_changed(self, *args):
+ """
+ Handle a gui change by setting the new param value,
+ calling the callback (if applicable), and updating.
+ """
+ #set the new value
+ self.param.set_value(self.get_text())
+ #call the callback
+ if self._callback: self._callback(*args)
+ else: self.param.validate()
+ #gui update
+ self._update_gui()
+
class EntryParam(InputParam):
"""Provide an entry box for strings and numbers."""
@@ -114,7 +149,9 @@ Error:
class Param(Element):
"""The graphical parameter."""
- def get_input_class(self):
+ def __init__(self): Element.__init__(self)
+
+ def get_input(self, *args, **kwargs):
"""
Get the graphical gtk class to represent this parameter.
An enum requires and combo parameter.
@@ -122,53 +159,9 @@ class Param(Element):
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.
- Update the graphical input by calling the change handler.
- """
- if hasattr(self, '_input'): self._handle_changed()
-
- def get_input_object(self, callback=None):
- """
- Get the graphical gtk object to represent this parameter.
- Create the input object with this data type and the handle changed method.
- @param callback a function of one argument(this param) to be called from the change handler
- @return gtk input object
- """
- self._callback = callback
- self._input = self.get_input_class()(self, self._handle_changed)
- if not self._callback: self.update()
- return self._input
-
- def _handle_changed(self, widget=None):
- """
- When the input changes, write the inputs to the data type.
- Finish by calling the exteral callback.
- """
- self.set_value(self._input.get_text())
- self.validate()
- #is param is involved in a callback? #FIXME: messy
- has_cb = \
- hasattr(self.get_parent(), 'get_callbacks') and \
- filter(lambda c: self.get_key() in c, self.get_parent()._callbacks)
- self._input.set_markup(Utils.parse_template(PARAM_LABEL_MARKUP_TMPL, param=self, has_cb=has_cb))
- #hide/show
- if self.get_hide() == 'all': self._input.hide_all()
- else: self._input.show_all()
- #set the color
- self._input.set_color(self.get_color())
- #set the tooltip
- if self._input.tp: self._input.tp.set_tip(
- self._input.entry,
- Utils.parse_template(TIP_MARKUP_TMPL, param=self).strip(),
- )
- #execute the external callback
- if self._callback: self._callback(self)
+ if self.is_enum(): return EnumParam(self, *args, **kwargs)
+ if self.get_options(): return EnumEntryParam(self, *args, **kwargs)
+ return EntryParam(self, *args, **kwargs)
def get_layout(self):
"""
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index 8f0aa533d..8bbfaca23 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -19,4 +19,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from Element import Element
-class Platform(Element): pass
+class Platform(Element):
+ def __init__(self): Element.__init__(self)
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 6fc2c4b15..6763f6cbd 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -34,7 +34,7 @@ PORT_MARKUP_TMPL="""\
class Port(Element):
"""The graphical port."""
- def __init__(self, *args, **kwargs):
+ def __init__(self):
"""
Port contructor.
Create list of connector coordinates.
@@ -42,9 +42,9 @@ class Port(Element):
Element.__init__(self)
self.connector_coordinates = dict()
- def update(self):
+ def create_shapes(self):
"""Create new areas and labels for the port."""
- self.clear()
+ Element.create_shapes(self)
#get current rotation
rotation = self.get_rotation()
#get all sibling ports
@@ -82,8 +82,9 @@ class Port(Element):
#the connector length
self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index
- def _create_labels(self):
+ def create_labels(self):
"""Create the labels for the socket."""
+ Element.create_labels(self)
self._bg_color = Colors.get_color(self.get_color())
#create the layout
layout = gtk.DrawingArea().create_pango_layout('')
@@ -114,7 +115,7 @@ class Port(Element):
border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_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
+ (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels
if self.is_horizontal():
window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
elif self.is_vertical():
diff --git a/grc/gui/ParamsDialog.py b/grc/gui/PropsDialog.py
index ccf19d1a2..496500416 100644
--- a/grc/gui/ParamsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -37,70 +37,116 @@ def get_title_label(title):
hbox.pack_start(label, False, False, padding=11)
return hbox
-class ParamsDialog(gtk.Dialog):
- """A dialog box to set block parameters."""
+class PropsDialog(gtk.Dialog):
+ """
+ A dialog to set block parameters, view errors, and view documentation.
+ """
def __init__(self, block):
"""
- SignalBlockParamsDialog contructor.
- @param block the signal block
+ Properties dialog contructor.
+ @param block a block instance
"""
+ self._hash = 0
+ LABEL_SPACING = 7
gtk.Dialog.__init__(self,
title='Properties: %s'%block.get_name(),
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE),
)
- self.block = block
+ self._block = block
self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
vbox = gtk.VBox()
- #Add the title label
- vbox.pack_start(get_title_label('Parameters'), False)
#Create the scrolled window to hold all the parameters
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled_window.add_with_viewport(vbox)
self.vbox.pack_start(scrolled_window, True)
+ #Params box for block parameters
+ self._params_box = gtk.VBox()
+ self._params_box.pack_start(get_title_label('Parameters'), False)
+ self._input_object_params = list()
#Error Messages for the block
self._error_box = gtk.VBox()
self._error_messages_text_display = TextDisplay()
- self._error_box.pack_start(gtk.Label(), False, False, 7) #spacing
+ self._error_box.pack_start(gtk.Label(), False, False, LABEL_SPACING)
self._error_box.pack_start(get_title_label('Error Messages'), False)
self._error_box.pack_start(self._error_messages_text_display, False)
#Docs for the block
self._docs_box = err_box = gtk.VBox()
self._docs_text_display = TextDisplay()
- self._docs_box.pack_start(gtk.Label(), False, False, 7) #spacing
+ self._docs_box.pack_start(gtk.Label(), False, False, LABEL_SPACING)
self._docs_box.pack_start(get_title_label('Documentation'), False)
self._docs_box.pack_start(self._docs_text_display, False)
- #Add all the parameters
- for param in self.block.get_params():
- vbox.pack_start(param.get_input_object(self._handle_changed), False)
- #Add the error and docs box
+ #Add the boxes
+ vbox.pack_start(self._params_box, False)
vbox.pack_start(self._error_box, False)
vbox.pack_start(self._docs_box, False)
- #connect and show
+ #connect events
self.connect('key_press_event', self._handle_key_press)
+ self.connect('show', self._update_gui)
+ #show all (performs initial gui update)
self.show_all()
- #initial update
- for param in self.block.get_params(): param.update()
- self._update()
- def _update(self):
+ def _params_changed(self):
+ """
+ Have the params in this dialog changed?
+ Ex: Added, removed, type change, hide change...
+ Make a hash that uniquely represents the params state.
+ @return true if changed
+ """
+ old_hash = self._hash
+ self._hash = 0
+ for param in self._block.get_params():
+ self._hash ^= hash(param)
+ self._hash ^= hash(param.get_type())
+ self._hash ^= hash(param.get_hide())
+ return self._hash != old_hash
+
+ def _handle_changed(self, *args):
+ """
+ A change occured within a param:
+ Rewrite/validate the block and update the gui.
"""
+ #update for the block
+ self._block.rewrite()
+ self._block.validate()
+ self._update_gui()
+
+ def _update_gui(self, *args):
+ """
+ Repopulate the parameters box (if changed).
+ Update all the input parameters.
Update the error messages box.
Hide the box if there are no errors.
Update the documentation block.
Hide the box if there are no docs.
"""
- self.block.validate()
+ #update the params box
+ if self._params_changed():
+ #hide params box before changing
+ self._params_box.hide_all()
+ #empty the params box
+ for io_param in list(self._input_object_params):
+ self._params_box.remove(io_param)
+ self._input_object_params.remove(io_param)
+ io_param.destroy()
+ #repopulate the params box
+ for param in self._block.get_params():
+ if param.get_hide() == 'all': continue
+ io_param = param.get_input(self._handle_changed)
+ self._input_object_params.append(io_param)
+ self._params_box.pack_start(io_param, False)
+ #show params box with new params
+ self._params_box.show_all()
#update the errors box
- if self.block.is_valid(): self._error_box.hide()
+ if self._block.is_valid(): self._error_box.hide()
else: self._error_box.show()
- messages = '\n\n'.join(self.block.get_error_messages())
+ messages = '\n\n'.join(self._block.get_error_messages())
self._error_messages_text_display.set_text(messages)
#update the docs box
- if self.block.get_doc(): self._docs_box.show()
+ if self._block.get_doc(): self._docs_box.show()
else: self._docs_box.hide()
- self._docs_text_display.set_text(self.block.get_doc())
+ self._docs_text_display.set_text(self._block.get_doc())
def _handle_key_press(self, widget, event):
"""
@@ -112,34 +158,17 @@ class ParamsDialog(gtk.Dialog):
if keyname == 'Return': self.response(gtk.RESPONSE_OK)
return False #forward the keypress
- def _handle_changed(self, param):
- """
- A change occured, update any dependent parameters:
- The enum inside the variable type may have changed and,
- the variable param will need an external update.
- @param param the graphical parameter that initiated the callback
- """
- #update dependent params
- if param.is_enum():
- for other_param in param.get_parent().get_params():
- if param.get_key() is not other_param.get_key() and (
- param.get_key() in other_param._type or \
- param.get_key() in other_param._hide): other_param.update()
- #update
- self._update()
- return True
-
def run(self):
"""
Call run().
@return true if a change occured.
"""
original_data = list()
- for param in self.block.get_params():
+ for param in self._block.get_params():
original_data.append(param.get_value())
gtk.Dialog.run(self)
self.destroy()
new_data = list()
- for param in self.block.get_params():
+ for param in self._block.get_params():
new_data.append(param.get_value())
return original_data != new_data