Filesystem Selecting

Began experimenting with a filesystem selector that can select both
files and directories.
This commit is contained in:
Bryan Schumaker 2010-09-10 17:46:42 -04:00
parent 2f562bcc81
commit 2aded0e67f
4 changed files with 85 additions and 5 deletions

View File

@ -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"

49
ocarina/fsselect.py Normal file
View File

@ -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)

View File

@ -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():

19
tests/fs_select.py Normal file
View File

@ -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)