Ejemplo n.º 1
0
 def create_move_copy_action(action_name,
                             window_name,
                             move=True,
                             focus_name=None):
     window = main_form.get_window_by_name(window_name)
     action = data.QAction(action_name, self)
     if move == True:
         func = window.move_editor_in
         action_func = functools.partial(
             func,
             basic_widget,
             parent.tabAt(cursor_position),
         )
         icon = functions.create_icon(
             'tango_icons/window-tab-move.png')
     else:
         func = window.copy_editor_in
         action_func = functools.partial(
             func, basic_widget, parent.tabAt(cursor_position),
             focus_name)
         icon = functions.create_icon(
             'tango_icons/window-tab-copy.png')
     action.setIcon(icon)
     action.triggered.connect(action_func)
     return action
Ejemplo n.º 2
0
 def add_corner_buttons(self):
     # Unique 1 button
     self.icon_manipulator.add_corner_button(
         functions.create_icon("tango_icons/diff-unique-1.png"),
         "Scroll to next unique line\nin document: '{:s}'".format(
             self.text_1_name), self.find_next_unique_1)
     # Unique 2 button
     self.icon_manipulator.add_corner_button(
         functions.create_icon("tango_icons/diff-unique-2.png"),
         "Scroll to next unique line\nin document: '{:s}'".format(
             self.text_2_name), self.find_next_unique_2)
     # Similar button
     self.icon_manipulator.add_corner_button(
         functions.create_icon("tango_icons/diff-similar.png"),
         "Scroll to next similar line\nin both documents",
         self.find_next_similar)
Ejemplo n.º 3
0
 def update_corner_button_icon(self, icon, index=0):
     if self.corner_groupbox == None:
         return
     layout = self.corner_groupbox.layout()
     if isinstance(icon, data.QIcon):
         layout.itemAt(index).widget().setIcon(icon)
     else:
         layout.itemAt(index).widget().setIcon(functions.create_icon(icon))
Ejemplo n.º 4
0
 def create_corner_button(self, icon, tooltip, function):
     button = data.QToolButton()
     if isinstance(icon, data.QIcon):
         button.setIcon(icon)
     else:
         button.setIcon(functions.create_icon(icon))
     button.setPopupMode(data.QToolButton.InstantPopup)
     button.setToolTip(tooltip)
     button.clicked.connect(function)
     return button
Ejemplo n.º 5
0
            def create_diff_action(action_name, main_form, compare_tab_1,
                                   compare_tab_2):
                def difference_function(main_form, compare_tab_1,
                                        compare_tab_2):
                    #Check for text documents in both tabs
                    if (isinstance(compare_tab_1, CustomEditor) == False and
                            isinstance(compare_tab_1, PlainEditor) == False):
                        main_form.display.repl_display_message(
                            "First tab is not a text document!",
                            message_type=data.MessageType.ERROR)
                        return
                    elif (isinstance(compare_tab_2, CustomEditor) == False
                          and isinstance(compare_tab_2, PlainEditor) == False):
                        main_form.display.repl_display_message(
                            "Second tab is not a text document!",
                            message_type=data.MessageType.ERROR)
                        return
                    #Initialize the compare parameters
                    text_1 = compare_tab_1.text()
                    text_1_name = compare_tab_1.name
                    text_2 = compare_tab_2.text()
                    text_2_name = compare_tab_2.name
                    #Display the text difference
                    main_form.display.show_text_difference(
                        text_1, text_2, text_1_name, text_2_name)

                diff_action = data.QAction(action_name, self)
                if "main" in action_name.lower():
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-main.png'))
                elif "upper" in action_name.lower():
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-upper.png'))
                else:
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-lower.png'))
                function = functools.partial(difference_function, main_form,
                                             compare_tab_1, compare_tab_2)
                diff_action.triggered.connect(function)
                return diff_action
Ejemplo n.º 6
0
 def __init__(self, settings_manipulator, parent, main_form):
     """Initialization"""
     #Initialize the superclass
     super().__init__(parent)
     # Initialize components
     self.icon_manipulator = components.IconManipulator(parent=self,
                                                        tab_widget=parent)
     self.add_corner_buttons()
     #Store the reference to the parent TabWidget from the "forms" module
     self._parent = parent
     #Store the reference to the MainWindow form from the "forms" module
     self.main_form = main_form
     # Set default font
     self.setFont(data.get_current_font())
     #Store the reference to the active SettingsManipulator
     self.settings_manipulator = settings_manipulator
     #Set the icon
     self.current_icon = functions.create_icon("tango_icons/sessions.png")
     #Store name of self
     self.name = "Session editing tree display"
     #Enable node expansion on double click
     self.setExpandsOnDoubleClick(True)
     #Set the node icons
     self.node_icon_group = functions.create_icon("tango_icons/folder.png")
     self.node_icon_session = functions.create_icon(
         "tango_icons/sessions.png")
     self.icon_session_add = functions.create_icon(
         "tango_icons/session-add.png")
     self.icon_session_remove = functions.create_icon(
         "tango_icons/session-remove.png")
     self.icon_session_overwrite = functions.create_icon(
         "tango_icons/session-overwrite.png")
     self.icon_group_add = functions.create_icon(
         "tango_icons/folder-add.png")
     self.icon_session_edit = functions.create_icon(
         "tango_icons/session-edit.png")
     #Connect the signals
     self.doubleClicked.connect(self._item_double_clicked)
