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 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):
dialog = gtk.MessageDialog(
@ -45,38 +51,32 @@ def select_file(strings):
return filename, basename
def start_webapp(webapp_port, onionshare_port, filename, onion_host):
global window
global qtapp
webapp.onionshare = onionshare
webapp.onionshare_port = onionshare_port
webapp.filename = filename
webapp.onion_host = onion_host
webapp.window = window
webapp.qtapp = qtapp
webapp.clipboard = qtapp.clipboard()
webapp.app.run(port=webapp_port)
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(webapp_port)
gtk.main_quit()
global window
window.set_title('{0} | OnionShare'.format(basename))
window.resize(520, 400)
window.set_resizable(False)
window.connect('destroy', on_destroy)
global qtapp
qtapp.connect(qtapp, SIGNAL("aboutToQuit()"), shutdown)
web = QWebView()
web.load(QUrl("http://127.0.0.1:{0}".format(webapp_port)))
web.show()
sys.exit(qtapp.exec_())
box = gtk.VBox(homogeneous=False, spacing=0)
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()
# todo: set window title, and do resizable stuff
def main():
onionshare.strings = onionshare.load_strings()

View File

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