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



commit ac3a2ad41ce320c38403af3a55e83ac6791ca460
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                     | 44 +++++++++++++------------------
 5 files changed, 72 insertions(+), 29 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index cd2e7d0d..793b9728 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..af9de8fc
--- /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 354b3ff9..53322bc3 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -84,6 +84,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 d6449d3d..cfae33bc 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -58,12 +58,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>'
 
@@ -80,13 +89,11 @@ class Window(Gtk.ApplicationWindow):
         select_none.connect('activate', self._select_none)
         self.add_action(select_none)
 
-        self.set_size_request(200, 100)
         WindowPlacement(self, self._settings)
 
         self.prev_view = None
         self.curr_view = None
 
-        self.notifications_popup = NotificationsPopup()
         self._setup_view()
 
         MediaKeys(self._player, self)
@@ -117,19 +124,10 @@ class Window(Gtk.ApplicationWindow):
 
     @log
     def _setup_view(self):
-        self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
         self._headerbar = HeaderBar()
-        self._searchbar = Searchbar()
         self._player = Player(self)
         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._headerbar.bind_property(
             "search-mode-enabled", self._searchbar, "search-mode-enabled",
@@ -143,13 +141,14 @@ class Window(Gtk.ApplicationWindow):
         self.bind_property(
             'selected-items-count', self._headerbar, 'selected-items-count')
         self.bind_property(
-            'selected-items-count', selection_toolbar, 'selected-items-count')
+            'selected-items-count', self._selection_toolbar,
+            'selected-items-count')
         self.bind_property(
             'selection-mode', self._headerbar, 'selection-mode',
             GObject.BindingFlags.BIDIRECTIONAL |
             GObject.BindingFlags.SYNC_CREATE)
         self.bind_property(
-            'selection-mode', selection_toolbar, 'visible',
+            'selection-mode', self._selection_toolbar, 'visible',
             GObject.BindingFlags.SYNC_CREATE)
         # Create only the empty view at startup
         # if no music, switch to empty view and hide stack
@@ -162,29 +161,22 @@ 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)
+
+        self.set_titlebar(self._headerbar)
 
         self._headerbar._search_button.connect(
             'toggled', self._on_search_toggled)
-        selection_toolbar.connect(
+        self._selection_toolbar.connect(
             'add-to-playlist', self._on_add_to_playlist)
 
         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]