Show More
@@ -507,10 +507,10 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||
|
507 | 507 | return |
|
508 | 508 | self._control.print_(printer) |
|
509 | 509 | |
|
510 |
def export |
|
|
511 |
self.export |
|
|
510 | def export_html_inline(self, parent = None): | |
|
511 | self.export_html(parent, inline = True) | |
|
512 | 512 | |
|
513 |
def export |
|
|
513 | def export_html(self, parent = None, inline = False): | |
|
514 | 514 | """ Export the contents of the ConsoleWidget as an HTML file. |
|
515 | 515 | |
|
516 | 516 | If inline == True, include images as inline PNGs. Otherwise, |
@@ -544,14 +544,14 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||
|
544 | 544 | # predictable... |
|
545 | 545 | img_re = re.compile(r'<img src="(?P<name>[\d]+)" />') |
|
546 | 546 | f.write(img_re.sub( |
|
547 | lambda x: self.imagetag(x, path = path, format = "PNG"), | |
|
547 | lambda x: self.image_tag(x, path = path, format = "PNG"), | |
|
548 | 548 | str(self._control.toHtml().toUtf8()))) |
|
549 | 549 | finally: |
|
550 | 550 | f.close() |
|
551 | 551 | return filename |
|
552 | 552 | return None |
|
553 | 553 | |
|
554 |
def export |
|
|
554 | def export_xhtml(self, parent = None): | |
|
555 | 555 | """ Export the contents of the ConsoleWidget as an XHTML file |
|
556 | 556 | with figures as inline SVG. |
|
557 | 557 | """ |
@@ -574,14 +574,14 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||
|
574 | 574 | html = ('<html xmlns="http://www.w3.org/1999/xhtml">\n'+ |
|
575 | 575 | html[offset+6:]) |
|
576 | 576 | f.write(img_re.sub( |
|
577 | lambda x: self.imagetag(x, path = None, format = "SVG"), | |
|
577 | lambda x: self.image_tag(x, path = None, format = "SVG"), | |
|
578 | 578 | html)) |
|
579 | 579 | finally: |
|
580 | 580 | f.close() |
|
581 | 581 | return filename |
|
582 | 582 | return None |
|
583 | 583 | |
|
584 | def imagetag(self, match, path = None): | |
|
584 | def image_tag(self, match, path = None): | |
|
585 | 585 | """ Given an re.match object matching an image name in an HTML export, |
|
586 | 586 | return an appropriate substitution string for the image tag |
|
587 | 587 | (e.g., link, embedded image, ...). As a side effect, files may |
@@ -828,13 +828,13 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||
|
828 | 828 | print_action = menu.addAction('Print', self.print_) |
|
829 | 829 | print_action.setEnabled(True) |
|
830 | 830 | html_action = menu.addAction('Export HTML (external PNGs)', |
|
831 |
self.export |
|
|
831 | self.export_html) | |
|
832 | 832 | html_action.setEnabled(True) |
|
833 | 833 | html_inline_action = menu.addAction('Export HTML (inline PNGs)', |
|
834 |
self.export |
|
|
834 | self.export_html_inline) | |
|
835 | 835 | html_inline_action.setEnabled(True) |
|
836 | 836 | xhtml_action = menu.addAction('Export XHTML (inline SVGs)', |
|
837 |
self.export |
|
|
837 | self.export_xhtml) | |
|
838 | 838 | xhtml_action.setEnabled(True) |
|
839 | 839 | return menu |
|
840 | 840 |
@@ -27,7 +27,7 b' class RichIPythonWidget(IPythonWidget):' | |||
|
27 | 27 | super(RichIPythonWidget, self).__init__(*args, **kw) |
|
28 | 28 | # Dictionary for resolving Qt names to images when |
|
29 | 29 | # generating XHTML output |
|
30 |
self._name |
|
|
30 | self._name_to_svg = {} | |
|
31 | 31 | |
|
32 | 32 | #--------------------------------------------------------------------------- |
|
33 | 33 | # 'ConsoleWidget' protected interface |
@@ -71,7 +71,7 b' class RichIPythonWidget(IPythonWidget):' | |||
|
71 | 71 | self._append_plain_text('Received invalid plot data.') |
|
72 | 72 | else: |
|
73 | 73 | format = self._add_image(image) |
|
74 |
self._name |
|
|
74 | self._name_to_svg[str(format.name())] = svg | |
|
75 | 75 | format.setProperty(self._svg_text_format_property, svg) |
|
76 | 76 | cursor = self._get_end_cursor() |
|
77 | 77 | cursor.insertBlock() |
@@ -126,7 +126,7 b' class RichIPythonWidget(IPythonWidget):' | |||
|
126 | 126 | image = self._get_image(name) |
|
127 | 127 | image.save(filename, format) |
|
128 | 128 | |
|
129 | def imagetag(self, match, path = None, format = "PNG"): | |
|
129 | def image_tag(self, match, path = None, format = "PNG"): | |
|
130 | 130 | """ Given an re.match object matching an image name in an HTML dump, |
|
131 | 131 | return an appropriate substitution string for the image tag |
|
132 | 132 | (e.g., link, embedded image, ...). As a side effect, files may |
@@ -158,7 +158,7 b' class RichIPythonWidget(IPythonWidget):' | |||
|
158 | 158 | |
|
159 | 159 | elif(format == "SVG"): |
|
160 | 160 | try: |
|
161 |
svg = str(self._name |
|
|
161 | svg = str(self._name_to_svg[match.group("name")]) | |
|
162 | 162 | except KeyError: |
|
163 | 163 | return "<b>Couldn't find image %s</b>" % match.group("name") |
|
164 | 164 |
General Comments 0
You need to be logged in to leave comments.
Login now