fixed auth window, connected to a webview
This commit is contained in:
parent
7e358e4950
commit
ced63f7ce9
5 changed files with 87 additions and 125 deletions
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
./Tentia.py
|
|
@ -1,80 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<!-- interface-requires gtk+ 3.0 -->
|
||||
<object class="GtkWindow" id="Preferences">
|
||||
<property name="width_request">300</property>
|
||||
<property name="height_request">193</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="title" translatable="yes">Preferences</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="window_position">center</property>
|
||||
<property name="type_hint">notification</property>
|
||||
<property name="skip_taskbar_hint">True</property>
|
||||
<property name="skip_pager_hint">True</property>
|
||||
<property name="has_resize_grip">False</property>
|
||||
<property name="startup_id">perferences</property>
|
||||
<child>
|
||||
<object class="GtkLayout" id="layout1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="width">488</property>
|
||||
<property name="height">270</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="Icon">
|
||||
<property name="width_request">100</property>
|
||||
<property name="height_request">100</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="pixbuf">Icon.png</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">18</property>
|
||||
<property name="y">24</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="add_entity_info">
|
||||
<property name="width_request">159</property>
|
||||
<property name="height_request">21</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Add you entity to log in:</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">142</property>
|
||||
<property name="y">25</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkEntry" id="entity">
|
||||
<property name="width_request">366</property>
|
||||
<property name="height_request">31</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="invisible_char">•</property>
|
||||
<property name="placeholder_text">https://example.tent.is</property>
|
||||
<property name="input_purpose">url</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">141</property>
|
||||
<property name="y">53</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="login">
|
||||
<property name="label" translatable="yes">button</property>
|
||||
<property name="width_request">100</property>
|
||||
<property name="height_request">30</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x">404</property>
|
||||
<property name="y">92</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
from PyQt4 import QtCore, QtGui
|
||||
import TentiaWindows
|
||||
|
@ -7,7 +8,8 @@ class Tentia:
|
|||
|
||||
def __init__(self):
|
||||
self.app = QtGui.QApplication(sys.argv)
|
||||
self.controller = Controller(self)
|
||||
self.controller = Controller()
|
||||
self.console = Console()
|
||||
|
||||
self.setup_windows()
|
||||
self.preferences.show()
|
||||
|
@ -24,6 +26,10 @@ class Tentia:
|
|||
def resources_path(self):
|
||||
return "../"
|
||||
|
||||
def resources_uri(self):
|
||||
return "file://localhost" + os.path.abspath(os.path.join(os.path.dirname(__file__), '..', "WebKit"))
|
||||
|
||||
|
||||
def login_with_entity(self, entity):
|
||||
self.controller.setStringForKey("entity", entity)
|
||||
self.oauth_implementation = TentiaWindows.OauthImplementation(self)
|
||||
|
@ -32,17 +38,33 @@ class Tentia:
|
|||
return self.controller;
|
||||
|
||||
|
||||
class Controller:
|
||||
class Controller(QtCore.QObject):
|
||||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.user_defaults = {}
|
||||
user_defaults = {}
|
||||
|
||||
@QtCore.pyqtSlot(str, str)
|
||||
def setStringForKey(self, string, key):
|
||||
self.user_defaults[string] = key
|
||||
|
||||
def getStringForKey(self, key):
|
||||
return self.user_defaults[key]
|
||||
def stringForKey(self, key):
|
||||
if key in self.user_defaults:
|
||||
return self.user_defaults[key]
|
||||
|
||||
|
||||
class Console(QtCore.QObject):
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def log(self, string):
|
||||
print "<js>: " + string
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def warn(self, string):
|
||||
print "<js WARN>: " + string
|
||||
|
||||
@QtCore.pyqtSlot(str)
|
||||
def error(self, string):
|
||||
print "<js ERROR>: " + string
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Tentia()
|
|
@ -3,51 +3,61 @@ from PyQt4 import QtCore, QtGui, QtWebKit
|
|||
class Preferences:
|
||||
|
||||
def __init__(self, app):
|
||||
|
||||
self.app = app
|
||||
|
||||
# window
|
||||
self.window = QtGui.QMainWindow()
|
||||
self.window.setWindowTitle("Preferences")
|
||||
self.window.resize(300, 500)
|
||||
self.window.setMinimumSize(150, 150)
|
||||
self.window.resize(480, 186)
|
||||
self.window.setMinimumSize(480, 186)
|
||||
self.window.setMaximumSize(480, 186)
|
||||
self.window.move(0, 0)
|
||||
|
||||
#hbox1 = QtGui.QHBoxLayout()
|
||||
#self.window.addWidget(hbox1)
|
||||
|
||||
# image view
|
||||
image = QtGui.QPixmap(self.app.resources_path() + "Icon.png")
|
||||
image_view = QtGui.QLabel(self.window)
|
||||
image_view.setGeometry(20, 20, 146, 146)
|
||||
image_view.setPixmap(image)
|
||||
image_view.setScaledContents(True)
|
||||
|
||||
label = QtGui.QLabel(self.window)
|
||||
label.setGeometry(20, 20, 150, 150)
|
||||
label.setPixmap(image)
|
||||
label.setScaledContents(True)
|
||||
# info text
|
||||
info_text = QtGui.QLabel(self.window)
|
||||
info_text.setGeometry(194, 60, 262, 17)
|
||||
info_text.setText("Add your entity to log in:")
|
||||
|
||||
# login button
|
||||
button = QtGui.QPushButton(self.window)
|
||||
button.setText("Login")
|
||||
button.setGeometry(390, 109, 72, 32)
|
||||
button.setAutoDefault(True)
|
||||
self.window.connect(button, QtCore.SIGNAL('clicked()'), self.on_login_button_clicked)
|
||||
|
||||
# text field
|
||||
self.text_field = QtGui.QLineEdit(self.window)
|
||||
self.text_field.setPlaceholderText("https://example.tent.is")
|
||||
self.text_field.setGeometry(194, 84, 262, 22)
|
||||
self.window.connect(self.text_field, QtCore.SIGNAL('returnPressed()'), self.on_login_button_clicked)
|
||||
entity = self.app.controller.stringForKey("entity")
|
||||
if entity:
|
||||
self.text_field.setText(entity)
|
||||
|
||||
# activity_indicator
|
||||
self.activity_indicator = QtGui.QProgressBar(self.window)
|
||||
self.activity_indicator.setMinimum(0)
|
||||
self.activity_indicator.setMaximum(0)
|
||||
self.activity_indicator.setGeometry(310, 114, 72, 22)
|
||||
|
||||
self.active(False)
|
||||
|
||||
|
||||
#scaled_buffer = pixbuffer.scale_simple(150, 150, gtk.gdk.INTERP_BILINEAR)
|
||||
#icon.set_from_pixbuf(scaled_buffer)
|
||||
#hbox1.pack_start(icon, False, False, 20)
|
||||
#
|
||||
#fix = gtk.Fixed()
|
||||
#hbox1.pack_start(fix, False, False, 20)
|
||||
#
|
||||
#label = gtk.Label("Please enter your entity:")
|
||||
#fix.put(label, 0, 30)
|
||||
#
|
||||
#self.entity_entry = gtk.Entry()
|
||||
#self.entity_entry.set_width_chars(36)
|
||||
#fix.put(self.entity_entry, 0, 52)
|
||||
#
|
||||
#self.login_button = gtk.Button(label="Login")
|
||||
#self.login_button.connect("clicked", self.on_login_button_clicked)
|
||||
#fix.put(self.login_button, 248, 82)
|
||||
|
||||
def quit(self, wiget, foo):
|
||||
self.window.hide()
|
||||
self.app.quit(self)
|
||||
|
||||
def on_login_button_clicked(self, widget):
|
||||
self.app.login_with_entity(self.entity_entry.get_text())
|
||||
def on_login_button_clicked(self):
|
||||
self.active(True)
|
||||
self.app.login_with_entity(self.text_field.text())
|
||||
|
||||
def show(self):
|
||||
self.window.show()
|
||||
|
@ -55,6 +65,12 @@ class Preferences:
|
|||
def hide(self):
|
||||
self.window.hide()
|
||||
|
||||
def active(self, active):
|
||||
if active:
|
||||
self.activity_indicator.show()
|
||||
else:
|
||||
self.activity_indicator.hide()
|
||||
|
||||
|
||||
class Timeline:
|
||||
|
||||
|
@ -75,7 +91,6 @@ class Timeline:
|
|||
self.web_view = webkit.WebView()
|
||||
scroller.add(self.web_view)
|
||||
|
||||
|
||||
def quit(self, widget, foo):
|
||||
self.window.hide()
|
||||
self.app.quit(self)
|
||||
|
@ -108,13 +123,20 @@ class OauthImplementation:
|
|||
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.web_view = gtk.WebView()
|
||||
self.web_view = QtWebKit.QWebView()
|
||||
self.web_view.settings().setAttribute(QtWebKit.QWebSettings.DeveloperExtrasEnabled, True)
|
||||
self.init_web_view()
|
||||
frame = self.web_view.page().mainFrame()
|
||||
frame.addToJavaScriptWindowObject("controller", self.app.controller)
|
||||
frame.addToJavaScriptWindowObject("console", self.app.console)
|
||||
insp = QtWebKit.QWebInspector()
|
||||
insp.setPage(self.web_view.page())
|
||||
insp.show()
|
||||
|
||||
def init_web_view(self):
|
||||
self.web_view.connect("load-finished", self.load_finished)
|
||||
self.web_view.open(self.app.resources_path() + "index_oauth.html")
|
||||
self.web_view.loadFinished.connect(self.load_finished)
|
||||
self.web_view.load(QtCore.QUrl(self.app.resources_uri() + "/index.html"))
|
||||
|
||||
def load_finished(self, widget):
|
||||
script = "setTimeout( function() { tentia_oauth = new OauthImplementation(); }, 2);"
|
||||
self.web_view.execute_script(stript)
|
||||
script = "function HostAppGo() { start('oauth'); }"
|
||||
self.web_view.page().mainFrame().evaluateJavaScript(script)
|
||||
|
|
Reference in a new issue