[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11115 - gnuradio/trunk/grc/src/platforms/gui
From: |
jblum |
Subject: |
[Commit-gnuradio] r11115 - gnuradio/trunk/grc/src/platforms/gui |
Date: |
Mon, 25 May 2009 10:38:59 -0600 (MDT) |
Author: jblum
Date: 2009-05-25 10:38:58 -0600 (Mon, 25 May 2009)
New Revision: 11115
Modified:
gnuradio/trunk/grc/src/platforms/gui/Block.py
gnuradio/trunk/grc/src/platforms/gui/Colors.py
gnuradio/trunk/grc/src/platforms/gui/Connection.py
gnuradio/trunk/grc/src/platforms/gui/Element.py
gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
gnuradio/trunk/grc/src/platforms/gui/Port.py
Log:
color code refactoring
Modified: gnuradio/trunk/grc/src/platforms/gui/Block.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Block.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/Block.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -115,7 +115,7 @@
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 @@
#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 @@
"""
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)
Modified: gnuradio/trunk/grc/src/platforms/gui/Colors.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Colors.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/Colors.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -21,14 +21,17 @@
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')
Modified: gnuradio/trunk/grc/src/platforms/gui/Connection.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Connection.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/Connection.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -23,7 +23,14 @@
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 @@
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 @@
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)
Modified: gnuradio/trunk/grc/src/platforms/gui/Element.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Element.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/Element.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -61,24 +61,24 @@
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):
Modified: gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -248,7 +248,7 @@
"""
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 @@
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():
Modified: gnuradio/trunk/grc/src/platforms/gui/Port.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Port.py 2009-05-24 01:29:15 UTC
(rev 11114)
+++ gnuradio/trunk/grc/src/platforms/gui/Port.py 2009-05-25 16:38:58 UTC
(rev 11115)
@@ -84,7 +84,7 @@
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 @@
#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 @@
@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():
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11115 - gnuradio/trunk/grc/src/platforms/gui,
jblum <=