-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
284 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
# vim: set fileencoding=utf-8 : | ||
# | ||
# Author: lambdalisue (lambdalisue@hashnote.net) | ||
# URL: http://hashnote.net/ | ||
# License: MIT license | ||
# Created: 2013-01-16 | ||
# | ||
try: | ||
from PySide import QtCore | ||
from PySide import QtGui | ||
except ImportError: | ||
from PyQt4 import QtCore | ||
from PyQt4 import QtGui | ||
|
||
from viewer import HTMLViewer | ||
from server import RequestServer | ||
|
||
|
||
class MainWindow(QtGui.QMainWindow): | ||
def __init__(self, title, parent=None): | ||
super(MainWindow, self).__init__(parent) | ||
|
||
self.setWindowTitle(title) | ||
|
||
self.viewer = HTMLViewer(self) | ||
self.setCentralWidget(self.viewer) | ||
|
||
status = self.statusBar() | ||
status.setSizeGripEnabled(True) | ||
|
||
|
||
def start_with(cui_server, title='Shareboard'): | ||
try: | ||
import sys | ||
app = QtGui.QApplication(sys.argv) | ||
|
||
server = RequestServer(cui_server) | ||
viewer = MainWindow(title) | ||
|
||
# server -> viewer | ||
server.request_recieved.connect(viewer.viewer.update) | ||
|
||
server.start() | ||
viewer.show() | ||
sys.exit(app.exec_()) | ||
except KeyboardInterrupt: | ||
sys.exit(0) | ||
|
||
if __name__ == '__main__': | ||
import sys | ||
app = QtGui.QApplication(sys.argv) | ||
window = MainWindow('Shareboard [DEBUG]') | ||
window.show() | ||
sys.exit(app.exec_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
# vim: set fileencoding=utf-8 : | ||
# | ||
# Author: lambdalisue (lambdalisue@hashnote.net) | ||
# URL: http://hashnote.net/ | ||
# License: MIT license | ||
# Created: 2013-01-16 | ||
# | ||
try: | ||
from PySide import QtCore | ||
from PySide import QtGui | ||
except ImportError: | ||
from PyQt4 import QtCore | ||
from PyQt4 import QtGui | ||
|
||
|
||
class RequestServer(QtCore.QThread): | ||
def __init__(self, cui_server): | ||
super(RequestServer, self).__init__() | ||
self.cui_server = cui_server | ||
self.cui_server.httpd.emitter = self | ||
|
||
def run(self): | ||
self.cui_server.start() | ||
|
||
def emit_request_recieved(self, value): | ||
self.request_recieved.emit(value) | ||
|
||
# --- signal | ||
request_recieved = QtCore.Signal(unicode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env python | ||
# vim: set fileencoding=utf-8 : | ||
# | ||
# Author: lambdalisue (lambdalisue@hashnote.net) | ||
# URL: http://hashnote.net/ | ||
# License: MIT license | ||
# Created: 2013-01-16 | ||
# | ||
try: | ||
from PySide import QtCore | ||
from PySide import QtGui | ||
from PySide.QtWebKit import QWebView | ||
from PySide.QtNetwork import QNetworkProxyFactory | ||
except ImportError: | ||
from PyQt4 import QtCore | ||
from PyQt4 import QtGui | ||
from PyQt4.QtWebKit import QWebView | ||
from PyQt4.QtNetwork import QNetworkProxyFactory | ||
|
||
|
||
# Use system proxy settings | ||
QNetworkProxyFactory.setUseSystemConfiguration(True) | ||
|
||
|
||
class HTMLViewer(QtGui.QWidget): | ||
def __init__(self, parent=None): | ||
super(HTMLViewer, self).__init__(parent) | ||
|
||
self.view = QWebView(self) | ||
layout = QtGui.QVBoxLayout(self) | ||
layout.setSpacing(0) | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
layout.addWidget(self.view) | ||
|
||
# Create ContextMenu | ||
context_menu = QtGui.QMenu(self.view) | ||
def open_context_menu(point): | ||
context_menu.exec_(self.view.mapToGlobal(point)) | ||
self.view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) | ||
self.view.customContextMenuRequested.connect(open_context_menu) | ||
|
||
action = QtGui.QAction('&Back', self, | ||
shortcut=QtGui.QKeySequence.Back, | ||
statusTip="Click to go back", | ||
triggered=self.view.back) | ||
action.setShortcut('Backspace') | ||
context_menu.addAction(action) | ||
|
||
action = QtGui.QAction('&Forward', self, | ||
shortcut=QtGui.QKeySequence.Forward, | ||
statusTip="Click to go forward", | ||
triggered=self.view.forward) | ||
action.setShortcut('Shift + Backspace') | ||
context_menu.addAction(action) | ||
|
||
action = QtGui.QAction('&Reload', self, | ||
shortcut=QtGui.QKeySequence.Refresh, | ||
statusTip="Click to refresh", | ||
triggered=self.view.reload) | ||
context_menu.addAction(action) | ||
context_menu.addSeparator() | ||
|
||
action = QtGui.QAction('&Print', self, | ||
shortcut=QtGui.QKeySequence.Print, | ||
statusTip="Click to print", | ||
triggered=self.print_) | ||
context_menu.addAction(action) | ||
|
||
def contextMenuEvent(self, event): | ||
self.context_menu.exec_(event.globalPos()) | ||
|
||
def print_(self): | ||
printer = QtGui.QPrinter() | ||
printer_dialog = QtGui.QPrintDialog(printer, self.view) | ||
if printer_dialog.exec_() != QtGui.QDialog.Accepted: | ||
# do nothing | ||
return | ||
# printout the view with selected printer | ||
self.view.print_(printer) | ||
|
||
# --- slots | ||
@QtCore.Slot(unicode) | ||
def update(self, value): | ||
# save vertical/horizontal scrollbar value | ||
m = self.view.page().mainFrame() | ||
v = m.scrollBarValue(QtCore.Qt.Vertical) | ||
h = m.scrollBarValue(QtCore.Qt.Horizontal) | ||
# set new HTML (value should be unicode) | ||
self.view.setHtml(value) | ||
# update vertical/horizontal scrollbar value | ||
m = self.view.page().mainFrame() | ||
m.setScrollBarValue(QtCore.Qt.Vertical, v) | ||
m.setScrollBarValue(QtCore.Qt.Horizontal, h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.