[d-feet/correctly-honour-theme-foreground-colour: 9/9] WIP: Correctly honour theme foreground colour
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [d-feet/correctly-honour-theme-foreground-colour: 9/9] WIP: Correctly honour theme foreground colour
- Date: Wed, 19 Sep 2018 10:44:30 +0000 (UTC)
commit 1ba12c121e984c689b1fedcad94a57d1c4a3b516
Author: Will Thompson <will willthompson co uk>
Date: Tue Sep 18 15:58:03 2018 +0100
WIP: Correctly honour theme foreground colour
src/dfeet/executemethoddialog.py | 3 +-
src/dfeet/introspection.py | 11 ++---
src/dfeet/introspection_helper.py | 84 +++++++++++++++++++--------------------
src/tests/tests.py.in | 2 +-
4 files changed, 51 insertions(+), 49 deletions(-)
---
diff --git a/src/dfeet/executemethoddialog.py b/src/dfeet/executemethoddialog.py
index caf96ef..1e1940c 100644
--- a/src/dfeet/executemethoddialog.py
+++ b/src/dfeet/executemethoddialog.py
@@ -34,7 +34,8 @@ class ExecuteMethodDialog:
self.label_min = ui.get_widget('label_min')
self.label_max = ui.get_widget('label_max')
ui.connect_signals(signal_dict)
- self.label_method_name.set_markup("%s" % (self.method_obj.markup_str))
+ self.label_method_name.set_markup("%s" % (
+ self.method_obj.markup_str(self.label_method_name)))
self.label_object_path.set_markup("%s" % (self.method_obj.object_path))
self.label_interface.set_markup("%s" % (self.method_obj.iface_info.name))
diff --git a/src/dfeet/introspection.py b/src/dfeet/introspection.py
index fd41b92..816f14c 100644
--- a/src/dfeet/introspection.py
+++ b/src/dfeet/introspection.py
@@ -115,7 +115,7 @@ class AddressInfo():
# update the object value so markup string is calculated correct
obj.value = result[0]
# set new markup string
- model[iter_][0] = obj.markup_str
+ model[iter_][0] = obj.markup_str(treeview)
else:
if treeview.row_expanded(path):
treeview.collapse_row(path)
@@ -205,7 +205,7 @@ class AddressInfo():
method_obj = DBusMethod(iface_obj, iface_method)
self.__treemodel.append(
iface_methods_iter,
- ["%s" % method_obj.markup_str, method_obj])
+ ["%s" % method_obj.markup_str(self.__treeview), method_obj])
# interface signals
if len(iface.signals) > 0:
iface_signals_iter = self.__treemodel.append(
@@ -214,7 +214,7 @@ class AddressInfo():
signal_obj = DBusSignal(iface_obj, iface_signal)
self.__treemodel.append(
iface_signals_iter,
- ["%s" % signal_obj.markup_str, signal_obj])
+ ["%s" % signal_obj.markup_str(self.__treeview), signal_obj])
# interface properties
if len(iface.properties) > 0:
iface_properties_iter = self.__treemodel.append(
@@ -223,7 +223,7 @@ class AddressInfo():
property_obj = DBusProperty(iface_obj, iface_property)
self.__treemodel.append(
iface_properties_iter,
- ["%s" % property_obj.markup_str, property_obj])
+ ["%s" % property_obj.markup_str(self.__treeview), property_obj])
# interface annotations
if len(iface.annotations) > 0:
iface_annotations_iter = self.__treemodel.append(
@@ -232,7 +232,8 @@ class AddressInfo():
annotation_obj = DBusAnnotation(iface_obj, iface_annotation)
self.__treemodel.append(
iface_annotations_iter,
- ["%s" % (annotation_obj.markup_str), annotation_obj])
+ ["%s" % (annotation_obj.markup_str(self.__treeview)),
+ annotation_obj])
# are more nodes left?
if len(node_info.nodes) > 0:
diff --git a/src/dfeet/introspection_helper.py b/src/dfeet/introspection_helper.py
index b718c1a..bab9621 100644
--- a/src/dfeet/introspection_helper.py
+++ b/src/dfeet/introspection_helper.py
@@ -3,29 +3,28 @@
from gi.repository import GObject, Gio, Gtk
from dfeet import dbus_utils
-_style_context = None
-_fg_color = "#000000"
-
-
-def fg_color():
- global _style_context, _fg_color
- if _style_context is None:
- _style_context = Gtk.StyleContext()
- color = _style_context.get_color(Gtk.StateFlags.NORMAL)
- _fg_color = "#%02x%02x%02x" % (
- int(color.red) * 255,
- int(color.green) * 255,
- int(color.blue) * 255,
- )
- return _fg_color
+
+def fg_color(widget):
+ if widget is None:
+ style_context = Gtk.StyleContext()
+ else:
+ style_context = widget.get_style_context()
+ color = style_context.get_color(Gtk.StateFlags.NORMAL)
+ return "#%02x%02x%02x" % (
+ int(color.red) * 255,
+ int(color.green) * 255,
+ int(color.blue) * 255,
+ )
-def args_signature_markup(arg_signature):
+def args_signature_markup(arg_signature, widget):
return '<small><span foreground="#2E8B57">%s</span></small>' % (arg_signature)
-def args_name_markup(arg_name):
- return '<small><span foreground="%s">%s</span></small>' % (fg_color(), arg_name)
+def args_name_markup(arg_name, widget):
+ return '<small><span foreground="%s">%s</span></small>' % (
+ fg_color(widget),
+ arg_name)
class DBusNode(GObject.GObject):
@@ -91,8 +90,7 @@ class DBusProperty(DBusInterface):
def value(self, new_val):
self.__value = new_val
- @property
- def markup_str(self):
+ def markup_str(self, widget):
sig = dbus_utils.sig_to_string(self.property_info.signature)
readwrite = list()
if self.readable:
@@ -100,8 +98,9 @@ class DBusProperty(DBusInterface):
if self.writable:
readwrite.append("write")
s = "%s %s <small>(%s)</small>" % (
- args_signature_markup(sig),
- args_name_markup(self.property_info.name), " / ".join(readwrite))
+ args_signature_markup(sig, widget),
+ args_name_markup(self.property_info.name, widget),
+ " / ".join(readwrite))
if self.value is not None:
s += " = %s" % (self.value,)
return s
@@ -147,17 +146,18 @@ class DBusSignal(DBusInterface):
args.append({'signature': sig, 'name': arg.name})
return args
- @property
- def args_markup_str(self):
+ def args_markup_str(self, widget):
result = ''
result += '<span foreground="#FF00FF">(</span>'
- result += ', '.join('%s' % (args_signature_markup(arg['signature'])) for arg in self.args)
+ result += ', '.join(
+ '%s' % (args_signature_markup(arg['signature'], widget))
+ for arg in self.args
+ )
result += '<span foreground="#FF00FF">)</span>'
return result
- @property
- def markup_str(self):
- return "%s %s" % (self.signal_info.name, self.args_markup_str)
+ def markup_str(self, widget):
+ return "%s %s" % (self.signal_info.name, self.args_markup_str(widget))
class DBusMethod(DBusInterface):
@@ -182,10 +182,12 @@ class DBusMethod(DBusInterface):
def method_info(self):
return self.__method_info
- @property
- def markup_str(self):
+ def markup_str(self, widget):
return "%s %s <b>↦</b> %s" % (
- self.method_info.name, self.in_args_markup_str, self.out_args_markup_str)
+ self.method_info.name,
+ self.in_args_markup_str(widget),
+ self.out_args_markup_str(widget),
+ )
@property
def in_args(self):
@@ -219,24 +221,23 @@ class DBusMethod(DBusInterface):
return result[0:-2]
- def __args_markup_str(self, args):
+ def __args_markup_str(self, args, widget):
"""markup a given list of args"""
result = ''
result += '<span foreground="#FF00FF">(</span>'
result += ', '.join(
'%s %s' % (
- args_signature_markup(arg['signature']),
- args_name_markup(arg['name'])) for arg in args)
+ args_signature_markup(arg['signature'], widget),
+ args_name_markup(arg['name'], widget)
+ ) for arg in args)
result += '<span foreground="#FF00FF">)</span>'
return result
- @property
- def in_args_markup_str(self):
- return self.__args_markup_str(self.in_args)
+ def in_args_markup_str(self, widget):
+ return self.__args_markup_str(self.in_args, widget)
- @property
- def out_args_markup_str(self):
- return self.__args_markup_str(self.out_args)
+ def out_args_markup_str(self, widget):
+ return self.__args_markup_str(self.out_args, widget)
class DBusAnnotation(DBusInterface):
@@ -253,6 +254,5 @@ class DBusAnnotation(DBusInterface):
def annotation_info(self):
return self.__annotation_info
- @property
- def markup_str(self):
+ def markup_str(self, widget):
return "%s: %s" % (self.annotation_info.key, self.annotation_info.value)
diff --git a/src/tests/tests.py.in b/src/tests/tests.py.in
index 152bef3..a46faaf 100755
--- a/src/tests/tests.py.in
+++ b/src/tests/tests.py.in
@@ -70,7 +70,7 @@ class IntrospectionHelperTest(unittest.TestCase):
# get the markup string with value for struct prop (see bgo #702593)
obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[2])
obj_prop.value = ("string", 1, 2)
- self.assertIn("'string', 1, 2", obj_prop.markup_str)
+ self.assertIn("'string', 1, 2", obj_prop.markup_str(None))
def test_dbus_signal(self):
"""test DBusSignal class"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]