Commit a2e9d193 authored by Marinus Schraal's avatar Marinus Schraal

window: Initial template port

Partially ports Window to use a Gtk.Builder template.

This work is incomplete because of pygobject#257.
parent cd2f1c3b
......@@ -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>
<?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>
<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>
......@@ -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
......
# Copyright (c) 2013 Eslam Mostafa <cseslam@gmail.com>
# Copyright (c) 2013 Vadim Rutkovsky <vrutkovs@redhat.com>
# Copyright (c) 2013 Sai Suman Prayaga <suman.sai14@gmail.com>
# Copyright (c) 2013 Arnel A. Borja <kyoushuu@yahoo.com>
# Copyright (c) 2013 Shivani Poddar <shivani.poddar92@gmail.com>
# Copyright (c) 2013 Manish Sinha <manishsinha@ubuntu.com>
# Copyright (c) 2013 Seif Lotfy <seif@gmail.com>
# Copyright (c) 2013 Guillaume Quintard <guillaume.quintard@gmail.com>
# Copyright 2019 The GNOME Music developers
#
# GNOME Music is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -47,11 +40,11 @@ from gnomemusic.views.searchview import SearchView
from gnomemusic.views.songsview import SongsView
from gnomemusic.views.playlistview import PlaylistView
from gnomemusic.widgets.headerbar import HeaderBar
from gnomemusic.widgets.notificationspopup import NotificationsPopup
from gnomemusic.widgets.notificationspopup import NotificationsPopup # noqa
from gnomemusic.widgets.playertoolbar import PlayerToolbar
from gnomemusic.widgets.playlistdialog import PlaylistDialog
from gnomemusic.widgets.searchbar import SearchBar
from gnomemusic.widgets.selectiontoolbar import SelectionToolbar
from gnomemusic.widgets.selectiontoolbar import SelectionToolbar # noqa: F401
from gnomemusic.windowplacement import WindowPlacement
import logging
......@@ -60,11 +53,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>'
......@@ -93,7 +95,6 @@ class Window(Gtk.ApplicationWindow):
self._player = app.props.player
self.notifications_popup = NotificationsPopup()
self._setup_view()
MediaKeys(self._player, self)
......@@ -124,11 +125,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 +142,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 +151,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 +174,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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment