Show More
@@ -547,15 +547,23 b' class MainWindow(QtGui.QMainWindow):' | |||||
547 | def update_all_magic_menu(self): |
|
547 | def update_all_magic_menu(self): | |
548 | # first define a callback which will get the list of all magic and put it in the menu. |
|
548 | # first define a callback which will get the list of all magic and put it in the menu. | |
549 | def populate_all_magic_menu(val=None): |
|
549 | def populate_all_magic_menu(val=None): | |
550 |
alm_magic_menu = self.magic_menu |
|
550 | alm_magic_menu = self.all_magic_menu | |
|
551 | alm_magic_menu.clear() | |||
551 | def make_dynamic_magic(i): |
|
552 | def make_dynamic_magic(i): | |
552 | def inner_dynamic_magic(): |
|
553 | def inner_dynamic_magic(): | |
553 | self.active_frontend.execute(i) |
|
554 | self.active_frontend.execute(i) | |
554 | inner_dynamic_magic.__name__ = "dynamics_magic_s" |
|
555 | inner_dynamic_magic.__name__ = "dynamics_magic_s" | |
555 | return inner_dynamic_magic |
|
556 | return inner_dynamic_magic | |
556 |
|
557 | |||
|
558 | # list of protected magic that don't like to be called without argument | |||
|
559 | # append '?' to the end to print the docstring when called from the menu | |||
|
560 | protected_magic= ["more","less","load_ext","pycat"] | |||
|
561 | ||||
557 | for magic in eval(val): |
|
562 | for magic in eval(val): | |
558 |
|
|
563 | if magic in protected_magic: | |
|
564 | pmagic = '%s%s%s'%('%',magic,'?') | |||
|
565 | else: | |||
|
566 | pmagic = '%s%s'%('%',magic) | |||
559 | xaction = QtGui.QAction(pmagic, |
|
567 | xaction = QtGui.QAction(pmagic, | |
560 | self, |
|
568 | self, | |
561 | triggered=make_dynamic_magic(pmagic) |
|
569 | triggered=make_dynamic_magic(pmagic) | |
@@ -566,12 +574,13 b' class MainWindow(QtGui.QMainWindow):' | |||||
566 | def init_magic_menu(self): |
|
574 | def init_magic_menu(self): | |
567 | self.magic_menu = self.menuBar().addMenu("&Magic") |
|
575 | self.magic_menu = self.menuBar().addMenu("&Magic") | |
568 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") |
|
576 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") | |
569 |
|
577 | |||
570 | self.pop = QtGui.QAction("&Populate All Magic Menu", |
|
578 | # this action should not appear as it will be cleard when menu | |
|
579 | # will be updated at first kernel response. | |||
|
580 | self.pop = QtGui.QAction("&Update All Magic Menu ", | |||
571 | self, |
|
581 | self, | |
572 | statusTip="Clear all varible from workspace", |
|
|||
573 | triggered=self.update_all_magic_menu) |
|
582 | triggered=self.update_all_magic_menu) | |
574 | self.add_menu_action(self.magic_menu, self.pop) |
|
583 | self.add_menu_action(self.all_magic_menu, self.pop) | |
575 |
|
584 | |||
576 | self.reset_action = QtGui.QAction("&Reset", |
|
585 | self.reset_action = QtGui.QAction("&Reset", | |
577 | self, |
|
586 | self, | |
@@ -609,33 +618,6 b' class MainWindow(QtGui.QMainWindow):' | |||||
609 | triggered=self.whos_magic_active_frontend) |
|
618 | triggered=self.whos_magic_active_frontend) | |
610 | self.add_menu_action(self.magic_menu, self.whos_action) |
|
619 | self.add_menu_action(self.magic_menu, self.whos_action) | |
611 |
|
620 | |||
612 | # allmagics submenu: |
|
|||
613 |
|
||||
614 | #for now this is just a copy and paste, but we should get this dynamically |
|
|||
615 | magiclist=["%alias", "%autocall", "%automagic", "%bookmark", "%cd", "%clear", |
|
|||
616 | "%colors", "%debug", "%dhist", "%dirs", "%doctest_mode", "%ed", "%edit", "%env", "%gui", |
|
|||
617 | "%guiref", "%hist", "%history", "%install_default_config", "%install_profiles", |
|
|||
618 | "%less", "%load_ext", "%loadpy", "%logoff", "%logon", "%logstart", "%logstate", |
|
|||
619 | "%logstop", "%lsmagic", "%macro", "%magic", "%man", "%more", "%notebook", "%page", |
|
|||
620 | "%pastebin", "%pdb", "%pdef", "%pdoc", "%pfile", "%pinfo", "%pinfo2", "%popd", "%pprint", |
|
|||
621 | "%precision", "%profile", "%prun", "%psearch", "%psource", "%pushd", "%pwd", "%pycat", |
|
|||
622 | "%pylab", "%quickref", "%recall", "%rehashx", "%reload_ext", "%rep", "%rerun", |
|
|||
623 | "%reset", "%reset_selective", "%run", "%save", "%sc", "%sx", "%tb", "%time", "%timeit", |
|
|||
624 | "%unalias", "%unload_ext", "%who", "%who_ls", "%whos", "%xdel", "%xmode"] |
|
|||
625 |
|
||||
626 | def make_dynamic_magic(i): |
|
|||
627 | def inner_dynamic_magic(): |
|
|||
628 | self.active_frontend.execute(i) |
|
|||
629 | inner_dynamic_magic.__name__ = "dynamics_magic_%s" % i |
|
|||
630 | return inner_dynamic_magic |
|
|||
631 |
|
||||
632 | for magic in magiclist: |
|
|||
633 | xaction = QtGui.QAction(magic, |
|
|||
634 | self, |
|
|||
635 | triggered=make_dynamic_magic(magic) |
|
|||
636 | ) |
|
|||
637 | self.all_magic_menu.addAction(xaction) |
|
|||
638 |
|
||||
639 | def init_window_menu(self): |
|
621 | def init_window_menu(self): | |
640 | self.window_menu = self.menuBar().addMenu("&Window") |
|
622 | self.window_menu = self.menuBar().addMenu("&Window") | |
641 | if sys.platform == 'darwin': |
|
623 | if sys.platform == 'darwin': |
@@ -451,6 +451,10 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
451 | self.window.log = self.log |
|
451 | self.window.log = self.log | |
452 | self.window.add_tab_with_frontend(self.widget) |
|
452 | self.window.add_tab_with_frontend(self.widget) | |
453 | self.window.init_menu_bar() |
|
453 | self.window.init_menu_bar() | |
|
454 | ||||
|
455 | #we need to populate the 'Magic Menu' once the kernel has answer at least once | |||
|
456 | self.kernel_manager.shell_channel.first_reply.connect(self.window.pop.trigger) | |||
|
457 | ||||
454 | self.window.setWindowTitle('Python' if self.pure else 'IPython') |
|
458 | self.window.setWindowTitle('Python' if self.pure else 'IPython') | |
455 |
|
459 | |||
456 | def init_colors(self): |
|
460 | def init_colors(self): |
General Comments 0
You need to be logged in to leave comments.
Login now