[gnome-music/wip/jfelder/adw-application: 3/3] application: Inherit from Adw.Application




commit b0993e13943ffcfb6a05a2325cc402fd06705184
Author: Jean Felder <jfelder src gnome org>
Date:   Sun Feb 20 13:09:16 2022 +0100

    application: Inherit from Adw.Application
    
    By renaming the CSS file to `style.css` and using Adw.Application
    instead of Gtk.Application, this allows to automatically load the
    stylesheet.
    
    Closes: #498

 data/org.gnome.Music.gresource.xml      |  2 +-
 data/{org.gnome.Music.css => style.css} |  0
 gnomemusic/application.py               | 13 ++-----------
 3 files changed, 3 insertions(+), 12 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 0b20f1289..2be39220b 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -2,7 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/Music">
     <file alias="gtk/help-overlay.ui" preprocess="xml-stripblanks">ui/help-overlay.ui</file>
-    <file>org.gnome.Music.css</file>
+    <file>style.css</file>
     <file>icons/welcome-music.svg</file>
     <file preprocess="xml-stripblanks">ui/AboutDialog.ui</file>
     <file preprocess="xml-stripblanks">ui/AlbumCover.ui</file>
diff --git a/data/org.gnome.Music.css b/data/style.css
similarity index 100%
rename from data/org.gnome.Music.css
rename to data/style.css
diff --git a/gnomemusic/application.py b/gnomemusic/application.py
index b00ff31da..30ba7606d 100644
--- a/gnomemusic/application.py
+++ b/gnomemusic/application.py
@@ -51,7 +51,7 @@ from gnomemusic.widgets.lastfmdialog import LastfmDialog
 from gnomemusic.window import Window
 
 
-class Application(Gtk.Application):
+class Application(Adw.Application):
 
     def __init__(self, application_id):
         super().__init__(
@@ -83,14 +83,6 @@ class Application(Gtk.Application):
         InhibitSuspend(self)
         PauseOnSuspend(self._player)
 
-    def _init_style(self):
-        css_provider = Gtk.CssProvider()
-        css_provider.load_from_resource('/org/gnome/Music/org.gnome.Music.css')
-        display = Gdk.Display.get_default()
-        style_context = self._window.get_style_context()
-        style_context.add_provider_for_display(
-            display, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
-
     @GObject.Property(
         type=CoreGrilo, default=None, flags=GObject.ParamFlags.READABLE)
     def coregrilo(self):
@@ -238,7 +230,7 @@ class Application(Gtk.Application):
         about.present()
 
     def do_startup(self):
-        Gtk.Application.do_startup(self)
+        Adw.Application.do_startup(self)
         Adw.StyleManager.get_default().set_color_scheme(
             Adw.ColorScheme.PREFER_LIGHT)
         self._set_actions()
@@ -251,7 +243,6 @@ class Application(Gtk.Application):
             self._window = Window(self)
             self.notify("window")
             self._window.set_default_icon_name(self.props.application_id)
-            self._init_style()
             if self.props.application_id == "org.gnome.Music.Devel":
                 self._window.get_style_context().add_class('devel')
             MPRIS(self)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]