Skip to content

Commit

Permalink
Merge pull request #40 from gnesterif/detail_view_theming
Browse files Browse the repository at this point in the history
Improve theming behaviour of DetailsView
  • Loading branch information
aleiepure authored Feb 9, 2025
2 parents f4066d7 + 3e4fdb0 commit 47ab808
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
border-radius: 6px;
}

.groupcolor list {
background-color: alpha(#dddddd, 0.2);
}

.progress_complete progress {
background-color: @success_color;
}
Expand Down
37 changes: 35 additions & 2 deletions src/pages/details_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ def __init__(self, content: MovieModel | SeriesModel):
super().__init__()

# Theme switcher (Adapted from https://gitlab.gnome.org/tijder/blueprintgtk/)
self._menu_btn.get_popover().add_child(ThemeSwitcher(), 'themeswitcher')

themeswitcher = ThemeSwitcher()
themeswitcher.connect(
'themer-clicked', self._on_themeswitcher_clicked,)
self._menu_btn.get_popover().add_child(themeswitcher, 'themeswitcher')

if type(content) is MovieModel:
self.content = local.get_movie_by_id(content.id)
else:
Expand Down Expand Up @@ -288,6 +291,7 @@ def _build_seasons_group(self) -> None:
episode_row = EpisodeRow(episode, small_controls=self.mobile)
episode_row.connect(
'watched-clicked', self._on_episode_watch_clicked, (button, season))
episode_row.add_css_class("groupcolor")
season_row.add_row(episode_row)
tmp.append(episode_row)

Expand Down Expand Up @@ -709,3 +713,32 @@ def _on_delete_done(self,

self.emit('deleted')
activity.end()

def _on_themeswitcher_clicked(self,
source: Gtk.Widget) -> None:
"""
Callback for "themer-clicked" signal.
Called after an theme is switched changes background picture if needed
Args:
source (Gtk.Widget): caller widget
Returns:
None
"""

if self.content.backdrop_path: # type: ignore
if not Adw.StyleManager.get_default().get_high_contrast():
self._background_picture.set_file(Gio.File.new_for_uri(
self.content.backdrop_path)) # type: ignore
# type: ignore
with Image.open(self.content.backdrop_path[7:]) as image:
stat = ImageStat.Stat(image.convert('L'))

luminance = [
min((stat.mean[0] + stat.extrema[0][0]) / 510, 0.7),
max((stat.mean[0] + stat.extrema[0][1]) / 510, 0.3),
]
self._background_picture.set_opacity(1 - luminance[0]
if Adw.StyleManager.get_default().get_dark()
else luminance[1])
4 changes: 3 additions & 1 deletion src/ui/pages/details_page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ template $DetailsView: Adw.NavigationPage {
]
}

Adw.PreferencesGroup _seasons_group {}
Adw.PreferencesGroup _seasons_group {
styles ["groupcolor"]
}

Separator {
margin-bottom: 16;
Expand Down
7 changes: 7 additions & 0 deletions src/widgets/theme_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@
class ThemeSwitcher(Gtk.Box):
__gtype_name__ = 'ThemeSwitcher'

__gsignals__ = {
'themer-clicked': (GObject.SIGNAL_RUN_FIRST, None, ()),
}

show_system = GObject.property(type=bool, default=True)
color_scheme = 'light'


system = Gtk.Template.Child()
light = Gtk.Template.Child()
Expand Down Expand Up @@ -70,3 +75,5 @@ def _on_color_scheme_changed(self, _widget, _paramspec):
if self.dark.get_active():
self.selected_color_scheme = 'dark' # type: ignore
shared.schema.set_string('style-scheme', 'dark')
# emit signal so we can change the background of details page if needed
self.emit('themer-clicked')

0 comments on commit 47ab808

Please sign in to comment.