[moserial] Fix deprecated Gtk.Color. Use CSS for textview colors and font.
- From: Michael J. Chudobiak <mjc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [moserial] Fix deprecated Gtk.Color. Use CSS for textview colors and font.
- Date: Sat, 16 Jan 2021 13:47:24 +0000 (UTC)
commit a68927e9789272815200529b31a624e0d61a9595
Author: Mictronics <github mictronics de>
Date: Sun Apr 26 19:40:36 2020 +0200
Fix deprecated Gtk.Color. Use CSS for textview colors and font.
data/ui/mainwindow.ui | 20 +++++++++++++
src/MainWindow.vala | 79 +++++++++++++++++++++++++++++++++++----------------
src/Preferences.vala | 6 ++--
3 files changed, 78 insertions(+), 27 deletions(-)
---
diff --git a/data/ui/mainwindow.ui b/data/ui/mainwindow.ui
index 7bb703b..e52fa2f 100644
--- a/data/ui/mainwindow.ui
+++ b/data/ui/mainwindow.ui
@@ -440,6 +440,10 @@
<property name="wrap_mode">word-char</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
+ <style>
+ <class name="TextviewColor"/>
+ <class name="TextFont"/>
+ </style>
</object>
</child>
</object>
@@ -467,6 +471,10 @@
<property name="editable">False</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
+ <style>
+ <class name="TextviewColor"/>
+ <class name="TextFont"/>
+ </style>
</object>
</child>
</object>
@@ -578,6 +586,10 @@
<property name="wrap_mode">word-char</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
+ <style>
+ <class name="TextviewColor"/>
+ <class name="TextFont"/>
+ </style>
</object>
</child>
</object>
@@ -605,6 +617,10 @@
<property name="editable">False</property>
<property name="left_margin">2</property>
<property name="right_margin">2</property>
+ <style>
+ <class name="TextviewColor"/>
+ <class name="TextFont"/>
+ </style>
</object>
</child>
</object>
@@ -677,6 +693,10 @@
<property name="invisible_char">●</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
+ <style>
+ <class name="TextInputColor"/>
+ <class name="TextFont"/>
+ </style>
</object>
<packing>
<property name="expand">True</property>
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index c78a58d..aa85f0e 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -379,13 +379,13 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
}
}
- private void clearIncoming() {
- incomingHexTextBuffer.clear();
+ private void clearIncoming () {
+ incomingHexTextBuffer.clear ();
incomingAsciiTextBuffer.set_text ("", 0);
}
- private void clearOutgoing() {
- outgoingHexTextBuffer.clear();
+ private void clearOutgoing () {
+ outgoingHexTextBuffer.clear ();
outgoingAsciiTextBuffer.set_text ("", 0);
}
@@ -658,29 +658,60 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
font = Preferences.getSystemDefaultMonospaceFont ();
else
font = currentPreferences.font;
- incomingAsciiTextView.override_font (Pango.FontDescription.from_string (font));
- incomingAsciiTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.fontColor));
- incomingAsciiTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.backgroundColor));
- echoTag.foreground = currentPreferences.highlightColor;
- incomingHexTextView.override_font (Pango.FontDescription.from_string (font));
- incomingHexTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.fontColor));
- incomingHexTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.backgroundColor));
- incomingHexTextBuffer.applyPreferences (currentPreferences);
+ Pango.FontDescription fd = Pango.FontDescription.from_string (font);
- outgoingAsciiTextView.override_font (Pango.FontDescription.from_string (font));
- outgoingAsciiTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.fontColor));
- outgoingAsciiTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.backgroundColor));
+ string unit = "px";
+ if (Gtk.check_version (3, 22, 0) == null) {
+ unit = "pt";
+ }
- outgoingHexTextView.override_font (Pango.FontDescription.from_string (font));
- outgoingHexTextView.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.fontColor));
- outgoingHexTextView.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.backgroundColor));
- outgoingHexTextBuffer.applyPreferences (currentPreferences);
+ var family = fd.get_family ().split (",")[0];
+ int size = (int) Math.round (fd.get_size () / Pango.SCALE);
+ int weight = (int) fd.get_weight ();
- entry.modify_font (Pango.FontDescription.from_string (font));
- entry.modify_text (Gtk.StateType.NORMAL, Preferences.getGdkColor (currentPreferences.fontColor));
- entry.modify_base (Gtk.StateType.NORMAL, Preferences.getGdkColor
(currentPreferences.backgroundColor));
+ var style = """
+ .TextviewColor text {
+ color: %s;
+ background-color: %s;
+ }
+ .TextInputColor {
+ color: %s;
+ background-color: %s;
+ }
+ .TextFont {
+ font-family: %s;
+ font-size: %d%s;
+ font-weight: %d;
+ }
+ """.printf (
+ currentPreferences.fontColor,
+ currentPreferences.backgroundColor,
+ currentPreferences.fontColor,
+ currentPreferences.backgroundColor,
+ family,
+ size,
+ unit,
+ weight
+ );
+
+ var css_provider = new Gtk.CssProvider ();
+ try {
+ css_provider.load_from_data (style, -1);
+ } catch (GLib.Error e) {
+ warning ("Failed to parse CSS style : %s", e.message);
+ }
+
+ Gtk.StyleContext.add_provider_for_screen (
+ Gdk.Screen.get_default (),
+ css_provider,
+ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
+ );
+
+ echoTag.foreground = currentPreferences.highlightColor;
+ incomingHexTextBuffer.applyPreferences (currentPreferences);
+ outgoingHexTextBuffer.applyPreferences (currentPreferences);
profileChanged = true;
}
@@ -1018,8 +1049,8 @@ public class moserial.MainWindow : Gtk.Window // Have to extend Gtk.Winow to get
}
private void clear () {
- this.clearOutgoing();
- this.clearIncoming();
+ this.clearOutgoing ();
+ this.clearIncoming ();
entry.set_text ("");
}
}
diff --git a/src/Preferences.vala b/src/Preferences.vala
index e33deb6..3d8b9d5 100644
--- a/src/Preferences.vala
+++ b/src/Preferences.vala
@@ -69,9 +69,9 @@ public class Preferences : GLib.Object {
return value;
}
- public static Gdk.Color getGdkColor (string color) {
- Gdk.Color c;
- Gdk.Color.parse (color, out c);
+ public static Gdk.RGBA getGdkRGBA (string color) {
+ Gdk.RGBA c = Gdk.RGBA ();
+ c.parse(color);
return c;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]