Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/org.gnome.hamster.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@
then the activity belongs to the previous hamster day.
</description>
</key>

<key type="s" name="theme-mode">
<default>'auto'</default>
<summary>Color theme mode</summary>
<description>
Controls the color theme used by Hamster.
'auto' follows the system theme preference,
'light' forces light theme colors,
'dark' forces dark theme colors.
</description>
</key>
</schema>
</schemalist>
76 changes: 76 additions & 0 deletions data/preferences.ui
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,82 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment_ui">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">12</property>
<property name="bottom_padding">8</property>
<property name="left_padding">4</property>
<property name="right_padding">4</property>
<child>
<object class="GtkBox" id="ui_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="orientation">vertical</property>
<property name="spacing">8</property>
<child>
<object class="GtkBox" id="theme-mode box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">8</property>
<child>
<object class="GtkLabel" id="theme_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Color theme</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">4</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="theme_combo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<items>
<item id="auto" translatable="yes">Auto (follow system)</item>
<item id="light" translatable="yes">Light</item>
<item id="dark" translatable="yes">Dark</item>
</items>
<signal name="changed" handler="on_theme_combo_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label_ui_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">UI</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down
4 changes: 4 additions & 0 deletions src/hamster-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from hamster.lib import default_logger, stuff
from hamster.lib import datetime as dt
from hamster.lib.fact import Fact
from hamster.lib.theme import get_theme_manager


logger = default_logger(__file__)
Expand Down Expand Up @@ -114,6 +115,9 @@ def __init__(self):
#inactivity_timeout=10000,
register_session=True)

# Initialize theme manager early to detect system theme
self.theme_manager = get_theme_manager()

