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



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

    window: Initial template port

 data/org.gnome.Music.gresource.xml       |  1 +
 data/ui/Window.ui                        | 40 ++++++++++++++++++++++++
 gnomemusic/widgets/notificationspopup.py |  7 +++--
 gnomemusic/widgets/searchbar.py          |  3 ++
 gnomemusic/window.py                     | 52 ++++++++++++++++----------------
 5 files changed, 74 insertions(+), 29 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..d31fc53a
--- /dev/null
+++ b/data/ui/Window.ui
@@ -0,0 +1,40 @@
+<?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="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..ac08d9df 100644
--- a/gnomemusic/widgets/searchbar.py
+++ b/gnomemusic/widgets/searchbar.py
@@ -88,6 +88,9 @@ class BaseManager(GObject.GObject):
         if selected_id == "":
             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..d3ee691a 100644
--- a/gnomemusic/window.py
+++ b/gnomemusic/window.py
@@ -60,11 +60,20 @@ 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()
+    _selection_toolbar = Gtk.Template.Child()
+    _stack = Gtk.Template.Child()
+
     def __repr__(self):
         return '<Window>'
 
@@ -124,11 +133,11 @@ 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._searchbar.props.stack = self._stack
+        self._headerbar = HeaderBar()
+
         self._search.bind_property(
             "search-mode-active", self._headerbar, "search-mode-active",
             GObject.BindingFlags.BIDIRECTIONAL
@@ -141,16 +150,8 @@ 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
         self._headerbar.connect(
             'back-button-clicked', self._switch_back_from_childview)
 
@@ -158,14 +159,18 @@ 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',
-            GObject.BindingFlags.SYNC_CREATE)
+            'selection-mode', self._player_toolbar, 'visible',
+            GObject.BindingFlags.INVERT_BOOLEAN)
+        self.bind_property(
+            'selection-mode', self._selection_toolbar, 'visible')
+
         # Create only the empty view at startup
         # if no music, switch to empty view and hide stack
         # if some music is available, populate stack with mainviews,
@@ -177,28 +182,23 @@ 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._box.reorder_child(self._searchbar, 0)
+        self._box.pack_end(self._player_toolbar, False, False, 0)
+
+        self.set_titlebar(self._headerbar)
 
-        selection_toolbar.connect(
+        self._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]