Show More
@@ -544,9 +544,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
544 | dialog = QtGui.QFileDialog(parent, 'Save Console as...') |
|
544 | dialog = QtGui.QFileDialog(parent, 'Save Console as...') | |
545 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) |
|
545 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) | |
546 | filters = [ |
|
546 | filters = [ | |
547 |
'HTML with |
|
547 | 'HTML with PNG figures (*.html *.htm)', | |
548 |
'HTML with |
|
548 | 'XHTML with inline SVG figures (*.xhtml *.xml)' | |
549 | 'XHTML with inline SVGs (*.xhtml *.xml)' |
|
|||
550 | ] |
|
549 | ] | |
551 | dialog.setNameFilters(filters) |
|
550 | dialog.setNameFilters(filters) | |
552 | if self._filename: |
|
551 | if self._filename: | |
@@ -562,7 +561,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
562 | if choice.startswith('XHTML'): |
|
561 | if choice.startswith('XHTML'): | |
563 | exporter = self.export_xhtml |
|
562 | exporter = self.export_xhtml | |
564 | else: |
|
563 | else: | |
565 |
exporter = |
|
564 | exporter = self.export_html | |
566 |
|
565 | |||
567 | try: |
|
566 | try: | |
568 | return exporter(filename) |
|
567 | return exporter(filename) | |
@@ -573,7 +572,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
573 | QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) |
|
572 | QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) | |
574 | return None |
|
573 | return None | |
575 |
|
574 | |||
576 |
def export_html(self, filename |
|
575 | def export_html(self, filename): | |
577 | """ Export the contents of the ConsoleWidget as HTML. |
|
576 | """ Export the contents of the ConsoleWidget as HTML. | |
578 |
|
577 | |||
579 | Parameters: |
|
578 | Parameters: | |
@@ -585,7 +584,21 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
585 | include them as links to external PNG files, mimicking |
|
584 | include them as links to external PNG files, mimicking | |
586 | web browsers' "Web Page, Complete" behavior. |
|
585 | web browsers' "Web Page, Complete" behavior. | |
587 | """ |
|
586 | """ | |
588 | if(inline): |
|
587 | # N.B. this is overly restrictive, but Qt's output is | |
|
588 | # predictable... | |||
|
589 | img_re = re.compile(r'<img src="(?P<name>[\d]+)" />') | |||
|
590 | html = self.fix_html_encoding( | |||
|
591 | str(self._control.toHtml().toUtf8())) | |||
|
592 | if img_re.search(html): | |||
|
593 | # there are images | |||
|
594 | title = self.window().windowTitle() | |||
|
595 | reply = QtGui.QMessageBox.question(self, title, "Images found."+ | |||
|
596 | "\nWould you like inline PNGs (single large html file) or "+ | |||
|
597 | "external image files?", "inline", "external") | |||
|
598 | inline = (reply == 0) | |||
|
599 | else: | |||
|
600 | inline = True | |||
|
601 | if inline: | |||
589 | path = None |
|
602 | path = None | |
590 | else: |
|
603 | else: | |
591 | root,ext = os.path.splitext(filename) |
|
604 | root,ext = os.path.splitext(filename) | |
@@ -595,11 +608,6 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
595 |
|
608 | |||
596 | f = open(filename, 'w') |
|
609 | f = open(filename, 'w') | |
597 | try: |
|
610 | try: | |
598 | # N.B. this is overly restrictive, but Qt's output is |
|
|||
599 | # predictable... |
|
|||
600 | img_re = re.compile(r'<img src="(?P<name>[\d]+)" />') |
|
|||
601 | html = self.fix_html_encoding( |
|
|||
602 | str(self._control.toHtml().toUtf8())) |
|
|||
603 | f.write(img_re.sub( |
|
611 | f.write(img_re.sub( | |
604 | lambda x: self.image_tag(x, path = path, format = "png"), |
|
612 | lambda x: self.image_tag(x, path = path, format = "png"), | |
605 | html)) |
|
613 | html)) |
General Comments 0
You need to be logged in to leave comments.
Login now