Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from ELC/PyQt4-Compatible
Browse files Browse the repository at this point in the history
Add Backward Compatibility with PyQt4
  • Loading branch information
ELC authored Feb 22, 2018
2 parents 9095c2b + a82d9c0 commit 73b4aea
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 90 deletions.
115 changes: 113 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,113 @@
*.pyc
.idea
# 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*
Binary file added PyQt4-4.11.4-cp36-cp36m-win_amd64.whl
Binary file not shown.
9 changes: 9 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
channels:
- defaults
dependencies:
- pyqt=4.11.4
- python=3.5
- pip:
- flask==0.12.2

48 changes: 48 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -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_()
83 changes: 0 additions & 83 deletions pyfladesk.py

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==0.12.2
PyQt4==4.11.4
11 changes: 6 additions & 5 deletions routes.py
Original file line number Diff line number Diff line change
@@ -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')
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h1 > Hello World! </h1>

<footer class="footer">
<p><a href="https://github.com/smoqadam/PyFladesk">github</a></p>
<p><a href="{{ url_for('page2') }}">Page 2</a></p>
</footer>

</div>
Expand Down
33 changes: 33 additions & 0 deletions templates/page2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Flask Desktop Application</title>


<link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">


</head>

<body>

<div class="container">
<div class="header">
<h3 class="text-muted">Flask Desktop Application</h3>
</div>

<div class="row marketing">
<div class="col-lg-12">
<h1 > Page2! </h1>
</div>
</div>

<footer class="footer">
<p><a href="{{ url_for('index') }}">Index</a></p>
</footer>

</div>
</body>

</html>

0 comments on commit 73b4aea

Please sign in to comment.