File chooser window
I have created my own file chooser window that can select both files and directories. Currently, the "OK" button must be clicked to select anything.
This commit is contained in:
parent
2aded0e67f
commit
4a5085d973
|
@ -3,11 +3,11 @@
|
|||
__all__ = ["collection"]
|
||||
|
||||
import libsaria
|
||||
import tagpy
|
||||
#import tagpy
|
||||
call = libsaria.event.call
|
||||
exists = libsaria.path.exists
|
||||
expand = libsaria.path.expand
|
||||
FileRef = tagpy.FileRef
|
||||
#FileRef = tagpy.FileRef
|
||||
|
||||
LIBRARY = 0
|
||||
PLAYLIST = 1
|
||||
|
|
|
@ -4,6 +4,7 @@ import ocarina
|
|||
LS = ocarina.libsaria
|
||||
gtk = ocarina.gtk
|
||||
|
||||
|
||||
class Button(gtk.Button):
|
||||
def __init__(self, stock, func=None, show=True):
|
||||
gtk.Button.__init__(self)
|
||||
|
@ -50,4 +51,6 @@ class OpenButton(Button):
|
|||
def __init__(self):
|
||||
Button.__init__(self, gtk.STOCK_OPEN)
|
||||
def clicked(self, button):
|
||||
from ocarina import fsselect
|
||||
fsselect.run_chooser2(LS.data.universal_open)
|
||||
print "OpenButton clicked"
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# Bryan Schumaker (June 2010)
|
||||
|
||||
import gtk
|
||||
import ocarina
|
||||
import gobject
|
||||
import os
|
||||
gtk = ocarina.gtk
|
||||
|
||||
#FS_OK = gobject.signal_new("filesystem_ok", gtk.FileChooserDialog,
|
||||
# gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
|
@ -10,6 +12,8 @@ import gobject
|
|||
|
||||
#print gobject.signal_query(FS_OK)
|
||||
#print gobject.signal_query(gtk.RESPONSE_OK)
|
||||
chooser_window = None
|
||||
chooser_widget = None
|
||||
|
||||
|
||||
def make_chooser(title, action):
|
||||
|
@ -18,6 +22,42 @@ def make_chooser(title, action):
|
|||
chooser.connect("response", response)
|
||||
return chooser
|
||||
|
||||
def make_chooser2(title, callback):
|
||||
global chooser_window
|
||||
global chooser_widget
|
||||
chooser_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
|
||||
chooser_box = gtk.VBox(spacing = 0)
|
||||
button_box = gtk.HBox()
|
||||
chooser_widget = gtk.FileChooserWidget()
|
||||
open_button = gtk.Button(stock=gtk.STOCK_OK)
|
||||
close_button = gtk.Button(stock=gtk.STOCK_CANCEL)
|
||||
button_box.pack_end(open_button, False, False, 10)
|
||||
button_box.pack_end(close_button, False, False)
|
||||
chooser_box.pack_start(chooser_widget, True, True, 10)
|
||||
chooser_box.pack_start(button_box, False, False, 10)
|
||||
|
||||
size = close_button.size_request()
|
||||
open_button.set_size_request(size[0], size[1])
|
||||
close_button.connect("clicked", hide_chooser)
|
||||
open_button.connect("clicked", select_path, callback)
|
||||
|
||||
chooser_window.add(chooser_box)
|
||||
chooser_window.resize(800, 600)
|
||||
chooser_window.show_all()
|
||||
|
||||
def hide_chooser(button):
|
||||
global chooser_window
|
||||
chooser_window.hide()
|
||||
|
||||
def select_path(button, callback):
|
||||
global chooser_widget
|
||||
global chooser_window
|
||||
chooser_window.hide()
|
||||
callback( chooser_widget.get_uri() )
|
||||
|
||||
def run_chooser2(callback):
|
||||
make_chooser2("title", callback)
|
||||
|
||||
def response(*args):
|
||||
print "here?"
|
||||
|
|
|
@ -3,17 +3,12 @@
|
|||
import ocarina
|
||||
from ocarina import fsselect
|
||||
|
||||
gtk = ocarina.gtk
|
||||
def callback(uri):
|
||||
print uri
|
||||
|
||||
chooser = gtk.FileChooserWidget()
|
||||
chooser.show()
|
||||
|
||||
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
|
||||
win.add(chooser)
|
||||
win.show()
|
||||
fsselect.run_chooser2(callback)
|
||||
|
||||
raw_input(">>>")
|
||||
print chooser
|
||||
#print chooser
|
||||
#chooser = fsselect.make_chooser("Test Chooser", gtk.FILE_CHOOSER_ACTION_OPEN)
|
||||
#fsselect.run_chooser(chooser)
|
||||
|
|
Loading…
Reference in New Issue