Show More
@@ -7,6 +7,7 b'' | |||||
7 | # Standard library imports |
|
7 | # Standard library imports | |
8 | from os.path import commonprefix |
|
8 | from os.path import commonprefix | |
9 | import re |
|
9 | import re | |
|
10 | import os | |||
10 | import sys |
|
11 | import sys | |
11 | from textwrap import dedent |
|
12 | from textwrap import dedent | |
12 |
|
13 | |||
@@ -525,8 +526,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
525 | """ |
|
526 | """ | |
526 | dialog = QtGui.QFileDialog(parent, 'Save HTML Document') |
|
527 | dialog = QtGui.QFileDialog(parent, 'Save HTML Document') | |
527 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) |
|
528 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) | |
528 | dialog.setDefaultSuffix('htm') |
|
529 | dialog.setDefaultSuffix('html') | |
529 |
dialog.setNameFilter('HTML |
|
530 | dialog.setNameFilter('HTML Document (*.htm *.html)') | |
530 | if dialog.exec_(): |
|
531 | if dialog.exec_(): | |
531 | filename = str(dialog.selectedFiles()[0]) |
|
532 | filename = str(dialog.selectedFiles()[0]) | |
532 | if(inline): |
|
533 | if(inline): | |
@@ -537,12 +538,14 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
537 | path = filename[:offset]+"_files" |
|
538 | path = filename[:offset]+"_files" | |
538 | else: |
|
539 | else: | |
539 | path = filename+"_files" |
|
540 | path = filename+"_files" | |
540 |
i |
|
541 | if os.path.isfile(path): | |
541 | try: |
|
542 | raise OSError("%s exists, but is not a dir"%path) | |
542 | os.mkdir(path) |
|
543 | # don't mkdir unless there are images | |
543 |
|
|
544 | # try: | |
544 | # TODO: check that this is an "already exists" error |
|
545 | # os.mkdir(path) | |
545 |
|
|
546 | # except OSError: | |
|
547 | # # TODO: check that this is an "already exists" error | |||
|
548 | # pass | |||
546 |
|
549 | |||
547 | f = open(filename, 'w') |
|
550 | f = open(filename, 'w') | |
548 | try: |
|
551 | try: | |
@@ -565,7 +568,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
565 | dialog = QtGui.QFileDialog(parent, 'Save XHTML Document') |
|
568 | dialog = QtGui.QFileDialog(parent, 'Save XHTML Document') | |
566 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) |
|
569 | dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) | |
567 | dialog.setDefaultSuffix('xml') |
|
570 | dialog.setDefaultSuffix('xml') | |
568 | dialog.setNameFilter('XHTML document (*.xml)') |
|
571 | dialog.setNameFilter('XHTML document (*.xml *.xhtml)') | |
569 | if dialog.exec_(): |
|
572 | if dialog.exec_(): | |
570 | filename = str(dialog.selectedFiles()[0]) |
|
573 | filename = str(dialog.selectedFiles()[0]) | |
571 | f = open(filename, 'w') |
|
574 | f = open(filename, 'w') | |
@@ -870,19 +873,21 b' class ConsoleWidget(Configurable, QtGui.QWidget):' | |||||
870 |
|
873 | |||
871 | menu.addSeparator() |
|
874 | menu.addSeparator() | |
872 | menu.addAction('Select All', self.select_all) |
|
875 | menu.addAction('Select All', self.select_all) | |
873 |
|
876 | |||
874 | menu.addSeparator() |
|
877 | if self.kind == 'rich': | |
875 | print_action = menu.addAction('Print', self.print_) |
|
878 | # only the rich frontend can export html/xml | |
876 | print_action.setEnabled(True) |
|
879 | menu.addSeparator() | |
877 |
|
|
880 | print_action = menu.addAction('Print', self.print_) | |
878 | self.export_html) |
|
881 | print_action.setEnabled(True) | |
879 | html_action.setEnabled(True) |
|
882 | html_action = menu.addAction('Export HTML (external PNGs)', | |
880 | html_inline_action = menu.addAction('Export HTML (inline PNGs)', |
|
883 | self.export_html) | |
881 | self.export_html_inline) |
|
884 | html_action.setEnabled(True) | |
882 | html_inline_action.setEnabled(True) |
|
885 | html_inline_action = menu.addAction('Export HTML (inline PNGs)', | |
883 | xhtml_action = menu.addAction('Export XHTML (inline SVGs)', |
|
886 | self.export_html_inline) | |
884 | self.export_xhtml) |
|
887 | html_inline_action.setEnabled(True) | |
885 | xhtml_action.setEnabled(True) |
|
888 | xhtml_action = menu.addAction('Export XHTML (inline SVGs)', | |
|
889 | self.export_xhtml) | |||
|
890 | xhtml_action.setEnabled(True) | |||
886 | return menu |
|
891 | return menu | |
887 |
|
892 | |||
888 | def _control_key_down(self, modifiers, include_command=True): |
|
893 | def _control_key_down(self, modifiers, include_command=True): |
@@ -1,4 +1,6 b'' | |||||
1 | # System library imports |
|
1 | # System library imports | |
|
2 | import os | |||
|
3 | import re | |||
2 | from PyQt4 import QtCore, QtGui |
|
4 | from PyQt4 import QtCore, QtGui | |
3 |
|
5 | |||
4 | # Local imports |
|
6 | # Local imports | |
@@ -154,7 +156,9 b' class RichIPythonWidget(IPythonWidget):' | |||||
154 | return "<b>Couldn't find image %s</b>" % match.group("name") |
|
156 | return "<b>Couldn't find image %s</b>" % match.group("name") | |
155 |
|
157 | |||
156 | if(path is not None): |
|
158 | if(path is not None): | |
157 | relpath = path[path.rfind("/")+1:] |
|
159 | if not os.path.exists(path): | |
|
160 | os.mkdir(path) | |||
|
161 | relpath = os.path.basename(path) | |||
158 | if(image.save("%s/qt_img%s.png" % (path,match.group("name")), |
|
162 | if(image.save("%s/qt_img%s.png" % (path,match.group("name")), | |
159 | "PNG")): |
|
163 | "PNG")): | |
160 | return '<img src="%s/qt_img%s.png">' % (relpath, |
|
164 | return '<img src="%s/qt_img%s.png">' % (relpath, | |
@@ -167,7 +171,6 b' class RichIPythonWidget(IPythonWidget):' | |||||
167 | buffer_.open(QtCore.QIODevice.WriteOnly) |
|
171 | buffer_.open(QtCore.QIODevice.WriteOnly) | |
168 | image.save(buffer_, "PNG") |
|
172 | image.save(buffer_, "PNG") | |
169 | buffer_.close() |
|
173 | buffer_.close() | |
170 | import re |
|
|||
171 | return '<img src="data:image/png;base64,\n%s\n" />' % ( |
|
174 | return '<img src="data:image/png;base64,\n%s\n" />' % ( | |
172 | re.sub(r'(.{60})',r'\1\n',str(ba.toBase64()))) |
|
175 | re.sub(r'(.{60})',r'\1\n',str(ba.toBase64()))) | |
173 |
|
176 |
General Comments 0
You need to be logged in to leave comments.
Login now