summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Koslowski <koslowski@kit.edu>2016-05-27 15:11:29 +0200
committerSebastian Koslowski <koslowski@kit.edu>2016-05-30 14:05:10 +0200
commit498715deea12451bd271d20b51c02f01530acd14 (patch)
tree87146befc7598cfc71ae18cb033a0ef1d8211b16
parent593ce05e7ea74871c23fa48a9a2486a157c5cfee (diff)
grc-refactor: move param entry colors spec in gui package
-rw-r--r--grc/core/Constants.py19
-rw-r--r--grc/core/Param.py32
-rw-r--r--grc/gui/Colors.py125
-rw-r--r--grc/gui/Param.py68
4 files changed, 100 insertions, 144 deletions
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index 462049cc73..4f278bb22d 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 d155800c43..73d54b6aff 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 686b378c38..a03a7bcade 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 a0ca6b66c3..1c5b0c9c8c 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):