From 2aded0e67f4e6a0d20bb8672aac3eaa4575c4c17 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Fri, 10 Sep 2010 17:46:42 -0400 Subject: [PATCH] Filesystem Selecting Began experimenting with a filesystem selector that can select both files and directories. --- ocarina/button.py | 7 +++++++ ocarina/fsselect.py | 49 +++++++++++++++++++++++++++++++++++++++++++++ ocarina/info.py | 15 +++++++++----- tests/fs_select.py | 19 ++++++++++++++++++ 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 ocarina/fsselect.py create mode 100644 tests/fs_select.py diff --git a/ocarina/button.py b/ocarina/button.py index 248c3b45..9f46e441 100644 --- a/ocarina/button.py +++ b/ocarina/button.py @@ -44,3 +44,10 @@ class PauseButton(Button): LS.event.invite("POSTSTOP", self.hide) def clicked(self, button): LS.music.pause() + + +class OpenButton(Button): + def __init__(self): + Button.__init__(self, gtk.STOCK_OPEN) + def clicked(self, button): + print "OpenButton clicked" diff --git a/ocarina/fsselect.py b/ocarina/fsselect.py new file mode 100644 index 00000000..774dc60a --- /dev/null +++ b/ocarina/fsselect.py @@ -0,0 +1,49 @@ +# Bryan Schumaker (June 2010) + +import gtk +import gobject + +#FS_OK = gobject.signal_new("filesystem_ok", gtk.FileChooserDialog, +# gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, +# (gtk.Dialog, int)) +#print FS_OK + +#print gobject.signal_query(FS_OK) +#print gobject.signal_query(gtk.RESPONSE_OK) + + +def make_chooser(title, action): + buttons = (gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OK, gtk.RESPONSE_OK) + chooser = gtk.FileChooserDialog(title, action=action, buttons=buttons) + chooser.connect("response", response) + return chooser + + +def response(*args): + print "here?" + print args + + +def run_chooser(chooser): + file = None + if chooser.run() == gtk.RESPONSE_OK: + file = chooser.get_filename() + chooser.hide() + return file + + +# Use for selecting a file through the GUI +def file(title="Select a song"): + chooser = makeChooser(title, gtk.FILE_CHOOSER_ACTION_OPEN) + return runChooser(chooser) + + +# Use for selecting a directory through the GUI +def dir(title="Select a directory"): + chooser = makeChooser(title, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER) + return runChooser(chooser) + + +def save(title="Select a location"): + chooser = makeChooser(title, gtk.FILE_CHOOSER_ACTION_SAVE) + return runChooser(chooser) diff --git a/ocarina/info.py b/ocarina/info.py index aa5b6684..cd8ac692 100644 --- a/ocarina/info.py +++ b/ocarina/info.py @@ -30,6 +30,15 @@ class Bar(gtk.VBox): self.contents.pack_start(widget, expand, fill) +class FilterBar(Bar): + def __init__(self): + Bar.__init__(self, False) + global button + global libsaria + + self.pack(button.OpenButton()) + + class InfoBar(Bar): def __init__(self): Bar.__init__(self, True) @@ -58,11 +67,7 @@ def init(): import button info = InfoBar() - filter = Bar(False) - - label2 = gtk.Label("Top label") - label2.show() - filter.pack(label2, True, True) + filter = FilterBar() def get_info(): diff --git a/tests/fs_select.py b/tests/fs_select.py new file mode 100644 index 00000000..ada2bf1a --- /dev/null +++ b/tests/fs_select.py @@ -0,0 +1,19 @@ +# Bryan Schumake (9/10/2010) + +import ocarina +from ocarina import fsselect + +gtk = ocarina.gtk + +chooser = gtk.FileChooserWidget() +chooser.show() + +win = gtk.Window(gtk.WINDOW_TOPLEVEL) + +win.add(chooser) +win.show() + +raw_input(">>>") +print chooser +#chooser = fsselect.make_chooser("Test Chooser", gtk.FILE_CHOOSER_ACTION_OPEN) +#fsselect.run_chooser(chooser)