Show More
@@ -102,7 +102,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
102 | executed = QtCore.Signal(object) |
|
102 | executed = QtCore.Signal(object) | |
103 |
|
103 | |||
104 | # Emitted when an exit request has been received from the kernel. |
|
104 | # Emitted when an exit request has been received from the kernel. | |
105 | exit_requested = QtCore.Signal() |
|
105 | exit_requested = QtCore.Signal(object) | |
106 |
|
106 | |||
107 | # Protected class variables. |
|
107 | # Protected class variables. | |
108 | _CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos']) |
|
108 | _CallTipRequest = namedtuple('_CallTipRequest', ['id', 'pos']) | |
@@ -422,7 +422,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
422 | "Close the Console?", |
|
422 | "Close the Console?", | |
423 | QtGui.QMessageBox.Yes,QtGui.QMessageBox.No) |
|
423 | QtGui.QMessageBox.Yes,QtGui.QMessageBox.No) | |
424 | if reply == QtGui.QMessageBox.Yes: |
|
424 | if reply == QtGui.QMessageBox.Yes: | |
425 |
s |
|
425 | self.exit_requested.emit(self) | |
426 | else: |
|
426 | else: | |
427 | reply = QtGui.QMessageBox.question(self, title, |
|
427 | reply = QtGui.QMessageBox.question(self, title, | |
428 | "Kernel has been reset. Clear the Console?", |
|
428 | "Kernel has been reset. Clear the Console?", | |
@@ -583,7 +583,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):' | |||||
583 | if content['ename']=='SystemExit': |
|
583 | if content['ename']=='SystemExit': | |
584 | keepkernel = content['evalue']=='-k' or content['evalue']=='True' |
|
584 | keepkernel = content['evalue']=='-k' or content['evalue']=='True' | |
585 | self._keep_kernel_on_exit = keepkernel |
|
585 | self._keep_kernel_on_exit = keepkernel | |
586 | self.exit_requested.emit() |
|
586 | self.exit_requested.emit(self) | |
587 | else: |
|
587 | else: | |
588 | traceback = ''.join(content['traceback']) |
|
588 | traceback = ''.join(content['traceback']) | |
589 | self._append_plain_text(traceback) |
|
589 | self._append_plain_text(traceback) |
@@ -503,7 +503,7 b' class IPythonWidget(FrontendWidget):' | |||||
503 |
|
503 | |||
504 | def _handle_payload_exit(self, item): |
|
504 | def _handle_payload_exit(self, item): | |
505 | self._keep_kernel_on_exit = item['keepkernel'] |
|
505 | self._keep_kernel_on_exit = item['keepkernel'] | |
506 | self.exit_requested.emit() |
|
506 | self.exit_requested.emit(self) | |
507 |
|
507 | |||
508 | def _handle_payload_next_input(self, item): |
|
508 | def _handle_payload_next_input(self, item): | |
509 | self.input_buffer = dedent(item['text'].rstrip()) |
|
509 | self.input_buffer = dedent(item['text'].rstrip()) |
@@ -97,8 +97,66 b' class MainWindow(QtGui.QMainWindow):' | |||||
97 | self._may_close = True |
|
97 | self._may_close = True | |
98 | self._frontend.exit_requested.connect(self.close) |
|
98 | self._frontend.exit_requested.connect(self.close) | |
99 | self._confirm_exit = confirm_exit |
|
99 | self._confirm_exit = confirm_exit | |
100 | self.setCentralWidget(frontend) |
|
|||
101 |
|
100 | |||
|
101 | self.tabWidget = QtGui.QTabWidget(self) | |||
|
102 | self.tabWidget.setDocumentMode(True) | |||
|
103 | self.tabWidget.setTabsClosable(True) | |||
|
104 | self.tabWidget.addTab(frontend,"QtConsole1") | |||
|
105 | self.tabWidget.tabCloseRequested[int].connect(self.closetab) | |||
|
106 | ||||
|
107 | self.setCentralWidget(self.tabWidget) | |||
|
108 | self.updateTabBarVisibility() | |||
|
109 | ||||
|
110 | def updateTabBarVisibility(self): | |||
|
111 | """ update visibility of the tabBar depending of the number of tab | |||
|
112 | ||||
|
113 | 0 or 1 tab, tabBar hiddent | |||
|
114 | 2+ tabs, tabbarHidden | |||
|
115 | ||||
|
116 | need to be called explicitely, or be connected to tabInserted/tabRemoved | |||
|
117 | """ | |||
|
118 | if self.tabWidget.count() <= 1: | |||
|
119 | self.tabWidget.tabBar().setVisible(False) | |||
|
120 | else: | |||
|
121 | self.tabWidget.tabBar().setVisible(True) | |||
|
122 | ||||
|
123 | def activeFrontend(self): | |||
|
124 | return self.tabWidget.currentWidget() | |||
|
125 | ||||
|
126 | def closetab(self,tab): | |||
|
127 | """ Called when a user try to close a tab | |||
|
128 | ||||
|
129 | It takes the number of the tab to be closed as argument, (does not for | |||
|
130 | now, but should) take care of whether or not shuting down the kernel | |||
|
131 | attached to the frontend | |||
|
132 | """ | |||
|
133 | print "closing tab",tab | |||
|
134 | try: | |||
|
135 | if self.tabWidget.widget(tab)._local_kernel: | |||
|
136 | kernel_manager = self.tabWidget.widget(tab).kernel_manager.shutdown_kernel() | |||
|
137 | else: | |||
|
138 | print "not owning the kernel" | |||
|
139 | except: | |||
|
140 | print "can't ask the kernel to shutdown" | |||
|
141 | #if self.tabWidget.count() == 1: | |||
|
142 | #self.close() | |||
|
143 | self.tabWidget.removeTab(tab) | |||
|
144 | self.updateTabBarVisibility() | |||
|
145 | ||||
|
146 | def addTabWithFrontend(self,frontend,name=None): | |||
|
147 | """ insert a tab with a given frontend in the tab bar, and give it a name | |||
|
148 | ||||
|
149 | """ | |||
|
150 | if not name: | |||
|
151 | name=str('no Name '+str(self.tabWidget.count())) | |||
|
152 | self.tabWidget.addTab(frontend,name) | |||
|
153 | self.updateTabBarVisibility() | |||
|
154 | frontend.exit_requested.connect(self.irequest) | |||
|
155 | ||||
|
156 | def irequest(self,obj): | |||
|
157 | print "I request to exit",obj | |||
|
158 | print "which is tab:",self.tabWidget.indexOf(obj) | |||
|
159 | self.closetab(self.tabWidget.indexOf(obj)) | |||
102 | # MenuBar is always present on Mac Os, so let's populate it with possible |
|
160 | # MenuBar is always present on Mac Os, so let's populate it with possible | |
103 | # action, don't do it on other platform as some user might not want the |
|
161 | # action, don't do it on other platform as some user might not want the | |
104 | # menu bar, or give them an option to remove it |
|
162 | # menu bar, or give them an option to remove it | |
@@ -123,14 +181,24 b' class MainWindow(QtGui.QMainWindow):' | |||||
123 | # as we are not sure of instanciating a _frontend which support all |
|
181 | # as we are not sure of instanciating a _frontend which support all | |
124 | # theses actions, but there might be a better way |
|
182 | # theses actions, but there might be a better way | |
125 | try: |
|
183 | try: | |
126 | self.fileMenu.addAction(self._frontend.print_action) |
|
184 | pass | |
|
185 | self.print_action = QtGui.QAction("Print", | |||
|
186 | self, | |||
|
187 | shortcut="Ctrl+P", | |||
|
188 | triggered=self.undo_active_frontend) | |||
|
189 | self.fileMenu.addAction(self.print_action) | |||
127 | except AttributeError: |
|
190 | except AttributeError: | |
128 | print "trying to add unexisting action, skipping" |
|
191 | print "trying to add unexisting action (print), skipping" | |
129 |
|
192 | |||
130 | try: |
|
193 | try: | |
131 | self.fileMenu.addAction(self._frontend.export_action) |
|
194 | self.export_action=QtGui.QAction("Export", | |
|
195 | self, | |||
|
196 | shortcut="Ctrl+S", | |||
|
197 | triggered=self.export_action_active_frontend | |||
|
198 | ) | |||
|
199 | self.fileMenu.addAction(self.export_action) | |||
132 | except AttributeError: |
|
200 | except AttributeError: | |
133 | print "trying to add unexisting action, skipping" |
|
201 | print "trying to add unexisting action (Export), skipping" | |
134 |
|
202 | |||
135 | try: |
|
203 | try: | |
136 | self.fileMenu.addAction(self._frontend.select_all_action) |
|
204 | self.fileMenu.addAction(self._frontend.select_all_action) | |
@@ -142,42 +210,42 b' class MainWindow(QtGui.QMainWindow):' | |||||
142 | self, |
|
210 | self, | |
143 | shortcut="Ctrl+Z", |
|
211 | shortcut="Ctrl+Z", | |
144 | statusTip="Undo last action if possible", |
|
212 | statusTip="Undo last action if possible", | |
145 |
triggered=self._frontend |
|
213 | triggered=self.undo_active_frontend) | |
146 |
|
214 | |||
147 | self.editMenu.addAction(self.undo_action) |
|
215 | self.editMenu.addAction(self.undo_action) | |
148 | except AttributeError: |
|
216 | except AttributeError: | |
149 | print "trying to add unexisting action, skipping" |
|
217 | print "trying to add unexisting action (undo), skipping" | |
150 |
|
218 | |||
151 | try: |
|
219 | try: | |
152 | self.redo_action = QtGui.QAction("Redo", |
|
220 | self.redo_action = QtGui.QAction("Redo", | |
153 | self, |
|
221 | self, | |
154 | shortcut="Ctrl+Shift+Z", |
|
222 | shortcut="Ctrl+Shift+Z", | |
155 | statusTip="Redo last action if possible", |
|
223 | statusTip="Redo last action if possible", | |
156 |
triggered=self._frontend |
|
224 | triggered=self.redo_active_frontend) | |
157 | self.editMenu.addAction(self.redo_action) |
|
225 | self.editMenu.addAction(self.redo_action) | |
158 | except AttributeError: |
|
226 | except AttributeError: | |
159 | print "trying to add unexisting action, skipping" |
|
227 | print "trying to add unexisting action(redo), skipping" | |
160 |
|
228 | |||
161 | try: |
|
229 | try: | |
162 |
self.fontMenu.addAction(self. |
|
230 | pass#self.fontMenu.addAction(self.increase_font_size_active_frontend) | |
163 | except AttributeError: |
|
231 | except AttributeError: | |
164 | print "trying to add unexisting action, skipping" |
|
232 | print "trying to add unexisting action (increase font size), skipping" | |
165 |
|
233 | |||
166 | try: |
|
234 | try: | |
167 |
self.fontMenu.addAction(self. |
|
235 | pass#self.fontMenu.addAction(self.decrease_font_size_active_frontend) | |
168 | except AttributeError: |
|
236 | except AttributeError: | |
169 | print "trying to add unexisting action, skipping" |
|
237 | print "trying to add unexisting action (decrease font size), skipping" | |
170 |
|
238 | |||
171 | try: |
|
239 | try: | |
172 |
self.fontMenu.addAction(self. |
|
240 | pass#self.fontMenu.addAction(self.reset_font_size_active_frontend) | |
173 | except AttributeError: |
|
241 | except AttributeError: | |
174 | print "trying to add unexisting action, skipping" |
|
242 | print "trying to add unexisting action (reset font size), skipping" | |
175 |
|
243 | |||
176 | try: |
|
244 | try: | |
177 | self.reset_action = QtGui.QAction("Reset", |
|
245 | self.reset_action = QtGui.QAction("Reset", | |
178 | self, |
|
246 | self, | |
179 | statusTip="Clear all varible from workspace", |
|
247 | statusTip="Clear all varible from workspace", | |
180 |
triggered=self. |
|
248 | triggered=self.reset_magic_active_frontend) | |
181 | self.magicMenu.addAction(self.reset_action) |
|
249 | self.magicMenu.addAction(self.reset_action) | |
182 | except AttributeError: |
|
250 | except AttributeError: | |
183 | print "trying to add unexisting action (reset), skipping" |
|
251 | print "trying to add unexisting action (reset), skipping" | |
@@ -186,7 +254,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
186 | self.history_action = QtGui.QAction("History", |
|
254 | self.history_action = QtGui.QAction("History", | |
187 | self, |
|
255 | self, | |
188 | statusTip="show command history", |
|
256 | statusTip="show command history", | |
189 |
triggered=self. |
|
257 | triggered=self.history_magic_active_frontend) | |
190 | self.magicMenu.addAction(self.history_action) |
|
258 | self.magicMenu.addAction(self.history_action) | |
191 | except AttributeError: |
|
259 | except AttributeError: | |
192 | print "trying to add unexisting action (history), skipping" |
|
260 | print "trying to add unexisting action (history), skipping" | |
@@ -195,7 +263,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
195 | self.save_action = QtGui.QAction("Export History ", |
|
263 | self.save_action = QtGui.QAction("Export History ", | |
196 | self, |
|
264 | self, | |
197 | statusTip="Export History as Python File", |
|
265 | statusTip="Export History as Python File", | |
198 |
triggered=self. |
|
266 | triggered=self.save_magic_active_frontend) | |
199 | self.magicMenu.addAction(self.save_action) |
|
267 | self.magicMenu.addAction(self.save_action) | |
200 | except AttributeError: |
|
268 | except AttributeError: | |
201 | print "trying to add unexisting action (save), skipping" |
|
269 | print "trying to add unexisting action (save), skipping" | |
@@ -204,7 +272,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
204 | self.clear_action = QtGui.QAction("Clear", |
|
272 | self.clear_action = QtGui.QAction("Clear", | |
205 | self, |
|
273 | self, | |
206 | statusTip="Clear the console", |
|
274 | statusTip="Clear the console", | |
207 |
triggered=self. |
|
275 | triggered=self.clear_magic_active_frontend) | |
208 | self.magicMenu.addAction(self.clear_action) |
|
276 | self.magicMenu.addAction(self.clear_action) | |
209 | except AttributeError: |
|
277 | except AttributeError: | |
210 | print "trying to add unexisting action, skipping" |
|
278 | print "trying to add unexisting action, skipping" | |
@@ -213,7 +281,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
213 | self.who_action = QtGui.QAction("Who", |
|
281 | self.who_action = QtGui.QAction("Who", | |
214 | self, |
|
282 | self, | |
215 | statusTip="List interactive variable", |
|
283 | statusTip="List interactive variable", | |
216 |
triggered=self. |
|
284 | triggered=self.who_magic_active_frontend) | |
217 | self.magicMenu.addAction(self.who_action) |
|
285 | self.magicMenu.addAction(self.who_action) | |
218 | except AttributeError: |
|
286 | except AttributeError: | |
219 | print "trying to add unexisting action (who), skipping" |
|
287 | print "trying to add unexisting action (who), skipping" | |
@@ -222,7 +290,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
222 | self.who_ls_action = QtGui.QAction("Who ls", |
|
290 | self.who_ls_action = QtGui.QAction("Who ls", | |
223 | self, |
|
291 | self, | |
224 | statusTip="Return a list of interactive variable", |
|
292 | statusTip="Return a list of interactive variable", | |
225 |
triggered=self. |
|
293 | triggered=self.who_ls_magic_active_frontend) | |
226 | self.magicMenu.addAction(self.who_ls_action) |
|
294 | self.magicMenu.addAction(self.who_ls_action) | |
227 | except AttributeError: |
|
295 | except AttributeError: | |
228 | print "trying to add unexisting action (who_ls), skipping" |
|
296 | print "trying to add unexisting action (who_ls), skipping" | |
@@ -231,12 +299,46 b' class MainWindow(QtGui.QMainWindow):' | |||||
231 | self.whos_action = QtGui.QAction("Whos", |
|
299 | self.whos_action = QtGui.QAction("Whos", | |
232 | self, |
|
300 | self, | |
233 | statusTip="List interactive variable with detail", |
|
301 | statusTip="List interactive variable with detail", | |
234 |
triggered=self. |
|
302 | triggered=self.whos_magic_active_frontend) | |
235 | self.magicMenu.addAction(self.whos_action) |
|
303 | self.magicMenu.addAction(self.whos_action) | |
236 | except AttributeError: |
|
304 | except AttributeError: | |
237 | print "trying to add unexisting action (whos), skipping" |
|
305 | print "trying to add unexisting action (whos), skipping" | |
238 |
|
306 | |||
239 |
|
307 | def undo_active_frontend(self): | ||
|
308 | self.activeFrontend().undo() | |||
|
309 | ||||
|
310 | def redo_active_frontend(self): | |||
|
311 | self.activeFrontend().redo() | |||
|
312 | def reset_magic_active_frontend(self): | |||
|
313 | self.activeFrontend().reset_magic() | |||
|
314 | def history_magic_active_frontend(self): | |||
|
315 | self.activeFrontend().history_magic() | |||
|
316 | def save_magic_active_frontend(self): | |||
|
317 | self.activeFrontend().save_magic() | |||
|
318 | def clear_magic_active_frontend(self): | |||
|
319 | self.activeFrontend().clear_magic() | |||
|
320 | def who_magic_active_frontend(self): | |||
|
321 | self.activeFrontend().who_magic() | |||
|
322 | def who_ls_magic_active_frontend(self): | |||
|
323 | self.activeFrontend().who_ls_magic() | |||
|
324 | def whos_magic_active_frontend(self): | |||
|
325 | self.activeFrontend().whos_magic() | |||
|
326 | ||||
|
327 | def print_action_active_frontend(self): | |||
|
328 | self.activeFrontend().print_action() | |||
|
329 | ||||
|
330 | def export_action_active_frontend(self): | |||
|
331 | self.activeFrontend().export_action() | |||
|
332 | ||||
|
333 | def select_all_action_frontend(self): | |||
|
334 | self.activeFrontend().select_all_action() | |||
|
335 | ||||
|
336 | def increase_font_size_active_frontend(self): | |||
|
337 | self.activeFrontend().increase_font_size() | |||
|
338 | def decrease_font_size_active_frontend(self): | |||
|
339 | self.activeFrontend().decrease_font_size() | |||
|
340 | def reset_font_size_active_frontend(self): | |||
|
341 | self.activeFrontend().reset_font_size() | |||
240 | #--------------------------------------------------------------------------- |
|
342 | #--------------------------------------------------------------------------- | |
241 | # QWidget interface |
|
343 | # QWidget interface | |
242 | #--------------------------------------------------------------------------- |
|
344 | #--------------------------------------------------------------------------- | |
@@ -617,6 +719,44 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
617 | self.kernel_manager.write_connection_file() |
|
719 | self.kernel_manager.write_connection_file() | |
618 | self.kernel_manager.start_channels() |
|
720 | self.kernel_manager.start_channels() | |
619 |
|
721 | |||
|
722 | def createTabWithNewFrontend(self): | |||
|
723 | kernel_manager = QtKernelManager( | |||
|
724 | shell_address=(self.ip, self.shell_port), | |||
|
725 | sub_address=(self.ip, self.iopub_port), | |||
|
726 | stdin_address=(self.ip, self.stdin_port), | |||
|
727 | hb_address=(self.ip, self.hb_port), | |||
|
728 | config=self.config | |||
|
729 | ) | |||
|
730 | # start the kernel | |||
|
731 | if not self.existing: | |||
|
732 | kwargs = dict(ip=self.ip, ipython=not self.pure) | |||
|
733 | kwargs['extra_arguments'] = self.kernel_argv | |||
|
734 | kernel_manager.start_kernel(**kwargs) | |||
|
735 | kernel_manager.start_channels() | |||
|
736 | local_kernel = (not self.existing) or self.ip in LOCAL_IPS | |||
|
737 | widget = self.widget_factory(config=self.config, | |||
|
738 | local_kernel=local_kernel) | |||
|
739 | widget.kernel_manager = kernel_manager | |||
|
740 | self.window.addTabWithFrontend(widget) | |||
|
741 | ||||
|
742 | def createTabAttachedToCurrentTabKernel(self): | |||
|
743 | currentWidget=self.window.tabWidget.currentWidget() | |||
|
744 | currentWidgetIndex=self.window.tabWidget.indexOf(currentWidget) | |||
|
745 | ckm=currentWidget.kernel_manager; | |||
|
746 | cwname=self.window.tabWidget.tabText(currentWidgetIndex); | |||
|
747 | kernel_manager = QtKernelManager( | |||
|
748 | shell_address=ckm.shell_address, | |||
|
749 | sub_address=ckm.sub_address, | |||
|
750 | stdin_address=ckm.stdin_address, | |||
|
751 | hb_address=ckm.hb_address, | |||
|
752 | config=self.config | |||
|
753 | ) | |||
|
754 | kernel_manager.start_channels() | |||
|
755 | local_kernel = (not self.existing) or self.ip in LOCAL_IPS | |||
|
756 | widget = self.widget_factory(config=self.config, | |||
|
757 | local_kernel=False) | |||
|
758 | widget.kernel_manager = kernel_manager | |||
|
759 | self.window.addTabWithFrontend(widget,name=str('('+cwname+') slave')) | |||
620 |
|
760 | |||
621 | def init_qt_elements(self): |
|
761 | def init_qt_elements(self): | |
622 | # Create the widget. |
|
762 | # Create the widget. | |
@@ -716,6 +856,17 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
716 | statusTip="Toggle between Fullscreen and Normal Size", |
|
856 | statusTip="Toggle between Fullscreen and Normal Size", | |
717 | triggered=self.toggleFullScreen) |
|
857 | triggered=self.toggleFullScreen) | |
718 |
|
858 | |||
|
859 | self.tabAndNewKernelAct =QtGui.QAction("Tab with New kernel", | |||
|
860 | self.window, | |||
|
861 | shortcut="Ctrl+T", | |||
|
862 | triggered=self.createTabWithNewFrontend) | |||
|
863 | self.window.windowMenu.addAction(self.tabAndNewKernelAct) | |||
|
864 | self.tabSameKernalAct =QtGui.QAction("Tab with Same kernel", | |||
|
865 | self.window, | |||
|
866 | shortcut="Ctrl+Shift+T", | |||
|
867 | triggered=self.createTabAttachedToCurrentTabKernel) | |||
|
868 | self.window.windowMenu.addAction(self.tabSameKernalAct) | |||
|
869 | self.window.windowMenu.addSeparator() | |||
719 |
|
870 | |||
720 | # creating shortcut in menubar only for Mac OS as I don't |
|
871 | # creating shortcut in menubar only for Mac OS as I don't | |
721 | # know the shortcut or if the windows manager assign it in |
|
872 | # know the shortcut or if the windows manager assign it in |
General Comments 0
You need to be logged in to leave comments.
Login now