I have a program that used to use QWebKit to show and print custom generated HTML reports in a dialog and now, I want to convert the whole thing to QWebEngine. Everything works fine so far, only printing doesn't!
Up to now I used QWebView.print() to hand the whole HTML data over to a QPrintPreviewDialog which wasn't a problem at all. Now, from what I understand, I thought I'd have to use QWebEngineView.QWebEnginepage.print(printer object, callback) to achieve the same.
Sadly, everything I tried so far hasn't worked. The preview pane of the QPrintPreviewDialog always stays empty and the result which is given back to the callback after printing is done is always False - although the printer object is still valid the whole time, even in the callback.
I tried out different things, which worked somehow and therefor I think, the QWebEnginePage.print() function is buggy somehow or there is a bug in PyQt, but in fact, I don't and perhaps it is me doing something wrong.
Successful workarounds (which I don't like ;-) ):
Don't use QPrintPreviewDialog, but generate the output via QWebEngineView.QWebEnginePage.printToPDF(filename): worked!
Generate a temporary QTextedit object and print this via QPrintPreviewDialog: also worked, but badly formatted HTML in my case...
Can someone tell me, if I'm assuming something wrong here or if there is a descent example on how to print HTML via QPrintPreviewDialog using QWebEngineView?
QtWebEngine currently doesn't support printing to a print preview, see QTBUG-57982. Printing to a QPrinter directly works though.
Related
I am wondering if anybody knows how to get the # back to the toolbar in Spyder 5.1.5. I used to use that a lot when searching for functions in long codes of mine. Recently, I updated to the most recent version of Spyder and could not find # anywhere. Now, I need to scroll down a lot to see where the functions I am looking for are.
Using find is also OK, but for that, it is better to remember the name of the function correctly. So, this makes searching and finding last a lot longer than using one click to the # button.
Any ideas of how to get the # back?
Or does anybody use any other tool/shortcut to access the functions inside a very long code?
Thanks in advance.
When writing a search, right after instantiating the actual Search object, auto complete works as expected. After using the query method, I lose the auto-complete.
If i write the code ignoring the fact that intellisense is not suggesting anything, it works ok! (assuming i wrote it correctly)
What am I doing wrong here?
To workaround this, i have a variable commented... if i need auto-complete, i uncomment it, check the auto-complete, and paste it on the appropriate spot...
Some odd reaction with PyQt5.8 on windows 10. I'm making this because I want to try to understand why I get this problem, as it's easily solved. (Shown below)
I try to do:
Command =''' testurl -x --audio-format "mp3" --audio-quality "0"'''
self.start('yotube-dl',Command.split())
but get the error from youtube-dl that the specified audio format is wrong. Which means that for some reason, "mp3" isn't after --audio-format. I also tried, --audio-format="mp3", and that also gives me an error, despite not having a space after the --audio-format
Now, if I do my "workaround":
self.start('youtube-dl'+Command)
It works as expected. It tells you the specified URL(since it's testurl) is not valid. Don't be mistakes, a working url behaves just the same. So, obviously one would think there's something funky with the .split() part of it, but this is how the list turns out when you use Command.split():
['testurl', '-x', '--audio-format', '"mp3"', '--audio-quality', '"0"']
And as far as I know, the arguments are passed in order of the list. I've had it working before, but as soon as I changed another configuration, it all went south. I just can't figure out why my results differ, and it's only for this specific audio conversion argument(-x --audio-format "mp3"), other arguments work pretty well, one of them containing spaces.
Also, I can let you know I tried with lots of "'s around in the string, and to no help. I'm presuming this has something to do with the way " are added in some places on windows according to Qt documentation(Link for reference), but I still can't make figure out what to change. For all I know, it's something stupid i'm doing.
So, if anyone has understanding of why it does this, i'd love to know. Again, i'm just looking for some clarity, as I already worked around it, but want to understand why it goes wrong.
I'm sure someone has come across this before, but it was hard thinking of how to search for it.
Suppose I have a file generate_data.py and another plot_utils.py which contains a function for plotting this data.
Of note, generate_data.py takes a long time to run and I would like to only have to run it once. However, I haven't finished working out the kinks in plot_utils.py, so I have to run this a bunch of times.
It seems in spyder that when I run generate_data (be it in the current console or in a new dedicated python interpreter) that it doesn't allow me to modify plot_utils.py and call "from plot_utils import plotter" in the command line. -- I mean it doesn't have an error, but it's clear the changes haven't been made.
I guess I kind of want cell mode between different .py files.
EDIT: After being forced to formulate exactly what I want, I think I got around this by putting "from plot_utils import plotter" \n "plotter(foo)" inside a cell in generate_data.py. I am now wondering if there is a more elegant solution.
SECOND EDIT: actually the method mentioned above in the edit does not work as I said it did. Still looking for a method.
You need to reload it:
# Python 2.7
plotter = reload(plotter)
or
# Python 3.x
from imp import reload
plotter = reload(plotter)
So I am trying to write a rich text editor in PyGTK, and originally used the older, third party script InteractivePangoBuffer from Gourmet to do this. While it worked alright, there were still plenty of bugs with it which made it frustrating to use at times, so I decided to write my own utilizing text tags. I have got them displaying and generally working alright, but now I am stuck at trying to figure out how to export them to a file when saving. I've seen that others have had the same problem I've had, though I haven't seen any solutions. I haven't come across any function (built in or otherwise) which comes close to actually getting the starting and ending position of each piece of text with a texttag applied to it so I can use it.
I have come up with one idea which should theoretically work, by walking the text by utilizing gtk.TextBuffer.get_iter_at_offset(), gtk.TextIter.get_offset(), gtk.TextIter.begins_tag(), and gtk.TextIter.ends_tag() in order to check each and every character to see if it begins or ends a tag and, if so, put the appropriate code. This would be horribly inefficient and slow, especially on larger documents, however, so I am wondering if anyone has any better solutions?
You can probably use gtk.TextIter.forward_to_tag_toggle(). I.e. loop over all tags you have and for each tags scan the buffer for the position where it is toggled.