From 12ff9b924e978b462dcf7be7a76b426a180f86c0 Mon Sep 17 00:00:00 2001 From: emdee Date: Wed, 16 Nov 2022 18:53:54 +0000 Subject: [PATCH 1/2] add setup.py --- qasync_phantompy.py | 12 ++++----- setup.py | 66 ++++++++++++++++++++++----------------------- 2 files changed, 38 insertions(+), 40 deletions(-) diff --git a/qasync_phantompy.py b/qasync_phantompy.py index fdd850e..99927ba 100644 --- a/qasync_phantompy.py +++ b/qasync_phantompy.py @@ -3,15 +3,15 @@ import sys import os -import qasync import asyncio import time import random -from PyQt5 import QtWidgets -from PyQt5.QtWidgets import (QProgressBar, QWidget, QVBoxLayout) +# let qasync figure out what Qt we are using - we dont care +from qasync import QApplication, QtWidgets, QEventLoop from phantompy import Render +# if you want an example of looking for things in downloaded HTML: # from lookupdns import LookFor as Render from support_phantompy import vsetup_logging, omain_argparser @@ -28,7 +28,7 @@ class Widget(QtWidgets.QWidget): box = QtWidgets.QHBoxLayout() self.setLayout(box) box.addWidget(self._label) - self.progress = QProgressBar() + self.progress = QtWidgets.QProgressBar() self.progress.setRange(0, 99) box.addWidget(self.progress) @@ -80,7 +80,7 @@ def iMain(largs): vsetup_logging(oargs.log_level, logfile='', stream=sys.stderr) except: pass - app = QtWidgets.QApplication([]) + app = QApplication([]) app.lstart = [] if bgui: widget = Widget() @@ -89,7 +89,7 @@ def iMain(largs): else: widget = None - loop = qasync.QEventLoop(app) + loop = QEventLoop(app) asyncio.set_event_loop(loop) url = oargs.html_url diff --git a/setup.py b/setup.py index 2311cdb..bdf9f6e 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*-mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -* from setuptools import setup @@ -8,36 +8,34 @@ long_description = "\n\n".join([ open("README.md").read(), ]) -setup( - name="pahntompy", - version=__version__, - description="""A simple replacement for phantomjs using PyQt""", - long_description=long_description, - author="Michael Franzl (originally) Goebel", - author_email='', - license="1clause BSD", - packages=['phantompy'], - # url="", - # These are for reference only, pip is not able to download packages - # from github because the archives do not include the project-name. - download_url="https://github.com/debops/yaml2rst/releases", - keywords=['JavaScript', 'phantomjs'], - python_requires=">=3.6", - # probably works on PyQt6 and PySide2 but untested - install_requires=['qasync', 'PyQt5'], - entry_points={ - 'console_scripts': [ - 'phantompy = phantompy.__main__:iMain', - ] - }, - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'Intended Audience :: Web Developers', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Documentation', - ], -) +if __name__ == '__main__': + setup( + name="phantompy", + version=__version__, + description="""A simple replacement for phantomjs using PyQt""", + long_description=long_description, + author="Michael Franzl (originally)", + author_email='', + license="1clause BSD", + packages=['phantompy'], + # url="", + # download_url="https://", + keywords=['JavaScript', 'phantomjs'], + # maybe less - nothing fancy + python_requires=">=3.6", + # probably works on PyQt6 and PySide2 but untested + # https://github.com/CabbageDevelopment/qasync/ + install_requires=['qasync', 'PyQt5'], + entry_points={ + 'console_scripts': ['phantompy = phantompy.__main__:iMain', ]}, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Web Developers', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: Python :: 3', + 'Topic :: Software Development :: Documentation', + ], + ) From 97db0946da61072dc0a87965f21c2e98cccb1a44 Mon Sep 17 00:00:00 2001 From: emdee Date: Wed, 16 Nov 2022 20:59:26 +0000 Subject: [PATCH 2/2] Fixes --- README.md | 4 ++-- support_phantompy.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 249992a..1f17af3 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,10 @@ for the PyQt ```app.exec``` and the exiting of the program. We've decided to use the best of the shims that merge the Python ```asyncio``` and Qt event loops: [qasyc](https://github.com/CabbageDevelopment/qasync). This is seen as -the successor to the sorta abandoned[quamash](https://github.com/harvimt/quamash). +the successor to the sorta abandoned [quamash](https://github.com/harvimt/quamash). The code is based on a [comment](https://github.com/CabbageDevelopment/qasync/issues/35#issuecomment-1315060043) -by [Alex Marcha](https://github.com/hosaka) who's excellent code helped me. +by [Alex March](https://github.com/hosaka) who's excellent code helped me. As this is my first use of ```asyncio``` and ```qasync``` I may have introduced some errors and it may be improved on, but it works, and it not a monolithic Qt program, so it can be used as a library. diff --git a/support_phantompy.py b/support_phantompy.py index c19968f..1c81f3f 100644 --- a/support_phantompy.py +++ b/support_phantompy.py @@ -108,7 +108,7 @@ def omain_argparser(_=None): help="Write loaded and javascripted result to a HTML file") parser.add_argument('--pdf_output', type=str, default='', help="Write loaded and javascripted result to a PDF file") - parser.add_argument('--show_gui', type=bool, default=False, store_action=True), + parser.add_argument('--show_gui', type=bool, default=False, store_action=True, help="show a progress meter that doesn't work") parser.add_argument('html_url', type=str, nargs='?', required=True,