def __init__(self, parent, main_form): # Initialize the superclass super().__init__() # Initialize components self.icon_manipulator = components.IconManipulator(self, parent) self.add_corner_buttons() # Store the main form and parent widget references self._parent = parent self.main_form = main_form # Set encoding format to UTF-8 (Unicode) self.setUtf8(True) # Tabs are spaces by default self.setIndentationsUseTabs(False) # Set line endings to be Unix style ("\n") self.setEolMode(settings.Editor.end_of_line_mode) # Initialize the namespace references self.hotspots = components.Hotspots() # Set the initial zoom factor self.zoomTo(settings.Editor.zoom_factor) # Set the theme self.set_theme(data.theme)
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)
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)