qas_editor/gui/utils.py
def update_editor(self, text_editor: GTextEditor) -> None:
        """Update the font format toolbar/actions when a new text selection is made. 
        This is neccessary to keep toolbars/etc. in sync with the current edit state.
        """ 
        self.setDisabled(text_editor is None)
        if text_editor == self.editor: return # Nothing to do here
        if self.editor is not None:
            self.text_type.currentIndexChanged.disconnect()
            self.fonts.currentFontChanged.disconnect()
            self.fontsize.currentIndexChanged[str].disconnect()
            self.bold_action.toggled.disconnect()
            self.underline_action.toggled.disconnect()
            self.italic_action.toggled.disconnect()
            self.alignl_action.triggered.disconnect()
            self.alignc_action.triggered.disconnect()
            self.alignr_action.triggered.disconnect()
            self.alignj_action.triggered.disconnect()
            self.wrap_action.triggered.disconnect()
        self.editor = text_editor  
        if self.editor is not None:
            for o in self._format_actions:  # Disable signals for all format widgets
                o.blockSignals(True)
            self.fonts.setCurrentFont(self.editor.currentFont())
            self.fontsize.setCurrentText(str(int(self.editor.fontPointSize())))
            self.italic_action.setChecked(self.editor.fontItalic())
            self.underline_action.setChecked(self.editor.fontUnderline())
            self.bold_action.setChecked(self.editor.fontWeight() == QFont.Bold)
            self.alignl_action.setChecked(self.editor.alignment() == Qt.AlignLeft)
            self.alignc_action.setChecked(self.editor.alignment() == Qt.AlignCenter)
            self.alignr_action.setChecked(self.editor.alignment() == Qt.AlignRight)
            self.alignj_action.setChecked(self.editor.alignment() == Qt.AlignJustify)
            self.text_type.setCurrentText(self.editor.text_format.name)
            for o in self._format_actions:
                o.blockSignals(False)
            self.text_type.currentIndexChanged.connect(self.editor._update_format)
            self.fonts.currentFontChanged.connect(self.editor.setCurrentFont)
            self.underline_action.toggled.connect(self.editor.setFontUnderline)
            self.italic_action.toggled.connect(self.editor.setFontItalic)
            self.fontsize.currentIndexChanged[str].connect(lambda s: 
                    self.editor.setFontPointSize(float(s)))
            self.bold_action.toggled.connect(lambda x: 
                    self.editor.setFontWeight(QFont.Bold if x else QFont.Normal))
            self.alignl_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignLeft))
            self.alignc_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignCenter))
            self.alignr_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignRight))
            self.alignj_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignJustify))
            self.wrap_action.triggered.connect(lambda: 
                    self.editor.setLineWrapMode(int(self.editor.lineWrapMode() == 0)))
Update the font format toolbar/actions when a new text selection is made. 
        This is neccessary to keep toolbars/etc. in sync with the current edit state.
        
Update the font format toolbar/actions when a new text selection is made.
This is neccessary to keep toolbars/etc. in sync with the current edit state.
Update the font format toolbar / actions when a new text selection is made . This is neccessary to keep toolbars / etc . in sync with the current edit state .
def update_editor(self, text_editor: GTextEditor) -> None:
        self.setDisabled(text_editor is None)
        if text_editor == self.editor: return 
        if self.editor is not None:
            self.text_type.currentIndexChanged.disconnect()
            self.fonts.currentFontChanged.disconnect()
            self.fontsize.currentIndexChanged[str].disconnect()
            self.bold_action.toggled.disconnect()
            self.underline_action.toggled.disconnect()
            self.italic_action.toggled.disconnect()
            self.alignl_action.triggered.disconnect()
            self.alignc_action.triggered.disconnect()
            self.alignr_action.triggered.disconnect()
            self.alignj_action.triggered.disconnect()
            self.wrap_action.triggered.disconnect()
        self.editor = text_editor  
        if self.editor is not None:
            for o in self._format_actions:  
                o.blockSignals(True)
            self.fonts.setCurrentFont(self.editor.currentFont())
            self.fontsize.setCurrentText(str(int(self.editor.fontPointSize())))
            self.italic_action.setChecked(self.editor.fontItalic())
            self.underline_action.setChecked(self.editor.fontUnderline())
            self.bold_action.setChecked(self.editor.fontWeight() == QFont.Bold)
            self.alignl_action.setChecked(self.editor.alignment() == Qt.AlignLeft)
            self.alignc_action.setChecked(self.editor.alignment() == Qt.AlignCenter)
            self.alignr_action.setChecked(self.editor.alignment() == Qt.AlignRight)
            self.alignj_action.setChecked(self.editor.alignment() == Qt.AlignJustify)
            self.text_type.setCurrentText(self.editor.text_format.name)
            for o in self._format_actions:
                o.blockSignals(False)
            self.text_type.currentIndexChanged.connect(self.editor._update_format)
            self.fonts.currentFontChanged.connect(self.editor.setCurrentFont)
            self.underline_action.toggled.connect(self.editor.setFontUnderline)
            self.italic_action.toggled.connect(self.editor.setFontItalic)
            self.fontsize.currentIndexChanged[str].connect(lambda s: 
                    self.editor.setFontPointSize(float(s)))
            self.bold_action.toggled.connect(lambda x: 
                    self.editor.setFontWeight(QFont.Bold if x else QFont.Normal))
            self.alignl_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignLeft))
            self.alignc_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignCenter))
            self.alignr_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignRight))
            self.alignj_action.triggered.connect(lambda: 
                    self.editor.setAlignment(Qt.AlignJustify))
            self.wrap_action.triggered.connect(lambda: 
                    self.editor.setLineWrapMode(int(self.editor.lineWrapMode() == 0)))
