fallback tk support

This commit is contained in:
j 2012-01-17 13:20:50 +05:30
parent 74eed215b5
commit 98581f7ec9
3 changed files with 59 additions and 40 deletions

View file

@ -33,7 +33,7 @@ def main(config):
backend = Backend(config)
root = Server(base, backend)
site = Site(root)
port = 2620
interface = '127.0.0.1'
port = int(backend.get('port', '2620'))
interface = backend.get('port', '127.0.0.1')
reactor.listenTCP(port, site, interface=interface)
reactor.run()

View file

@ -3,7 +3,7 @@
import os
from server import actions, json_response
import ui
from ui import ui
def init(backend, site, data):
response = {}

View file

@ -1,43 +1,62 @@
# encoding: utf-8
# vi:si:et:sw=4:sts=4:ts=4
import pygtk
pygtk.require('2.0')
import gtk
try:
import pygtk
pygtk.require('2.0')
import gtk
use_gtk = True
except:
import tkFileDialog
use_gtk = False
def selectFolder(data):
dialog = gtk.FileChooserDialog("Select Folder..",
None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
class GtkUI:
def selectFolder(self, data):
dialog = gtk.FileChooserDialog("Select Folder..",
None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, 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
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
def selectFile(data):
dialog = gtk.FileChooserDialog("Select File..",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)
def selectFile(self, data):
dialog = gtk.FileChooserDialog("Select File..",
None,
gtk.FILE_CHOOSER_ACTION_OPEN,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OPEN, 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