[gnome-music/wip/mschraal/window-template: 1/4] window: Initial template port



commit 30c56903778b7abc06e66e23fe260c1774487cda
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Sep 5 14:55:33 2018 +0200

    window: Initial template port
    
    Does not yet work as expected because of an issue with template usage.

 data/org.gnome.Music.gresource.xml       |  1 +
 data/ui/Window.ui                        | 45 ++++++++++++++++++++++++++++++++
 gnomemusic/widgets/notificationspopup.py |  7 ++---
 gnomemusic/widgets/searchbar.py          |  4 +++
 gnomemusic/window.py                     | 42 +++++++++++++----------------
 5 files changed, 72 insertions(+), 27 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 2ac5d2c6..5d7f0e50 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -25,5 +25,6 @@
     <file preprocess="xml-stripblanks">ui/SidebarRow.ui</file>
     <file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
     <file preprocess="xml-stripblanks">ui/TwoLineTip.ui</file>
+    <file preprocess="xml-stripblanks">ui/Window.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/Window.ui b/data/ui/Window.ui
new file mode 100644
index 00000000..07fdb05c
--- /dev/null
+++ b/data/ui/Window.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="Window" parent="GtkApplicationWindow">
+    <property name="default-height">500</property>
+    <property name="default-width">300</property>
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkBox" id="_box">
+        <property name="orientation">vertical</property>
+        <property name="visible">True</property>
+        <child>
+          <object class="SearchBar" id="_searchbar">
+            <property name="hexpand">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkOverlay" id="_overlay">
+            <property name="vexpand">True</property>
+            <property name="visible">True</property>
+            <child type="overlay">
+              <object class="GtkStack" id="_stack">
+                <property name="can-focus">False</property>
+                <property name="homogeneous">False</property>
+                <property name="transition-duration">100</property>
+                <property name="transition-type">crossfade</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child type="overlay">
+              <object class="NotificationsPopup" id="notifications_popup">
+                <property name="halign">center</property>
+                <property name="transition-type">slide-down</property>
+                <property name="valign">start</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="SelectionToolbar" id="_selection_toolbar"/>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+
diff --git a/gnomemusic/widgets/notificationspopup.py b/gnomemusic/widgets/notificationspopup.py
index 4861c9dc..40ae1474 100644
--- a/gnomemusic/widgets/notificationspopup.py
+++ b/gnomemusic/widgets/notificationspopup.py
@@ -38,14 +38,15 @@ class NotificationsPopup(Gtk.Revealer):
     Messages are arranged under each other
     """
 
+    __gtype_name__ = 'NotificationsPopup'
+
     def __repr__(self):
         return '<NotificationsPopup>'
 
     @log
     def __init__(self):
-        super().__init__(
-            halign=Gtk.Align.CENTER, valign=Gtk.Align.START,
-            transition_type=Gtk.RevealerTransitionType.SLIDE_DOWN)
+        super().__init__()
+
         self._setup_view()
 
     @log
diff --git a/gnomemusic/widgets/searchbar.py b/gnomemusic/widgets/searchbar.py
index 4d5c07a7..40ddb922 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -88,6 +88,10 @@ class BaseManager(GObject.GObject):
         if selected_id == "":
             return
 
+        return
+        # if self.entry is None:
+        #    return
+
         selected_value = [
             x for x in self.values if x[BaseModelColumns.ID] == selected_id]
 
diff --git a/gnomemusic/window.py b/gnomemusic/window.py
index 6af945ee..d89a3c70 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -50,7 +50,7 @@ from gnomemusic.widgets.headerbar import HeaderBar
 from gnomemusic.widgets.notificationspopup import NotificationsPopup
 from gnomemusic.widgets.playertoolbar import PlayerToolbar
 from gnomemusic.widgets.playlistdialog import PlaylistDialog
-from gnomemusic.widgets.searchbar import SearchBar
+from gnomemusic.widgets.searchbar import SearchBar  # noqa: F401
 from gnomemusic.widgets.selectiontoolbar import SelectionToolbar
 from gnomemusic.windowplacement import WindowPlacement
 
@@ -60,11 +60,21 @@ logger = logging.getLogger(__name__)
 playlists = Playlists.get_default()
 
 
+@Gtk.Template(resource_path='/org/gnome/Music/ui/Window.ui')
 class Window(Gtk.ApplicationWindow):
 
+    __gtype_name__ = 'Window'
+
     selected_items_count = GObject.Property(type=int, default=0, minimum=0)
     selection_mode = GObject.Property(type=bool, default=False)
 
+    notifications_popup = Gtk.Template.Child()
+    _box = Gtk.Template.Child()
+    _overlay = Gtk.Template.Child()
+    _searchbar = Gtk.Template.Child()
+    _selection_toolbar = Gtk.Template.Child()
+    _stack = Gtk.Template.Child()
+
     def __repr__(self):
         return '<Window>'
 
@@ -124,11 +134,9 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _setup_view(self):
-        self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-
         self._search = Search()
         self._headerbar = HeaderBar()
-        self._searchbar = SearchBar()
+
         self._search.bind_property(
             "search-mode-active", self._headerbar, "search-mode-active",
             GObject.BindingFlags.BIDIRECTIONAL
@@ -141,16 +149,10 @@ class Window(Gtk.ApplicationWindow):
             GObject.BindingFlags.SYNC_CREATE)
 
         self._player_toolbar = PlayerToolbar(self._player, self)
-        selection_toolbar = SelectionToolbar()
         self.views = [None] * len(View)
-        self._stack = Gtk.Stack(
-            transition_type=Gtk.StackTransitionType.CROSSFADE,
-            transition_duration=100,
-            homogeneous=False,
-            visible=True,
-            can_focus=False)
 
         self._searchbar.props.stack = self._stack
+        selection_toolbar = SelectionToolbar()
         self._headerbar.connect(
             'back-button-clicked', self._switch_back_from_childview)
 
@@ -177,28 +179,20 @@ class Window(Gtk.ApplicationWindow):
         # bottom line of the searchbar
         self._stack.get_style_context().add_class('background')
 
-        self._overlay = Gtk.Overlay()
-        self._overlay.add(self._stack)
         # FIXME: Need to find a proper way to do this.
         self._overlay.add_overlay(self._searchbar._dropdown)
-        self._overlay.add_overlay(self.notifications_popup)
-        self.set_titlebar(self._headerbar)
-        self._box.pack_start(self._searchbar, False, False, 0)
-        self._box.pack_start(self._overlay, True, True, 0)
+
         self._box.pack_start(self._player_toolbar, False, False, 0)
-        self._box.pack_start(selection_toolbar, False, False, 0)
-        self.add(self._box)
 
-        selection_toolbar.connect(
-            'add-to-playlist', self._on_add_to_playlist)
+        self.set_titlebar(self._headerbar)
+
+        selection_toolbar.connect('add-to-playlist', self._on_add_to_playlist)
         self._search.connect("notify::state", self._on_search_state_changed)
 
         self._headerbar.props.state = HeaderBar.State.MAIN
         self._headerbar.show()
-        self._overlay.show()
+
         self._player_toolbar.show_all()
-        self._box.show()
-        self.show()
 
         def songs_available_cb(available):
             if available:


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