self.about_controller = None # 'about' window controller
self.fact_controller = None # fact window controller
self.overview_controller = None # overview window controller
Expand Down
41 changes: 24 additions & 17 deletions src/hamster/lib/charting.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@ def __init__(self, max_bar_width = 20, legend_width = 70, value_format = "%.2f",
self.connect("on-click", self.on_click)

def find_colors(self):
bg_color = "#eee" #self.get_style().bg[gtk.StateType.NORMAL].to_string()
if self.theme:
bg_color = self.theme.bg_secondary
fg_color = self.theme.fg_muted
else:
bg_color = "#eee"
fg_color = "#aaa"
self.bar_color = self.colors.contrast(bg_color, 30)

# now for the text - we want reduced contrast for relaxed visuals
fg_color = "#aaa" #self.get_style().fg[gtk.StateType.NORMAL].to_string()
self.label_color = self.colors.contrast(fg_color, 80)
self.label_color = self.colors.contrast(fg_color, 80)


def on_mouse_over(self, scene, bar):
if bar.key not in self.selected_keys:
bar.fill = "#999" #self.get_style().base[gtk.StateType.PRELIGHT].to_string()
hover_color = self.theme.fg_muted if self.theme else "#999"
bar.fill = hover_color

def on_mouse_out(self, scene, bar):
if bar.key not in self.selected_keys:
Expand Down Expand Up @@ -177,30 +182,32 @@ def on_enter_frame(self, scene, context):
bar.width = self.plot_area.width

if bar.key in self.selected_keys:
bar.fill = "#aaa" #self.get_style().bg[gtk.StateType.SELECTED].to_string()
selected_bg = self.theme.fg_muted if self.theme else "#aaa"
selected_fg = self.theme.fg_secondary if self.theme else "#666"
bar.fill = selected_bg

if bar.normalized == 0:
bar.label.color = "#666" #self.get_style().fg[gtk.StateType.SELECTED].to_string()
bar.label_background.fill = "#aaa" #self.get_style().bg[gtk.StateType.SELECTED].to_string()
bar.label.color = selected_fg
bar.label_background.fill = selected_bg
bar.label_background.visible = True
else:
bar.label_background.visible = False
if bar.label.x < round(bar.width * bar.normalized):
bar.label.color = "#666" #self.get_style().fg[gtk.StateType.SELECTED].to_string()
bar.label.color = selected_fg
else:
bar.label.color = self.label_color

if not bar.fill:
else:
# Not selected - use theme bar color
bar.fill = self.bar_color

bar.label.color = self.label_color
bar.label_background.fill = None

label.y = y + (bar_width - label.height) / 2 + self.plot_area.y

label.width = legend_width
if not label.color:
label.color = self.label_color
# Always update label color from theme
label.color = self.label_color

y += bar_width + 1

Expand Down Expand Up @@ -277,8 +284,8 @@ def on_enter_frame(self, scene, context):


# now for the text - we want reduced contrast for relaxed visuals
fg_color = "#666" #self.get_style().fg[gtk.StateType.NORMAL].to_string()
label_color = self.colors.contrast(fg_color, 80)
fg_color = self.theme.fg_secondary if self.theme else "#666"
label_color = self.colors.contrast(fg_color, 80)

self.layout.set_alignment(pango.Alignment.RIGHT)
self.layout.set_ellipsize(pango.ELLIPSIZE_END)
Expand All @@ -289,8 +296,8 @@ def on_enter_frame(self, scene, context):
factor = max_bar_size / float(end_hour - start_hour)

# determine bar color
bg_color = "#eee" #self.get_style().bg[gtk.StateType.NORMAL].to_string()
base_color = self.colors.contrast(bg_color, 30)
bg_color = self.theme.bg_secondary if self.theme else "#eee"
base_color = self.colors.contrast(bg_color, 30)

for i, label in enumerate(keys):
g.set_color(label_color)
Expand Down Expand Up @@ -323,7 +330,7 @@ def on_enter_frame(self, scene, context):
last_position = positions[keys[-1]]


grid_color = "#aaa" # self.get_style().bg[gtk.StateType.NORMAL].to_string()
grid_color = self.theme.fg_muted if self.theme else "#aaa"

for i in range(start_hour + 60, end_hour, pace):
x = round((i - start_hour) * factor)
Expand Down
10 changes: 10 additions & 0 deletions src/hamster/lib/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,15 @@ def day_start(self):
hours, minutes = divmod(day_start_minutes, 60)
return dt.time(hours, minutes)

@property
def theme_mode(self):
"""Theme mode setting ('auto', 'light', or 'dark')."""
return self.get("theme-mode")

@theme_mode.setter
def theme_mode(self, value):
"""Set theme mode ('auto', 'light', or 'dark')."""
self.set("theme-mode", value)


conf = GSettingsStore()
35 changes: 35 additions & 0 deletions src/hamster/lib/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
except: # we can also live without tweener. Scene.animate will not work
pytweener = None

try:
from hamster.lib.theme import get_theme_manager
except ImportError:
get_theme_manager = None

import colorsys
from collections import deque

Expand Down Expand Up @@ -1869,6 +1874,15 @@ def __init__(self, interactive = True, framerate = 60,

self.__last_mouse_move = None

# Theme support
self._theme_manager = None
self._theme_handler_id = None
if get_theme_manager:
self._theme_manager = get_theme_manager()
self._theme_handler_id = self._theme_manager.connect(
'changed', self._on_theme_changed)
self.connect("destroy", self._on_destroy_theme_cleanup)

self.connect("realize", self.__on_realize)

if interactive:
Expand Down Expand Up @@ -2242,6 +2256,27 @@ def __on_button_release(self, scene, event):
self.__check_mouse(event.x, event.y)
return True

@property
def theme(self):
"""Get the current theme palette colors.

Returns the ThemePalette from the ThemeManager, or None if
theme support is not available.
"""
if self._theme_manager:
return self._theme_manager.colors
return None

def _on_theme_changed(self, theme_manager):
"""Handle theme change by requesting a redraw."""
self.redraw()

def _on_destroy_theme_cleanup(self, widget):
"""Disconnect theme handler on widget destroy."""
if self._theme_manager and self._theme_handler_id:
self._theme_manager.disconnect(self._theme_handler_id)
self._theme_handler_id = None

def __on_realize(self, widget):
# Store as soon as available. Maybe for performance reasons,
# to avoid get_window() calls in __on_mouse_move ?
Expand Down
Loading