Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Refactored and improved Qt console's HTML export facility #281

0 commits merged into from

3 participants


In an effort to reduce the size of ConsoleWidget, which has grown to behemoth proportions, I have moved most of the HTML exportation code into a separate file. Specifically, I have:

  • Made HTML exportation work again (I broke it while adding PySide support)
  • Fixed missing spacing in the HTML output. The exported HTML now looks almost identical to what is in the actual widget.
  • Removed the unnecessary check for the rich widget. QPlainTextEdit in fact supports HTML extraction, although this is not well advertised in the documentation.
  • Done some other minor cleanup

When saving to HTML with inline png images from the Pyside version, I get:

Traceback (most recent call last):
  File "/home/fperez/ipython/ipython/IPython/frontend/qt/", line 115, in export
    title = self.window().windowTitle()
AttributeError: 'HtmlExporter' object has no attribute 'window'

Do you know what this is?


I fixed the immediate problem, which I hadn't encountered because my exports weren't failing.

It seems to be working on both PySide and PyQt4; I had to manually raise an exception for this code path to be exercised. This means that there is potentially some other problem behind your error. In any case, now you should be able to see what it is.


Hi Evan,

now I get this message:

Error exporting HTML to /home/fperez/tmp/junk/ipython2.html
'PySide.QtGui.QImage' object has no attribute 'toPyObject'

but in a popup dialog box whose title is "Error". The saved file is created but with 0 size.

The session only had this in two cells:


for i in range(10):
    print i,

and I requested inline png images. The session had been started with '--pylab inline'. I'm running pyside from trunk, with the most recent commit I have being:

commit c3d180fdc269183cb4f46ee773bb8521f283bff0
Author: Renato Araujo Oliveira Filho 
Date:   Thu Feb 10 14:01:59 2011 -0300

    Created unit test for bug #671.

I'm leaving now for the SIAM conference, so I will likely not be able to do much testing until next weekend, unfortunately, but I'll try.


I'm not sure how I missed this, but thanks for your thoroughness Fernando. It should work now.

@@ -0,0 +1,237 @@
+""" Defines classes and functions for working with Qt's rich text system.
+# Imports
+from __future__ import with_statement
@fperez Owner
fperez added a note

This import isn't necessary anymore: we depend on python >= 2.6, so the with statement is always available to us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
((167 lines not shown))
+ A utf-8 encoded Python string containing the Qt HTML to export.
+ filename : str
+ The file to be saved.
+ image_tag : callable, optional (default None)
+ Used to convert images. See ``default_image_tag()`` for information.
+ """
+ if image_tag is None:
+ image_tag = default_image_tag
+ with open(filename, 'w') as f:
+ # Hack to make xhtml header -- note that we are not doing any check for
+ # valid XML.
+ offset = html.find("<html>")
+ assert(offset > -1)
@fperez Owner
fperez added a note

A naked assertion isn't very useful, because it makes it very hard to debug a problem for someone else who didn't know the original intent of the code. At least there should be a more useful error message than simply 'assertion error'. I'd suggest instead code like

if offset <= -1:
  raise ValueError("Malformed html input, missing '' tag").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Very minor fixes (see my comments inline). Once you address those easy ones, merge away. And thanks for the good work!

Sorry for the delayed review, last week's travels did a number on my schedule.



Is there a way to use the export as HTML + base64 png facilities from a script?

I would like to run the script from the command line, to make it generate
an HTML "report" in the current directory, which I could then view with a browser.


import ???
print "this is the graph"
p.plot([1,2,3], [22,11,33])

ex usage:

python ./

then I see a report.html in that folder...

(I guess what I want is a %run that outputs to HTML)
(if it echos the inputs that would be even cooler ;)


@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@mattvonrocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
@minrk minrk runtime warning for possible inputhook collision between pyreadline a…
…nd qt

See #281

closes gh-550
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 0 additions and 0 deletions.
Something went wrong with that request. Please try again.