[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 16/22: grc: add domain property color and u
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 16/22: grc: add domain property color and use it for connections |
Date: |
Tue, 23 Dec 2014 09:38:58 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 20c71cb44a6f7500e64a8e9e394e9e1b372aa46d
Author: Sebastian Koslowski <address@hidden>
Date: Fri Dec 12 17:27:42 2014 +0100
grc: add domain property color and use it for connections
---
grc/base/Platform.py | 17 ++++++++++++++++-
grc/base/domain.dtd | 3 ++-
grc/blocks/gr_stream_domain.xml | 1 +
grc/gui/Colors.py | 4 +++-
grc/gui/Connection.py | 42 +++++++++++++++++++++++++++--------------
grc/gui/Element.py | 1 +
6 files changed, 51 insertions(+), 17 deletions(-)
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 75b4901..5fd86ba 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -100,7 +100,7 @@ class Platform(_Element):
# print >> sys.stderr, 'Warning: Block validation
failed:\n\t%s\n\tIgnoring: %s' % (e, xml_file)
pass
except Exception as e:
- print >> sys.stderr, 'Warning: Block loading
failed:\n\t%s\n\tIgnoring: %s' % (e, xml_file)
+ print >> sys.stderr, 'Warning: XML parsing
failed:\n\t%s\n\tIgnoring: %s' % (e, xml_file)
def iter_xml_files(self):
"""Iterator for block descriptions and category trees"""
@@ -139,16 +139,31 @@ class Platform(_Element):
n = ParseXML.from_file(xml_file).find('domain')
key = n.find('key')
+ if not key:
+ print >> sys.stderr, 'Warning: Domain with emtpy key.\n\tIgnoring:
%s' % xml_file
+ return
if key in self.get_domains(): # test against repeated keys
print >> sys.stderr, 'Warning: Domain with key "%s" already
exists.\n\tIgnoring: %s' % (key, xml_file)
return
to_bool = lambda s, d: d if s is None else \
s.lower() not in ('false', 'off', '0', '')
+
+ color_code = n.find('color') or ''
+ try:
+ import gtk # ugly, but handy
+ color = gtk.gdk.color_parse(color_code)
+ except (ValueError, ImportError):
+ if color_code: # no color is okay
+ print >> sys.stderr, 'Warning: Can\'t parse color code "%s" ' \
+ 'for domain "%s" ' % (key,
str(color_code))
+ color = None # default color set in gui
+
self._domains[key] = dict(
name=n.find('name') or key,
multiple_sinks=to_bool(n.find('multiple_sinks'), True),
multiple_sources=to_bool(n.find('multiple_sources'), False),
+ color=color
)
for connection_n in n.findall('connection'):
source_domain = connection_n.find('source_domain') or
DEFAULT_DOMAIN
diff --git a/grc/base/domain.dtd b/grc/base/domain.dtd
index 1dc2959..b5b0b8b 100644
--- a/grc/base/domain.dtd
+++ b/grc/base/domain.dtd
@@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public
License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-->
-<!ELEMENT domain (name, key, multiple_sinks?, multiple_sources?, connection*)>
+<!ELEMENT domain (name, key, color?, multiple_sinks?, multiple_sources?,
connection*)>
<!--
Sub level elements.
-->
@@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA
<!ELEMENT key (#PCDATA)>
<!ELEMENT multiple_sinks (#PCDATA)>
<!ELEMENT multiple_sources (#PCDATA)>
+<!ELEMENT color (#PCDATA)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT source_domain (#PCDATA)>
<!ELEMENT sink_domain (#PCDATA)>
diff --git a/grc/blocks/gr_stream_domain.xml b/grc/blocks/gr_stream_domain.xml
index 047f4a2..6602644 100644
--- a/grc/blocks/gr_stream_domain.xml
+++ b/grc/blocks/gr_stream_domain.xml
@@ -7,6 +7,7 @@
<domain>
<name>GR Stream</name>
<key>gr_stream</key>
+ <color>#000</color>
<connection>
<source_domain>gr_stream</source_domain>
<sink_domain>gr_stream</sink_domain>
diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py
index 541d8db..fcde5c5 100644
--- a/grc/gui/Colors.py
+++ b/grc/gui/Colors.py
@@ -25,7 +25,7 @@ try:
def get_color(color_code): return _COLORMAP.alloc_color(color_code, True,
True)
HIGHLIGHT_COLOR = get_color('#00FFFF')
- BORDER_COLOR = get_color('black')
+ BORDER_COLOR = get_color('#444444')
# missing blocks stuff
MISSING_BLOCK_BACKGROUND_COLOR = get_color('#FFF2F2')
MISSING_BLOCK_BORDER_COLOR = get_color('red')
@@ -41,5 +41,7 @@ try:
CONNECTION_ENABLED_COLOR = get_color('black')
CONNECTION_DISABLED_COLOR = get_color('#999999')
CONNECTION_ERROR_COLOR = get_color('red')
+
+ DEFAULT_DOMAIN_COLOR = get_color('#666666')
except:
print 'Unable to import Colors'
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index e8e925c..9655c0e 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -35,7 +35,10 @@ class Connection(Element):
The arrow coloring exposes the enabled and valid states.
"""
- def __init__(self): Element.__init__(self)
+ def __init__(self):
+ Element.__init__(self)
+ self._color = Colors.CONNECTION_ENABLED_COLOR
+ self._bg_color = Colors.CONNECTION_ENABLED_COLOR
def get_coordinate(self):
"""
@@ -78,21 +81,25 @@ class Connection(Element):
Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT,
-CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()),
Utils.get_rotated_coordinate((-CONNECTOR_ARROW_HEIGHT,
CONNECTOR_ARROW_BASE/2), self.get_sink().get_rotation()),
]
- self._update_after_move()
- if not self.get_enabled():
- self._arrow_color = Colors.CONNECTION_DISABLED_COLOR
- elif not self.is_valid():
- self._arrow_color = Colors.CONNECTION_ERROR_COLOR
+ source_domain = self.get_source().get_domain()
+ sink_domain = self.get_sink().get_domain()
+ if source_domain == GR_MESSAGE_DOMAIN:
+ self.line_attributes[1] = gtk.gdk.LINE_ON_OFF_DASH
else:
- self._arrow_color = Colors.CONNECTION_ENABLED_COLOR
+ self.line_attributes[1] = gtk.gdk.LINE_DOUBLE_DASH
+ get_domain_color = lambda d: (
+ self.get_parent().get_parent().get_domain(d) or {}
+ ).get('color') or Colors.DEFAULT_DOMAIN_COLOR
+ self._color = get_domain_color(source_domain)
+ self._bg_color = get_domain_color(sink_domain)
+
+ self._update_after_move()
def _update_after_move(self):
"""Calculate coordinates."""
self.clear() #FIXME do i want this here?
#source connector
source = self.get_source()
- if source.get_domain() == GR_MESSAGE_DOMAIN:
- self.line_attributes[1] = gtk.gdk.LINE_ON_OFF_DASH
X, Y = source.get_connector_coordinate()
x1, y1 = self.x1 + X, self.y1 + Y
self.add_line((x1, y1), (X, Y))
@@ -155,14 +162,21 @@ class Connection(Element):
self._sink_coor = sink.get_coordinate()
self._source_coor = source.get_coordinate()
#draw
- 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
+ border_color = (
+ Colors.HIGHLIGHT_COLOR if self.is_highlighted() else
+ Colors.CONNECTION_DISABLED_COLOR if not self.get_enabled() else
+ self._color
+ )
+ bg_color = (
+ Colors.HIGHLIGHT_COLOR if self.is_highlighted() else
+ Colors.CONNECTION_DISABLED_COLOR if not self.get_enabled() else
+ self._bg_color
+ )
# make message connections dashed (no areas here)
- Element.draw(self, gc, window, bg_color=None,
border_color=border_color)
+ Element.draw(self, gc, window, border_color, bg_color)
#draw arrow on sink port
try:
- gc.set_foreground(self._arrow_color)
+ gc.set_foreground(bg_color)
gc.set_line_attributes(0, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT,
gtk.gdk.JOIN_MITER)
window.draw_polygon(gc, True, self._arrow)
except:
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 67e8e10..18fb321 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -106,6 +106,7 @@ class Element(object):
window.draw_rectangle(gc, False, aX, aY, W, H)
for (x1, y1), (x2, y2) in self._lines_list:
gc.set_foreground(border_color)
+ gc.set_background(bg_color)
window.draw_line(gc, X+x1, Y+y1, X+x2, Y+y2)
def rotate(self, rotation):
- [Commit-gnuradio] [gnuradio] branch master updated (3427a66 -> 2402ccc), git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 07/22: grc: per element line styles (for custom domain ports and message connections), git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 08/22: grc: add gr_message domain, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 12/22: grc: port connections by domain, block name in generated code, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 10/22: grc: add multiple_sources flag to domain.dtd, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 13/22: runtime: whitespace fixes, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 15/22: runtime: add tests for new decorators in hier_block2, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 14/22: runtime: refactor top/hier block python wrappers, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 17/22: grc: fix connections error log and color, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 11/22: grc: PEP8 fixes in Generator, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 16/22: grc: add domain property color and use it for connections,
git <=
- [Commit-gnuradio] [gnuradio] 06/22: grc: domain-specific port keys, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 09/22: grc: make Generator use gr_message domain, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 03/22: grc: draw ports with custom domain differently, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 22/22: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 04/22: grc: don't fail for unknown domains, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 19/22: Merge branch 'port_domains' into master_grcwg, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 05/22: grc: use domain connection templates in Generator, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 21/22: Merge remote-tracking branch 'skoslowski/msg_connect_extended', git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 18/22: grc: port domain code clean-up, git, 2014/12/23
- [Commit-gnuradio] [gnuradio] 20/22: Merge branch 'maint', git, 2014/12/23