[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/101: grc-refactor: move param entry colo
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/101: grc-refactor: move param entry colors spec in gui package |
Date: |
Thu, 16 Mar 2017 14:57:56 +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 498715deea12451bd271d20b51c02f01530acd14
Author: Sebastian Koslowski <address@hidden>
Date: Fri May 27 15:11:29 2016 +0200
grc-refactor: move param entry colors spec in gui package
---
grc/core/Constants.py | 19 +-------
grc/core/Param.py | 32 -------------
grc/gui/Colors.py | 125 +++++++++++++++++++++++++++++++++-----------------
grc/gui/Param.py | 68 ++++++---------------------
4 files changed, 100 insertions(+), 144 deletions(-)
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index 462049c..4f278bb 100644
--- a/grc/core/Constants.py
+++ b/grc/core/Constants.py
@@ -70,8 +70,8 @@ COMPLEX_TYPES = tuple(COMPLEX_TYPES + REAL_TYPES + INT_TYPES)
REAL_TYPES = tuple(REAL_TYPES + INT_TYPES)
INT_TYPES = tuple(INT_TYPES)
-# Updating colors. Using the standard color pallette from:
-# http://www.google.com/design/spec/style/color.html#color-color-palette
+# Updating colors. Using the standard color palette from:
+# http://www.google.com/design/spec/style/color.html#color-color-palette
# Most are based on the main, primary color standard. Some are within
# that color's spectrum when it was deemed necessary.
GRC_COLOR_BROWN = '#795548'
@@ -132,18 +132,3 @@ for name, key, sizeof, color in CORE_TYPES:
for key, (sizeof, color) in ALIAS_TYPES.iteritems():
TYPE_TO_COLOR[key] = color
TYPE_TO_SIZEOF[key] = sizeof
-
-# Coloring
-COMPLEX_COLOR_SPEC = '#3399FF'
-FLOAT_COLOR_SPEC = '#FF8C69'
-INT_COLOR_SPEC = '#00FF99'
-SHORT_COLOR_SPEC = '#FFFF66'
-BYTE_COLOR_SPEC = '#FF66FF'
-COMPLEX_VECTOR_COLOR_SPEC = '#3399AA'
-FLOAT_VECTOR_COLOR_SPEC = '#CC8C69'
-INT_VECTOR_COLOR_SPEC = '#00CC99'
-SHORT_VECTOR_COLOR_SPEC = '#CCCC33'
-BYTE_VECTOR_COLOR_SPEC = '#CC66CC'
-ID_COLOR_SPEC = '#DDDDDD'
-WILDCARD_COLOR_SPEC = '#FFFFFF'
-MSG_COLOR_SPEC = '#777777'
diff --git a/grc/core/Param.py b/grc/core/Param.py
index d155800..73d54b6 100644
--- a/grc/core/Param.py
+++ b/grc/core/Param.py
@@ -292,38 +292,6 @@ class Param(Element):
def __str__(self):
return 'Param - {}({})'.format(self.get_name(), self.get_key())
- def get_color(self):
- """
- Get the color that represents this param's type.
-
- Returns:
- a hex color code.
- """
- try:
- return {
- # Number types
- 'complex': Constants.COMPLEX_COLOR_SPEC,
- 'real': Constants.FLOAT_COLOR_SPEC,
- 'float': Constants.FLOAT_COLOR_SPEC,
- 'int': Constants.INT_COLOR_SPEC,
- # Vector types
- 'complex_vector': Constants.COMPLEX_VECTOR_COLOR_SPEC,
- 'real_vector': Constants.FLOAT_VECTOR_COLOR_SPEC,
- 'float_vector': Constants.FLOAT_VECTOR_COLOR_SPEC,
- 'int_vector': Constants.INT_VECTOR_COLOR_SPEC,
- # Special
- 'bool': Constants.INT_COLOR_SPEC,
- 'hex': Constants.INT_COLOR_SPEC,
- 'string': Constants.BYTE_VECTOR_COLOR_SPEC,
- 'id': Constants.ID_COLOR_SPEC,
- 'stream_id': Constants.ID_COLOR_SPEC,
- 'grid_pos': Constants.INT_VECTOR_COLOR_SPEC,
- 'notebook': Constants.INT_VECTOR_COLOR_SPEC,
- 'raw': Constants.WILDCARD_COLOR_SPEC,
- }[self.get_type()]
- except:
- return '#FFFFFF'
-
def get_hide(self):
"""
Get the hide value from the base class.
diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py
index 686b378..a03a7bc 100644
--- a/grc/gui/Colors.py
+++ b/grc/gui/Colors.py
@@ -17,45 +17,86 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-try:
- import gi
- gi.require_version('Gtk', '3.0')
- from gi.repository import Gdk
-
- # Not gtk3?
- #COLORMAP = Gdk.colormap_get_system() #create all of the colors
- #def get_color(color_code): return _COLORMAP.alloc_color(color_code, True,
True)
-
- def get_color(color_code):
- 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)
-
- HIGHLIGHT_COLOR = get_color('#00FFFF')
- BORDER_COLOR = get_color('#444444')
-
- # Missing blocks stuff
- MISSING_BLOCK_BACKGROUND_COLOR = get_color('#FFF2F2')
- MISSING_BLOCK_BORDER_COLOR = get_color('#FF0000')
-
- # Param entry boxes
- PARAM_ENTRY_TEXT_COLOR = get_color('#000000')
- ENTRYENUM_CUSTOM_COLOR = get_color('#EEEEEE')
-
- # Flow graph color constants
- FLOWGRAPH_BACKGROUND_COLOR = get_color('#FFFFFF')
- COMMENT_BACKGROUND_COLOR = get_color('#F3F3F3')
- FLOWGRAPH_EDGE_COLOR = COMMENT_BACKGROUND_COLOR
-
- # Block color constants
- BLOCK_ENABLED_COLOR = get_color('#F1ECFF')
- BLOCK_DISABLED_COLOR = get_color('#CCCCCC')
- BLOCK_BYPASSED_COLOR = get_color('#F4FF81')
-
- # Connection color constants
- CONNECTION_ENABLED_COLOR = get_color('#000000')
- CONNECTION_DISABLED_COLOR = get_color('#BBBBBB')
- CONNECTION_ERROR_COLOR = get_color('#FF0000')
-
-except Exception as e:
- print 'Unable to import Colors', e
+
+
+def get_color(color_code):
+ 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)
+
+HIGHLIGHT_COLOR = get_color('#00FFFF')
+BORDER_COLOR = get_color('#444444')
+
+# Missing blocks stuff
+MISSING_BLOCK_BACKGROUND_COLOR = get_color('#FFF2F2')
+MISSING_BLOCK_BORDER_COLOR = get_color('#FF0000')
+
+# Flow graph color constants
+FLOWGRAPH_BACKGROUND_COLOR = get_color('#FFFFFF')
+COMMENT_BACKGROUND_COLOR = get_color('#F3F3F3')
+FLOWGRAPH_EDGE_COLOR = COMMENT_BACKGROUND_COLOR
+
+# Block color constants
+BLOCK_ENABLED_COLOR = get_color('#F1ECFF')
+BLOCK_DISABLED_COLOR = get_color('#CCCCCC')
+BLOCK_BYPASSED_COLOR = get_color('#F4FF81')
+
+# Connection color constants
+CONNECTION_ENABLED_COLOR = get_color('#000000')
+CONNECTION_DISABLED_COLOR = get_color('#BBBBBB')
+CONNECTION_ERROR_COLOR = get_color('#FF0000')
+
+#################################################################################
+# param box colors
+#################################################################################
+
+from gi.repository import Gdk
+
+
+def _color_parse(color_code):
+ color = Gdk.RGBA()
+ color.parse(color_code)
+ return color
+
+COMPLEX_COLOR_SPEC = _color_parse('#3399FF')
+FLOAT_COLOR_SPEC = _color_parse('#FF8C69')
+INT_COLOR_SPEC = _color_parse('#00FF99')
+SHORT_COLOR_SPEC = _color_parse('#FFFF66')
+BYTE_COLOR_SPEC = _color_parse('#FF66FF')
+
+ID_COLOR_SPEC = _color_parse('#DDDDDD')
+WILDCARD_COLOR_SPEC = _color_parse('#FFFFFF')
+
+COMPLEX_VECTOR_COLOR_SPEC = _color_parse('#3399AA')
+FLOAT_VECTOR_COLOR_SPEC = _color_parse('#CC8C69')
+INT_VECTOR_COLOR_SPEC = _color_parse('#00CC99')
+SHORT_VECTOR_COLOR_SPEC = _color_parse('#CCCC33')
+BYTE_VECTOR_COLOR_SPEC = _color_parse('#CC66CC')
+
+PARAM_ENTRY_COLORS = {
+
+ # Number types
+ 'complex': COMPLEX_COLOR_SPEC,
+ 'real': FLOAT_COLOR_SPEC,
+ 'float': FLOAT_COLOR_SPEC,
+ 'int': INT_COLOR_SPEC,
+
+ # Vector types
+ 'complex_vector': COMPLEX_VECTOR_COLOR_SPEC,
+ 'real_vector': FLOAT_VECTOR_COLOR_SPEC,
+ 'float_vector': FLOAT_VECTOR_COLOR_SPEC,
+ 'int_vector': INT_VECTOR_COLOR_SPEC,
+
+ # Special
+ 'bool': INT_COLOR_SPEC,
+ 'hex': INT_COLOR_SPEC,
+ 'string': BYTE_VECTOR_COLOR_SPEC,
+ 'id': ID_COLOR_SPEC,
+ 'stream_id': ID_COLOR_SPEC,
+ 'grid_pos': INT_VECTOR_COLOR_SPEC,
+ 'notebook': INT_VECTOR_COLOR_SPEC,
+ 'raw': WILDCARD_COLOR_SPEC,
+}
+
+PARAM_ENTRY_DEFAULT_COLOR = _color_parse('#FFFFFF')
+PARAM_ENTRY_ENUM_CUSTOM_COLOR = _color_parse('#EEEEEE')
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index a0ca6b6..1c5b0c9 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -76,7 +76,10 @@ class InputParam(Gtk.HBox):
'red',
label=Utils.encode(self.param.get_name())
))
- self.set_color(self.param.get_color())
+
+ self.set_color(Colors.PARAM_ENTRY_COLORS.get(
+ self.param.get_type(), Colors.PARAM_ENTRY_DEFAULT_COLOR)
+ )
errors = param.get_error_messages()
tooltip_lines = ['Key: ' + param.get_key(), 'Type: ' +
param.get_type()]
@@ -149,19 +152,7 @@ class EntryParam(InputParam):
return self._input.get_text()
def set_color(self, color):
- need_status_color = self.label not in self.get_children()
- text_color = (
- Colors.PARAM_ENTRY_TEXT_COLOR if not need_status_color else
- Gtk.gdk.color_parse('blue') if self._have_pending_changes else
- Gtk.gdk.color_parse('red') if not self.param.is_valid() else
- Colors.PARAM_ENTRY_TEXT_COLOR)
- base_color = (
- Colors.BLOCK_DISABLED_COLOR
- if need_status_color and not self.param.get_parent().get_enabled()
- else Gtk.gdk.color_parse(color)
- )
- self._input.modify_base(Gtk.StateType.NORMAL, base_color)
- self._input.modify_text(Gtk.StateType.NORMAL, text_color)
+ self._input.override_background_color(Gtk.StateType.NORMAL, color)
def set_tooltip_text(self, text):
try:
@@ -196,8 +187,7 @@ class MultiLineEntryParam(InputParam):
buf.get_end_iter()).strip()
def set_color(self, color):
- self._view.modify_base(Gtk.StateType.NORMAL, Gdk.color_parse(color))
- self._view.modify_text(Gtk.StateType.NORMAL,
Colors.PARAM_ENTRY_TEXT_COLOR)
+ self._view.override_background_color(Gtk.StateType.NORMAL, color)
def set_tooltip_text(self, text):
try:
@@ -260,10 +250,6 @@ class PythonEditorParam(InputParam):
def get_text(self):
pass # we never update the value from here
- def set_color(self, color):
- # self._button.modify_base(Gtk.StateType.NORMAL,
Gdk.color_parse(color))
- self._button.modify_text(Gtk.StateType.NORMAL,
Colors.PARAM_ENTRY_TEXT_COLOR)
-
def _apply_change(self, *args):
pass
@@ -307,6 +293,10 @@ class EnumEntryParam(InputParam):
self._input.get_child().connect('key-press-event',
self._handle_key_press)
self.pack_start(self._input, False)
+ @property
+ def has_custom_value(self):
+ return self._input.get_active() == -1
+
def get_text(self):
if self._input.get_active() == -1: return
self._input.get_child().get_text()
return self.param.get_option_keys()[self._input.get_active()]
@@ -321,12 +311,10 @@ class EnumEntryParam(InputParam):
pass # no tooltips for old GTK
def set_color(self, color):
- if self._input.get_active() == -1: #custom entry, use color
- self._input.get_child().modify_base(Gtk.StateType.NORMAL,
Gdk.color_parse(color))
- self._input.get_child().modify_text(Gtk.StateType.NORMAL,
Colors.PARAM_ENTRY_TEXT_COLOR)
- else: #from enum, make pale background
- self._input.get_child().modify_base(Gtk.StateType.NORMAL,
Colors.ENTRYENUM_CUSTOM_COLOR)
- self._input.get_child().modify_text(Gtk.StateType.NORMAL,
Colors.PARAM_ENTRY_TEXT_COLOR)
+ self._input.get_child().modify_base(
+ Gtk.StateType.NORMAL,
+ color if not self.has_custom_value else
Colors.PARAM_ENTRY_ENUM_CUSTOM_COLOR
+ )
class FileParam(EntryParam):
@@ -375,33 +363,7 @@ class FileParam(EntryParam):
self._input.set_text(file_path)
self._editing_callback()
self._apply_change()
- file_dialog.destroy() #destroy the dialog
-
-
-TIP_MARKUP_TMPL="""\
-########################################
-#def truncate(string)
- #set $max_len = 100
- #set $string = str($string)
- #if len($string) > $max_len
-$('%s...%s'%($string[:$max_len/2], $string[-$max_len/2:]))#slurp
- #else
-$string#slurp
- #end if
-#end def
-########################################
-Key: $param.get_key()
-Type: $param.get_type()
-#if $param.is_valid()
-Value: $truncate($param.get_evaluated())
-#elif len($param.get_error_messages()) == 1
-Error: $(param.get_error_messages()[0])
-#else
-Error:
- #for $error_msg in $param.get_error_messages()
- * $error_msg
- #end for
-#end if"""
+ file_dialog.destroy() # destroy the dialog
class Param(Element, _Param):
- [Commit-gnuradio] [gnuradio] branch python3 updated (50bfc3d -> 00e775f), git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 07/101: grc-refactor: move param input widgets to separate file, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 04/101: grc: remove all Cheetah templates from GUI, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 03/101: grc-refactor: start clean-up Block.py, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 05/101: grc-refactor: move param entry colors spec in gui package,
git <=
- [Commit-gnuradio] [gnuradio] 10/101: grc: gtk3: remove some deprecated warnings, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 19/101: grc-refactor: block documentation prop, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 18/101: grc-refactor: block state handling, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 20/101: grc-refactor: Block: remove name getter, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 15/101: grc: gtk3: fix paste and domain color settings, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 08/101: grc: gtk3: remove canvas size and enable zooming, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 06/101: grc: gtk3: update props dialog, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 17/101: grc-refactor: move more port type color stuff to gui, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 09/101: grc-refactor: replace some unnecessary getters, git, 2017/03/16
- [Commit-gnuradio] [gnuradio] 24/101: grc-refactor: the hopeless cause of bus ports..., git, 2017/03/16