Ejemplo n.º 7
0
    def __init__(self,
                 parent,
                 main_form,
                 text_1=None,
                 text_2=None,
                 text_1_name="",
                 text_2_name=""):
        """Initialization"""
        # Initialize the superclass
        super().__init__(parent)
        # Initialize components
        self.icon_manipulator = components.IconManipulator(self, parent)
        # Initialize colors according to theme
        self.Indicator_Unique_1_Color = data.theme.TextDifferColors.Indicator_Unique_1_Color
        self.Indicator_Unique_2_Color = data.theme.TextDifferColors.Indicator_Unique_2_Color
        self.Indicator_Similar_Color = data.theme.TextDifferColors.Indicator_Similar_Color
        # Store the reference to the parent
        self._parent = parent
        # Store the reference to the main form
        self.main_form = main_form
        # Set the differ icon
        self.current_icon = functions.create_icon(
            'tango_icons/compare-text.png')
        #Set the name of the differ widget
        if text_1_name != None and text_2_name != None:
            self.name = "Text difference: {:s} / {:s}".format(
                text_1_name, text_2_name)
            self.text_1_name = text_1_name
            self.text_2_name = text_2_name
        else:
            self.name = "Text difference"
            self.text_1_name = "TEXT 1"
            self.text_2_name = "TEXT 2"
        # Initialize diff icons
        self.icon_unique_1 = functions.create_icon(
            "tango_icons/diff-unique-1.png")
        self.icon_unique_2 = functions.create_icon(
            "tango_icons/diff-unique-2.png")
        self.icon_similar = functions.create_icon(
            "tango_icons/diff-similar.png")
        # Create the horizontal splitter and two editor widgets
        self.splitter = data.QSplitter(data.Qt.Horizontal, self)
        self.editor_1 = CustomEditor(self, main_form)
        self.init_editor(self.editor_1)
        self.editor_2 = CustomEditor(self, main_form)
        self.init_editor(self.editor_2)
        self.editor_1.choose_lexer("text")
        self.editor_2.choose_lexer("text")
        self.splitter.addWidget(self.editor_1)
        self.splitter.addWidget(self.editor_2)
        self.layout = data.QVBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.addWidget(self.splitter)
        # Set the layout
        self.setLayout(self.layout)
        # Connect the necessary signals
        self.editor_1.SCN_UPDATEUI.connect(self._scn_updateui_1)
        self.editor_2.SCN_UPDATEUI.connect(self._scn_updateui_2)
        self.editor_1.cursorPositionChanged.connect(self._cursor_change_1)
        self.editor_2.cursorPositionChanged.connect(self._cursor_change_2)
        # Overwrite the CustomEditor parent widgets to point to the TextDiffers' PARENT
        self.editor_1._parent = self._parent
        self.editor_2._parent = self._parent
        # Add a new attribute to the CustomEditor that will hold the TextDiffer reference
        self.editor_1.actual_parent = self
        self.editor_2.actual_parent = self
        # Set the embedded flag
        self.editor_1.embedded = True
        self.editor_2.embedded = True

        # Add decorators to each editors mouse clicks and mouse wheel scrolls
        def focus_decorator(function_to_decorate, focused_editor):
            def decorated_function(*args, **kwargs):
                self.focused_editor = focused_editor
                function_to_decorate(*args, **kwargs)

            return decorated_function

        self.editor_1.mousePressEvent = focus_decorator(
            self.editor_1.mousePressEvent, self.editor_1)
        self.editor_1.wheelEvent = focus_decorator(self.editor_1.wheelEvent,
                                                   self.editor_1)
        self.editor_2.mousePressEvent = focus_decorator(
            self.editor_2.mousePressEvent, self.editor_2)
        self.editor_2.wheelEvent = focus_decorator(self.editor_2.wheelEvent,
                                                   self.editor_2)
        # Add corner buttons
        self.add_corner_buttons()
        # Focus the first editor on initialization
        self.focused_editor = self.editor_1
        self.focused_editor.setFocus()
        # Initialize markers
        self.init_markers()
        # Set the theme
        self.set_theme(data.theme)
        # Set editor functions that have to be propagated from the TextDiffer
        # to the child editor
        self._init_editor_functions()
        # Check the text validity
        if text_1 == None or text_2 == None:
            #One of the texts is unspecified
            return
        # Create the diff
        self.compare(text_1, text_2)
