diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Colors.py | 39 | ||||
-rw-r--r-- | grc/gui/Connection.py | 20 | ||||
-rw-r--r-- | grc/gui/Dialogs.py | 4 | ||||
-rw-r--r-- | grc/gui/Port.py | 65 |
4 files changed, 80 insertions, 48 deletions
diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py index 6ee31e5e18..157c07ea35 100644 --- a/grc/gui/Colors.py +++ b/grc/gui/Colors.py @@ -19,12 +19,37 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA from __future__ import absolute_import +from gi.repository import Gdk, cairo +# import pycairo + +from . import Constants + + +def _color_parse(color_code): + color = Gdk.RGBA() + color.parse(color_code) + return color + 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) +################################################################################# +# fg colors +################################################################################# + HIGHLIGHT_COLOR = get_color('#00FFFF') BORDER_COLOR = get_color('#444444') @@ -49,18 +74,18 @@ CONNECTION_ERROR_COLOR = get_color('#FF0000') DEFAULT_DOMAIN_COLOR = get_color('#777777') + ################################################################################# -# param box colors +# port colors ################################################################################# -from gi.repository import Gdk +PORT_TYPE_TO_COLOR = {key: get_color(color) for name, key, sizeof, color in Constants.CORE_TYPES} +PORT_TYPE_TO_COLOR.update((key, get_color(color)) for key, (_, color) in Constants.ALIAS_TYPES.items()) -def _color_parse(color_code): - color = Gdk.RGBA() - color.parse(color_code) - return color - +################################################################################# +# param box colors +################################################################################# COMPLEX_COLOR_SPEC = _color_parse('#3399FF') FLOAT_COLOR_SPEC = _color_parse('#FF8C69') INT_COLOR_SPEC = _color_parse('#00FF99') diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index d893060aa6..b1a22e3949 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -45,6 +45,9 @@ class Connection(Element, _Connection): # can't use Colors.CONNECTION_ENABLED_COLOR here, might not be defined (grcc) self._bg_color = self._arrow_color = self._color = None + self._sink_rot = self._source_rot = None + self._sink_coor = self._source_coor = None + def get_coordinate(self): """ Get the 0,0 coordinate. @@ -74,12 +77,12 @@ class Connection(Element, _Connection): self._source_coor = None #get the source coordinate try: - connector_length = self.source_port.get_connector_length() + connector_length = self.source_port.connector_length except: - return + return # todo: why? self.x1, self.y1 = Utils.get_rotated_coordinate((connector_length, 0), self.source_port.get_rotation()) #get the sink coordinate - connector_length = self.sink_port.get_connector_length() + CONNECTOR_ARROW_HEIGHT + connector_length = self.sink_port.connector_length + CONNECTOR_ARROW_HEIGHT self.x2, self.y2 = Utils.get_rotated_coordinate((-connector_length, 0), self.sink_port.get_rotation()) #build the arrow self.arrow = [(0, 0), @@ -106,7 +109,7 @@ class Connection(Element, _Connection): def _update_after_move(self): """Calculate coordinates.""" - self.clear() #FIXME do i want this here? + self.clear() #source connector source = self.source_port X, Y = source.get_connector_coordinate() @@ -118,11 +121,11 @@ class Connection(Element, _Connection): x2, y2 = self.x2 + X, self.y2 + Y self.add_line((x2, y2), (X, Y)) #adjust arrow - self._arrow = [(x+X, y+Y) for x,y in self.arrow] + self._arrow = [(x+X, y+Y) for x, y in self.arrow] #add the horizontal and vertical lines in this connection if abs(source.get_connector_direction() - sink.get_connector_direction()) == 180: #2 possible point sets to create a 3-line connector - mid_x, mid_y = (x1 + x2)/2.0, (y1 + y2)/2.0 + mid_x, mid_y = (x1 + x2) / 2.0, (y1 + y2) / 2.0 points = [((mid_x, y1), (mid_x, y2)), ((x1, mid_y), (x2, mid_y))] #source connector -> points[0][0] should be in the direction of source (if possible) if Utils.get_angle_from_coordinates((x1, y1), points[0][0]) != source.get_connector_direction(): points.reverse() @@ -155,12 +158,13 @@ class Connection(Element, _Connection): sink = self.sink_port source = self.source_port #check for changes - if self._sink_rot != sink.get_rotation() or self._source_rot != source.get_rotation(): self.create_shapes() + 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(): try: self._update_after_move() except: - return + return # todo: why? #cache values self._sink_rot = sink.get_rotation() self._source_rot = source.get_rotation() diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py index 8f0f60d764..da271fe46e 100644 --- a/grc/gui/Dialogs.py +++ b/grc/gui/Dialogs.py @@ -27,7 +27,7 @@ from gi.repository import GObject import sys from distutils.spawn import find_executable -from . import Utils, Actions +from . import Utils, Actions, Constants from ..core import Messages @@ -207,7 +207,7 @@ def HelpDialog(): MessageDialogHelper( def TypesDialog(platform): - colors = platform.get_colors() + colors = [(name, color) for name, key, sizeof, color in Constants.CORE_TYPES] max_len = 10 + max(len(name) for name, code in colors) message = '\n'.join( diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 8c4500f960..62086c76e4 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -23,15 +23,10 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, PangoCairo -from . import Actions, Colors, Utils -from .Constants import ( - PORT_SEPARATION, PORT_SPACING, CONNECTOR_EXTENSION_MINIMAL, - CONNECTOR_EXTENSION_INCREMENT, PORT_LABEL_PADDING, PORT_MIN_WIDTH, - PORT_LABEL_HIDDEN_WIDTH, PORT_FONT -) +from . import Actions, Colors, Utils, Constants from .Element import Element -from ..core.Constants import DEFAULT_DOMAIN, GR_MESSAGE_DOMAIN +from ..core.Constants import DEFAULT_DOMAIN, GR_MESSAGE_DOMAIN from ..core.Port import Port as _Port @@ -45,24 +40,42 @@ class Port(_Port, Element): """ _Port.__init__(self, block, n, dir) Element.__init__(self) - self.W = self.w = self.h = 0 - self.H = 20 # todo: fix self._connector_coordinate = (0, 0) - self._connector_length = 0 self._hovering = True self._force_label_unhidden = False + self._bg_color = (0, 0, 0) + + self.W = self.w = self.h = 0 + self.H = 20 # todo: fix + self.connector_length = 0 + self.layout = Gtk.DrawingArea().create_pango_layout('') - self._bg_color = Colors.get_color(self.get_color()) + + def _get_color(self): + """ + Get the color that represents this port's type. + Codes differ for ports where the vec length is 1 or greater than 1. + + Returns: + a hex color code. + """ + color = Colors.PORT_TYPE_TO_COLOR[self.get_type()] + vlen = self.get_vlen() + if vlen > 1: + dark = (0, 0, 30 / 255.0, 50 / 255.0, 70 / 255.0)[min(4, vlen)] + color = tuple(max(c - dark, 0) for c in color) + return color def create_shapes(self): """Create new areas and labels for the port.""" Element.create_shapes(self) - self._bg_color = Colors.get_color(self.get_color()) + self._bg_color = self._get_color() + if self.get_hide(): return # this port is hidden, no need to create shapes - if self.get_domain() == GR_MESSAGE_DOMAIN: + if self.get_domain() == Constants.GR_MESSAGE_DOMAIN: pass - elif self.get_domain() != DEFAULT_DOMAIN: + elif self.get_domain() != Constants.DEFAULT_DOMAIN: self.line_attributes[0] = 2 #get current rotation rotation = self.get_rotation() @@ -71,22 +84,22 @@ class Port(_Port, Element): if self.is_source else self.parent.get_sinks_gui() ports = [p for p in ports if not p.get_hide()] #get the max width - self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH]) - W = self.W if not self._label_hidden() else PORT_LABEL_HIDDEN_WIDTH + self.W = max([port.W for port in ports] + [Constants.PORT_MIN_WIDTH]) + W = self.W if not self._label_hidden() else Constants.PORT_LABEL_HIDDEN_WIDTH #get a numeric index for this port relative to its sibling ports try: index = ports.index(self) except: if hasattr(self, '_connector_length'): - del self._connector_length + del self.connector_length return #reverse the order of ports for these rotations if rotation in (180, 270): index = len(ports)-index-1 - port_separation = PORT_SEPARATION \ + port_separation = Constants.PORT_SEPARATION \ if not self.parent.has_busses[self.is_source] \ - else max([port.H for port in ports]) + PORT_SPACING + else max([port.H for port in ports]) + Constants.PORT_SPACING offset = (self.parent.H - (len(ports)-1)*port_separation - self.H)/2 #create areas and connector coordinates @@ -111,12 +124,12 @@ class Port(_Port, Element): self.add_area((x, y), (self.H, W)) self._connector_coordinate = (x+self.H/2, y+1+W) #the connector length - self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index + self.connector_length = Constants.CONNECTOR_EXTENSION_MINIMAL + Constants.CONNECTOR_EXTENSION_INCREMENT * index def create_labels(self): """Create the labels for the socket.""" self.layout.set_markup("""<span foreground="black" font_desc="{font}">{name}</span>""".format( - name=Utils.encode(self.get_name()), font=PORT_FONT + name=Utils.encode(self.get_name()), font=Constants.PORT_FONT )) def draw(self, widget, cr): @@ -169,16 +182,6 @@ class Port(_Port, Element): if self.is_source: return self.get_rotation() elif self.is_sink: return (self.get_rotation() + 180)%360 - def get_connector_length(self): - """ - Get the length of the connector. - The connector length increases as the port index changes. - - Returns: - the length in pixels - """ - return self._connector_length - def get_rotation(self): """ Get the parent's rotation rather than self. |