Change back to 1st arg being a URL or HTML file

This commit is contained in:
emdee 2022-11-16 07:50:28 +00:00
parent a06a1829d6
commit 1d4c214ac3
2 changed files with 15 additions and 21 deletions

View File

@ -15,10 +15,10 @@ that he wrote up in his
PDF is generated. (YMMV - it segfaults for me. ) PDF is generated. (YMMV - it segfaults for me. )
* Generate a HTML save file screenshot of the web page after it is * Generate a HTML save file screenshot of the web page after it is
completely loaded and the javascript has run. completely loaded and the javascript has run.
* console.logs will be printed to stdout. * console.log's will be printed to stdout.
* Easily add new features by changing the source code of this script, * Easily add new features by changing the source code of this script,
without compiling C++ code. For more advanced applications, consider without compiling C++ code. For more advanced applications, consider
attaching PyQt objects/methods to WebKits JavaScript space by using attaching PyQt objects/methods to WebKit's JavaScript space by using
QWebFrame::addToJavaScriptWindowObject(). QWebFrame::addToJavaScriptWindowObject().
If you execute an external ```javascript-file```, phantompy has no If you execute an external ```javascript-file```, phantompy has no
@ -27,12 +27,7 @@ reason, the external script should execute at the end
```console.log("__PHANTOM_PY_DONE__");``` when done. This will trigger ```console.log("__PHANTOM_PY_DONE__");``` when done. This will trigger
the PDF generation or the file saving, after which phantompy will exit. the PDF generation or the file saving, after which phantompy will exit.
If no ```__PHANTOM_PY_DONE__``` string is seen on the console for 10 It is important to remember that since you're just running WebKit, you can
seconds, phantom.py will exit without doing anything. This behavior
could be implemented more elegantly without console.logs but it is
the simplest solution.
It is important to remember that since youre just running WebKit, you can
use everything that WebKit supports, including the usual JS client use everything that WebKit supports, including the usual JS client
libraries, CSS, CSS @media types, etc. libraries, CSS, CSS @media types, etc.
@ -40,7 +35,7 @@ libraries, CSS, CSS @media types, etc.
* Python3 * Python3
* PyQt5 (this should work with PySide2 and PyQt6 - let us know.) * PyQt5 (this should work with PySide2 and PyQt6 - let us know.)
* [qasyc](https://github.com/CabbageDevelopment/qasync) for the * [qasnyc](https://github.com/CabbageDevelopment/qasync) for the
standalone program ```qasync_lookup.py``` standalone program ```qasync_lookup.py```
## Standalone ## Standalone
@ -62,13 +57,13 @@ 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 We've decided to use the best of the shims that merge the Python
```asyncio``` and Qt event loops: ```asyncio``` and Qt event loops:
[qasyc](https://github.com/CabbageDevelopment/qasync). This is seen as [qasyc](https://github.com/CabbageDevelopment/qasync). This is seen as
the successor to the sorta abandonned[](https://github.com/harvimt/quamash). the successor to the sorta abandoned[quamash](https://github.com/harvimt/quamash).
The code is based on a The code is based on a
[comment](https://github.com/CabbageDevelopment/qasync/issues/35#issuecomment-1315060043) [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 Marcha](https://github.com/hosaka) who's excellent code helped me.
As this is my first use of ```asyncio``` and ```qasync``` I may have 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 introduced some errors and it may be improved on, but it works, and
it not a monolithic Qt program. it not a monolithic Qt program, so it can be used as a library.
## Usage ## Usage
@ -82,7 +77,8 @@ The standalone program is ```quash_phantompy.py```
<pdf-file> Path and name of PDF file to generate <pdf-file> Path and name of PDF file to generate
[<javascript-file>] (optional) Path and name of a JavaScript file to execute [<javascript-file>] (optional) Path and name of a JavaScript file to execute
``` ```
Setting ```DEBUG=1``` in the environment will give debugging messages
on ```stderr```.
## Postscript ## Postscript

View File

@ -55,16 +55,15 @@ async def main(widget, app, ilen):
async with ContextManager() as ctx: async with ContextManager() as ctx:
for i in range(1, 120): for i in range(1, 120):
seconds = await ctx.tick() seconds = await ctx.tick()
LOG.info(str(seconds))
perc = 50 + int(float(len(app.lfps))*100.0/ilen)
if widget: if widget:
widget.update(str(perc)) widget.update(str(i))
LOG.debug(f"{app.lfps} {perc} {seconds}") if len(app.ldone) == ilen:
if len(app.lfps) == ilen: LOG.info(f"Finished with {app.ldone}")
print('\n'.join(app.lfps)) print('\n'.join(app.ldone))
app.exit() app.exit()
# raise asyncio.CancelledError # raise asyncio.CancelledError
break return
LOG.debug(f"{app.ldone} {perc} {seconds}")
except asyncio.CancelledError as ex: except asyncio.CancelledError as ex:
LOG.debug("Task cancelled") LOG.debug("Task cancelled")
@ -93,8 +92,7 @@ def iMain(largs, bgui=True):
LOG.info(f"queued {len(app.lstart)} urls") LOG.info(f"queued {len(app.lstart)} urls")
# run until app.exec() is finished (Qt window is closed) task = loop.create_task(main(widget, app, 1))
task = loop.create_task(main(widget, app, len(lelts)))
loop.run_forever() loop.run_forever()
# cancel remaining tasks and wait for them to complete # cancel remaining tasks and wait for them to complete