diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2016-08-01 21:25:32 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2016-08-08 20:36:48 +0200 |
commit | e682374d9f7eda4fd2c2701092470ee912e6c33b (patch) | |
tree | a65d25fc13b8be9e043f59ccbce7243a571c498c | |
parent | e413d4a3e21969f5b0c7bf9c8f821efb14e4ffad (diff) |
grc: gtk3: fancier coloring for disabled and bypassed blocks
-rw-r--r-- | grc/gui/Block.py | 40 | ||||
-rw-r--r-- | grc/gui/Colors.py | 20 | ||||
-rw-r--r-- | grc/gui/Connection.py | 24 | ||||
-rw-r--r-- | grc/gui/DrawingArea.py | 2 | ||||
-rw-r--r-- | grc/gui/Param.py | 16 | ||||
-rw-r--r-- | grc/gui/Port.py | 11 |
6 files changed, 56 insertions, 57 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 4546b784b3..6cbfa5f4f5 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -56,9 +56,8 @@ class Block(CoreBlock, Element): self._comment_layout = None self._area = [] - self._border_color = (Colors.MISSING_BLOCK_BORDER_COLOR if self.is_dummy_block else - Colors.BORDER_COLOR) - self._bg_color = Colors.BLOCK_ENABLED_COLOR + self._border_color = self._bg_color = Colors.BLOCK_ENABLED_COLOR + self._font_color = list(Colors.FONT_COLOR) @property def coordinate(self): @@ -106,6 +105,19 @@ class Block(CoreBlock, Element): """ self.states['_rotation'] = rot + def _update_colors(self): + self._bg_color = ( + Colors.MISSING_BLOCK_BACKGROUND_COLOR if self.is_dummy_block else + Colors.BLOCK_BYPASSED_COLOR if self.state == 'bypassed' else + Colors.BLOCK_ENABLED_COLOR if self.state == 'enabled' else + Colors.BLOCK_DISABLED_COLOR + ) + self._font_color[-1] = 1.0 if self.state == 'enabled' else 0.4 + self._border_color = ( + Colors.MISSING_BLOCK_BORDER_COLOR if self.is_dummy_block else + Colors.BORDER_COLOR_DISABLED if not self.state == 'enabled' else Colors.BORDER_COLOR + ) + def create_shapes(self): """Update the block, parameters, and ports when a change occurs.""" if self.is_horizontal(): @@ -136,19 +148,11 @@ class Block(CoreBlock, Element): def create_labels(self): """Create the labels for the signal block.""" - self._bg_color = ( - Colors.MISSING_BLOCK_BACKGROUND_COLOR if self.is_dummy_block else - Colors.BLOCK_BYPASSED_COLOR if self.get_bypassed() else - Colors.BLOCK_ENABLED_COLOR if self.enabled else - Colors.BLOCK_DISABLED_COLOR - ) - - # update the title layout title_layout, params_layout = self._surface_layouts title_layout.set_markup( - '<span foreground="{foreground}" font_desc="{font}"><b>{name}</b></span>'.format( - foreground='black' if self.is_valid() else 'red', font=BLOCK_FONT, + '<span {foreground} font_desc="{font}"><b>{name}</b></span>'.format( + foreground='foreground="red"' if not self.is_valid() else '', font=BLOCK_FONT, name=Utils.encode(self.name) ) ) @@ -159,9 +163,7 @@ class Block(CoreBlock, Element): markups = [param.format_block_surface_markup() for param in self.params.values() if param.get_hide() not in ('all', 'part')] else: - markups = ['<span foreground="black" font_desc="{font}"><b>key: </b>{key}</span>'.format( - font=PARAM_FONT, key=self.key - )] + markups = ['<span font_desc="{font}"><b>key: </b>{key}</span>'.format(font=PARAM_FONT, key=self.key)] params_layout.set_spacing(LABEL_SEPARATION * Pango.SCALE) params_layout.set_markup('\n'.join(markups)) @@ -177,6 +179,7 @@ class Block(CoreBlock, Element): width = label_width + 2 * BLOCK_LABEL_PADDING height = label_height + 2 * BLOCK_LABEL_PADDING + self._update_colors() self.create_port_labels() def get_min_height_for_ports(ports): @@ -254,9 +257,9 @@ class Block(CoreBlock, Element): cr.restore() cr.rectangle(*self._area) - cr.set_source_rgb(*self._bg_color) + cr.set_source_rgba(*self._bg_color) cr.fill_preserve() - cr.set_source_rgb(*border_color) + cr.set_source_rgba(*border_color) cr.stroke() # title and params label @@ -265,6 +268,7 @@ class Block(CoreBlock, Element): cr.translate(-self.width, 0) cr.translate(*self._surface_layout_offsets) + cr.set_source_rgba(*self._font_color) for layout in self._surface_layouts: PangoCairo.update_layout(cr, layout) PangoCairo.show_layout(cr, layout) diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py index 157c07ea35..73a0f5ab5f 100644 --- a/grc/gui/Colors.py +++ b/grc/gui/Colors.py @@ -32,19 +32,11 @@ def _color_parse(color_code): def get_color(color_code): - # color = _color_parse(color_code) - # print(dir(cairo.SolidPattern)) - # cairo_pattern = cairo.SolidPattern( - # red=color.red, - # green=color.green, - # blue=color.blue, - # alpha=color.alpha - # ) - # return cairo_pattern - - chars_per_color = 2 if len(color_code) > 4 else 1 - offsets = range(1, 3 * chars_per_color + 1, chars_per_color) - return tuple(int(color_code[o:o + 2], 16) / 255.0 for o in offsets) + color = _color_parse(color_code) + return color.red, color.green, color.blue, color.alpha + # chars_per_color = 2 if len(color_code) > 4 else 1 + # offsets = range(1, 3 * chars_per_color + 1, chars_per_color) + # return tuple(int(color_code[o:o + 2], 16) / 255.0 for o in offsets) ################################################################################# # fg colors @@ -52,6 +44,8 @@ def get_color(color_code): HIGHLIGHT_COLOR = get_color('#00FFFF') BORDER_COLOR = get_color('#444444') +BORDER_COLOR_DISABLED = get_color('#888888') +FONT_COLOR = get_color('#000000') # Missing blocks stuff MISSING_BLOCK_BACKGROUND_COLOR = get_color('#FFF2F2') diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index 90a9098d77..b5238bc2a6 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -81,10 +81,11 @@ class Connection(CoreConnection, Element): connector_length = self.sink_port.connector_length + CONNECTOR_ARROW_HEIGHT self.x2, self.y2 = Utils.get_rotated_coordinate((-connector_length, 0), self.sink_port.rotation) #build the arrow - self.arrow = [(0, 0), + self._arrow_base = [ + (0, 0), Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, -CONNECTOR_ARROW_BASE/2), self.sink_port.rotation), Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT, CONNECTOR_ARROW_BASE/2), self.sink_port.rotation), - ] + ] if self.sink_block.state != 'bypassed' else [] source_domain = self.source_port.domain sink_domain = self.sink_port.domain @@ -120,7 +121,7 @@ class Connection(CoreConnection, Element): p2 = x2, y2 = self.x2 + x3, self.y2 + y3 p1 = x1, y1 = self.x1, self.y1 p0 = x_start - x_pos, y_start - y_pos - self._arrow = [(x + x3, y + y3) for x, y in self.arrow] + self._arrow = [(x + x3, y + y3) for x, y in self._arrow_base] if abs(source_dir - sink.get_connector_direction()) == 180: # 2 possible point sets to create a 3-line connector @@ -185,21 +186,22 @@ class Connection(CoreConnection, Element): cr.line_to(*point) if color1: # not a message connection - cr.set_source_rgb(*color1) + cr.set_source_rgba(*color1) cr.stroke_preserve() if color1 != color2: cr.save() cr.set_dash([5.0, 5.0], 5.0 if color1 else 0.0) - cr.set_source_rgb(*color2) + cr.set_source_rgba(*color2) cr.stroke() cr.restore() else: cr.new_path() - cr.set_source_rgb(*arrow_color) - cr.move_to(*self._arrow[0]) - cr.line_to(*self._arrow[1]) - cr.line_to(*self._arrow[2]) - cr.close_path() - cr.fill() + if self._arrow: + cr.set_source_rgba(*arrow_color) + cr.move_to(*self._arrow[0]) + cr.line_to(*self._arrow[1]) + cr.line_to(*self._arrow[2]) + cr.close_path() + cr.fill() diff --git a/grc/gui/DrawingArea.py b/grc/gui/DrawingArea.py index cc82c70c57..c729bbad24 100644 --- a/grc/gui/DrawingArea.py +++ b/grc/gui/DrawingArea.py @@ -188,7 +188,7 @@ class DrawingArea(Gtk.DrawingArea): def draw(self, widget, cr): width = widget.get_allocated_width() height = widget.get_allocated_height() - cr.set_source_rgb(*Colors.FLOWGRAPH_BACKGROUND_COLOR) + cr.set_source_rgba(*Colors.FLOWGRAPH_BACKGROUND_COLOR) cr.rectangle(0, 0, width, height) cr.scale(self.zoom_factor, self.zoom_factor) diff --git a/grc/gui/Param.py b/grc/gui/Param.py index fb62e3d9bb..ed5257ae69 100644 --- a/grc/gui/Param.py +++ b/grc/gui/Param.py @@ -67,11 +67,10 @@ class Param(_Param): hasattr(block, 'get_callbacks') and \ any(self.key in callback for callback in block._callbacks) - return '<span underline="{line}" foreground="{color}" font_desc="Sans 9">{label}</span>'.format( - line='low' if has_callback else 'none', - color='blue' if have_pending_changes else - 'black' if self.is_valid() else - 'red', + return '<span {underline} {foreground} font_desc="Sans 9">{label}</span>'.format( + underline='underline="low"' if has_callback else '', + foreground='foreground="blue"' if have_pending_changes else + 'foreground="red"' if not self.is_valid() else '', label=Utils.encode(self.name) ) @@ -157,8 +156,7 @@ class Param(_Param): Returns: a pango markup string """ - return '<span foreground="{color}" font_desc="{font}"><b>{label}:</b> {value}</span>'.format( - color='black' if self.is_valid() else 'red', font=Constants.PARAM_FONT, - label=Utils.encode(self.name), - value=Utils.encode(self.pretty_print().replace('\n', ' ')) + return '<span {foreground} font_desc="{font}"><b>{label}:</b> {value}</span>'.format( + foreground='foreground="red"' if not self.is_valid() else '', font=Constants.PARAM_FONT, + label=Utils.encode(self.name), value=Utils.encode(self.pretty_print().replace('\n', ' ')) ) diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 0c95b502fd..d995470fdb 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -44,7 +44,7 @@ class Port(_Port, Element): self.force_show_label = False self._area = [] - self._bg_color = self._border_color = 0, 0, 0 + self._bg_color = self._border_color = 0, 0, 0, 0 self._line_width_factor = 1.0 self._label_layout_offsets = 0, 0 @@ -73,7 +73,7 @@ class Port(_Port, Element): """ if not self.parent_block.enabled: self._bg_color = Colors.BLOCK_DISABLED_COLOR - self._border_color = Colors.BORDER_COLOR + self._border_color = Colors.BORDER_COLOR_DISABLED return color = Colors.PORT_TYPE_TO_COLOR.get(self.get_type()) or Colors.PORT_TYPE_TO_COLOR.get('') @@ -110,7 +110,7 @@ class Port(_Port, Element): self._update_colors() layout = self.label_layout - layout.set_markup("""<span foreground="black" font_desc="{font}">{name}</span>""".format( + layout.set_markup('<span font_desc="{font}">{name}</span>'.format( name=Utils.encode(self.name), font=Constants.PORT_FONT )) label_width, label_height = self.label_layout.get_pixel_size() @@ -132,9 +132,9 @@ class Port(_Port, Element): cr.translate(*self.coordinate) cr.rectangle(*self._area) - cr.set_source_rgb(*self._bg_color) + cr.set_source_rgba(*self._bg_color) cr.fill_preserve() - cr.set_source_rgb(*border_color) + cr.set_source_rgba(*border_color) cr.stroke() if not self._show_label: @@ -145,6 +145,7 @@ class Port(_Port, Element): cr.translate(-self.width, 0) cr.translate(*self._label_layout_offsets) + cr.set_source_rgba(*Colors.FONT_COLOR) PangoCairo.update_layout(cr, self.label_layout) PangoCairo.show_layout(cr, self.label_layout) |