[meld: 155/180] meld: Migrate from CSS to GtkSourceView style schemes
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld: 155/180] meld: Migrate from CSS to GtkSourceView style schemes
- Date: Thu, 23 Jul 2015 21:44:24 +0000 (UTC)
commit ac832d8e4473dc4bb635212bd7f5b63efd7ae9cb
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Jan 10 12:09:03 2015 +1000
meld: Migrate from CSS to GtkSourceView style schemes
bin/meld | 6 +++++-
data/meld.css | 21 ---------------------
data/styles/meld-base.xml | 16 ++++++++++++++++
meld/diffmap.py | 3 +--
meld/gutterrendererchunk.py | 4 +---
meld/linkmap.py | 3 +--
meld/misc.py | 40 ++++++++++++++++++++++++----------------
meld/sourceview.py | 10 +++++-----
8 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index c6bea2c..c6f3011 100755
--- a/bin/meld
+++ b/bin/meld
@@ -184,6 +184,7 @@ def setup_resources():
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk
+ from gi.repository import GtkSource
if GObject.pygobject_version <= (3, 11):
GObject.threads_init()
@@ -203,6 +204,9 @@ def setup_resources():
Gdk.Screen.get_default(), provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
+ style_path = os.path.join(meld.conf.DATADIR, "styles")
+ GtkSource.StyleSchemeManager.get_default().append_search_path(style_path)
+
def setup_settings():
import meld.conf
@@ -255,8 +259,8 @@ if __name__ == '__main__':
setup_logging()
disable_stdout_buffering()
check_requirements()
- setup_settings()
setup_resources()
+ setup_settings()
environment_hacks()
import meld.meldapp
diff --git a/data/meld.css b/data/meld.css
index 073d2eb..8aa1251 100644
--- a/data/meld.css
+++ b/data/meld.css
@@ -1,25 +1,4 @@
- define-color insert-bg #d0ffa3;
- define-color insert-outline shade(@insert-bg, 0.8);
- define-color insert-text #008800;
- define-color delete-bg White;
- define-color delete-outline shade(@delete-bg, 0.8);
- define-color delete-text #880000;
- define-color replace-bg #bdddff;
- define-color replace-outline shade(@replace-bg, 0.8);
- define-color replace-text #0044dd;
- define-color conflict-bg #ffa5a3;
- define-color conflict-outline shade(@conflict-bg, 0.8);
- define-color conflict-text #ff0000;
- define-color error-bg #fce94f;
- define-color error-outline shade(@error-bg, 0.8);
- define-color error-text #faad3d;
- define-color inline-bg #8ac2ff;
- define-color unknown-text #888888;
- define-color current-line-highlight #ffff00;
- define-color syncpoint-outline #555555;
- define-color current-chunk-highlight alpha(#ffffff, 0.5);
-
.meld-notebook-toolbar.toolbar {
background-image: none;
background-color: @theme_base_color;
diff --git a/data/styles/meld-base.xml b/data/styles/meld-base.xml
new file mode 100644
index 0000000..b2a2538
--- /dev/null
+++ b/data/styles/meld-base.xml
@@ -0,0 +1,16 @@
+<style-scheme id="meld-base" _name="Meld base scheme" version="1.0">
+ <author>Kai Willadsen</author>
+ <_description>Base color scheme for Meld highlighting</_description>
+
+ <!-- Meld -->
+ <style name="meld:insert" background="#d0ffa3" foreground="#008800" line-background="#a5ff4c"/>
+ <style name="meld:replace" background="#bdddff" foreground="#0044dd" line-background="#65b2ff"/>
+ <style name="meld:conflict" background="#ffa5a3" foreground="#ff0000" line-background="#ff4f4c"/>
+ <style name="meld:delete" background="#ffffff" foreground="#880000" line-background="#cccccc"/>
+ <style name="meld:error" background="#fce94f" foreground="#faad3d" line-background="#fade0a"/>
+ <style name="meld:inline" background="#8ac2ff"/>
+ <style name="meld:current-line-highlight" background="#ffff00"/>
+ <style name="meld:unknown-text" background="#888888"/>
+ <style name="meld:syncpoint-outline" background="#555555"/>
+ <style name="meld:current-chunk-highlight" background="rgba(255, 255, 255, 0.5)"/>
+</style-scheme>
diff --git a/meld/diffmap.py b/meld/diffmap.py
index ca11c84..42582c0 100644
--- a/meld/diffmap.py
+++ b/meld/diffmap.py
@@ -73,8 +73,7 @@ class DiffMap(Gtk.DrawingArea):
def do_style_updated(self, *args):
Gtk.DrawingArea.do_style_updated(self)
- style = self.get_style_context()
- self.fill_colors, self.line_colors = get_common_theme(style)
+ self.fill_colors, self.line_colors = get_common_theme()
def on_scrollbar_style_updated(self, scrollbar):
value = GObject.Value(int)
diff --git a/meld/gutterrendererchunk.py b/meld/gutterrendererchunk.py
index 1ebaf0e..26696fd 100644
--- a/meld/gutterrendererchunk.py
+++ b/meld/gutterrendererchunk.py
@@ -113,9 +113,7 @@ class GutterRendererChunkAction(GtkSource.GutterRendererPixbuf):
def do_style_updated(self):
# GtkSource.GutterRendererPixbuf.do_style_updated(self)
# FIXME: Should be self.get_view() or something, but when and how?
- widget = self.views[0]
- style = widget.get_style_context()
- self.fill_colors, self.line_colors = get_common_theme(style)
+ self.fill_colors, self.line_colors = get_common_theme()
def do_draw(self, context, background_area, cell_area, start, end, state):
line = start.get_line()
diff --git a/meld/linkmap.py b/meld/linkmap.py
index 6449892..281d642 100644
--- a/meld/linkmap.py
+++ b/meld/linkmap.py
@@ -56,8 +56,7 @@ class LinkMap(Gtk.DrawingArea):
def do_style_updated(self, *args):
Gtk.DrawingArea.do_style_updated(self)
- style = self.get_style_context()
- self.fill_colors, self.line_colors = get_common_theme(style)
+ self.fill_colors, self.line_colors = get_common_theme()
def do_draw(self, context):
if not self.filediff:
diff --git a/meld/misc.py b/meld/misc.py
index 6ecba03..019d69d 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -143,28 +143,36 @@ def make_tool_button_widget(label):
return hbox
-def colour_lookup_with_fallback(style, name, default):
- found, colour = style.lookup_color(name)
- if not found:
- colour = Gdk.RGBA()
- colour.parse(default)
+def colour_lookup_with_fallback(source_style, name, attribute, default):
+ style = source_style.get_style(name)
+ if style:
+ style_attr = getattr(style.props, attribute)
+ if style_attr:
+ default = style_attr
+ colour = Gdk.RGBA()
+ colour.parse(default)
return colour
-def get_common_theme(style):
- lookup = lambda *args: colour_lookup_with_fallback(style, *args)
+def get_common_theme():
+ # TODO: Everywhere that calls get_common_theme needs to bind to the
+ # gsettings style-scheme key instead of triggering on style_updated
+ from meld.settings import meldsettings
+ source_style = meldsettings.style_scheme
+ lookup = lambda *args: colour_lookup_with_fallback(source_style, *args)
fill_colours = {
- "insert": lookup("insert-bg", "DarkSeaGreen1"),
- "delete": lookup("insert-bg", "DarkSeaGreen1"),
- "conflict": lookup("conflict-bg", "Pink"),
- "replace": lookup("replace-bg", "#ddeeff"),
- "current-chunk-highlight": lookup("current-chunk-highlight", '#ffffff')
+ "insert": lookup("meld:insert", "background", "DarkSeaGreen1"),
+ "delete": lookup("meld:insert", "background", "DarkSeaGreen1"),
+ "conflict": lookup("meld:conflict", "background", "Pink"),
+ "replace": lookup("meld:replace", "background", "#ddeeff"),
+ "current-chunk-highlight": lookup(
+ "meld:current-chunk-highlight", "background", '#ffffff')
}
line_colours = {
- "insert": lookup("insert-outline", "#77f077"),
- "delete": lookup("insert-outline", "#77f077"),
- "conflict": lookup("conflict-outline", "#f0768b"),
- "replace": lookup("replace-outline", "#8bbff3"),
+ "insert": lookup("meld:insert", "line-background", "#77f077"),
+ "delete": lookup("meld:insert", "line-background", "#77f077"),
+ "conflict": lookup("meld:conflict", "line-background", "#f0768b"),
+ "replace": lookup("meld:replace", "line-background", "#8bbff3"),
}
return fill_colours, line_colours
diff --git a/meld/sourceview.py b/meld/sourceview.py
index 77778e7..a1025a3 100644
--- a/meld/sourceview.py
+++ b/meld/sourceview.py
@@ -146,16 +146,16 @@ class MeldSourceView(GtkSource.View):
def do_style_updated(self):
GtkSource.View.do_style_updated(self)
- style = self.get_style_context()
+ style = self.get_buffer().get_style_scheme()
self.highlight_color = colour_lookup_with_fallback(
- style, "current-line-highlight", "#ffff00")
+ style, "meld:current-line-highlight", "background", "#ffff00")
self.syncpoint_color = colour_lookup_with_fallback(
- style, "syncpoint-outline", "#555555")
- self.fill_colors, self.line_colors = get_common_theme(style)
+ style, "meld:syncpoint-outline", "foreground", "#555555")
+ self.fill_colors, self.line_colors = get_common_theme()
tag = self.get_buffer().get_tag_table().lookup("inline")
tag.props.background_rgba = colour_lookup_with_fallback(
- style, "inline-bg", "LightSteelBlue2")
+ style, "meld:inline", "background", "LightSteelBlue2")
def do_draw_layer(self, layer, context):
if layer != Gtk.TextViewLayer.BELOW:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]