[gnome-music/wip/jfelder/searchview-new-style: 1/15] searchview: Use Gtk.Builder
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/searchview-new-style: 1/15] searchview: Use Gtk.Builder
- Date: Sun, 4 Aug 2019 01:34:51 +0000 (UTC)
commit fe7a7163a798955cdd5f779a79274c5aff581cd0
Author: Jean Felder <jfelder src gnome org>
Date: Thu Aug 1 00:11:07 2019 +0200
searchview: Use Gtk.Builder
data/org.gnome.Music.gresource.xml | 1 +
data/ui/SearchView.ui | 49 +++++++++++++++++++++++++++++++++
gnomemusic/views/searchview.py | 56 ++++++++++----------------------------
3 files changed, 64 insertions(+), 42 deletions(-)
---
diff --git a/data/org.gnome.Music.gresource.xml b/data/org.gnome.Music.gresource.xml
index 75d3e02f..8326914c 100644
--- a/data/org.gnome.Music.gresource.xml
+++ b/data/org.gnome.Music.gresource.xml
@@ -23,6 +23,7 @@
<file preprocess="xml-stripblanks">ui/PlaylistDialogRow.ui</file>
<file preprocess="xml-stripblanks">ui/PlaylistTile.ui</file>
<file preprocess="xml-stripblanks">ui/SearchBar.ui</file>
+ <file preprocess="xml-stripblanks">ui/SearchView.ui</file>
<file preprocess="xml-stripblanks">ui/SelectionBarMenuButton.ui</file>
<file preprocess="xml-stripblanks">ui/SelectionToolbar.ui</file>
<file preprocess="xml-stripblanks">ui/SongWidget.ui</file>
diff --git a/data/ui/SearchView.ui b/data/ui/SearchView.ui
new file mode 100644
index 00000000..064276dc
--- /dev/null
+++ b/data/ui/SearchView.ui
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.18"/>
+ <template class="SearchView" parent="GtkStack">
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkScrolledWindow" id="_search_results">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkBox" id="container">
+ <property name="orientation">vertical</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkFlowBox" id="_album_flowbox">
+ <property name="halign">fill</property>
+ <property name="hexpand">True</property>
+ <property name="valign">start</property>
+ <property name="homogeneous">True</property>
+ <property name="min_children_per_line">1</property>
+ <property name="max_children_per_line">20</property>
+ <property name="margin">18</property>
+ <property name="row_spacing">12</property>
+ <property name="column_spacing">6</property>
+ <property name="selection_mode">none</property>
+ <property name="visible">True</property>
+ <signal name="child-activated" handler="_on_album_activated" swapped="no"/>
+ <style>
+ <class name="content-view"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkFlowBox" id="_artist_listbox">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBox" id="_songs_listbox">
+ <property name="visible">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gnomemusic/views/searchview.py b/gnomemusic/views/searchview.py
index 1900b5dd..b74e3140 100644
--- a/gnomemusic/views/searchview.py
+++ b/gnomemusic/views/searchview.py
@@ -28,7 +28,6 @@ from gnomemusic import log
from gnomemusic.player import PlayerPlaylist
from gnomemusic.utils import View
from gnomemusic.search import Search
-from gnomemusic.views.baseview import BaseView
from gnomemusic.widgets.albumcover import AlbumCover
from gnomemusic.widgets.albumwidget import AlbumWidget
from gnomemusic.widgets.headerbar import HeaderBar
@@ -37,16 +36,24 @@ from gnomemusic.widgets.artisttile import ArtistTile
from gnomemusic.widgets.songwidget import SongWidget
+@Gtk.Template(resource_path="/org/gnome/Music/ui/SearchView.ui")
class SearchView(Gtk.Stack):
"""Gridlike view of search results.
Three sections: artists, albums, songs.
"""
+ __gtype_name__ = "SearchView"
+
search_state = GObject.Property(type=int, default=Search.State.NONE)
selected_items_count = GObject.Property(type=int, default=0, minimum=0)
selection_mode = GObject.Property(type=bool, default=False)
+ _album_flowbox = Gtk.Template.Child()
+ _artist_listbox = Gtk.Template.Child()
+ _search_results = Gtk.Template.Child()
+ _songs_listbox = Gtk.Template.Child()
+
def __repr__(self):
return '<SearchView>'
@@ -70,19 +77,9 @@ class SearchView(Gtk.Stack):
self._player = self._application.props.player
- self._grid = Gtk.Grid(orientation=Gtk.Orientation.HORIZONTAL)
- self._box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
-
- # Setup the main view
- self._setup_view()
-
- self._grid.add(self._box)
-
self._window = application.props.window
self._headerbar = self._window._headerbar
- self.add(self._grid)
-
self.connect("notify::selection-mode", self._on_selection_mode_changed)
self.bind_property(
@@ -103,37 +100,11 @@ class SearchView(Gtk.Stack):
self._search_mode_active = False
# self.connect("notify::search-state", self._on_search_state_changed)
- @log
- def _setup_view(self):
- view_container = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
- self._box.pack_start(view_container, True, True, 0)
-
- self._songs_listbox = Gtk.ListBox()
+ self._artist_listbox.bind_model(
+ self._artist_model, self._create_artist_widget)
self._songs_listbox.bind_model(self._model, self._create_song_widget)
-
- self._album_flowbox = Gtk.FlowBox(
- homogeneous=True, hexpand=True, halign=Gtk.Align.FILL,
- valign=Gtk.Align.START, selection_mode=Gtk.SelectionMode.NONE,
- margin=18, row_spacing=12, column_spacing=6,
- min_children_per_line=1, max_children_per_line=20, visible=True)
- self._album_flowbox.get_style_context().add_class('content-view')
self._album_flowbox.bind_model(
self._album_model, self._create_album_widget)
- self._album_flowbox.connect(
- "child-activated", self._on_album_activated)
-
- self._artist_listbox = Gtk.ListBox()
- self._artist_listbox.bind_model(
- self._artist_model, self._create_artist_widget)
-
- self._all_results_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
- self._all_results_box.pack_start(self._album_flowbox, True, True, 0)
- self._all_results_box.pack_start(self._artist_listbox, True, True, 0)
- self._all_results_box.pack_start(self._songs_listbox, True, True, 0)
-
- view_container.add(self._all_results_box)
-
- self._box.show_all()
def _create_song_widget(self, coresong):
song_widget = SongWidget(coresong)
@@ -200,6 +171,7 @@ class SearchView(Gtk.Stack):
return True
+ @Gtk.Template.Callback()
def _on_album_activated(self, widget, child, user_data=None):
corealbum = child.props.corealbum
if self.props.selection_mode:
@@ -278,11 +250,11 @@ class SearchView(Gtk.Stack):
if self.get_visible_child() == self._artist_albums_widget:
self._artist_albums_widget.destroy()
self._artist_albums_widget = None
- elif self.get_visible_child() == self._grid:
+ elif self.get_visible_child() == self._search_results:
self._window.views[View.ALBUM].set_visible_child(
self._window.views[View.ALBUM]._grid)
- self.set_visible_child(self._grid)
+ self.set_visible_child(self._search_results)
self.props.search_mode_active = True
self._headerbar.props.state = HeaderBar.State.MAIN
@@ -319,5 +291,5 @@ class SearchView(Gtk.Stack):
# the child views.
self._search_mode_active = value
if (not self._search_mode_active
- and self.get_visible_child() == self._grid):
+ and self.get_visible_child() == self._search_results):
self.props.search_state = Search.State.NONE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]