Skip to content

Commit

Permalink
Added support for GTK dark Theme Fixed getting-things-gnome#150
Browse files Browse the repository at this point in the history
  • Loading branch information
akash0675 committed Dec 11, 2015
1 parent 8415e62 commit ec22864
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
2 changes: 2 additions & 0 deletions GTG/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# TODO: Remove toolbar and quick_add options from configuration
# They won't be used in GTG 0.4
'browser': {
"dark_theme_enable": False,
"bg_color_enable": True,
"contents_preview_enable": False,
'tag_pane': False,
Expand All @@ -54,6 +55,7 @@
"font_name": "",
'hour': "00",
'min': "00",

},
'tag_editor': {
"custom_colors": [],
Expand Down
15 changes: 15 additions & 0 deletions GTG/gtk/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def __init__(self, requester, vmanager):
self.builder = Gtk.Builder()
self.builder.add_from_file(GnomeConfig.BROWSER_UI_FILE)

# Set Theme
self._init_gtk_theme()

# Define aliases for specific widgets
self._init_widget_aliases()

Expand Down Expand Up @@ -131,6 +134,18 @@ def _init_icon_theme(self):
# TODO(izidor): Set it outside browser as it applies to every window
Gtk.Window.set_default_icon_name("gtg")

def _init_gtk_theme(self):
"""
sets gtk theme to dark or light depending on the configuration
"""
theme_state = self.config.get("dark_theme_enable")
if theme_state:
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path("gtk-dark.css")
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)

def _init_widget_aliases(self):
"""
defines aliases for UI elements found in the glide file
Expand Down
26 changes: 26 additions & 0 deletions GTG/gtk/general_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, req, vmanager):
self.font_button = builder.get_object("font_button")
self.shortcut_popover = builder.get_object("shortcut_popover")
self.set_shortcut = builder.get_object("set_shortcut")
self.theme_button = builder.get_object("theme_button")

self.shortcut = ShortcutWidget(builder)

Expand Down Expand Up @@ -101,6 +102,9 @@ def _refresh_preferences_store(self):
bg_color = self.config.get("bg_color_enable")
self.bg_color_button.set_active(bg_color)

dark_theme = self.config.get("dark_theme_enable")
self.theme_button.set_active(dark_theme)

self.refresh_time.set_text(self.timer.get_formatted_time())
self.refresh_time.modify_fg(Gtk.StateFlags.NORMAL, None)

Expand Down Expand Up @@ -147,6 +151,28 @@ def on_autostart_toggled(self, widget, state):
else:
autostart.disable()

def on_theme_toggled(self, widget, state):
"""Toggle GTK dark Theme"""
curstate = self.config.get("dark_theme_enable")
if curstate != self.theme_button.get_active():
self.config.set("dark_theme_enable", not curstate)
if self.theme_button.get_active():
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path("gtk-dark.css")
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self._refresh_task_browser()
else:
cssProvider = Gtk.CssProvider()
cssProvider.load_from_path("gtk.css")
screen = Gdk.Screen.get_default()
styleContext = Gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self._refresh_task_browser()



def on_shortcut_toggled(self, widget, state):
self.shortcut.on_shortcut_toggled(widget, state)

Expand Down
63 changes: 63 additions & 0 deletions GTG/gtk/ui/general_preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,69 @@
<property name="fill">True</property>
</packing>
</child>
<!-- -->
<child>
<object class="GtkLabel" id="theme_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Theme</property>
<property name="xalign">0.0</property>
<property name="margin-start">10</property>
<property name="margin-top">6</property>
<style>
<class name="dim-label"/>
</style>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkBox" id="theme_box">
<property name="visible">True</property>
<property name="margin-start">40</property>
<property name="margin-end">20</property>
<property name="margin-top">10</property>
<property name="homogeneous">False</property>
<child>
<object class="GtkSwitch" id="theme_button">
<property name="visible">True</property>
<property name="valign">center</property>
<signal handler="on_theme_toggled" name="state-set" swapped="no"/>
</object>
</child>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="visible">True</property>
<property name="margin-start">10</property>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Change theme to dark</property>
<property name="visible">True</property>
<property name="xalign">0.0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Change Getting Things GNOME! to GTK dark theme</property>
<property name="visible">True</property>
<property name="single-line-mode">True</property>
<style>
<class name="dim-label"/>
</style>
<attributes>
<attribute name="scale" value="0.833333"/>
</attributes>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- -->
</object>
</child>
</object>
Expand Down
4 changes: 4 additions & 0 deletions gtk-dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*Clone https://git.gnome.org/browse/gtk+
*Use "gtk+/gtk/resources/theme/Adwaita" for reference*/

@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained-dark.css");
4 changes: 4 additions & 0 deletions gtk.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*Clone https://git.gnome.org/browse/gtk+
*Use "gtk+/gtk/resources/theme/Adwaita" for reference*/

@import url("resource:///org/gtk/libgtk/theme/Adwaita/gtk-contained.css");

0 comments on commit ec22864

Please sign in to comment.