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

View file

@ -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 = {}

View file

@ -1,10 +1,16 @@
# encoding: utf-8 # encoding: utf-8
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
try:
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
use_gtk = True
except:
import tkFileDialog
use_gtk = False
def selectFolder(data): class GtkUI:
def selectFolder(self, data):
dialog = gtk.FileChooserDialog("Select Folder..", dialog = gtk.FileChooserDialog("Select Folder..",
None, None,
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
@ -23,7 +29,7 @@ def selectFolder(data):
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,
@ -41,3 +47,16 @@ def selectFile(data):
dialog.destroy() dialog.destroy()
print "done" print "done"
return filename 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()