Show More
@@ -236,14 +236,14 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
236 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) |
|
236 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) | |
237 | action.triggered.connect(self.print_) |
|
237 | action.triggered.connect(self.print_) | |
238 | self.addAction(action) |
|
238 | self.addAction(action) | |
239 |
self. |
|
239 | self.print_action = action | |
240 |
|
240 | |||
241 | action = QtGui.QAction('Save as HTML/XML', None) |
|
241 | action = QtGui.QAction('Save as HTML/XML', None) | |
242 | action.setShortcut(QtGui.QKeySequence.Save) |
|
242 | action.setShortcut(QtGui.QKeySequence.Save) | |
243 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) |
|
243 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) | |
244 | action.triggered.connect(self.export_html) |
|
244 | action.triggered.connect(self.export_html) | |
245 | self.addAction(action) |
|
245 | self.addAction(action) | |
246 |
self. |
|
246 | self.export_action = action | |
247 |
|
247 | |||
248 | action = QtGui.QAction('Select All', None) |
|
248 | action = QtGui.QAction('Select All', None) | |
249 | action.setEnabled(True) |
|
249 | action.setEnabled(True) | |
@@ -251,7 +251,73 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
251 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) |
|
251 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) | |
252 | action.triggered.connect(self.select_all) |
|
252 | action.triggered.connect(self.select_all) | |
253 | self.addAction(action) |
|
253 | self.addAction(action) | |
254 |
self. |
|
254 | self.select_all_action = action | |
|
255 | ||||
|
256 | self.increase_font_size = QtGui.QAction("Bigger Font", | |||
|
257 | self, | |||
|
258 | shortcut="Ctrl++", | |||
|
259 | statusTip="Increase the font size by one point", | |||
|
260 | triggered=self._increase_font_size) | |||
|
261 | self.addAction(self.increase_font_size) | |||
|
262 | ||||
|
263 | self.decrease_font_size = QtGui.QAction("Smaller Font", | |||
|
264 | self, | |||
|
265 | shortcut="Ctrl+-", | |||
|
266 | statusTip="Decrease the font size by one point", | |||
|
267 | triggered=self._decrease_font_size) | |||
|
268 | self.addAction(self.decrease_font_size) | |||
|
269 | ||||
|
270 | self.reset_font_size = QtGui.QAction("Normal Font", | |||
|
271 | self, | |||
|
272 | shortcut="Ctrl+0", | |||
|
273 | statusTip="Restore the Normal font size", | |||
|
274 | triggered=self.reset_font) | |||
|
275 | self.addAction(self.reset_font_size) | |||
|
276 | ||||
|
277 | self.undo_action = QtGui.QAction("Undo", | |||
|
278 | self, | |||
|
279 | shortcut="Ctrl+Z", | |||
|
280 | statusTip="Undo last action if possible", | |||
|
281 | triggered=self._control.undo) | |||
|
282 | self.addAction(self.undo_action) | |||
|
283 | ||||
|
284 | self.redo_action = QtGui.QAction("Redo", | |||
|
285 | self, | |||
|
286 | shortcut="Ctrl+Shift+Z", | |||
|
287 | statusTip="Redo last action if possible", | |||
|
288 | triggered=self._control.redo) | |||
|
289 | self.addAction(self.redo_action) | |||
|
290 | ||||
|
291 | self.reset_action = QtGui.QAction("Reset", | |||
|
292 | self, | |||
|
293 | statusTip="Clear all varible from workspace", | |||
|
294 | triggered=self.reset_magic) | |||
|
295 | self.addAction(self.reset_action) | |||
|
296 | ||||
|
297 | self.clear_action = QtGui.QAction("Clear", | |||
|
298 | self, | |||
|
299 | statusTip="Clear the console", | |||
|
300 | triggered=self.clear_magic) | |||
|
301 | self.addAction(self.clear_action) | |||
|
302 | ||||
|
303 | self.who_action = QtGui.QAction("Who", | |||
|
304 | self, | |||
|
305 | statusTip="List interactive variable", | |||
|
306 | triggered=self.who_magic) | |||
|
307 | self.addAction(self.who_action) | |||
|
308 | ||||
|
309 | self.whos_action = QtGui.QAction("Whos", | |||
|
310 | self, | |||
|
311 | statusTip="List interactive variable with detail", | |||
|
312 | triggered=self.whos_magic) | |||
|
313 | self.addAction(self.whos_action) | |||
|
314 | ||||
|
315 | self.who_ls_action = QtGui.QAction("Who ls", | |||
|
316 | self, | |||
|
317 | statusTip="Return a list of interactive variable", | |||
|
318 | triggered=self.who_ls_magic) | |||
|
319 | self.addAction(self.who_ls_action) | |||
|
320 | ||||
255 |
|
321 | |||
256 | def eventFilter(self, obj, event): |
|
322 | def eventFilter(self, obj, event): | |
257 | """ Reimplemented to ensure a console-like behavior in the underlying |
|
323 | """ Reimplemented to ensure a console-like behavior in the underlying | |
@@ -579,12 +645,14 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
579 |
|
645 | |||
580 | font = property(_get_font, _set_font) |
|
646 | font = property(_get_font, _set_font) | |
581 |
|
647 | |||
582 | def paste(self, mode=QtGui.QClipboard.Clipboard): |
|
648 | def paste(self, mode=QtGui.QClipboard.Clipboard,text=None): | |
583 |
""" Paste the contents of the clipboard |
|
649 | """ Paste the contents of the clipboard, or given text, | |
|
650 | into the input region. | |||
584 |
|
651 | |||
585 | Parameters: |
|
652 | Parameters: | |
586 | ----------- |
|
653 | ----------- | |
587 | mode : QClipboard::Mode, optional [default QClipboard::Clipboard] |
|
654 | mode : QClipboard::Mode, optional [default QClipboard::Clipboard] | |
|
655 | text : string, optional, overide mode if given. | |||
588 |
|
656 | |||
589 | Controls which part of the system clipboard is used. This can be |
|
657 | Controls which part of the system clipboard is used. This can be | |
590 | used to access the selection clipboard in X11 and the Find buffer |
|
658 | used to access the selection clipboard in X11 and the Find buffer | |
@@ -597,9 +665,30 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
597 |
|
665 | |||
598 | # Remove any trailing newline, which confuses the GUI and forces the |
|
666 | # Remove any trailing newline, which confuses the GUI and forces the | |
599 | # user to backspace. |
|
667 | # user to backspace. | |
600 | text = QtGui.QApplication.clipboard().text(mode).rstrip() |
|
668 | if not text: | |
|
669 | text = QtGui.QApplication.clipboard().text(mode).rstrip() | |||
601 | self._insert_plain_text_into_buffer(cursor, dedent(text)) |
|
670 | self._insert_plain_text_into_buffer(cursor, dedent(text)) | |
602 |
|
671 | |||
|
672 | def pasteMagic(self,text): | |||
|
673 | self._keyboard_quit() | |||
|
674 | self.paste(text=text) | |||
|
675 | self.execute() | |||
|
676 | ||||
|
677 | def who_magic(self): | |||
|
678 | self.pasteMagic("%who") | |||
|
679 | ||||
|
680 | def whos_magic(self): | |||
|
681 | self.pasteMagic("%whos") | |||
|
682 | ||||
|
683 | def who_ls_magic(self): | |||
|
684 | self.pasteMagic("%who_ls") | |||
|
685 | ||||
|
686 | def clear_magic(self): | |||
|
687 | self.pasteMagic("%clear") | |||
|
688 | ||||
|
689 | def reset_magic(self): | |||
|
690 | self.pasteMagic("%reset") | |||
|
691 | ||||
603 | def print_(self, printer = None): |
|
692 | def print_(self, printer = None): | |
604 | """ Print the contents of the ConsoleWidget to the specified QPrinter. |
|
693 | """ Print the contents of the ConsoleWidget to the specified QPrinter. | |
605 | """ |
|
694 | """ | |
@@ -652,6 +741,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
652 | font.setPointSize(size) |
|
741 | font.setPointSize(size) | |
653 | self._set_font(font) |
|
742 | self._set_font(font) | |
654 |
|
743 | |||
|
744 | def _increase_font_size(self): | |||
|
745 | self.change_font_size(1) | |||
|
746 | ||||
|
747 | def _decrease_font_size(self): | |||
|
748 | self.change_font_size(-1) | |||
|
749 | ||||
655 | def select_all(self): |
|
750 | def select_all(self): | |
656 | """ Selects all the text in the buffer. |
|
751 | """ Selects all the text in the buffer. | |
657 | """ |
|
752 | """ | |
@@ -855,11 +950,11 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
855 | paste_action.setShortcut(QtGui.QKeySequence.Paste) |
|
950 | paste_action.setShortcut(QtGui.QKeySequence.Paste) | |
856 |
|
951 | |||
857 | menu.addSeparator() |
|
952 | menu.addSeparator() | |
858 |
menu.addAction(self. |
|
953 | menu.addAction(self.select_all_action) | |
859 |
|
954 | |||
860 | menu.addSeparator() |
|
955 | menu.addSeparator() | |
861 |
menu.addAction(self. |
|
956 | menu.addAction(self.export_action) | |
862 |
menu.addAction(self. |
|
957 | menu.addAction(self.print_action) | |
863 |
|
958 | |||
864 | return menu |
|
959 | return menu | |
865 |
|
960 | |||
@@ -1058,18 +1153,6 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
1058 | self._kill_ring.kill_cursor(cursor) |
|
1153 | self._kill_ring.kill_cursor(cursor) | |
1059 | intercepted = True |
|
1154 | intercepted = True | |
1060 |
|
1155 | |||
1061 | elif key in (QtCore.Qt.Key_Plus, QtCore.Qt.Key_Equal): |
|
|||
1062 | self.change_font_size(1) |
|
|||
1063 | intercepted = True |
|
|||
1064 |
|
||||
1065 | elif key == QtCore.Qt.Key_Minus: |
|
|||
1066 | self.change_font_size(-1) |
|
|||
1067 | intercepted = True |
|
|||
1068 |
|
||||
1069 | elif key == QtCore.Qt.Key_0: |
|
|||
1070 | self.reset_font() |
|
|||
1071 | intercepted = True |
|
|||
1072 |
|
||||
1073 | #------ Alt modifier --------------------------------------------------- |
|
1156 | #------ Alt modifier --------------------------------------------------- | |
1074 |
|
1157 | |||
1075 | elif alt_down: |
|
1158 | elif alt_down: |
@@ -31,6 +31,18 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
31 | self._history_index = 0 |
|
31 | self._history_index = 0 | |
32 | self._history_prefix = '' |
|
32 | self._history_prefix = '' | |
33 |
|
33 | |||
|
34 | self.history_action = QtGui.QAction("History", | |||
|
35 | self, | |||
|
36 | statusTip="show command history", | |||
|
37 | triggered=self.history_magic) | |||
|
38 | self.addAction(self.history_action) | |||
|
39 | ||||
|
40 | self.save_action = QtGui.QAction("Export History ", | |||
|
41 | self, | |||
|
42 | statusTip="Export History as Python File", | |||
|
43 | triggered=self.save_magic) | |||
|
44 | self.addAction(self.save_action) | |||
|
45 | ||||
34 | #--------------------------------------------------------------------------- |
|
46 | #--------------------------------------------------------------------------- | |
35 | # 'ConsoleWidget' public interface |
|
47 | # 'ConsoleWidget' public interface | |
36 | #--------------------------------------------------------------------------- |
|
48 | #--------------------------------------------------------------------------- | |
@@ -204,6 +216,22 b' class HistoryConsoleWidget(ConsoleWidget):' | |||||
204 | """ |
|
216 | """ | |
205 | return self._history[-n:] |
|
217 | return self._history[-n:] | |
206 |
|
218 | |||
|
219 | def history_magic(self): | |||
|
220 | self.pasteMagic("%history") | |||
|
221 | ||||
|
222 | def save_magic(self): | |||
|
223 | file_name, ok = QtGui.QInputDialog.getText(self, | |||
|
224 | 'Enter A file Name', | |||
|
225 | 'Please enter a filename to wich export the history as python file:', | |||
|
226 | text='untilted.py') | |||
|
227 | if ok: | |||
|
228 | hist_range, ok = QtGui.QInputDialog.getText(self, | |||
|
229 | 'Please enter an interval of command to save', | |||
|
230 | 'Saving commands:', | |||
|
231 | text='1-500') | |||
|
232 | if ok: | |||
|
233 | self.pasteMagic("%save"+" "+file_name+" "+str(hist_range)) | |||
|
234 | ||||
207 | #--------------------------------------------------------------------------- |
|
235 | #--------------------------------------------------------------------------- | |
208 | # 'HistoryConsoleWidget' protected interface |
|
236 | # 'HistoryConsoleWidget' protected interface | |
209 | #--------------------------------------------------------------------------- |
|
237 | #--------------------------------------------------------------------------- |
@@ -23,7 +23,7 b' import signal' | |||||
23 | import sys |
|
23 | import sys | |
24 |
|
24 | |||
25 | # System library imports |
|
25 | # System library imports | |
26 | from IPython.external.qt import QtGui |
|
26 | from IPython.external.qt import QtGui,QtCore | |
27 | from pygments.styles import get_all_styles |
|
27 | from pygments.styles import get_all_styles | |
28 |
|
28 | |||
29 | # Local imports |
|
29 | # Local imports | |
@@ -74,7 +74,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
74 | #--------------------------------------------------------------------------- |
|
74 | #--------------------------------------------------------------------------- | |
75 | # 'object' interface |
|
75 | # 'object' interface | |
76 | #--------------------------------------------------------------------------- |
|
76 | #--------------------------------------------------------------------------- | |
77 |
|
77 | |||
78 | def __init__(self, app, frontend, existing=False, may_close=True, |
|
78 | def __init__(self, app, frontend, existing=False, may_close=True, | |
79 | confirm_exit=True): |
|
79 | confirm_exit=True): | |
80 | """ Create a MainWindow for the specified FrontendWidget. |
|
80 | """ Create a MainWindow for the specified FrontendWidget. | |
@@ -98,6 +98,49 b' class MainWindow(QtGui.QMainWindow):' | |||||
98 | self._confirm_exit = confirm_exit |
|
98 | self._confirm_exit = confirm_exit | |
99 | self.setCentralWidget(frontend) |
|
99 | self.setCentralWidget(frontend) | |
100 |
|
100 | |||
|
101 | # MenuBar is always present on Mac Os, so let's populate | |||
|
102 | # it with possible action, don't do it on other platform | |||
|
103 | # as some user might not want the menu bar, or give them | |||
|
104 | # an option to remove it | |||
|
105 | if sys.platform == 'darwin': | |||
|
106 | #create menu in the order they should appear in the menu bar | |||
|
107 | self.fileMenu = self.menuBar().addMenu("File") | |||
|
108 | self.editMenu = self.menuBar().addMenu("Edit") | |||
|
109 | self.fontMenu = self.menuBar().addMenu("Font") | |||
|
110 | self.windowMenu = self.menuBar().addMenu("Window") | |||
|
111 | self.magicMenu = self.menuBar().addMenu("Magic") | |||
|
112 | ||||
|
113 | # please keep the Help menu in Mac Os even if empty. It will | |||
|
114 | # automatically contain a search field to search inside menus and | |||
|
115 | # please keep it spelled in English, as long as Qt Doesn't support | |||
|
116 | # a QAction.MenuRole like HelpMenuRole otherwise it will loose | |||
|
117 | # this search field fonctionnality | |||
|
118 | ||||
|
119 | self.helpMenu = self.menuBar().addMenu("Help") | |||
|
120 | ||||
|
121 | # sould wrap every line of the following block into a try/except, | |||
|
122 | # as we are not sure of instanciating a _frontend which support all | |||
|
123 | # theses actions, but there might be a better way | |||
|
124 | ||||
|
125 | self.fileMenu.addAction(self._frontend.print_action) | |||
|
126 | self.fileMenu.addAction(self._frontend.export_action) | |||
|
127 | self.fileMenu.addAction(self._frontend.select_all_action) | |||
|
128 | ||||
|
129 | self.editMenu.addAction(self._frontend.undo_action) | |||
|
130 | self.editMenu.addAction(self._frontend.redo_action) | |||
|
131 | ||||
|
132 | self.fontMenu.addAction(self._frontend.increase_font_size) | |||
|
133 | self.fontMenu.addAction(self._frontend.decrease_font_size) | |||
|
134 | self.fontMenu.addAction(self._frontend.reset_font_size) | |||
|
135 | ||||
|
136 | self.magicMenu.addAction(self._frontend.reset_action) | |||
|
137 | self.magicMenu.addAction(self._frontend.history_action) | |||
|
138 | self.magicMenu.addAction(self._frontend.save_action) | |||
|
139 | self.magicMenu.addAction(self._frontend.clear_action) | |||
|
140 | self.magicMenu.addAction(self._frontend.who_action) | |||
|
141 | self.magicMenu.addAction(self._frontend.who_ls_action) | |||
|
142 | self.magicMenu.addAction(self._frontend.whos_action) | |||
|
143 | ||||
101 | #--------------------------------------------------------------------------- |
|
144 | #--------------------------------------------------------------------------- | |
102 | # QWidget interface |
|
145 | # QWidget interface | |
103 | #--------------------------------------------------------------------------- |
|
146 | #--------------------------------------------------------------------------- | |
@@ -562,16 +605,76 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
562 | self.init_window_shortcut() |
|
605 | self.init_window_shortcut() | |
563 |
|
606 | |||
564 | def init_window_shortcut(self): |
|
607 | def init_window_shortcut(self): | |
565 | fullScreenAction = QtGui.QAction('Toggle Full Screen', self.window) |
|
|||
566 | fullScreenAction.setShortcut('Ctrl+Meta+Space') |
|
|||
567 | fullScreenAction.triggered.connect(self.toggleFullScreen) |
|
|||
568 | self.window.addAction(fullScreenAction) |
|
|||
569 |
|
608 | |||
|
609 | self.fullScreenAct = QtGui.QAction("Full Screen", | |||
|
610 | self.window, | |||
|
611 | shortcut="Ctrl+Meta+Space", | |||
|
612 | statusTip="Toggle between Fullscreen and Normal Size", | |||
|
613 | triggered=self.toggleFullScreen) | |||
|
614 | ||||
|
615 | ||||
|
616 | # creating shortcut in menubar only for Mac OS as I don't | |||
|
617 | # know the shortcut or if the windows manager assign it in | |||
|
618 | # other platform. | |||
|
619 | if sys.platform == 'darwin': | |||
|
620 | self.minimizeAct = QtGui.QAction("Minimize", | |||
|
621 | self.window, | |||
|
622 | shortcut="Ctrl+m", | |||
|
623 | statusTip="Minimize the window/Restore Normal Size", | |||
|
624 | triggered=self.toggleMinimized) | |||
|
625 | self.maximizeAct = QtGui.QAction("Maximize", | |||
|
626 | self.window, | |||
|
627 | shortcut="Ctrl+Shift+M", | |||
|
628 | statusTip="Maximize the window/Restore Normal Size", | |||
|
629 | triggered=self.toggleMaximized) | |||
|
630 | ||||
|
631 | self.onlineHelpAct = QtGui.QAction("Open Online Help", | |||
|
632 | self.window, | |||
|
633 | triggered=self._open_online_help) | |||
|
634 | ||||
|
635 | self.windowMenu = self.window.windowMenu | |||
|
636 | self.windowMenu.addAction(self.minimizeAct) | |||
|
637 | self.windowMenu.addAction(self.maximizeAct) | |||
|
638 | self.windowMenu.addSeparator() | |||
|
639 | self.windowMenu.addAction(self.fullScreenAct) | |||
|
640 | ||||
|
641 | self.window.helpMenu.addAction(self.onlineHelpAct) | |||
|
642 | else: | |||
|
643 | # if we don't put it in a menu, we add it to the window so | |||
|
644 | # that it can still be triggerd by shortcut | |||
|
645 | self.window.addAction(self.fullScreenAct) | |||
|
646 | ||||
|
647 | def toggleMinimized(self): | |||
|
648 | if not self.window.isMinimized(): | |||
|
649 | self.window.showMinimized() | |||
|
650 | else: | |||
|
651 | self.window.showNormal() | |||
|
652 | ||||
|
653 | def _open_online_help(self): | |||
|
654 | QtGui.QDesktopServices.openUrl( | |||
|
655 | QtCore.QUrl("http://ipython.org/documentation.html", | |||
|
656 | QtCore.QUrl.TolerantMode) | |||
|
657 | ) | |||
|
658 | ||||
|
659 | def toggleMaximized(self): | |||
|
660 | if not self.window.isMaximized(): | |||
|
661 | self.window.showMaximized() | |||
|
662 | else: | |||
|
663 | self.window.showNormal() | |||
|
664 | ||||
|
665 | # Min/Max imizing while in full screen give a bug | |||
|
666 | # when going out of full screen, at least on OSX | |||
570 | def toggleFullScreen(self): |
|
667 | def toggleFullScreen(self): | |
571 | if not self.window.isFullScreen(): |
|
668 | if not self.window.isFullScreen(): | |
572 | self.window.showFullScreen() |
|
669 | self.window.showFullScreen() | |
|
670 | if sys.platform == 'darwin': | |||
|
671 | self.maximizeAct.setEnabled(False) | |||
|
672 | self.minimizeAct.setEnabled(False) | |||
573 | else: |
|
673 | else: | |
574 | self.window.showNormal() |
|
674 | self.window.showNormal() | |
|
675 | if sys.platform == 'darwin': | |||
|
676 | self.maximizeAct.setEnabled(True) | |||
|
677 | self.minimizeAct.setEnabled(True) | |||
575 |
|
678 | |||
576 | def start(self): |
|
679 | def start(self): | |
577 |
|
680 |
General Comments 0
You need to be logged in to leave comments.
Login now