diff options
-rw-r--r-- | grc/src/platforms/gui/Block.py | 10 | ||||
-rw-r--r-- | grc/src/platforms/gui/Colors.py | 23 | ||||
-rw-r--r-- | grc/src/platforms/gui/Connection.py | 22 | ||||
-rw-r--r-- | grc/src/platforms/gui/Element.py | 12 | ||||
-rw-r--r-- | grc/src/platforms/gui/FlowGraph.py | 6 | ||||
-rw-r--r-- | grc/src/platforms/gui/Port.py | 11 |
6 files changed, 50 insertions, 34 deletions
diff --git a/grc/src/platforms/gui/Block.py b/grc/src/platforms/gui/Block.py index b574892d3..862a59393 100644 --- a/grc/src/platforms/gui/Block.py +++ b/grc/src/platforms/gui/Block.py @@ -115,7 +115,7 @@ class Block(Element): 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 @@ -148,9 +148,8 @@ class Block(Element): #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) - gc.foreground = Colors.TXT_COLOR #draw the layouts h_off = 0 for i,layout in enumerate(layouts): @@ -175,7 +174,10 @@ class Block(Element): """ 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) diff --git a/grc/src/platforms/gui/Colors.py b/grc/src/platforms/gui/Colors.py index 353cd1c9f..f0b989b37 100644 --- a/grc/src/platforms/gui/Colors.py +++ b/grc/src/platforms/gui/Colors.py @@ -21,14 +21,17 @@ 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) +_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') diff --git a/grc/src/platforms/gui/Connection.py b/grc/src/platforms/gui/Connection.py index 9f243215e..013bcb00f 100644 --- a/grc/src/platforms/gui/Connection.py +++ b/grc/src/platforms/gui/Connection.py @@ -23,7 +23,14 @@ import Colors 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): """ @@ -59,8 +66,9 @@ class Connection(Element): 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.""" @@ -123,8 +131,10 @@ class Connection(Element): 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) #draw arrow on sink port + gc.set_foreground(self._arrow_color) window.draw_polygon(gc, True, self._arrow) diff --git a/grc/src/platforms/gui/Element.py b/grc/src/platforms/gui/Element.py index 8ef288ed1..315191723 100644 --- a/grc/src/platforms/gui/Element.py +++ b/grc/src/platforms/gui/Element.py @@ -61,24 +61,24 @@ class Element(object): 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 - @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 - gc.foreground = BG_color + gc.set_foreground(bg_color) 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()]: - 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): diff --git a/grc/src/platforms/gui/FlowGraph.py b/grc/src/platforms/gui/FlowGraph.py index 7e2330669..40f391811 100644 --- a/grc/src/platforms/gui/FlowGraph.py +++ b/grc/src/platforms/gui/FlowGraph.py @@ -248,7 +248,7 @@ class FlowGraph(Element): """ 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()): @@ -259,9 +259,9 @@ class FlowGraph(Element): 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) - 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(): diff --git a/grc/src/platforms/gui/Port.py b/grc/src/platforms/gui/Port.py index a763e406d..d1f36f8b9 100644 --- a/grc/src/platforms/gui/Port.py +++ b/grc/src/platforms/gui/Port.py @@ -84,7 +84,7 @@ class Port(Element): 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)) @@ -93,9 +93,8 @@ class Port(Element): #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) - 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) @@ -110,8 +109,10 @@ class Port(Element): @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(): |