Beispiel #1
0
    def new_tab(self, tab_name=None, init_features=True):
        """
        Creates a new tab.
        """
        count = self.count()
        index = 0 if count == 0 else count - 1
        editor = EDITOR.Editor(handle_shortcuts=False, init_features=init_features)

        if (tab_name is None
                or not tab_name):
            tab_name = 'Tab {0}'.format(index)

        editor.name = tab_name
        editor.tab_index = index

        self.insertTab(index,
                       editor,
                       tab_name
                       )
        self.setCurrentIndex(index)

        # relay the contents saved signal
        editor.contents_saved_signal.connect(self.contents_saved_signal)

        self.tab_count = self.count()
        self.current_index = self.currentIndex()
        editor.setFocus()
        return editor
Beispiel #2
0
    def show_diff_text(self, text):
        editor_text = self.editor.toPlainText()
        l1 = text.splitlines(True)
        l2 = editor_text.splitlines(True)

        ctx_diff = difflib.context_diff(l1, l2)
        diff_text = ''
        for i in ctx_diff:
            diff_text += i

        self.diff_editor = editor.Editor()
        self.diff_editor.setPlainText(diff_text)
        self.diff_editor.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)

        self.diff_editor.show()
    def build_layout(self):
        """
        Create the layout.
        """
        layout = QtWidgets.QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        # self.setup_menu()
        self.read_only = True
        self.menubar = menubar.MenuBar(self)

        left_widget = QtWidgets.QWidget()
        left_layout = QtWidgets.QVBoxLayout(left_widget)

        path_edit = QtWidgets.QLineEdit()
        path_edit.textChanged.connect(self.update_tree)
        self.path_edit = path_edit

        splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
        self.splitter = splitter

        self.xpanded = False
        self.setLayout(layout)
        self.tool_button = QtWidgets.QToolButton()
        self.tool_button.setText('<')
        self.tool_button.clicked.connect(self.xpand)
        self.tool_button.setMaximumWidth(20)

        layout.addWidget(splitter)

        browse = browser.FileTree(NUKE_DIR)
        self.browser = browse
        left_layout.addWidget(self.path_edit)
        left_layout.addWidget(self.browser)

        self.editor = editor.Editor(handle_shortcuts=True)
        self.editor.path = 'C:/Users/tsalx/Desktop/temp_editor_save.py'

        widgets = [left_widget, self.tool_button, self.editor]
        for w in widgets:
            splitter.addWidget(w)

        splitter.setSizes([200, 10, 800])
        self.browser.path_signal.connect(self.read)
        self.editor.textChanged.connect(self.write)
        self.editor.modificationChanged.connect(self.handle_changed)
Beispiel #4
0
    def __init__(self, parent=None):
        super(TabEditor, self).__init__(parent)
        if parent is not None:
            self.setParent(parent)

        self.setLayout(QtWidgets.QVBoxLayout(self))
        self.layout().setContentsMargins(0, 0, 0, 0)

        self.tab_widget = QtWidgets.QWidget()
        twl = QtWidgets.QHBoxLayout(self.tab_widget)
        self.tab_widget_layout = twl
        self.tab_widget_layout.setContentsMargins(0, 0, 0, 0)
        self.tabs = Tabs()
        self.tab_widget_layout.addWidget(self.tabs)

        # add corner buttons
        tb = QtWidgets.QToolButton()
        self.tab_list_button = tb
        tb.setArrowType(QtCore.Qt.DownArrow)
        tb.setToolTip('Click for a list of tabs.')
        tb.setAutoRaise(True)
        tb.setFixedSize(24, 24)
        self.tab_list_button.clicked.connect(self.show_tab_menu)

        nb = QtWidgets.QToolButton()
        self.new_tab_button = nb
        nb.setToolTip('Click to add a new tab.')
        nb.setText('+')
        nb.setAutoRaise(True)
        self.new_tab_button.clicked.connect(self.new_tab)

        for button in [self.new_tab_button, self.tab_list_button]:
            self.tab_widget_layout.addWidget(button)

        self.editor = editor.Editor(handle_shortcuts=False)

        for widget in self.tab_widget, self.editor:
            self.layout().addWidget(widget)

        # Give the autosave a chance to load all
        # tabs before connecting signals between
        # tabs and editor.
        QtCore.QTimer.singleShot(0, self.connect_signals)
