def update(self):
"""Update the block, parameters, and ports when a change occurs."""
def update(self):
"""Update the block, parameters, and ports when a change occurs."""
- self.bg_color = self.get_enabled() and Colors.BG_COLOR or Colors.DISABLED_BG_COLOR
+ 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.clear()
self._create_labels()
self.W = self.label_width + 2*BLOCK_LABEL_PADDING
#setup the pixmap
pixmap = self.get_parent().new_pixmap(width, height)
gc = pixmap.new_gc()
#setup the pixmap
pixmap = self.get_parent().new_pixmap(width, height)
gc = pixmap.new_gc()
- gc.foreground = self.bg_color
+ gc.set_foreground(self._bg_color)
pixmap.draw_rectangle(gc, True, 0, 0, width, height)
pixmap.draw_rectangle(gc, True, 0, 0, width, height)
- gc.foreground = Colors.TXT_COLOR
#draw the layouts
h_off = 0
for i,layout in enumerate(layouts):
#draw the layouts
h_off = 0
for i,layout in enumerate(layouts):
"""
x, y = self.get_coordinate()
#draw main block
"""
x, y = self.get_coordinate()
#draw main block
- Element.draw(self, gc, window, BG_color=self.bg_color)
+ Element.draw(
+ self, gc, window, bg_color=self._bg_color,
+ border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR,
+ )
#draw label image
if self.is_horizontal():
window.draw_image(gc, self.horizontal_label, 0, 0, x+BLOCK_LABEL_PADDING, y+(self.H-self.label_height)/2, -1, -1)
#draw label image
if self.is_horizontal():
window.draw_image(gc, self.horizontal_label, 0, 0, x+BLOCK_LABEL_PADDING, y+(self.H-self.label_height)/2, -1, -1)
pygtk.require('2.0')
import gtk
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)
+_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
-DISABLED_BG_COLOR = get_color('#CCCCCC') #disabled background
-DISABLED_FG_COLOR = get_color('#999999') #disabled foreground
-H_COLOR = get_color('#00FFFF') #Highlight border color
-TXT_COLOR = get_color('black') #text color
-ERROR_COLOR = get_color('red') #error color
+HIGHLIGHT_COLOR = get_color('#00FFFF')
+BORDER_COLOR = get_color('black')
+#flow graph color constants
+FLOWGRAPH_BACKGROUND_COLOR = get_color('#FFF9FF')
+#block color constants
+BLOCK_ENABLED_COLOR = get_color('#F1ECFF')
+BLOCK_DISABLED_COLOR = get_color('#CCCCCC')
+#connection color constants
+CONNECTION_ENABLED_COLOR = get_color('black')
+CONNECTION_DISABLED_COLOR = get_color('#999999')
+CONNECTION_ERROR_COLOR = get_color('red')
from Constants import CONNECTOR_ARROW_BASE, CONNECTOR_ARROW_HEIGHT
class Connection(Element):
from Constants import CONNECTOR_ARROW_BASE, CONNECTOR_ARROW_HEIGHT
class Connection(Element):
- """A graphical connection for ports."""
+ """
+ A graphical connection for ports.
+ The connection has 2 parts, the arrow and the wire.
+ The coloring of the arrow and wire exposes the status of 3 states:
+ enabled/disabled, valid/invalid, highlighted/non-highlighted.
+ The wire coloring exposes the enabled and highlighted states.
+ The arrow coloring exposes the enabled and valid states.
+ """
def get_coordinate(self):
"""
def get_coordinate(self):
"""
Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()),
]
self._update_after_move()
Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()),
]
self._update_after_move()
- if self.is_valid(): self._foreground = Colors.FG_COLOR
- else: self._foreground = Colors.ERROR_COLOR
+ if not self.get_enabled(): self._arrow_color = Colors.CONNECTION_DISABLED_COLOR
+ elif not self.is_valid(): self._arrow_color = Colors.CONNECTION_ERROR_COLOR
+ else: self._arrow_color = Colors.CONNECTION_ENABLED_COLOR
def _update_after_move(self):
"""Calculate coordinates."""
def _update_after_move(self):
"""Calculate coordinates."""
self._sink_coor = sink.get_coordinate()
self._source_coor = source.get_coordinate()
#draw
self._sink_coor = sink.get_coordinate()
self._source_coor = source.get_coordinate()
#draw
- fg_color = self.get_enabled() and Colors.FG_COLOR or Colors.DISABLED_FG_COLOR
- Element.draw(self, gc, window, FG_color=fg_color)
- gc.foreground = self._foreground
+ if self.is_highlighted(): border_color = Colors.HIGHLIGHT_COLOR
+ elif self.get_enabled(): border_color = Colors.CONNECTION_ENABLED_COLOR
+ else: border_color = Colors.CONNECTION_DISABLED_COLOR
+ Element.draw(self, gc, window, bg_color=None, border_color=border_color)
+ gc.set_foreground(self._arrow_color)
window.draw_polygon(gc, True, self._arrow)
window.draw_polygon(gc, True, self._arrow)
rotation = rotation or self.get_rotation()
return rotation in (90, 270)
rotation = rotation or self.get_rotation()
return rotation in (90, 270)
- def draw(self, gc, window, BG_color=Colors.BG_COLOR, FG_color=Colors.FG_COLOR):
+ def draw(self, gc, window, border_color, bg_color):
"""
Draw in the given window.
@param gc the graphics context
@param window the gtk window to draw on
"""
Draw in the given window.
@param gc the graphics context
@param window the gtk window to draw on
- @param BG_color the background color
- @param FG_color the foreground color
+ @param border_color the color for lines and rectangle borders
+ @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()]:
aX = X + rX
aY = Y + rY
"""
X,Y = self.get_coordinate()
for (rX,rY),(W,H) in self.areas_dict[self.get_rotation()]:
aX = X + rX
aY = Y + rY
- gc.foreground = BG_color
+ gc.set_foreground(bg_color)
window.draw_rectangle(gc, True, aX, aY, W, H)
window.draw_rectangle(gc, True, aX, aY, W, H)
- gc.foreground = self.is_highlighted() and Colors.H_COLOR or FG_color
+ 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()]:
window.draw_rectangle(gc, False, aX, aY, W, H)
for (x1, y1),(x2, y2) in self.lines_dict[self.get_rotation()]:
- gc.foreground = self.is_highlighted() and Colors.H_COLOR or FG_color
+ gc.set_foreground(border_color)
window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
def rotate(self, rotation):
window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
def rotate(self, rotation):
"""
W,H = self.get_size()
#draw the background
"""
W,H = self.get_size()
#draw the background
- gc.foreground = Colors.BACKGROUND_COLOR
+ gc.set_foreground(Colors.FLOWGRAPH_BACKGROUND_COLOR)
window.draw_rectangle(gc, True, 0, 0, W, H)
#draw multi select rectangle
if self.mouse_pressed and (not self.get_selected_elements() or self.get_ctrl_mask()):
window.draw_rectangle(gc, True, 0, 0, W, H)
#draw multi select rectangle
if self.mouse_pressed and (not self.get_selected_elements() or self.get_ctrl_mask()):
x, y = int(min(x1, x2)), int(min(y1, y2))
w, h = int(abs(x1 - x2)), int(abs(y1 - y2))
#draw
x, y = int(min(x1, x2)), int(min(y1, y2))
w, h = int(abs(x1 - x2)), int(abs(y1 - y2))
#draw
- gc.foreground = Colors.H_COLOR
+ gc.set_foreground(Colors.HIGHLIGHT_COLOR)
window.draw_rectangle(gc, True, x, y, w, h)
window.draw_rectangle(gc, True, x, y, w, h)
- gc.foreground = Colors.TXT_COLOR
+ gc.set_foreground(Colors.BORDER_COLOR)
window.draw_rectangle(gc, False, x, y, w, h)
#draw blocks on top of connections
for element in self.get_connections() + self.get_blocks():
window.draw_rectangle(gc, False, x, y, w, h)
#draw blocks on top of connections
for element in self.get_connections() + self.get_blocks():
def _create_labels(self):
"""Create the labels for the socket."""
def _create_labels(self):
"""Create the labels for the socket."""
- self.BG_color = Colors.get_color(self.get_color())
+ self._bg_color = Colors.get_color(self.get_color())
#create the layout
layout = gtk.DrawingArea().create_pango_layout('')
layout.set_markup(Utils.parse_template(PORT_MARKUP_TMPL, port=self))
#create the layout
layout = gtk.DrawingArea().create_pango_layout('')
layout.set_markup(Utils.parse_template(PORT_MARKUP_TMPL, port=self))
#create the pixmap
pixmap = self.get_parent().get_parent().new_pixmap(self.w, self.h)
gc = pixmap.new_gc()
#create the pixmap
pixmap = self.get_parent().get_parent().new_pixmap(self.w, self.h)
gc = pixmap.new_gc()
- gc.foreground = self.BG_color
+ gc.set_foreground(self._bg_color)
pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
- gc.foreground = Colors.TXT_COLOR
pixmap.draw_layout(gc, 0, 0, layout)
#create the images
self.horizontal_label = image = pixmap.get_image(0, 0, self.w, self.h)
pixmap.draw_layout(gc, 0, 0, layout)
#create the images
self.horizontal_label = image = pixmap.get_image(0, 0, self.w, self.h)
@param gc the graphics context
@param window the gtk window to draw on
"""
@param gc the graphics context
@param window the gtk window to draw on
"""
- Element.draw(self, gc, window, BG_color=self.BG_color)
- gc.foreground = Colors.TXT_COLOR
+ Element.draw(
+ self, gc, window, bg_color=self._bg_color,
+ 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
if self.is_horizontal():
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 self.is_horizontal():