rind: Add a New Libray button
Clicking the button shows a popover with a file chooser widget, which can be used to select a library path. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
b03877129d
commit
ff3b9c4b5a
382
emmental.ui
382
emmental.ui
|
@ -2,6 +2,11 @@
|
|||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkFileFilter" id="filefilter1">
|
||||
<mime-types>
|
||||
<mime-type>inode/directory</mime-type>
|
||||
</mime-types>
|
||||
</object>
|
||||
<object class="GtkAdjustment" id="progress_adjustment">
|
||||
<property name="upper">100</property>
|
||||
<property name="step_increment">5</property>
|
||||
|
@ -269,175 +274,262 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPaned">
|
||||
<object class="GtkOverlay">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="position">150</property>
|
||||
<property name="position_set">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkPaned">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="position">150</property>
|
||||
<property name="position_set">True</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="manager_treeview">
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="expander_column">treeviewcolumn1</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">50</property>
|
||||
<property name="title" translatable="yes">column</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf">
|
||||
<property name="stock_size">1</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="icon-name">0</attribute>
|
||||
</attributes>
|
||||
<object class="GtkTreeView" id="manager_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="headers_visible">False</property>
|
||||
<property name="expander_column">treeviewcolumn1</property>
|
||||
<property name="enable_tree_lines">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">column</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="markup">1</attribute>
|
||||
</attributes>
|
||||
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">50</property>
|
||||
<property name="title" translatable="yes">column</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererPixbuf">
|
||||
<property name="stock_size">1</property>
|
||||
</object>
|
||||
<attributes>
|
||||
<attribute name="icon-name">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">column</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="markup">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="playlist_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscroll_policy">natural</property>
|
||||
<property name="vscroll_policy">natural</property>
|
||||
<property name="fixed_height_mode">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">#</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">250</property>
|
||||
<property name="title" translatable="yes">Title</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">Length</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Artist</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Album</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">4</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">Year</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">5</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Genre</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">6</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">True</property>
|
||||
<property name="index">-1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="overlay">
|
||||
<object class="GtkButton" id="library_add">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="valign">end</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="icon_name">folder-music</property>
|
||||
<property name="icon_size">5</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="circular"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPopover" id="library_popover">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="relative_to">library_add</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkFileChooserWidget" id="library_chooser">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="create_folders">False</property>
|
||||
<property name="filter">filefilter1</property>
|
||||
<property name="preview_widget_active">False</property>
|
||||
<property name="use_preview_label">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="width">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<object class="GtkButton" id="library_cancel">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="playlist_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscroll_policy">natural</property>
|
||||
<property name="vscroll_policy">natural</property>
|
||||
<property name="fixed_height_mode">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">#</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">250</property>
|
||||
<property name="title" translatable="yes">Title</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">Length</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Artist</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Album</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">4</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="title" translatable="yes">Year</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">5</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">fixed</property>
|
||||
<property name="fixed_width">150</property>
|
||||
<property name="title" translatable="yes">Genre</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">6</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">True</property>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="library_ok">
|
||||
<property name="label">gtk-ok</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from . import gtk
|
||||
from . import playlist
|
||||
import curds
|
||||
import os
|
||||
from gi.repository import GObject, Gtk, GLib
|
||||
|
||||
toplevel = [ "Collection", "Previous", None, "Genre", None, "Library" ]
|
||||
|
@ -130,8 +131,32 @@ class ManagerModel(GObject.GObject, Gtk.TreeModel):
|
|||
playlist.PlistModel.set_playlist(plist)
|
||||
|
||||
|
||||
MgrModel = ManagerModel()
|
||||
Treeview = gtk.Builder.get_object("manager_treeview")
|
||||
def library_add_clicked(self, *args):
|
||||
folder = os.path.join(os.path.expanduser("~"), "Music")
|
||||
LibraryChooser.set_filename(folder)
|
||||
LibraryPopover.popup()
|
||||
|
||||
def library_cancel_clicked(self, *args):
|
||||
LibraryPopover.popdown()
|
||||
|
||||
def library_ok_clicked(self, *args):
|
||||
path = LibraryChooser.get_filename()
|
||||
LibraryPopover.popdown()
|
||||
curds.PlaylistManager["Library"].add(path)
|
||||
|
||||
|
||||
LibraryAdd = gtk.Builder.get_object("library_add")
|
||||
LibraryCancel = gtk.Builder.get_object("library_cancel")
|
||||
LibraryChooser = gtk.Builder.get_object("library_chooser")
|
||||
LibraryOk = gtk.Builder.get_object("library_ok")
|
||||
LibraryPopover = gtk.Builder.get_object("library_popover")
|
||||
MgrModel = ManagerModel()
|
||||
Treeview = gtk.Builder.get_object("manager_treeview")
|
||||
|
||||
LibraryAdd.connect("clicked", library_add_clicked)
|
||||
LibraryCancel.connect("clicked", library_cancel_clicked)
|
||||
LibraryOk.connect("clicked", library_ok_clicked)
|
||||
|
||||
Treeview.set_model(MgrModel)
|
||||
Treeview.get_selection().set_select_function(MgrModel.can_select_path)
|
||||
Treeview.get_selection().connect("changed", MgrModel.on_selection_changed)
|
||||
|
|
|
@ -4,6 +4,7 @@ from . import manager
|
|||
from . import playlist
|
||||
import curds
|
||||
import os
|
||||
import time
|
||||
import unittest
|
||||
from gi.repository import Gtk, GObject, GLib
|
||||
|
||||
|
@ -29,7 +30,12 @@ class TestManager(unittest.TestCase):
|
|||
|
||||
def test_init(self):
|
||||
self.assertIsInstance(gtk.Builder.get_object("manager_treeview"), Gtk.TreeView)
|
||||
self.assertIsInstance(manager.MgrModel, Gtk.TreeModel)
|
||||
self.assertIsInstance(manager.LibraryAdd, Gtk.Button)
|
||||
self.assertIsInstance(manager.LibraryCancel, Gtk.Button)
|
||||
self.assertIsInstance(manager.LibraryChooser, Gtk.FileChooser)
|
||||
self.assertIsInstance(manager.LibraryOk, Gtk.Button)
|
||||
self.assertIsInstance(manager.LibraryPopover, Gtk.Popover)
|
||||
self.assertIsInstance(manager.MgrModel, Gtk.TreeModel)
|
||||
self.assertEqual(manager.Treeview, gtk.Builder.get_object("manager_treeview"))
|
||||
self.assertEqual(manager.Treeview.get_model(), manager.MgrModel)
|
||||
|
||||
|
@ -155,3 +161,34 @@ class TestManager(unittest.TestCase):
|
|||
self.assertEqual(playlist.PlistModel.playlist, plist)
|
||||
|
||||
selection.unselect_all()
|
||||
|
||||
def test_manager_new_library(self):
|
||||
music_dir = os.path.join(os.path.expanduser("~"), "Music")
|
||||
|
||||
self.assertFalse(manager.LibraryPopover.is_visible())
|
||||
manager.LibraryAdd.clicked()
|
||||
time.sleep(0.2)
|
||||
while Gtk.events_pending(): Gtk.main_iteration_do(True)
|
||||
self.assertTrue(manager.LibraryPopover.is_visible())
|
||||
self.assertEqual(len(plist_mgr["Library"]), 0)
|
||||
|
||||
manager.LibraryCancel.clicked()
|
||||
time.sleep(0.2)
|
||||
while Gtk.events_pending(): Gtk.main_iteration_do(True)
|
||||
self.assertFalse(manager.LibraryPopover.is_visible())
|
||||
self.assertEqual(len(plist_mgr["Library"]), 0)
|
||||
|
||||
manager.LibraryAdd.clicked()
|
||||
time.sleep(0.2)
|
||||
while Gtk.events_pending(): Gtk.main_iteration_do(True)
|
||||
self.assertTrue(manager.LibraryPopover.is_visible())
|
||||
self.assertEqual(manager.LibraryChooser.get_filename(), music_dir)
|
||||
self.assertEqual(len(plist_mgr["Library"]), 0)
|
||||
|
||||
manager.LibraryChooser.set_filename(test_album1)
|
||||
while Gtk.events_pending(): Gtk.main_iteration_do(True)
|
||||
manager.LibraryOk.clicked()
|
||||
time.sleep(0.2)
|
||||
while Gtk.events_pending(): Gtk.main_iteration_do(True)
|
||||
self.assertFalse(manager.LibraryPopover.is_visible())
|
||||
self.assertEqual(len(plist_mgr["Library"]), 1)
|
||||
|
|
Loading…
Reference in New Issue