def close_all_notebooks_after_modified_check(self):
        notebooks = self.workspace.get_unsaved_notebooks()
        active_notebook = self.workspace.get_active_notebook()

        if len(notebooks) == 0 or active_notebook == None or ServiceLocator.get_dialog('close_confirmation').run(notebooks)['all_save_to_close']: 
            for notebook in list(self.workspace.open_notebooks.values()):
                self.close_notebook(notebook)
 def on_open_action(self, action=None, pathname=None):
     if pathname == None:
         pathname = ServiceLocator.get_dialog('open_notebook').run()
     if pathname != None:
         notebook = self.workspace.get_notebook_by_pathname(pathname)
         if notebook == None:
             if pathname.split('.')[-1] == 'ipynb':
                 notebook = model_notebook.Notebook(pathname)
                 try:
                     notebook.load_from_disk()
                 except FileNotFoundError:
                     notebook = None
                 except model_notebook.KernelMissing as e:
                     ServiceLocator.get_dialog('kernel_missing').run(str(e))
                 else:
                     self.workspace.add_notebook(notebook)
                     self.workspace.set_active_notebook(notebook)
         else:
             self.workspace.set_active_notebook(notebook)
Beispiel #3
0
    def save_quit(self, accel_group=None, window=None, key=None, mask=None):
        ''' signal handler, ask user to save unsaved notebooks or discard changes '''
        
        notebooks = self.workspace.get_unsaved_notebooks()
        active_notebook = self.workspace.get_active_notebook()

        if len(notebooks) == 0 or active_notebook == None or ServiceLocator.get_dialog('close_confirmation').run(notebooks)['all_save_to_close']: 
            self.save_window_state()
            self.workspace.shutdown_all_kernels()
            self.quit()
    def on_create_action(self, action=None, parameter=None):
        parameters = ServiceLocator.get_dialog('create_notebook').run()
        if parameters != None:
            pathname, kernelname = parameters
            self.workspace.recently_opened_notebooks.remove_notebook_by_pathname(pathname)
            self.workspace.remove_notebook_by_pathname(pathname)

            notebook = model_notebook.Notebook(pathname)
            notebook.set_kernelname(kernelname)
            notebook.create_cell(0, '', activate=True)
            notebook.save_to_disk()
            self.workspace.add_notebook(notebook)
            self.workspace.set_active_notebook(notebook)
 def delete_notebook(self, notebook):
     if ServiceLocator.get_dialog('delete_notebook').run(notebook):
         self.close_notebook(notebook, add_to_recently_opened=False)
         notebook.remove_from_disk()
 def show_about_dialog(self, action, parameter=''):
     ServiceLocator.get_dialog('about').run()
 def show_preferences_dialog(self, action=None, parameter=''):
     ServiceLocator.get_dialog('preferences').run()
 def show_shortcuts_window(self, action, parameter=''):
     ServiceLocator.get_dialog('keyboard_shortcuts').run()
 def close_notebook_after_modified_check(self, notebook):
     if notebook.get_save_state() != 'modified' or ServiceLocator.get_dialog('close_confirmation').run([notebook])['all_save_to_close']:
         self.close_notebook(notebook)
Beispiel #10
0
 def on_save_as_action(self, action=None, parameter=None):
     notebook = self.workspace.get_active_notebook()
     if notebook != None:
         ServiceLocator.get_dialog('save_as').run(notebook)