コード例 #1
0
 def load_from_disk(self):
     nb = nbformat.read(self.pathname, nbformat.current_nbformat)
     if self.get_cell_count() == 0:
         kernelname = nb.metadata['kernelspec']['name']
         if not ServiceLocator.get_kernelspecs().is_installed(kernelname):
             raise KernelMissing(kernelname)
         self.set_kernelname(kernelname)
         self.set_kernel_state('kernel_to_start')
         is_first_cell = True
         for cell in nb.cells:
             if cell.cell_type == 'markdown':
                 new_cell = self.create_markdowncell('last', cell.source)
                 try: in_edit_mode = cell.metadata['in_edit_mode']
                 except KeyError: in_edit_mode = False
                 if len(cell.source) > 0 and in_edit_mode == False:
                     new_cell.evaluate_now()
             elif cell.cell_type == 'code':
                 new_cell = self.create_cell('last', cell.source)
                 if is_first_cell == True:
                     is_first_cell = False
                     self.set_active_cell(new_cell)
                 for output in cell.outputs:
                     if output['output_type'] == 'error':
                         result = self.result_factory.get_error_from_nbformat_dict(output)
                         new_cell.set_result(result)
                     elif output['output_type'] == 'execute_result' or output['output_type'] == 'display_data':
                         try: data = output['data']
                         except KeyError: pass
                         else:
                             result = self.result_factory.get_result_from_blob(data)
                             new_cell.set_result(result)
                     elif output['output_type'] == 'stream':
                         new_cell.add_to_stream(output['name'], output['text'])
     self.set_save_state('saved')
コード例 #2
0
ファイル: __main__.py プロジェクト: tonghuaWN/Porto
    def do_activate(self):
        ''' Everything starts here. '''
        
        # load settings
        self.settings = ServiceLocator.get_settings()

        # init view
        self.main_window = view.MainWindow(self)
        ServiceLocator.init_main_window(self.main_window)
        self.main_window.set_default_size(self.settings.get_value('window_state', 'width'), 
                                          self.settings.get_value('window_state', 'height'))
        if self.settings.get_value('window_state', 'is_maximized'): self.main_window.maximize()
        else: self.main_window.unmaximize()
        if self.settings.get_value('window_state', 'is_fullscreen'): self.main_window.fullscreen()
        else: self.main_window.unfullscreen()
        self.main_window.show_all()

        self.workspace = Workspace()
        kernelspecs = ServiceLocator.get_kernelspecs()
        ServiceLocator.init_dialogs(self.main_window, self.workspace, kernelspecs)

        # controllers
        self.main_window.quit_action.connect('activate', self.on_quit_action)

        # watch changes in view
        self.observe_main_window()
コード例 #3
0
 def __init__(self, workspace, recently_opened_notebooks):
     self.sidebar = ServiceLocator.get_main_window().sidebar
     self.hbchooser = ServiceLocator.get_main_window(
     ).headerbar.hb_right.notebook_chooser
     self.kernelspecs = ServiceLocator.get_kernelspecs()
     self.workspace = workspace
     self.recently_opened_notebooks = recently_opened_notebooks
     self.recently_opened_notebooks.register_observer(self)
コード例 #4
0
ファイル: notebook_list_item.py プロジェクト: tonghuaWN/Porto
    def __init__(self, notebook):
        Observable.__init__(self)
        self.notebook = notebook
        self.kernelspecs = ServiceLocator.get_kernelspecs()

        self.sb_view = nbli_view.OpenNotebookListViewItem(
            notebook, notebook.get_last_saved())
        self.hb_view = nbli_view.OpenNotebookListViewItem(
            notebook, notebook.get_last_saved())
        self.presenter = nbli_presenter.NotebookListItemPresenter(
            notebook, self, self.sb_view, self.hb_view)
        self.controller = nbli_controller.NotebookListItemController(
            notebook, self, self.sb_view, self.hb_view)

        self.set_kernel(notebook.get_kernelname())
コード例 #5
0
    def __init__(self, workspace):
        self.workspace = workspace
        self.headerbar = ServiceLocator.get_main_window().headerbar
        self.kernelspecs = ServiceLocator.get_kernelspecs()

        self.window_mode = None
        self.activate_welcome_page_mode()
        self.setup_kernel_changer()

        if self.workspace.show_sidebar:
            self.on_show_sidebar()
        else:
            self.on_hide_sidebar()

        self.workspace.register_observer(self)