def update_editor ( self , text_editor : GTextEditor ) -> None : self . setDisabled ( text_editor is None ) if text_editor == self . editor : return if self . editor is not None : self . text_type . currentIndexChanged . disconnect ( ) self . fonts . currentFontChanged . disconnect ( ) self . fontsize . currentIndexChanged [ str ] . disconnect ( ) self . bold_action . toggled . disconnect ( ) self . underline_action . toggled . disconnect ( ) self . italic_action . toggled . disconnect ( ) self . alignl_action . triggered . disconnect ( ) self . alignc_action . triggered . disconnect ( ) self . alignr_action . triggered . disconnect ( ) self . alignj_action . triggered . disconnect ( ) self . wrap_action . triggered . disconnect ( ) self . editor = text_editor if self . editor is not None : for o in self . _format_actions : o . blockSignals ( True ) self . fonts . setCurrentFont ( self . editor . currentFont ( ) ) self . fontsize . setCurrentText ( str ( int ( self . editor . fontPointSize ( ) ) ) ) self . italic_action . setChecked ( self . editor . fontItalic ( ) ) self . underline_action . setChecked ( self . editor . fontUnderline ( ) ) self . bold_action . setChecked ( self . editor . fontWeight ( ) == QFont . Bold ) self . alignl_action . setChecked ( self . editor . alignment ( ) == Qt . AlignLeft ) self . alignc_action . setChecked ( self . editor . alignment ( ) == Qt . AlignCenter ) self . alignr_action . setChecked ( self . editor . alignment ( ) == Qt . AlignRight ) self . alignj_action . setChecked ( self . editor . alignment ( ) == Qt . AlignJustify ) self . text_type . setCurrentText ( self . editor . text_format . name ) for o in self . _format_actions : o . blockSignals ( False ) self . text_type . currentIndexChanged . connect ( self . editor . _update_format ) self . fonts . currentFontChanged . connect ( self . editor . setCurrentFont ) self . underline_action . toggled . connect ( self . editor . setFontUnderline ) self . italic_action . toggled . connect ( self . editor . setFontItalic ) self . fontsize . currentIndexChanged [ str ] . connect ( lambda s : self . editor . setFontPointSize ( float ( s ) ) ) self . bold_action . toggled . connect ( lambda x : self . editor . setFontWeight ( QFont . Bold if x else QFont . Normal ) ) self . alignl_action . triggered . connect ( lambda : self . editor . setAlignment ( Qt . AlignLeft ) ) self . alignc_action . triggered . connect ( lambda : self . editor . setAlignment ( Qt . AlignCenter ) ) self . alignr_action . triggered . connect ( lambda : self . editor . setAlignment ( Qt . AlignRight ) ) self . alignj_action . triggered . connect ( lambda : self . editor . setAlignment ( Qt . AlignJustify ) ) self . wrap_action . triggered . connect ( lambda : self . editor . setLineWrapMode ( int ( self . editor . lineWrapMode ( ) == 0 ) ) )
Update the font format toolbar/actions when a new text selection is made.
Update the font format toolbar / actions when a new text selection is made .
"""Update the font format toolbar/actions when a new text selection is made. 
        This is neccessary to keep toolbars/etc. in sync with the current edit state.
        """ # Nothing to do here # Disable signals for all format widgets
self
text_editor
GTextEditor