Example #1
0
    def test_yes_no(self):
        with patch.object(QMessageBox, 'question',
                          return_value=QMessageBox.No):
            self.assertFalse(yes_no("ffff"))

        with patch.object(QMessageBox,
                          'question',
                          return_value=QMessageBox.Yes):
            self.assertTrue(yes_no("ffff"))
Example #2
0
    def _replace_all(self):
        find_text = self._view.search_replace.controls["search-edit"].text()
        repl_text = self._view.search_replace.controls["replace-edit"].text()

        flags = QTextDocument.FindFlags()
        if self._view.search_replace.controls["cs-box"].isChecked():
            flags |= QTextDocument.FindCaseSensitively

        old_cursor = self._view.text.textCursor()
        self._view.text.moveCursor(QTextCursor.Start)

        cnt = 0
        while self._view.text.find(find_text, options=flags):
            cnt += 1

        self._view.text.setTextCursor(old_cursor)
        if not cnt:
            return

        txt = (self.tr("Results found: ") + str(cnt) +
               self.tr(". Replace everything ?"))
        if not yes_no(txt, self):
            return

        cnt = 0
        self._view.text.moveCursor(QTextCursor.Start)
        while self._view.text.find(find_text, options=flags):
            self._doc.replace(repl_text)
            cnt += 1

        if cnt:
            txt = self.tr("Replacements done")
            self._view.show_info(f'{txt}: {cnt}')
Example #3
0
 def _clear_format(self):
     """
     Clearing format ALL text
     """
     msg = self.tr("Are you sure want for clear text formatting ?")
     if yes_no(msg, self):
         self._doc.clear_format()
Example #4
0
 def save_text_tab(self, idx_tab):
     w = self._tabs.widget(idx_tab)
     name = w.file_path() if w.file_path() else w.get_name()
     t1 = self.tr("The file")
     t2 = self.tr("is changed")
     t3 = self.tr("Save it ?")
     if w.is_modified():
         if yes_no(f"{t1} <b>{name}</b> {t2}.<br><br>{t3}", self):
             w.save()
Example #5
0
    def set_option(self, **options):  # implementation of interface IEditor

        # ---------------------------------------------------------------------
        if "retranslate" in options:
            self._retranslate_ui()

        # ---------------------------------------------------------------------
        if "format" in options:
            old_txt_mode = self._cfg.get("TextEditor/PlainText", 0)
            new_txt_mode = options["format"].upper() != "HTML"
            if old_txt_mode == new_txt_mode:
                return False

            if new_txt_mode:
                msg1 = self.tr("Text formatting will be lost")
                msg2 = self.tr("do you want to continue ?")
                if not yes_no(f"{msg1},\n{msg2}", self):
                    return False

            self._set_vars(new_txt_mode)
            self._view.update_ui()
            if new_txt_mode:
                self._set_format_text()
            else:
                self._set_format_html()

            return True

        # ---------------------------------------------------------------------
        if "highlighter" in options:
            self._set_highlighter(options["highlighter"])

        # ---------------------------------------------------------------------
        if "invisible_symbol" in options:
            self._actions["invisible-symbol"].trigger()

        # ---------------------------------------------------------------------
        if "word_wrap" in options:
            self._cfg["TextEditor/WordWrap"] = (
                not self._cfg.get("TextEditor/WordWrap", 0))
            self._view.update_ui()

        # ---------------------------------------------------------------------
        if "btn_save_visible" in options:
            self._set_btn_save_visible(options["btn_save_visible"])

        # ---------------------------------------------------------------------
        if "readonly" in options:
            self._set_readonly(options["readonly"])

        # ---------------------------------------------------------------------
        if "auto_save" in options:
            self._cfg["TextEditor/AutoSave"] = options["auto_save"]
            self._set_btn_save_visible(not bool(options["auto_save"]))

        # ---------------------------------------------------------------------
        if "margin_line" in options:
            self._cfg["TextEditor/MarginLine"] = options["margin_line"]
            self._view.update_ui()

        # ---------------------------------------------------------------------
        if "show_status_bar" in options:
            self._cfg["TextEditor/ShowStatusBar"] = options["show_status_bar"]
            self._view.update_ui()