beginning to rip out gtk and replace with Qt

This commit is contained in:
Micah Lee 2014-06-19 16:19:46 -04:00
parent 590011545a
commit 1c59072a2b
2 changed files with 30 additions and 29 deletions

View File

@ -1,7 +1,13 @@
import onionshare, webapp import onionshare, webapp
import threading, gtk, gobject, webkit, os, sys, subprocess import threading, os, sys, subprocess
window = gtk.Window() import gtk
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
qtapp = QApplication(sys.argv)
def alert(msg, type=gtk.MESSAGE_INFO): def alert(msg, type=gtk.MESSAGE_INFO):
dialog = gtk.MessageDialog( dialog = gtk.MessageDialog(
@ -45,38 +51,32 @@ def select_file(strings):
return filename, basename return filename, basename
def start_webapp(webapp_port, onionshare_port, filename, onion_host): def start_webapp(webapp_port, onionshare_port, filename, onion_host):
global window global qtapp
webapp.onionshare = onionshare webapp.onionshare = onionshare
webapp.onionshare_port = onionshare_port webapp.onionshare_port = onionshare_port
webapp.filename = filename webapp.filename = filename
webapp.onion_host = onion_host webapp.onion_host = onion_host
webapp.window = window
webapp.qtapp = qtapp
webapp.clipboard = qtapp.clipboard()
webapp.app.run(port=webapp_port) webapp.app.run(port=webapp_port)
def launch_window(webapp_port, onionshare_port, basename): def launch_window(webapp_port, onionshare_port, basename):
def on_destroy(widget, data=None): def shutdown():
print 'shutting down'
onionshare.tails_close_port(onionshare_port) onionshare.tails_close_port(onionshare_port)
onionshare.tails_close_port(webapp_port) onionshare.tails_close_port(webapp_port)
gtk.main_quit()
global window global qtapp
window.set_title('{0} | OnionShare'.format(basename)) qtapp.connect(qtapp, SIGNAL("aboutToQuit()"), shutdown)
window.resize(520, 400) web = QWebView()
window.set_resizable(False) web.load(QUrl("http://127.0.0.1:{0}".format(webapp_port)))
window.connect('destroy', on_destroy) web.show()
sys.exit(qtapp.exec_())
box = gtk.VBox(homogeneous=False, spacing=0) # todo: set window title, and do resizable stuff
window.add(box)
browser = webkit.WebView()
box.pack_start(browser, expand=True, fill=True, padding=0)
window.show_all()
# wait half a second for server to start
gobject.timeout_add(500, browser.open, 'http://127.0.0.1:{0}/'.format(webapp_port))
gtk.main()
def main(): def main():
onionshare.strings = onionshare.load_strings() onionshare.strings = onionshare.load_strings()

View File

@ -1,13 +1,13 @@
from flask import Flask, render_template from flask import Flask, render_template
import threading, json, os, gtk, gobject import threading, json, os, time
onionshare = None onionshare = None
onionshare_port = None onionshare_port = None
filename = None filename = None
onion_host = None onion_host = None
window = None qtapp = None
clipboard = None
clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
url = None url = None
app = Flask(__name__, template_folder='./templates') app = Flask(__name__, template_folder='./templates')
@ -49,7 +49,7 @@ def start_onionshare():
@app.route("/copy_url") @app.route("/copy_url")
def copy_url(): def copy_url():
global clipboard global clipboard
clipboard.set_text(url) clipboard.setText(url)
return '' return ''
@app.route("/heartbeat") @app.route("/heartbeat")
@ -69,7 +69,8 @@ def check_for_requests():
@app.route("/close") @app.route("/close")
def close(): def close():
global window global qtapp
gobject.timeout_add(1000, window.destroy) time.sleep(1)
qtapp.closeAllWindows()
return '' return ''