diff options
Diffstat (limited to 'grc/gui/canvas')
-rw-r--r-- | grc/gui/canvas/block.py | 38 | ||||
-rw-r--r-- | grc/gui/canvas/colors.py | 8 | ||||
-rw-r--r-- | grc/gui/canvas/connection.py | 15 | ||||
-rw-r--r-- | grc/gui/canvas/flowgraph.py | 66 | ||||
-rw-r--r-- | grc/gui/canvas/param.py | 12 | ||||
-rw-r--r-- | grc/gui/canvas/port.py | 13 |
6 files changed, 93 insertions, 59 deletions
diff --git a/grc/gui/canvas/block.py b/grc/gui/canvas/block.py index a2964bd7e7..c80e2b8771 100644 --- a/grc/gui/canvas/block.py +++ b/grc/gui/canvas/block.py @@ -64,7 +64,8 @@ class Block(CoreBlock, Drawable): """ coor = Utils.scale(coor, reverse=True) if Actions.TOGGLE_SNAP_TO_GRID.get_active(): - offset_x, offset_y = (0, self.height / 2) if self.is_horizontal() else (self.height / 2, 0) + offset_x, offset_y = ( + 0, self.height / 2) if self.is_horizontal() else (self.height / 2, 0) coor = ( Utils.align_to_grid(coor[0] + offset_x) - offset_x, Utils.align_to_grid(coor[1] + offset_y) - offset_y @@ -137,8 +138,10 @@ class Block(CoreBlock, Drawable): for ports, has_busses in zip((self.active_sources, self.active_sinks), bussified): if not ports: continue - port_separation = Constants.PORT_SEPARATION if not has_busses else ports[0].height + Constants.PORT_SPACING - offset = (self.height - (len(ports) - 1) * port_separation - ports[0].height) / 2 + port_separation = Constants.PORT_SEPARATION if not has_busses else ports[ + 0].height + Constants.PORT_SPACING + offset = (self.height - (len(ports) - 1) * + port_separation - ports[0].height) / 2 for port in ports: port.create_shapes() port.coordinate = { @@ -148,7 +151,8 @@ class Block(CoreBlock, Drawable): 270: (offset, +self.width), }[port.connector_direction] - offset += Constants.PORT_SEPARATION if not has_busses else port.height + Constants.PORT_SPACING + offset += Constants.PORT_SEPARATION if not has_busses else port.height + \ + Constants.PORT_SPACING def create_labels(self, cr=None): """Create the labels for the signal block.""" @@ -178,7 +182,8 @@ class Block(CoreBlock, Drawable): markups = [param.format_block_surface_markup() for param in self.params.values() if (param.hide not in ('all', 'part') or (param.dtype == 'id' and force_show_id))] else: - markups = ['<span font_desc="{font}"><b>key: </b>{key}</span>'.format(font=Constants.PARAM_FONT, key=self.key)] + markups = ['<span font_desc="{font}"><b>key: </b>{key}</span>'.format( + font=Constants.PARAM_FONT, key=self.key)] params_layout.set_spacing(Constants.LABEL_SEPARATION * Pango.SCALE) params_layout.set_markup('\n'.join(markups)) @@ -197,12 +202,13 @@ class Block(CoreBlock, Drawable): self.create_port_labels() def get_min_height_for_ports(ports): - min_height = 2 * Constants.PORT_BORDER_SEPARATION + len(ports) * Constants.PORT_SEPARATION + min_height = 2 * Constants.PORT_BORDER_SEPARATION + \ + len(ports) * Constants.PORT_SEPARATION # If any of the ports are bus ports - make the min height larger if any([p.dtype == 'bus' for p in ports]): min_height = 2 * Constants.PORT_BORDER_SEPARATION + sum( port.height + Constants.PORT_SPACING for port in ports if port.dtype == 'bus' - ) - Constants.PORT_SPACING + ) - Constants.PORT_SPACING else: if ports: @@ -213,11 +219,13 @@ class Block(CoreBlock, Drawable): get_min_height_for_ports(self.active_sinks), get_min_height_for_ports(self.active_sources)) - self.width, self.height = width, height = Utils.align_to_grid((width, height)) + self.width, self.height = width, height = Utils.align_to_grid( + (width, height)) self._surface_layouts_offsets = [ (0, (height - label_height) / 2.0), - (0, (height - label_height) / 2.0 + Constants.LABEL_SEPARATION + title_height / Pango.SCALE) + (0, (height - label_height) / 2.0 + + Constants.LABEL_SEPARATION + title_height / Pango.SCALE) ] title_layout.set_width(width * Pango.SCALE) @@ -243,7 +251,8 @@ class Block(CoreBlock, Drawable): complexity = utils.flow_graph_complexity.calculate(self.parent) markups.append( '<span foreground="#444" size="medium" font_desc="{font}">' - '<b>Complexity: {num}bal</b></span>'.format(num=Utils.num_to_str(complexity), font=Constants.BLOCK_FONT) + '<b>Complexity: {num}bal</b></span>'.format( + num=Utils.num_to_str(complexity), font=Constants.BLOCK_FONT) ) comment = self.comment # Returns None if there are no comments if comment: @@ -303,7 +312,8 @@ class Block(CoreBlock, Drawable): for port in self.active_ports(): port_selected = port.what_is_selected( coor=[a - b for a, b in zip(coor, self.coordinate)], - coor_m=[a - b for a, b in zip(coor, self.coordinate)] if coor_m is not None else None + coor_m=[ + a - b for a, b in zip(coor, self.coordinate)] if coor_m is not None else None ) if port_selected: return port_selected @@ -359,7 +369,8 @@ class Block(CoreBlock, Drawable): true for change """ type_templates = ' '.join(p.dtype for p in self.params.values()) + ' ' - type_templates += ' '.join(p.get_raw('dtype') for p in (self.sinks + self.sources)) + type_templates += ' '.join(p.get_raw('dtype') + for p in (self.sinks + self.sources)) type_param = None for key, param in self.params.items(): if not param.is_enum(): @@ -396,7 +407,8 @@ class Block(CoreBlock, Drawable): """ changed = False # Concat the nports string from the private nports settings of all ports - nports_str = ' '.join(str(port.get_raw('multiplicity')) for port in self.ports()) + nports_str = ' '.join(str(port.get_raw('multiplicity')) + for port in self.ports()) # Modify all params whose keys appear in the nports string for key, param in self.params.items(): if param.is_enum() or param.key not in nports_str: diff --git a/grc/gui/canvas/colors.py b/grc/gui/canvas/colors.py index 2ab4933761..89f5025d0e 100644 --- a/grc/gui/canvas/colors.py +++ b/grc/gui/canvas/colors.py @@ -25,6 +25,7 @@ def get_color(color_code): # fg colors ################################################################################# + HIGHLIGHT_COLOR = get_color('#00FFFF') BORDER_COLOR = get_color('#616161') BORDER_COLOR_DISABLED = get_color('#888888') @@ -62,8 +63,10 @@ DEFAULT_DOMAIN_COLOR = get_color('#777777') # port colors ################################################################################# -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()) +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()) ################################################################################# @@ -109,4 +112,3 @@ LIGHT_THEME_STYLES = b""" #enum_custom { background-color: #EEEEEE; } """ - diff --git a/grc/gui/canvas/connection.py b/grc/gui/canvas/connection.py index 316ecbdd09..be5db73b65 100644 --- a/grc/gui/canvas/connection.py +++ b/grc/gui/canvas/connection.py @@ -73,11 +73,13 @@ class Connection(CoreConnection, Drawable): # first two components relative to source connector, rest relative to sink connector self._rel_points = [ - rotate((15, 0), source.rotation), # line from 0,0 to here, bezier curve start + # line from 0,0 to here, bezier curve start + rotate((15, 0), source.rotation), rotate((50, 0), source.rotation), # bezier curve control point 1 rotate((-50, 0), sink.rotation), # bezier curve control point 2 rotate((-15, 0), sink.rotation), # bezier curve end - rotate((-CONNECTOR_ARROW_HEIGHT, 0), sink.rotation), # line to arrow head + rotate((-CONNECTOR_ARROW_HEIGHT, 0), + sink.rotation), # line to arrow head ] self._current_coordinates = None # triggers _make_path() @@ -110,7 +112,8 @@ class Connection(CoreConnection, Drawable): # make rel_point all relative to source connector p0 = 0, 0 # x_start - x_pos, y_start - y_pos - p1, p2, (dx_e1, dy_e1), (dx_e2, dy_e2), (dx_e3, dy_e3) = self._rel_points + p1, p2, (dx_e1, dy_e1), (dx_e2, dy_e2), (dx_e3, + dy_e3) = self._rel_points p3 = x_e + dx_e1, y_e + dy_e1 p4 = x_e + dx_e2, y_e + dy_e2 p5 = x_e + dx_e3, y_e + dy_e3 @@ -137,7 +140,8 @@ class Connection(CoreConnection, Drawable): self.create_shapes() # triggers _make_path() call below self._current_port_rotations = port_rotations - new_coordinates = (source.parent_block.coordinate, sink.parent_block.coordinate) + new_coordinates = (source.parent_block.coordinate, + sink.parent_block.coordinate) if self._current_coordinates != new_coordinates: self._make_path(cr) self._current_coordinates = new_coordinates @@ -175,7 +179,7 @@ class Connection(CoreConnection, Drawable): cr.set_source_rgba(*color2) cr.rotate(self._arrow_rotation) cr.rel_move_to(CONNECTOR_ARROW_HEIGHT, 0) - cr.rel_line_to(-CONNECTOR_ARROW_HEIGHT, -CONNECTOR_ARROW_BASE/2) + cr.rel_line_to(-CONNECTOR_ARROW_HEIGHT, -CONNECTOR_ARROW_BASE / 2) cr.rel_line_to(0, CONNECTOR_ARROW_BASE) cr.close_path() cr.fill() @@ -238,4 +242,5 @@ class DummyCoreConnection(object): def has_real_sink(self): return self.sink_port is not self._dummy_port + DummyConnection = Connection.make_cls_with_base(DummyCoreConnection) diff --git a/grc/gui/canvas/flowgraph.py b/grc/gui/canvas/flowgraph.py index cb63f578ac..7c086f3641 100644 --- a/grc/gui/canvas/flowgraph.py +++ b/grc/gui/canvas/flowgraph.py @@ -125,7 +125,8 @@ class FlowGraph(CoreFlowgraph, Drawable): editor.open_editor() except Exception as e: # Problem launching the editor. Need to select a new editor. - Messages.send('>>> Error opening an external editor. Please select a different editor.\n') + Messages.send( + '>>> Error opening an external editor. Please select a different editor.\n') # Reset the editor to force the user to select a new one. self.parent_platform.config.editor = '' @@ -153,10 +154,13 @@ class FlowGraph(CoreFlowgraph, Drawable): # calculate the position coordinate h_adj = scroll_pane.get_hadjustment() v_adj = scroll_pane.get_vadjustment() - if coor is None: coor = ( - int(random.uniform(.25, .75)*h_adj.get_page_size() + h_adj.get_value()), - int(random.uniform(.25, .75)*v_adj.get_page_size() + v_adj.get_value()), - ) + if coor is None: + coor = ( + int(random.uniform(.25, .75) * + h_adj.get_page_size() + h_adj.get_value()), + int(random.uniform(.25, .75) * + v_adj.get_page_size() + v_adj.get_value()), + ) # get the new block block = self.new_block(key) block.coordinate = coor @@ -218,17 +222,17 @@ class FlowGraph(CoreFlowgraph, Drawable): Returns: the clipboard """ - #get selected blocks + # get selected blocks blocks = list(self.selected_blocks()) if not blocks: return None - #calc x and y min + # calc x and y min x_min, y_min = blocks[0].coordinate for block in blocks: x, y = block.coordinate x_min = min(x, x_min) y_min = min(y, y_min) - #get connections between selected blocks + # get connections between selected blocks connections = list(filter( lambda c: c.source_block in blocks and c.sink_block in blocks, self.connections, @@ -281,7 +285,8 @@ class FlowGraph(CoreFlowgraph, Drawable): block.move((x_off, y_off)) while any(Utils.align_to_grid(block.coordinate) == Utils.align_to_grid(other.coordinate) for other in self.blocks if other is not block): - block.move((Constants.CANVAS_GRID_SIZE, Constants.CANVAS_GRID_SIZE)) + block.move((Constants.CANVAS_GRID_SIZE, + Constants.CANVAS_GRID_SIZE)) # shift all following blocks x_off += Constants.CANVAS_GRID_SIZE y_off += Constants.CANVAS_GRID_SIZE @@ -353,15 +358,16 @@ class FlowGraph(CoreFlowgraph, Drawable): if not blocks: return - min_x, min_y = self.selected_block.coordinate + min_x, min_y = self.selected_block.coordinate for selected_block in blocks: x, y = selected_block.coordinate min_x, min_y = min(min_x, x), min(min_y, y) # Sanitize delta_coordinate so that blocks don't move to negative coordinate - delta_coordinate = max(delta_coordinate[0],-min_x), max(delta_coordinate[1], -min_y) + delta_coordinate = max( + delta_coordinate[0], -min_x), max(delta_coordinate[1], -min_y) - # Move selected blocks + # Move selected blocks for selected_block in blocks: selected_block.move(delta_coordinate) self.element_moved = True @@ -388,15 +394,15 @@ class FlowGraph(CoreFlowgraph, Drawable): x += selected_block.width y += selected_block.height max_x, max_y = max(max_x, x), max(max_y, y) - ctr_x, ctr_y = (max_x + min_x)/2, (max_y + min_y)/2 + ctr_x, ctr_y = (max_x + min_x) / 2, (max_y + min_y) / 2 # align the blocks as requested transform = { Actions.BLOCK_VALIGN_TOP: lambda x, y, w, h: (x, min_y), - Actions.BLOCK_VALIGN_MIDDLE: lambda x, y, w, h: (x, ctr_y - h/2), + Actions.BLOCK_VALIGN_MIDDLE: lambda x, y, w, h: (x, ctr_y - h / 2), Actions.BLOCK_VALIGN_BOTTOM: lambda x, y, w, h: (x, max_y - h), Actions.BLOCK_HALIGN_LEFT: lambda x, y, w, h: (min_x, y), - Actions.BLOCK_HALIGN_CENTER: lambda x, y, w, h: (ctr_x-w/2, y), + Actions.BLOCK_HALIGN_CENTER: lambda x, y, w, h: (ctr_x - w / 2, y), Actions.BLOCK_HALIGN_RIGHT: lambda x, y, w, h: (max_x - w, y), }.get(calling_action, lambda *args: args) @@ -419,21 +425,22 @@ class FlowGraph(CoreFlowgraph, Drawable): """ if not any(self.selected_blocks()): return False - #initialize min and max coordinates + # initialize min and max coordinates min_x, min_y = max_x, max_y = self.selected_block.coordinate # rotate each selected block, and find min/max coordinate for selected_block in self.selected_blocks(): selected_block.rotate(rotation) - #update the min/max coordinate + # update the min/max coordinate x, y = selected_block.coordinate min_x, min_y = min(min_x, x), min(min_y, y) max_x, max_y = max(max_x, x), max(max_y, y) - #calculate center point of selected blocks - ctr_x, ctr_y = (max_x + min_x)/2, (max_y + min_y)/2 - #rotate the blocks around the center point + # calculate center point of selected blocks + ctr_x, ctr_y = (max_x + min_x) / 2, (max_y + min_y) / 2 + # rotate the blocks around the center point for selected_block in self.selected_blocks(): x, y = selected_block.coordinate - x, y = Utils.get_rotated_coordinate((x - ctr_x, y - ctr_y), rotation) + x, y = Utils.get_rotated_coordinate( + (x - ctr_x, y - ctr_y), rotation) selected_block.coordinate = (x + ctr_x, y + ctr_y) return True @@ -496,7 +503,7 @@ class FlowGraph(CoreFlowgraph, Drawable): element.create_labels(cr) def create_shapes(self): - #TODO - this is a workaround for bus ports not having a proper coordinate + # TODO - this is a workaround for bus ports not having a proper coordinate # until the shape is drawn. The workaround is to draw blocks before connections for element in filter(lambda x: x.is_block, self._elements_to_draw): @@ -582,7 +589,8 @@ class FlowGraph(CoreFlowgraph, Drawable): else: # called from a mouse release if not self.element_moved and (not self.selected_elements or self.drawing_area.ctrl_mask) and not self._new_connection: - selected_elements = self.what_is_selected(self.coordinate, self.press_coor) + selected_elements = self.what_is_selected( + self.coordinate, self.press_coor) # this selection and the last were ports, try to connect them if self.make_connection(): @@ -635,7 +643,8 @@ class FlowGraph(CoreFlowgraph, Drawable): if selected_port and selected_port.is_source: selected.remove(selected_port.parent_block) - self._new_connection = DummyConnection(selected_port, coordinate=coor) + self._new_connection = DummyConnection( + selected_port, coordinate=coor) self.drawing_area.queue_draw() # update selected ports if selected_port is not self._new_selected_port: @@ -806,19 +815,21 @@ class FlowGraph(CoreFlowgraph, Drawable): dX, dY = x - X, y - Y if Actions.TOGGLE_SNAP_TO_GRID.get_active() or self.drawing_area.mod1_mask: - dX, dY = int(round(dX / Constants.CANVAS_GRID_SIZE)), int(round(dY / Constants.CANVAS_GRID_SIZE)) + dX, dY = int(round(dX / Constants.CANVAS_GRID_SIZE) + ), int(round(dY / Constants.CANVAS_GRID_SIZE)) dX, dY = dX * Constants.CANVAS_GRID_SIZE, dY * Constants.CANVAS_GRID_SIZE else: dX, dY = int(round(dX)), int(round(dY)) if dX != 0 or dY != 0: self.move_selected((dX, dY)) - self.coordinate = (X+dX, Y+dY) + self.coordinate = (X + dX, Y + dY) redraw = True return redraw def get_extents(self): show_comments = Actions.TOGGLE_SHOW_BLOCK_COMMENTS.get_active() + def sub_extents(): for element in self._elements_to_draw: yield element.get_extents() @@ -828,5 +839,6 @@ class FlowGraph(CoreFlowgraph, Drawable): extent = 10000000, 10000000, 0, 0 cmps = (min, min, max, max) for sub_extent in sub_extents(): - extent = [cmp(xy, e_xy) for cmp, xy, e_xy in zip(cmps, extent, sub_extent)] + extent = [cmp(xy, e_xy) + for cmp, xy, e_xy in zip(cmps, extent, sub_extent)] return tuple(extent) diff --git a/grc/gui/canvas/param.py b/grc/gui/canvas/param.py index 6b33ef223c..488ca7a5c3 100644 --- a/grc/gui/canvas/param.py +++ b/grc/gui/canvas/param.py @@ -86,20 +86,20 @@ class Param(CoreParam): tooltip_lines.extend(' * ' + msg for msg in errors) return '\n'.join(tooltip_lines) - - ################################################## # Truncate helper method ################################################## + def truncate(self, string, style=0): max_len = max(27 - len(self.name), 3) if len(string) > max_len: if style < 0: # Front truncate - string = '...' + string[3-max_len:] + string = '...' + string[3 - max_len:] elif style == 0: # Center truncate - string = string[:max_len//2 - 3] + '...' + string[-max_len//2:] + string = string[:max_len // 2 - 3] + \ + '...' + string[-max_len // 2:] elif style > 0: # Rear truncate - string = string[:max_len-3] + '...' + string = string[:max_len - 3] + '...' return string def pretty_print(self): @@ -183,5 +183,5 @@ class Param(CoreParam): display_value = expr_string 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, + foreground='foreground="red"' if not self.is_valid() else '', font=Constants.PARAM_FONT, label=Utils.encode(self.name), value=display_value) diff --git a/grc/gui/canvas/port.py b/grc/gui/canvas/port.py index d963964cdc..f78fd62179 100644 --- a/grc/gui/canvas/port.py +++ b/grc/gui/canvas/port.py @@ -68,9 +68,11 @@ class Port(CorePort, Drawable): color = colors.PORT_TYPE_TO_COLOR.get('message') else: self._font_color[-1] = 1.0 - color = colors.PORT_TYPE_TO_COLOR.get(self.dtype) or colors.PORT_TYPE_TO_COLOR.get('') + color = colors.PORT_TYPE_TO_COLOR.get( + self.dtype) or colors.PORT_TYPE_TO_COLOR.get('') if self.vlen > 1: - dark = (0, 0, 30 / 255.0, 50 / 255.0, 70 / 255.0)[min(4, self.vlen)] + dark = (0, 0, 30 / 255.0, 50 / 255.0, + 70 / 255.0)[min(4, self.vlen)] color = tuple(max(c - dark, 0) for c in color) self._bg_color = color self._border_color = tuple(max(c - 0.3, 0) for c in color) @@ -84,8 +86,8 @@ class Port(CorePort, Drawable): self.bounds_from_area(self._area) self._connector_coordinate = { - 0: (self.width, self.height / 2), - 90: (self.height / 2, 0), + 0: (self.width, self.height / 2), + 90: (self.height / 2, 0), 180: (0, self.height / 2), 270: (self.height / 2, self.width) }[self.connector_direction] @@ -112,7 +114,8 @@ class Port(CorePort, Drawable): label_width, label_height = self.label_layout.get_size() self.width = 2 * Constants.PORT_LABEL_PADDING + label_width / Pango.SCALE - self.height = (2 * Constants.PORT_LABEL_PADDING + label_height*(3 if self.dtype == 'bus' else 1)) / Pango.SCALE + self.height = (2 * Constants.PORT_LABEL_PADDING + label_height * + (3 if self.dtype == 'bus' else 1)) / Pango.SCALE self._label_layout_offsets = [0, Constants.PORT_LABEL_PADDING] self.height += self.height % 2 # uneven height |