fallback tk support
This commit is contained in:
parent
74eed215b5
commit
98581f7ec9
3 changed files with 59 additions and 40 deletions
|
@ -33,7 +33,7 @@ def main(config):
|
||||||
backend = Backend(config)
|
backend = Backend(config)
|
||||||
root = Server(base, backend)
|
root = Server(base, backend)
|
||||||
site = Site(root)
|
site = Site(root)
|
||||||
port = 2620
|
port = int(backend.get('port', '2620'))
|
||||||
interface = '127.0.0.1'
|
interface = backend.get('port', '127.0.0.1')
|
||||||
reactor.listenTCP(port, site, interface=interface)
|
reactor.listenTCP(port, site, interface=interface)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from server import actions, json_response
|
from server import actions, json_response
|
||||||
import ui
|
from ui import ui
|
||||||
|
|
||||||
def init(backend, site, data):
|
def init(backend, site, data):
|
||||||
response = {}
|
response = {}
|
||||||
|
|
|
@ -1,43 +1,62 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
import pygtk
|
try:
|
||||||
pygtk.require('2.0')
|
import pygtk
|
||||||
import gtk
|
pygtk.require('2.0')
|
||||||
|
import gtk
|
||||||
|
use_gtk = True
|
||||||
|
except:
|
||||||
|
import tkFileDialog
|
||||||
|
use_gtk = False
|
||||||
|
|
||||||
def selectFolder(data):
|
class GtkUI:
|
||||||
dialog = gtk.FileChooserDialog("Select Folder..",
|
def selectFolder(self, data):
|
||||||
None,
|
dialog = gtk.FileChooserDialog("Select Folder..",
|
||||||
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
None,
|
||||||
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||||
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
||||||
|
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||||
|
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == gtk.RESPONSE_OK:
|
if response == gtk.RESPONSE_OK:
|
||||||
filename = dialog.get_filename()
|
filename = dialog.get_filename()
|
||||||
print filename, 'selected'
|
print filename, 'selected'
|
||||||
elif response == gtk.RESPONSE_CANCEL:
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
print 'Closed, no files selected'
|
print 'Closed, no files selected'
|
||||||
filename = None
|
filename = None
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
print "done"
|
print "done"
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def selectFile(data):
|
def selectFile(self, data):
|
||||||
dialog = gtk.FileChooserDialog("Select File..",
|
dialog = gtk.FileChooserDialog("Select File..",
|
||||||
None,
|
None,
|
||||||
gtk.FILE_CHOOSER_ACTION_OPEN,
|
gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||||
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||||
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
|
||||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||||
|
|
||||||
|
response = dialog.run()
|
||||||
|
if response == gtk.RESPONSE_OK:
|
||||||
|
filename = dialog.get_filename()
|
||||||
|
print filename, 'selected'
|
||||||
|
elif response == gtk.RESPONSE_CANCEL:
|
||||||
|
print 'Closed, no files selected'
|
||||||
|
filename = None
|
||||||
|
dialog.destroy()
|
||||||
|
print "done"
|
||||||
|
return filename
|
||||||
|
|
||||||
|
class TkUI:
|
||||||
|
def selectFolder(self, data):
|
||||||
|
return tkFileDialog.askdirectory()
|
||||||
|
|
||||||
|
def selectFile(self, data):
|
||||||
|
return tkFileDialog.askopenfilename()
|
||||||
|
|
||||||
|
if use_gtk:
|
||||||
|
ui = GtkUI()
|
||||||
|
else:
|
||||||
|
ui = TkUI()
|
||||||
|
|
||||||
response = dialog.run()
|
|
||||||
if response == gtk.RESPONSE_OK:
|
|
||||||
filename = dialog.get_filename()
|
|
||||||
print filename, 'selected'
|
|
||||||
elif response == gtk.RESPONSE_CANCEL:
|
|
||||||
print 'Closed, no files selected'
|
|
||||||
filename = None
|
|
||||||
dialog.destroy()
|
|
||||||
print "done"
|
|
||||||
return filename
|
|
||||||
|
|
Loading…
Reference in a new issue