Ejemplo n.º 8
0
        def __init__(self, parent, main_form, basic_widget, editor_widget,
                     cursor_position):
            #Nested function for creating a move or copy action
            def create_move_copy_action(action_name,
                                        window_name,
                                        move=True,
                                        focus_name=None):
                window = main_form.get_window_by_name(window_name)
                action = data.QAction(action_name, self)
                if move == True:
                    func = window.move_editor_in
                    action_func = functools.partial(
                        func,
                        basic_widget,
                        parent.tabAt(cursor_position),
                    )
                    icon = functions.create_icon(
                        'tango_icons/window-tab-move.png')
                else:
                    func = window.copy_editor_in
                    action_func = functools.partial(
                        func, basic_widget, parent.tabAt(cursor_position),
                        focus_name)
                    icon = functions.create_icon(
                        'tango_icons/window-tab-copy.png')
                action.setIcon(icon)
                action.triggered.connect(action_func)
                return action

            #Nested function for creating text difference actions
            def create_diff_action(action_name, main_form, compare_tab_1,
                                   compare_tab_2):
                def difference_function(main_form, compare_tab_1,
                                        compare_tab_2):
                    #Check for text documents in both tabs
                    if (isinstance(compare_tab_1, CustomEditor) == False and
                            isinstance(compare_tab_1, PlainEditor) == False):
                        main_form.display.repl_display_message(
                            "First tab is not a text document!",
                            message_type=data.MessageType.ERROR)
                        return
                    elif (isinstance(compare_tab_2, CustomEditor) == False
                          and isinstance(compare_tab_2, PlainEditor) == False):
                        main_form.display.repl_display_message(
                            "Second tab is not a text document!",
                            message_type=data.MessageType.ERROR)
                        return
                    #Initialize the compare parameters
                    text_1 = compare_tab_1.text()
                    text_1_name = compare_tab_1.name
                    text_2 = compare_tab_2.text()
                    text_2_name = compare_tab_2.name
                    #Display the text difference
                    main_form.display.show_text_difference(
                        text_1, text_2, text_1_name, text_2_name)

                diff_action = data.QAction(action_name, self)
                if "main" in action_name.lower():
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-main.png'))
                elif "upper" in action_name.lower():
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-upper.png'))
                else:
                    diff_action.setIcon(
                        functions.create_icon(
                            'tango_icons/compare-text-lower.png'))
                function = functools.partial(difference_function, main_form,
                                             compare_tab_1, compare_tab_2)
                diff_action.triggered.connect(function)
                return diff_action

            #Nested function for checking is the basic widgets current tab is an editor
            def check_for_editor(basic_widget):
                current_tab = basic_widget.currentWidget()
                if (isinstance(current_tab, CustomEditor) == True
                        or isinstance(current_tab, PlainEditor) == True):
                    return True
                else:
                    return False

            #Nested function for updating the current working directory
            def update_cwd():
                #Get the document path
                path = os.path.dirname(editor_widget.save_name)
                #Check if the path is not an empty string
                if path == "":
                    message = "Document path is not valid!"
                    main_form.display.repl_display_message(
                        message, message_type=data.MessageType.WARNING)
                    return
                main_form.set_cwd(path)

            #Initialize the superclass
            super().__init__(parent)
            #Change the basic widget name to lowercase
            basic_widget_name = basic_widget.name.lower()
            #Add actions according to the parent BasicWidget
            #Move actions
            move_to_main = create_move_copy_action("Move to main window",
                                                   "main")
            move_to_upper = create_move_copy_action("Move to upper window",
                                                    "upper")
            move_to_lower = create_move_copy_action("Move to lower window",
                                                    "lower")
            #Copy action
            copy_to_main = create_move_copy_action("Copy to main window",
                                                   "main",
                                                   move=False,
                                                   focus_name="main")
            copy_to_upper = create_move_copy_action("Copy to upper window",
                                                    "upper",
                                                    move=False,
                                                    focus_name="upper")
            copy_to_lower = create_move_copy_action("Copy to lower window",
                                                    "lower",
                                                    move=False,
                                                    focus_name="lower")
            #Clear REPL MESSAGES tab action
            clear_repl_action = data.QAction("Clear messages", self)
            clear_repl_action.setIcon(
                functions.create_icon('tango_icons/edit-clear.png'))
            clear_repl_action.triggered.connect(
                main_form.display.repl_clear_tab)
            #Text difference actions
            diff_main_action = create_diff_action(
                "Text diff to main window", main_form,
                main_form.main_window.currentWidget(), editor_widget)
            diff_upper_action = create_diff_action(
                "Text diff to upper window", main_form,
                main_form.upper_window.currentWidget(), editor_widget)
            diff_lower_action = create_diff_action(
                "Text diff to lower window", main_form,
                main_form.lower_window.currentWidget(), editor_widget)
            #Update current working directory action
            if hasattr(editor_widget, "save_name") == True:
                update_cwd_action = data.QAction("Update CWD", self)
                update_cwd_action.setIcon(
                    functions.create_icon('tango_icons/update-cwd.png'))
                update_cwd_action.triggered.connect(update_cwd)
                self.addAction(update_cwd_action)
                self.addSeparator()
            # Add the 'copy file name to clipboard' action
            clipboard_copy_action = data.QAction(
                "Copy document name to clipboard", self)

            def clipboard_copy():
                cb = data.application.clipboard()
                cb.clear(mode=cb.Clipboard)
                cb.setText(editor_widget.name, mode=cb.Clipboard)

            clipboard_copy_action.setIcon(
                functions.create_icon('tango_icons/edit-copy.png'))
            clipboard_copy_action.triggered.connect(clipboard_copy)
            self.addAction(clipboard_copy_action)
            self.addSeparator()

            #Nested function for adding diff actions
            def add_diff_actions():
                #Diff to main window
                if (check_for_editor(main_form.main_window) == True
                        and editor_widget !=
                        main_form.main_window.currentWidget()):
                    self.addAction(diff_main_action)
                #Diff to upper window
                if (check_for_editor(main_form.upper_window) == True
                        and editor_widget !=
                        main_form.upper_window.currentWidget()):
                    self.addAction(diff_upper_action)
                #Diff to lower window
                if (check_for_editor(main_form.lower_window) == True
                        and editor_widget !=
                        main_form.lower_window.currentWidget()):
                    self.addAction(diff_lower_action)

            #Check which basic widget is the parent to the clicked tab
            if "main" in basic_widget_name:
                #Add the actions to the menu
                self.addAction(move_to_upper)
                self.addAction(move_to_lower)
                self.addSeparator()
                #Check the tab widget type
                if isinstance(editor_widget, CustomEditor) == True:
                    #Copy functions are only available to custom editors
                    self.addAction(copy_to_upper)
                    self.addAction(copy_to_lower)
                elif (isinstance(editor_widget, PlainEditor) == True
                      and editor_widget.name == "REPL MESSAGES"):
                    #REPL MESSAGES tab clear option
                    self.addAction(clear_repl_action)
                if (isinstance(editor_widget, CustomEditor) == True
                        or isinstance(editor_widget, PlainEditor) == True):
                    #Diff functions for plain and custom editors
                    self.addSeparator()
                    add_diff_actions()
            elif "upper" in basic_widget_name:
                #Add the actions to the menu
                self.addAction(move_to_main)
                self.addAction(move_to_lower)
                self.addSeparator()
                #Check the tab widget type
                if isinstance(editor_widget, CustomEditor) == True:
                    #Copy functions are only available to custom editors
                    self.addAction(copy_to_main)
                    self.addAction(copy_to_lower)
                elif (isinstance(editor_widget, PlainEditor) == True
                      and editor_widget.name == "REPL MESSAGES"):
                    #REPL MESSAGES tab clear option
                    self.addAction(clear_repl_action)
                if (isinstance(editor_widget, CustomEditor) == True
                        or isinstance(editor_widget, PlainEditor) == True):
                    #Diff functions for plain and custom editors
                    self.addSeparator()
                    add_diff_actions()
            elif "lower" in basic_widget_name:
                #Add the actions to the menu
                self.addAction(move_to_main)
                self.addAction(move_to_upper)
                self.addSeparator()
                #Check the tab widget type
                if isinstance(editor_widget, CustomEditor) == True:
                    #Copy functions are only available to custom editors
                    self.addAction(copy_to_main)
                    self.addAction(copy_to_upper)
                elif (isinstance(editor_widget, PlainEditor) == True
                      and editor_widget.name == "REPL MESSAGES"):
                    #REPL MESSAGES tab clear option
                    self.addAction(clear_repl_action)
                if (isinstance(editor_widget, CustomEditor) == True
                        or isinstance(editor_widget, PlainEditor) == True):
                    #Diff functions for plain and custom editors
                    self.addSeparator()
                    add_diff_actions()
            # Closing
            self.addSeparator()
            close_other_action = data.QAction(
                "Close all other tabs in this window", self)
            close_other_action.setIcon(
                functions.create_icon('tango_icons/close-all-tabs.png'))
            close_other_action.triggered.connect(
                functools.partial(main_form.close_window_tabs, basic_widget,
                                  editor_widget))
            self.addAction(close_other_action)