diff --git a/.gitignore b/.gitignore index b32d8aa..cf92d96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,113 @@ -*.pyc -.idea \ No newline at end of file +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +.static_storage/ +.media/ +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +venv* \ No newline at end of file diff --git a/PyQt4-4.11.4-cp36-cp36m-win_amd64.whl b/PyQt4-4.11.4-cp36-cp36m-win_amd64.whl new file mode 100644 index 0000000..a39959f Binary files /dev/null and b/PyQt4-4.11.4-cp36-cp36m-win_amd64.whl differ diff --git a/app.py b/app.py new file mode 100644 index 0000000..1d518ce --- /dev/null +++ b/app.py @@ -0,0 +1,9 @@ +from flask import Flask +from gui import init_gui + +app = Flask(__name__) + +from routes import * + +if __name__ == '__main__': + init_gui(app) \ No newline at end of file diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..7f1a4e6 --- /dev/null +++ b/environment.yml @@ -0,0 +1,8 @@ +channels: +- defaults +dependencies: +- pyqt=4.11.4 +- python=3.5 +- pip: + - flask==0.12.2 + diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..5250588 --- /dev/null +++ b/gui.py @@ -0,0 +1,48 @@ +import sys +import webbrowser + +from PyQt4.QtCore import QThread, QUrl, SIGNAL +from PyQt4.QtGui import QApplication, QMainWindow, QIcon +from PyQt4.QtWebKit import QWebView, QWebPage + + +def init_gui(application, port=5000, width=300, height=400, + window_title="PyFladesk", icon="appicon.png"): + + ROOT_URL = 'http://localhost:{}'.format(port) + + # open links in browser from http://stackoverflow.com/a/3188942/1103397 :D + def link_clicked(url): + ready_url = url.toEncoded().data().decode() + if ROOT_URL not in ready_url: + webbrowser.open(ready_url) + else: + window.webView.load(QUrl(ready_url)) + + def run_app(): + application.run(port=port, threaded=True) + + qtapp = QApplication(sys.argv) + + webapp = QThread() + webapp.__del__ = webapp.wait + webapp.run = run_app + webapp.start() + + qtapp.aboutToQuit.connect(webapp.terminate) + + window = QMainWindow() + window.resize(width, height) + window.setWindowTitle(window_title) + window.webView = QWebView(window) + window.setCentralWidget(window.webView) + window.setWindowIcon(QIcon(icon)) + + window.webView.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) + link_signal = SIGNAL("linkClicked (const QUrl&)") + window.webView.connect(window.webView, link_signal, link_clicked) + + window.webView.load(QUrl(ROOT_URL)) + window.show() + + return qtapp.exec_() diff --git a/pyfladesk.py b/pyfladesk.py deleted file mode 100644 index 0aecdb7..0000000 --- a/pyfladesk.py +++ /dev/null @@ -1,83 +0,0 @@ -import sys,webbrowser - -from PyQt4.QtCore import QThread, QUrl,SIGNAL,QSize -from PyQt4.QtGui import QApplication,QMainWindow,QIcon -from PyQt4.QtWebKit import QWebView,QWebPage - -# CONFIG -PORT = 5000 -ROOT_URL = 'http://localhost:{}'.format(PORT) -WIDTH = 300 -HEIGHT = 400 -WINDOW_TITLE = "PyFladesk" -ICON = 'appicon.png' - - -# run flask on seperate theared -class FlaskThread(QThread): - def __init__(self, application): - QThread.__init__(self) - self.application = application - - def __del__(self): - self.wait() - - def run(self): - self.application.run(port=PORT) - - -class MainWindow(QMainWindow): - - def __init__(self): - QMainWindow.__init__(self) - self.resize (WIDTH , HEIGHT) - self.setWindowTitle(WINDOW_TITLE) - self.webView = WebView(self) - self.setCentralWidget(self.webView) - - - -class WebView(QWebView): - def __init__(self ,parent=None): - super(WebView,self).__init__(parent) - - def dragEnterEvent(self,e): - e.ignore() - - def dropEvent(self,e): - e.ignore() - - def contextMenuEvent(self,e): - pass - - # open links in default browser - # stolen from http://stackoverflow.com/a/3188942/1103397 :D - def linkClicked(self,url): - webbrowser.open(url.toEncoded().data()) - - -def provide_GUI_for(application): - qtapp = QApplication(sys.argv) - - webapp = FlaskThread(application) - webapp.start() - - qtapp.aboutToQuit.connect(webapp.terminate) - - mainWindow = MainWindow() - # set app icon - mainWindow.setWindowIcon(QIcon(ICON)) - - # prevent open urls in QWebView. - mainWindow.webView.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) - mainWindow.webView.connect(mainWindow.webView, SIGNAL("linkClicked (const QUrl&)"), mainWindow.webView.linkClicked) - - mainWindow.webView.load(QUrl(ROOT_URL)) - mainWindow.show() - - return qtapp.exec_() - - -if __name__ == '__main__': - from routes import app - provide_GUI_for(app) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6da6bb0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==0.12.2 +PyQt4==4.11.4 \ No newline at end of file diff --git a/routes.py b/routes.py index 34ca1ae..1631f0e 100644 --- a/routes.py +++ b/routes.py @@ -1,9 +1,10 @@ -from flask import Flask, render_template - - -app = Flask(__name__) - +from flask import render_template +from app import app @app.route('/') def index(): return render_template('index.html') + +@app.route('/page2') +def page2(): + return render_template('page2.html') diff --git a/templates/index.html b/templates/index.html index 67702ef..34cc057 100644 --- a/templates/index.html +++ b/templates/index.html @@ -25,6 +25,7 @@

Hello World!

diff --git a/templates/page2.html b/templates/page2.html new file mode 100644 index 0000000..c3075c6 --- /dev/null +++ b/templates/page2.html @@ -0,0 +1,33 @@ + + + + + Flask Desktop Application + + + + + + + + + +
+
+

Flask Desktop Application

+
+ +
+
+

Page2!

+
+
+ + + +
+ + + \ No newline at end of file