Beispiel #5
0
def test_all_shortcuts():
    """
    TODO: These will be broken out into individual functions.
    """
    pprint(actions.load_actions_from_json())
    #&& # actual tests begin here.
    test_editor = editor.Editor()

    # test_editor.show()
    # QtTest.QTest.qWaitForWindowShown(test_editor)

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Alt+Return',
        input_text='if this:',
        expected_result=u'if this:\n    ',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Alt+Enter',
        input_text='if this:',
        expected_result=u'if this:\n    ',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Enter',
        input_text='if this:',
        expected_result=u'if this:\n    ',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Return',
        input_text='if this:',
        expected_result=u'if this:\n    ',
    )

    # for this one we need to test what's in the clipboard
    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+C',
        input_text='some_text',
        expected_result=u'some_text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+X',
        input_text='some_text',
        expected_result=u'',
    )

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Ctrl+X',
                       input_text='some_text',
                       expected_result=u'some_',
                       selected_text=u'text')

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Shift+K',
        input_text='some_text',
        expected_result=u'',
    )

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Ctrl+Shift+Del',
                       input_text='some_text',
                       expected_result=u'some_',
                       cursor_placement=5)

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Ctrl+Shift+Backspace',
                       input_text='some_text',
                       expected_result=u'text',
                       cursor_placement=5)

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Shift+D',
        input_text='some_text',
        expected_result=u'some_text\nsome_text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Enter',
        input_text='test_editor.clear()',
        expected_result=u'',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Return',
        input_text='test_editor.clear()',
        expected_result=u'',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+B',
        input_text='test_editor.clear()',
        expected_result=u'',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+]',
        input_text='text',
        expected_result=u'    text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+[',
        input_text='    text',
        expected_result=u'text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Shift+Tab',
        input_text='    text',
        expected_result=u'text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Shift+Backtab',
        input_text='    text',
        expected_result=u'text',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+J',
        input_text='text\ntext',
        expected_result=u'texttext',
        cursor_placement=4,
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Shift+Return',
        input_text='text',
        expected_result=u'\ntext',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+Alt+Return',
        input_text='text',
        expected_result=u'text\n',
        cursor_placement=1,
    )

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Tab',
                       input_text='text',
                       expected_result=u'    text',
                       selected_text='te')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Ctrl+Alt+Home',
                       input_text='\nword new\nnext thing',
                       expected_result=u'next thing\nword new\n',
                       selected_text='next thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='Ctrl+Alt+End',
                       input_text='next thing\nword new\n',
                       expected_result=u'\nword new\nnext thing',
                       selected_text='next thing')

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+\\',
        input_text='C:\\path\\file.txt',
        expected_result=u'C:/path/file.txt',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+\\',
        input_text='C:/path/file.txt',
        expected_result=u'C:\\\\path\\\\file.txt',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+/',
        input_text='thing',
        expected_result=u'#thing',
    )

    run_ascii_shortcut(
        widget=test_editor,
        shortcut='Ctrl+/',
        input_text='#thing',
        expected_result=u'thing',
    )

    run_ascii_shortcut(widget=test_editor,
                       shortcut='"',
                       input_text='thing',
                       expected_result=u'"thing"',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='[',
                       input_text='thing',
                       expected_result=u'[thing]',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut=']',
                       input_text='thing',
                       expected_result=u'[thing]',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='(',
                       input_text='thing',
                       expected_result=u'(thing)',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut=')',
                       input_text='thing',
                       expected_result=u'(thing)',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='{',
                       input_text='thing',
                       expected_result=u'{thing}',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut='}',
                       input_text='thing',
                       expected_result=u'{thing}',
                       selected_text='thing')

    run_ascii_shortcut(widget=test_editor,
                       shortcut="'",
                       input_text='thing',
                       expected_result=u"'thing'",
                       selected_text='thing')

    #&& # a few more
    'Ctrl+Shift+Down'
    'Ctrl+Shift+Up'
Beispiel #6
0
    def __init__(self, parent=None):
        super(TabEditor, self).__init__(parent)
        if parent is not None:
            self.setParent(parent)

        self.setLayout(
            QVBoxLayout(self)
        )
        self.layout().setContentsMargins(0,0,0,0)

        self.tab_widget = QWidget()
        twl = QHBoxLayout(
            self.tab_widget
        )
        self.tab_widget_layout = twl
        self.tab_widget_layout.setContentsMargins(
            0,0,0,0
        )

        lb = QToolButton()
        self.tab_left_button = lb
        lb.setArrowType(Qt.LeftArrow)
        lb.setAutoRaise(True)
        lb.setToolTip('Go to previous tab.')
        self.tab_widget_layout.addWidget(lb)
        self.tab_left_button.clicked.connect(self.tab_left)

        self.tabs = Tabs()
        self.tab_widget_layout.addWidget(self.tabs)

        rb = QToolButton()
        self.tab_right_button = rb
        rb.setArrowType(Qt.RightArrow)
        rb.setAutoRaise(True)
        rb.setToolTip('Go to next tab.')
        self.tab_widget_layout.addWidget(rb)
        self.tab_right_button.clicked.connect(self.tab_right)

        # add corner buttons
        tb = QToolButton()
        self.tab_list_button = tb
        tb.setArrowType(Qt.DownArrow)
        tb.setToolTip(
            'Click for a list of tabs.'
        )
        tb.setAutoRaise(True)
        self.tab_list_button.clicked.connect(
            self.show_tab_menu
        )

        nb = QToolButton()
        self.new_tab_button = nb
        nb.setToolTip(
            'Click to add a new tab.'
        )
        nb.setText('+')
        nb.setAutoRaise(True)
        self.new_tab_button.clicked.connect(
            self.new_tab
        )

        for button in [
                self.new_tab_button,
                self.tab_list_button
            ]:
            self.tab_widget_layout.addWidget(button)

        self.editor = editor.Editor(
            parent=self,
            handle_shortcuts=False
        )

        for widget in self.tab_widget, self.editor:
            self.layout().addWidget(widget)

        # Give the autosave a chance to load all
        # tabs before connecting signals between
        # tabs and editor.
        QTimer.singleShot(
            0,
            self.connect_signals
        )

        self.setStyleSheet(TAB_STYLESHEET)