Esempio n. 1
0
    def test_background_color(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")

        # with patch.object(QColorDialog, 'getColor',
        #                  return_value=QColor("blue")):
        #    doc.color()
        doc.background_color("blue")

        color = doc._text_edit_cursor.charFormat().background().color().name()
        self.assertEqual(color, QColor("blue").name())

        doc = Doc(Config())

        def in_table():
            # is exists table in document ?
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            _in_table = False
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    _in_table = True
                    doc.background_color("blue")
                    cc = doc._text_edit_cursor
                    cell = cc.currentTable().cellAt(cc).format()
                    clr = cell.background().color().name()
                    self.assertEqual(clr, QColor("blue").name())
                    break
            return _in_table

        doc.insert_table({"padding": 0, "space": 0, "rows": 1, "cols": 1})
        self.assertEqual(in_table(), True)
Esempio n. 2
0
    def test_get_text(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")

        cleantext = re.sub(re.compile('<.*?>'), '', doc.get_text())
        cleantext = cleantext.replace("p, li { white-space: pre-wrap; }", "")
        self.assertEqual("1 row\n 2 row\n3 row", cleantext.strip())
Esempio n. 3
0
    def test_text_align(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")

        alignment = doc._text_edit_cursor.blockFormat().alignment()
        self.assertEqual(alignment, Qt.AlignLeft)

        doc.text_align(Qt.AlignRight, QTextCharFormat.AlignBottom)

        alignment = doc._text_edit_cursor.blockFormat().alignment()
        self.assertEqual(alignment, Qt.AlignRight)

        doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2})

        def in_table():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    doc.text_align(Qt.AlignRight, QTextCharFormat.AlignBottom)
                    a = doc._text_edit_cursor.charFormat().verticalAlignment()
                    self.assertEqual(a, QTextCharFormat.AlignBottom)
                    break

        in_table()
Esempio n. 4
0
    def setUpClass(cls):
        cls.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        # noinspection PyUnusedLocal
        def save(txt):  # pragma: no cover
            return None

        def load():
            return "HELLO hello1 hell привет приве 2"  # i18n

        cls.widget = TestableWidget(None)
        cls.editor = TextEditor(cls.widget,
                                Config(),
                                save=save,
                                load=load,
                                spell=SpellChecker(enabled=True),
                                auto_load=True,
                                auto_key_switch=True)
        cls.keyswitcher = cls.editor._keyswitcher
        cls.spell = cls.editor._spell

        # ---------------------------------------------------------------------
        # customize the widget for placement
        layout = QHBoxLayout()
        layout.addWidget(cls.editor, alignment=Qt.Alignment())
        cls.widget.setLayout(layout)
        cls.widget.resize(800, 450)
        cls.widget.move(800, 150)

        cls.test.show_and_wait_for_active(cls.widget)
Esempio n. 5
0
 def test_font_size(self):
     doc = Doc(Config())
     font_size = doc.text.defaultFont().pointSize()
     font_size = 12 if font_size == 10 else 10
     doc.font_size(font_size)
     fsize = doc._text_edit_cursor.charFormat().font().pointSize()
     self.assertEqual(font_size, fsize)
Esempio n. 6
0
    def test_split_cells(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")
        doc.insert_table({"padding": 0, "space": 0, "rows": 4, "cols": 3})

        def in_table():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    cc = doc.table().cellAt(2, 2)
                    cc.firstCursorPosition().insertText("Hello1")

                    cc = doc.table().cellAt(2, 1)
                    cc.firstCursorPosition().insertText("Hello")

                    c.movePosition(QTextCursor.EndOfBlock,
                                   QTextCursor.KeepAnchor)
                    break

        in_table()
        doc.table().mergeCells(0, 0, 2, 2)
        doc.split_cells()
        self.assertFalse("colspan" in doc.text.toHtml())
Esempio n. 7
0
    def setUpClass(cls):
        cls.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        # noinspection PyUnusedLocal
        def save(txt):
            return None

        def load():
            return "HELLO"

        cls.widget = TestableWidget(None)
        cls.spell = SpellChecker(enabled=True)
        cls.editor = TextEditor(cls.widget,
                                Config(),
                                save=save,
                                load=load,
                                spell=cls.spell)

        # ---------------------------------------------------------------------
        # customize the widget for placement
        layout = QHBoxLayout()
        layout.addWidget(cls.editor, alignment=Qt.Alignment())
        cls.widget.setLayout(layout)
        cls.widget.resize(800, 450)
        cls.widget.move(800, 150)

        cls.test.show_and_wait_for_active(cls.widget)
Esempio n. 8
0
    def test_load(self):
        doc = Doc(Config())

        def load():
            return "HELLO"

        self.assertNotEqual(doc.text.toPlainText(), "HELLO")
        doc.load(load)
        self.assertEqual(doc.text.toPlainText(), "HELLO")

        cfg = Config()
        cfg["TextEditor/PlainText"] = True
        doc = Doc(cfg)

        self.assertNotEqual(doc.text.toPlainText(), "HELLO")
        doc.load(load)
        self.assertEqual(doc.text.toPlainText(), "HELLO")
Esempio n. 9
0
 def test_show_hide_hidden_char(self):
     doc = Doc(Config())
     doc.show_hide_hidden_char(True)
     flags = doc.text.defaultTextOption().flags()
     self.assertEqual(int(flags & QTextOption.ShowTabsAndSpaces), 1)
     doc.show_hide_hidden_char(False)
     flags = doc.text.defaultTextOption().flags()
     self.assertEqual(int(flags & QTextOption.ShowTabsAndSpaces), 0)
Esempio n. 10
0
    def test_width(self):
        cfg = Config()
        e = QTextEdit()
        ln = LineNumberArea(e, cfg)

        cfg["TextEditor/ShowLineNumbers"] = 1
        self.assertTrue(ln.width() > 0)
        cfg["TextEditor/ShowLineNumbers"] = 0
        self.assertTrue(ln.width() == 0)
Esempio n. 11
0
    def test_insert(self):
        t = TableParamsDlg(config=Config())
        self.assertFalse(len(t.table_params))

        t.insert()

        t.controls[0].setValue(1)
        t.controls[1].setValue(1)
        t.insert()
        self.assertEqual(len(t.table_params), 4)
Esempio n. 12
0
    def test_highlight_cur_line(self):
        cfg = Config()
        v = View(TestableWidget(None), cfg)

        cfg["TextEditor/HighlightCurrentLine"] = 0
        v.contents_change()
        self.assertEqual(len(v.text.extraSelections()), 0)

        cfg["TextEditor/HighlightCurrentLine"] = 1
        v.highlight_cur_line()
        self.assertEqual(len(v.text.extraSelections()), 1)
Esempio n. 13
0
    def test_color(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")

        # with patch.object(QColorDialog, 'getColor',
        #                  return_value=QColor("blue")):
        #    doc.color()
        doc.color("blue")

        color = doc._text_edit_cursor.charFormat().foreground().color().name()
        self.assertEqual(color, QColor("blue").name())
Esempio n. 14
0
    def test_insert(self):
        def click_insert(widget):
            test = QTestHelper()
            test.mouse_click(widget.controls[-1], QPoint(1, 1))
            test.sleep(0.5)
            widget.close()

        self.test.handle_modal_widget(click_insert)
        tt = TableParamsDlg(self.w, config=Config())
        tt.exec_()
        self.test.sleep()
        self.assertEqual(tt.table_params, {})
Esempio n. 15
0
    def test_get_image(self):

        doc = Doc(Config())
        img = QImage(10, 10, QImage.Format_ARGB32)
        doc.ins_image(img, "png", 10, 15)

        image, width, height, fmt = doc.get_image(doc.text.toHtml())

        self.assertEqual(fmt, "png")
        self.assertEqual(width, 10)
        self.assertEqual(height, 15)
        self.assertTrue("QPixmap" in str(type(image)))
Esempio n. 16
0
    def test_ins_image(self):

        doc = Doc(Config())
        img = QImage(10, 10, QImage.Format_ARGB32)

        self.assertFalse("data:image/png;base64" in doc.text.toHtml())
        self.assertFalse('width="10"' in doc.text.toHtml())

        doc.ins_image(img, "png", 10, 10)

        self.assertTrue("data:image/png;base64" in doc.text.toHtml())
        self.assertTrue('width="10"' in doc.text.toHtml())
Esempio n. 17
0
    def test_set_visible(self):
        cfg = Config()
        w = TestableWidget(None)
        v = View(w, cfg)

        QTestHelper().show_and_wait_for_active(w)
        w.resize(100, 100)
        w.move(100, 500)

        self.assertFalse(v.search_replace.isVisible())
        v.search_replace.set_visible(True)
        self.assertTrue(v.search_replace.isVisible())
Esempio n. 18
0
    def test_hline(self):
        doc = Doc(Config())

        result = []

        def chg(param):
            result.append(param["right"][-2:-1])

        doc.changed_status.connect(chg)
        doc.change()
        doc.hline()  # add line + new line (new block)

        self.assertEqual(result, ["1", "3"])
Esempio n. 19
0
    def test_font(self):
        doc = Doc(Config())

        font_name = doc.text.defaultFont().family()
        font_size = doc.text.defaultFont().pointSize()

        font_name = "Arial" if font_name == "Mono" else "Mono"
        font_size = 12 if font_size == 10 else 10

        font = QFont(font_name, font_size)
        doc.font(font)
        fname = doc._text_edit_cursor.charFormat().font().family()
        self.assertEqual(font_name, fname)
Esempio n. 20
0
    def test_copy_format(self):
        doc = Doc(Config())
        fmt = doc._text_edit_cursor.charFormat()
        fmt.font().setBold(True)

        fmt = doc._text_edit_cursor.charFormat()
        self.assertFalse(fmt.font().bold())

        font = fmt.font()
        font.setBold(True)
        fmt.setFont(font)

        doc.copy_format(fmt)
        fmt = doc._text_edit_cursor.charFormat()
        self.assertTrue(fmt.font().bold())
Esempio n. 21
0
    def test_bold(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")

        result = []

        def chg(param):
            result.append(param)

        doc.changed_bold.connect(chg)

        doc.bold()  # add 'True'
        doc.bold()  # add 'False'

        self.assertEqual(result, [True, False])
Esempio n. 22
0
    def test_in_image(self):

        doc = Doc(Config())
        img = QImage(10, 10, QImage.Format_ARGB32)
        doc._text_edit_cursor.insertImage(img)

        def in_image():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_image():
                    break

        in_image()
        self.assertTrue(doc.in_image())
Esempio n. 23
0
    def test_table(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")
        self.assertEqual(doc.table(), None)
        doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2})

        def in_table():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    break

        in_table()
        self.assertTrue("QTextTable" in str(type(doc.table())))
Esempio n. 24
0
    def test_set_default_font(self):
        cfg = Config()
        doc = Doc(cfg)

        font_name = doc.text.defaultFont().family()
        font_size = doc.text.defaultFont().pointSize()

        font_name = "Arial" if font_name == "Mono" else "Mono"
        font_size = 12 if font_size == 10 else 10

        cfg["SYSTEM", "TextEditor/Font"] = font_name
        cfg["SYSTEM", "TextEditor/FontSize"] = font_size

        doc.set_default_font(True)

        self.assertEqual(font_name, doc.text.defaultFont().family())
        self.assertEqual(font_size, doc.text.defaultFont().pointSize())
Esempio n. 25
0
    def test_in_table(self):
        doc = Doc(Config())

        def in_table():
            # is exists table in document ?
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            _in_table = False
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    _in_table = True
                    break
            return _in_table

        self.assertEqual(in_table(), False)
        doc.insert_table({"padding": 0, "space": 0, "rows": 1, "cols": 1})
        self.assertEqual(in_table(), True)
Esempio n. 26
0
    def test_change(self):
        cfg = Config()
        doc = Doc(cfg)
        txt = "1 row\n 2 row\n3 row"

        def chg(param):
            cnt_lines = len(txt.split("\n"))
            self.assertTrue(f"[{cnt_lines}]" in param["right"])

        def esave(param):
            self.assertEqual(param, True)

        doc.changed_status.connect(chg)
        doc.enabled_save.connect(esave)

        self.assertEqual(doc.is_modified(), False)
        doc.text.setPlainText(txt)
        doc.change()
Esempio n. 27
0
    def test_paint(self):
        ok = []

        # noinspection PyUnusedLocal
        def effect(*args, **kwargs):
            ok.append("OK")

        cfg = Config()
        cfg["TextEditor/PlainText"] = 1
        cfg["TextEditor/MarginLine"] = 1
        w = TestableWidget(None)
        View(w, cfg)
        QTestHelper().show_and_wait_for_active(w)

        with patch.object(QPainter, 'drawLine', side_effect=effect):
            w.repaint()

        self.assertTrue(ok)
        self.assertEqual(ok[-1], "OK")
Esempio n. 28
0
    def test_save(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")
        doc.text.setModified(True)

        def save(txt):
            if txt:
                return None

        def save1(txt):
            if txt:
                return True

        self.assertTrue(doc.is_modified())
        doc.save(save)
        self.assertFalse(doc.is_modified())
        doc.text.setModified(True)
        doc.save(save1)
        self.assertTrue(doc.is_modified())
Esempio n. 29
0
    def test_ins_col(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")
        doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2})

        def in_table():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    break

        in_table()

        self.assertEqual(doc.table().rows(), 3)
        self.assertEqual(doc.table().columns(), 2)
        doc.ins_col()
        self.assertEqual(doc.table().rows(), 3)
        self.assertEqual(doc.table().columns(), 3)
Esempio n. 30
0
    def test_cell(self):
        doc = Doc(Config())
        doc.text.setPlainText("1 row\n 2 row\n3 row")
        doc.insert_table({"padding": 0, "space": 0, "rows": 3, "cols": 2})

        def in_table():
            c = QTextCursor(doc.text)
            c.movePosition(QTextCursor.Start)
            while c.movePosition(QTextCursor.NextCharacter,
                                 QTextCursor.KeepAnchor):
                if doc.in_table():
                    cc = doc.table().cellAt(2, 1)
                    cc.firstCursorPosition().insertText("Hello")
                    doc.change(cc.firstCursorPosition())
                    break

        in_table()
        self.assertTrue("QTextTableCell" in str(type(doc.cell())))
        self.assertEqual(doc.cell().row(), 2)
        self.assertEqual(doc.cell().column(), 1)