Ejemplo n.º 1
0
    def open_file(self, path, rel_path, switch_to=True):
        '''This will open file for editing in the DesignerTabbedPanel.
        :param switch_to: if should switch to the new tab
        :param rel_path: relative file path
        :param path: absolute file path to open
        '''
        for i, tab_item in enumerate(self.tab_list):
            if hasattr(tab_item, 'rel_path') and tab_item.rel_path == rel_path:
                # self.switch_to(self.tab_list[len(self.tab_list) - i - 2])
                self.switch_to(tab_item)
                return

        panel_item = DesignerCloseableTab(title=os.path.basename(path))
        panel_item.bind(on_close=self.on_close_tab)
        f = open(path, 'r', encoding='utf-8')
        scroll = PyScrollView()
        _py_code_input = scroll.code_input
        _py_code_input.text = f.read()
        _py_code_input.path = path
        _py_code_input.bind(
            on_show_edit=App.get_running_app().root.on_show_edit)
        _py_code_input.bind(saved=panel_item.on_tab_content_saved)
        _py_code_input.bind(error=panel_item.on_tab_content_error)
        f.close()

        d = get_designer()
        if _py_code_input not in d.code_inputs:
            d.code_inputs.append(_py_code_input)

        panel_item.content = scroll
        panel_item.rel_path = rel_path
        self.add_widget(panel_item)
        if switch_to:
            self.switch_to(self.tab_list[0])
Ejemplo n.º 2
0
    def do_diff(self, *args):
        '''Open a CodeInput with git diff
        '''
        diff = self.repo.git.diff()

        designer = get_designer()
        designer_content = designer.designer_content
        tabs = designer_content.tab_pannel

        # check if diff is visible on tabbed panel.
        # if so, update the text content
        for i, code_input in enumerate(tabs.list_py_code_inputs):
            if code_input == self.diff_code_input:
                tabs.switch_to(tabs.tab_list[len(tabs.tab_list) - i - 2])
                code_input.text = diff
                return

        # if not displayed, create or add it to the screen
        if self.diff_code_input is None:
            panel_item = DesignerTabbedPanelItem(text='Git diff')
            scroll = PyScrollView()
            _py_code_input = scroll.code_input
            _py_code_input.rel_file_path = 'designer.DesigerGit.diff_code_input'
            _py_code_input.text = diff
            _py_code_input.readonly = True
            _py_code_input.lexer = DiffLexer()
            tabs.list_py_code_inputs.append(_py_code_input)
            panel_item.content = scroll
            self.diff_code_input = panel_item
        else:
            self.diff_code_input.content.code_input.text = diff
        tabs.add_widget(self.diff_code_input)
        tabs.switch_to(tabs.tab_list[0])
    def open_file(self, path, rel_path, switch_to=True):
        '''This will open py file for editing in the DesignerTabbedPanel.
        '''

        for i, code_input in enumerate(self.list_py_code_inputs):
            if code_input.rel_file_path == rel_path:
                self.switch_to(self.tab_list[len(self.tab_list) - i - 2])
                return

        panel_item = DesignerTabbedPanelItem(text=os.path.basename(path))
        f = open(path, 'r')
        scroll = PyScrollView()
        _py_code_input = scroll.code_input
        _py_code_input.rel_file_path = rel_path
        _py_code_input.text = f.read()
        _py_code_input.bind(
            on_show_edit=App.get_running_app().root.on_show_edit)
        f.close()
        self.list_py_code_inputs.append(_py_code_input)
        panel_item.content = scroll
        self.add_widget(panel_item)
        if switch_to:
            self.switch_to(self.tab_list[0])
Ejemplo n.º 4
0
    def do_diff(self, *args):
        '''Open a CodeInput with git diff
        '''
        diff = self.repo.git.diff()
        if not diff:
            diff = 'Empty diff'

        d = get_designer()
        panel = d.designer_content.tab_pannel
        inputs = d.code_inputs

        # check if diff is visible on tabbed panel.
        # if so, update the text content
        for i, code_input in enumerate(panel.tab_list):
            if code_input == self.diff_code_input:
                panel.switch_to(panel.tab_list[len(panel.tab_list) - i - 2])
                code_input.content.code_input.text = diff
                return

        # if not displayed, create or add it to the screen
        if self.diff_code_input is None:
            panel_item = DesignerCloseableTab(title='Git diff')
            panel_item.bind(on_close=panel.on_close_tab)
            scroll = PyScrollView()
            _py_code_input = scroll.code_input
            _py_code_input.text = diff
            _py_code_input.path = ''
            _py_code_input.readonly = True
            _py_code_input.lexer = DiffLexer()
            _py_code_input.saved = True
            panel_item.content = scroll
            panel_item.rel_path = ''
            self.diff_code_input = panel_item
        else:
            self.diff_code_input.content.code_input.text = diff
        panel.add_widget(self.diff_code_input)
        panel.switch_to(panel.tab_list[0])