[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 33/101: grc: gtk3: update block surface dra
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 33/101: grc: gtk3: update block surface draw code |
Date: |
Thu, 16 Mar 2017 14:58:02 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch python3
in repository gnuradio.
commit c01e2d0d9280bbfdec229d75f9a9186aa66f4701
Author: Sebastian Koslowski <address@hidden>
Date: Tue Jul 12 11:53:42 2016 +0200
grc: gtk3: update block surface draw code
---
grc/gui/Block.py | 113 ++++++++++++++++++++++++++++-------------------------
grc/gui/Element.py | 22 +++++------
2 files changed, 69 insertions(+), 66 deletions(-)
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 94887ee..3d60a80 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -28,7 +28,7 @@ from . import Actions, Colors, Utils
from .Constants import (
BLOCK_LABEL_PADDING, PORT_SPACING, PORT_SEPARATION, LABEL_SEPARATION,
- PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS, BLOCK_FONT, PARAM_FONT
+ PORT_BORDER_SEPARATION, BLOCK_FONT, PARAM_FONT
)
from . Element import Element
from ..core.Param import num_to_str
@@ -36,7 +36,7 @@ from ..core.utils.complexity import
calculate_flowgraph_complexity
from ..core.Block import Block as _Block
-class Block(Element, _Block):
+class Block(_Block, Element):
"""The graphical signal block."""
def __init__(self, flow_graph, n):
@@ -47,11 +47,16 @@ class Block(Element, _Block):
_Block.__init__(self, flow_graph, n)
self.states.update(_coordinate=(0, 0), _rotation=0)
- Element.__init__(self) # needs the states
-
self.W = self.H = 0
- self._param_layouts = []
+ Element.__init__(self) # needs the states and initial sizes
+
+ self._surface_layouts = [
+ Gtk.DrawingArea().create_pango_layout(''), # title
+ Gtk.DrawingArea().create_pango_layout(''), # params
+ ]
+ self._surface_layout_offsets = 0, 0
self._comment_layout = None
+
self._bg_color = Colors.BLOCK_ENABLED_COLOR
self.has_busses = [False, False] # source, sink
@@ -91,7 +96,7 @@ class Block(Element, _Block):
def set_rotation(self, rot):
"""
Set the rotation into the position param.
-q
+
Args:
rot: the rotation in degrees
"""
@@ -112,33 +117,40 @@ q
Colors.BLOCK_BYPASSED_COLOR if self.get_bypassed()
else \
Colors.BLOCK_ENABLED_COLOR if self.get_enabled() else
\
Colors.BLOCK_DISABLED_COLOR
- del self._param_layouts[:]
- #create the main layout
- layout = Gtk.DrawingArea().create_pango_layout('')
- 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,
name=Utils.encode(self.name)
- ))
- self.label_width, self.label_height = layout.get_pixel_size()
- self._param_layouts.append(layout)
- #display the params
- if self.is_dummy_block:
+
+ # 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,
+ name=Utils.encode(self.name)
+ )
+ )
+ title_width, title_height = title_layout.get_pixel_size()
+
+ # update the params layout
+ if not self.is_dummy_block:
+ 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
)]
- else:
- markups = [param.format_block_surface_markup()
- for param in self.params.values() if param.get_hide()
not in ('all', 'part')]
- if markups:
- layout = Gtk.DrawingArea().create_pango_layout('')
- layout.set_spacing(LABEL_SEPARATION*Pango.SCALE)
- layout.set_markup('\n'.join(markups))
- self._param_layouts.append(layout)
- w, h = layout.get_pixel_size()
- self.label_width = max(w, self.label_width)
- self.label_height += h + LABEL_SEPARATION
- #calculate width and height needed
- W = self.label_width + 2 * BLOCK_LABEL_PADDING
+ params_layout.set_spacing(LABEL_SEPARATION * Pango.SCALE)
+ params_layout.set_markup('\n'.join(markups))
+ params_width, params_height = params_layout.get_pixel_size() if
markups else (0, 0)
+
+ label_width = max(title_width, params_width)
+ label_height = title_height + LABEL_SEPARATION + params_height
+
+ title_layout.set_width(label_width * Pango.SCALE)
+ title_layout.set_alignment(Pango.Alignment.CENTER)
+
+ # calculate width and height needed
+ width = label_width + 2 * BLOCK_LABEL_PADDING
+ height = label_height + 2 * BLOCK_LABEL_PADDING
def get_min_height_for_ports():
visible_ports = [p for p in ports if not p.get_hide()]
@@ -146,9 +158,9 @@ q
if visible_ports:
min_height -= ports[0].H
return min_height
- H = max(
+ height = max(
[ # labels
- self.label_height + 2 * BLOCK_LABEL_PADDING
+ height
] +
[ # ports
get_min_height_for_ports() for ports in
(self.get_sources_gui(), self.get_sinks_gui())
@@ -159,7 +171,13 @@ q
for ports in (self.get_sources_gui(), self.get_sinks_gui())
]
)
- self.W, self.H = Utils.align_to_grid((W, H))
+ self.W, self.H = width, height = Utils.align_to_grid((width, height))
+
+ self._surface_layout_offsets = [
+ (width - label_width) / 2.0,
+ (height - label_height) / 2.0
+ ]
+
self.has_busses = [
any(port.get_type() == 'bus' for port in ports)
for ports in (self.get_sources_gui(), self.get_sinks_gui())
@@ -194,7 +212,6 @@ q
"""
Draw the signal block with label and inputs/outputs.
"""
- # draw main block
bg_color = self._bg_color
border_color = (
Colors.HIGHLIGHT_COLOR if self.is_highlighted() else
@@ -206,31 +223,21 @@ q
cr.save()
port.draw(widget, cr, border_color, bg_color)
cr.restore()
+
+ # draw main block
Element.draw(self, widget, cr, border_color, bg_color)
- # create the param label
- width = self.label_width
- cr.set_source_rgb(*self._bg_color)
- if self.is_horizontal():
- cr.translate(BLOCK_LABEL_PADDING, (self.H - self.label_height) / 2)
- elif self.is_vertical():
- cr.translate((self.H - self.label_height) / 2, BLOCK_LABEL_PADDING)
+ # title and params label
+ if self.is_vertical():
cr.rotate(-90 * math.pi / 180.)
- cr.translate(-width, 0)
-
- # draw the layouts
- h_off = 0
- for i, layout in enumerate(self._param_layouts):
- w, h = layout.get_pixel_size()
- if i == 0:
- w_off = (width - w) / 2
- else:
- w_off = 0
- cr.translate(w_off, h_off)
+ cr.translate(-self.W, 0)
+ cr.translate(*self._surface_layout_offsets)
+
+ for layout in self._surface_layouts:
PangoCairo.update_layout(cr, layout)
PangoCairo.show_layout(cr, layout)
- cr.translate(-w_off, -h_off)
- h_off += h + LABEL_SEPARATION
+ _, h = layout.get_pixel_size()
+ cr.translate(0, h + LABEL_SEPARATION)
def what_is_selected(self, coor, coor_m=None):
"""
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index c4d5b5e..9513b44 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -21,11 +21,7 @@ from __future__ import absolute_import
from .Constants import LINE_SELECT_SENSITIVITY
from .Constants import POSSIBLE_ROTATIONS
-import gi
from six.moves import zip
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
class Element(object):
@@ -41,12 +37,10 @@ class Element(object):
"""
self.set_rotation(POSSIBLE_ROTATIONS[0])
self.set_coordinate((0, 0))
- self.clear()
self.highlighted = False
- self.line_attributes = []
- """ # No idea where this is in pygobject
- 0, Gdk.LINE_SOLID, Gdk.CAP_BUTT, Gdk.JOIN_MITER
- ]"""
+
+ self._areas_list = []
+ self._lines_list = []
def is_horizontal(self, rotation=None):
"""
@@ -81,7 +75,8 @@ class Element(object):
Create labels (if applicable) and call on all children.
Call this base method before creating labels in the element.
"""
- for child in self.get_children():child.create_labels()
+ for child in self.get_children():
+ child.create_labels()
def create_shapes(self):
"""
@@ -89,7 +84,8 @@ class Element(object):
Call this base method before creating shapes in the element.
"""
self.clear()
- for child in self.get_children(): child.create_shapes()
+ for child in self.get_children():
+ child.create_shapes()
def draw(self, widget, cr, border_color, bg_color):
"""
@@ -131,8 +127,8 @@ class Element(object):
def clear(self):
"""Empty the lines and areas."""
- self._areas_list = list()
- self._lines_list = list()
+ del self._areas_list[:]
+ del self._lines_list[:]
def set_coordinate(self, coor):
"""
- [Commit-gnuradio] [gnuradio] 37/101: grc: refactor: fixup selection code and core connection changes, (continued)
- [Commit-gnuradio] [gnuradio] 37/101: grc: refactor: fixup selection code and core connection changes, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 22/101: grc-refactor: Block: make more public attribs, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 35/101: grc: gtk3: quick fix for file dialogs, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 41/101: grc: gtk3: fix PythonEditorParam widget, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 02/101: gtk3: add flowgraph draw code and other gtk3 fixes (WIP), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 21/101: grc-refactor: Block: remove key getters, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 31/101: grc: gtk3: refactor connection draw code, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 14/101: grc-refactor: rewrite tree-api in core, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 42/101: grc: gtk3: update main and checks, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 27/101: grc: gtk3: refactor and update draw code WIP, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 33/101: grc: gtk3: update block surface draw code,
git <=
- [Commit-gnuradio] [gnuradio] 45/101: grc: fix block init, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 38/101: grc: gtk3: update & fix port drawing code, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 32/101: grc: refactor: remote port domain getter, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 16/101: Merge remote-tracking branch 'grcwg/next_grcwg' into gtk3, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 57/101: grc: gtk3: remove left-over gtk2 usage in generator template, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 43/101: grc: refactor: minor clean-up and fixes, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 44/101: grc: gtk3: fix connection arrows, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 56/101: grc: gtk3: fix generating virtual/bypassed connections, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 46/101: grc: dynamic super-classing proof-of-concept =), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 53/101: grc: make dummy blocks a block subclass, git, 2017/03/16