示例#1
0
 def init_ui(self):
     self.setWindowTitle('Example Dialog')
     v = QVBoxLayout()
     self.text.setText("HELLO")
     v.addWidget(self.text, alignment=Qt.Alignment())
     v.addWidget(self.btn_ok, alignment=Qt.Alignment())
     v.addWidget(self.btn_cancel, alignment=Qt.Alignment())
     self.setLayout(v)
     self.btn_ok.clicked.connect(self.ok)
     self.btn_cancel.clicked.connect(self.cancel)
示例#2
0
文件: align.py 项目: ligm74/LiGM
    def __init__(self, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)
        self._text = self.tr("Alignment text")

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)

        b = "border: 1px solid #9b9b9b;"
        self._styles = {
            "border": b,
            "border_blue": "border: 0px solid blue;",
            "frame": 'QFrame[frameShape="4"]{color: #9b9b9b;}'
        }

        self.setStyleSheet(self._styles["frame"])

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(self._text)
        self._lbl_caption.setStyleSheet(self._styles["border_blue"])
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(
            f"background-color: {color_caption}; {self._styles['border']}")

        # -- CELLS GRID -------------------------------
        cellsbox = QFrame(self, flags=Qt.WindowFlags())
        cells = QGridLayout()
        cellsbox.setLayout(cells)
        cells.setContentsMargins(9, 0, 9, 9)
        self._clrbtn = []
        for i in range(1, 4):
            for j in range(1, 5):
                self._clrbtn.append(QToolButton())
                self._clrbtn[-1].clicked.connect(
                    lambda z, y=i, x=j: self.select_align_(x, y))
                self._clrbtn[-1].setAutoRaise(True)

                sz = 48
                self._clrbtn[-1].setFixedSize(sz, sz)
                self._clrbtn[-1].setIconSize(QSize(sz, sz))

                self._clrbtn[-1].setIcon(QIcon(img(f"editor/a{i}{j}.png")))
                # noinspection PyArgumentList
                cells.addWidget(self._clrbtn[-1], i - 1, j - 1)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(cellsbox, alignment=Qt.Alignment())

        self.setLayout(main_layout)
示例#3
0
 def init_ui(self):
     self.setGeometry(900, 300, 500, 320)
     self.setWindowTitle('Simple APP')
     v = QVBoxLayout()
     self.text.setText(
         "In ten hours a day you have time to fall twice as far " +
         "behind your commitments as in five hours a day.\n" +
         "CORRECT:\n" +
         "Data expands to fill the space available for storage.")
     self.btn_msgbox.clicked.connect(self.msgbox)
     self.btn_mydlg.clicked.connect(self.mydlg)
     v.addWidget(self.text, alignment=Qt.Alignment())
     v.addWidget(self.btn_msgbox, alignment=Qt.Alignment())
     v.addWidget(self.btn_mydlg, alignment=Qt.Alignment())
     self.setLayout(v)
示例#4
0
文件: tabedit.py 项目: ligm74/LiGM
    def __init__(self,
                 parent: TWidget,
                 file_path=None,
                 text_format="HTML",
                 highlighter="",
                 func_after_save=None,
                 spell=None):
        super(TabEdit, self).__init__()

        self._editor = TextEditor(parent,
                                  parent.cfg,
                                  show_status_bar=True,
                                  show_tool_bar=True,
                                  format=text_format,
                                  load=self._load,
                                  save=self._save,
                                  spell=spell)
        self._editor.enabled_save_signal.connect(self.set_enabled_save)
        self._func_after_save = func_after_save
        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
        layout.addWidget(self._editor, alignment=Qt.Alignment())

        self._parent = parent
        self._file_path = file_path
        self._text_format = text_format.upper()
        name = "HTML" if text_format.upper() == "HTML" else "TEXT"
        self._prev_text_format = name
        self._highlighter = highlighter
        self._is_modified = False
        self._editor.set_option(highlighter=highlighter)
        self._editor.load()
示例#5
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)
示例#6
0
def _set_widget(widget,
                layout=None,
                horizontal=None,
                vertical=None,
                size=None,
                alignment=None,
                hstretch=10,
                vstretch=10,
                style=None,
                **kwargs):
    if style is not None:
        widget.setStyleSheet("* {%s}" % style)
    if layout is not None:
        alignment = getattr(Qt, alignment) if alignment else Qt.Alignment(0)
        layout.addWidget(widget, alignment=alignment)
    if (horizontal, vertical, hstretch, vstretch) is not (None, None, None, None):
        policy = widget.sizePolicy()
        if horizontal is not None:
            policy.setHorizontalPolicy(getattr(QSizePolicy, horizontal))
        if hstretch is not None:
            policy.setHorizontalStretch(int(hstretch))
        if vstretch is not None:
            policy.setVerticalStretch(int(vstretch))
        if vertical is not None:
            policy.setVerticalPolicy(getattr(QSizePolicy, vertical))
        widget.setSizePolicy(policy)
    if size is not None:
        qsize = QSize(*size)
        if __debug__:
            print("Setting sizeHint to %s" % qsize)
        widget.sizeHint = lambda: qsize
        widget.setMinimumSize(qsize)
        widget.setMaximumSize(qsize)
    widget.updateGeometry()
    _set_object(widget, **kwargs)
示例#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)
示例#8
0
    def setUpClass(cls):
        cls.test = QTestHelper()
        cls.insert_table = []

        cls.w = TestableWidget()
        cls.w.setWindowTitle("Test insert table")
        cls.w.setGeometry(900, 300, 500, 500)
        cls.cp = InsertTable(config=Config())
        cls.cp.insert_table.connect(lambda data: cls.insert_table.append(data))
        cls.cw = cls.cp._colors_widget

        cls.v = QVBoxLayout()
        cls.v.addWidget(cls.cp, alignment=Qt.Alignment())
        cls.v.addWidget(QLabel(""), alignment=Qt.Alignment())
        cls.v.addItem(
            QSpacerItem(0, 0, QSizePolicy.Fixed, QSizePolicy.Expanding))

        cls.lbl = QLabel("")
        cls.v.addWidget(cls.lbl, alignment=Qt.Alignment())
        cls.w.setLayout(cls.v)

        cls.test.show_and_wait_for_active(cls.w)
示例#9
0
    def setUpClass(cls):
        cls.test = QTestHelper()
        cls.selected_colors = []

        cls.w = TestableWidget()
        cls.w.setWindowTitle("Test select color")
        cls.w.setGeometry(900, 300, 500, 320)
        cls.cp = ColorPicker(config=Config())
        cls.cp.select_color.connect(
            lambda color: cls.selected_colors.append(color))
        cls.cw = cls.cp._colors_widget

        cls.v = QVBoxLayout()
        cls.v.addWidget(cls.cp, alignment=Qt.Alignment())
        cls.v.addWidget(QLabel(""), alignment=Qt.Alignment())
        cls.v.addItem(QSpacerItem(0, 0,
                                  QSizePolicy.Fixed, QSizePolicy.Expanding))

        cls.lbl = QLabel("")
        cls.v.addWidget(cls.lbl, alignment=Qt.Alignment())
        cls.w.setLayout(cls.v)

        cls.test.show_and_wait_for_active(cls.w)
示例#10
0
    def setUpClass(cls):
        cls.test = QTestHelper()
        cls.select_align = []

        cls.w = TestableWidget()
        cls.w.setWindowTitle("Test align text")
        cls.w.setGeometry(900, 300, 500, 320)
        cls.cp = AlignText()
        cls.cp.select_align.connect(lambda h, v: cls.select_align.append(
            (h, v)))
        cls.cw = cls.cp._colors_widget

        cls.v = QVBoxLayout()
        cls.v.addWidget(cls.cp, alignment=Qt.Alignment())
        cls.v.addWidget(QLabel(""), alignment=Qt.Alignment())
        cls.v.addItem(
            QSpacerItem(0, 0, QSizePolicy.Fixed, QSizePolicy.Expanding))

        cls.lbl = QLabel("")
        cls.v.addWidget(cls.lbl, alignment=Qt.Alignment())
        cls.w.setLayout(cls.v)

        cls.test.show_and_wait_for_active(cls.w)
示例#11
0
    def test_highlightBlock(self):

        self.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        text = 'd-ef 1 from 112\n"""\ncomment """ class   from\n def'

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

        def load():
            return text

        # ---------------------------------------------------------------------

        self.widget = TestableWidget(None)
        self.editor = TextEditor(self.widget,
                                 Config(),
                                 save=save,
                                 load=load,
                                 format="TEXT")
        self.editor.set_option(highlighter="PYTHON")
        self.editor.load()

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

        self.test.show_and_wait_for_active(self.widget)

        idx = {
            text.index("def"): [None, STYLES["defclass"]],
            text.index("from"): [None, STYLES["keyword"]],
            text.index("112"): [None, STYLES["numbers"]],
            text.index("comment"): [None, STYLES["string2"]],
            text.index("class"): [None, STYLES["defclass"]],
        }

        cursor = self.editor._view.text.textCursor()
        cursor.movePosition(QTextCursor.Start)
        for i in range(len(text)):
            pos_in_block = cursor.positionInBlock()
            formats = cursor.block().layout().additionalFormats()

            for fmt in formats:
                if fmt.start <= pos_in_block < fmt.start + fmt.length:
                    if i in idx:
                        idx[i][0] = fmt

            cursor.movePosition(QTextCursor.NextCharacter)

        self.test.sleep()

        for i in idx:
            if idx[i][0] is None:  # pragma: no cover
                self.fail()
            self.assertEqual(idx[i][0].format.foreground().color().name(),
                             idx[i][1].foreground().color().name())
            self.assertEqual(idx[i][0].format.fontWeight(),
                             idx[i][1].fontWeight())
示例#12
0
    def __init__(self, text, colors, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        border = "border: 1px solid #9b9b9b;"
        self.setStyleSheet('QFrame[frameShape="4"]{  color: #9b9b9b;}')

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(text)
        self._lbl_caption.setStyleSheet("border: 0px solid blue;")
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(f"background-color: {color_caption}; {border}")

        # -- COLORS GRID ------------------------------
        colorbox = QFrame(self, flags=Qt.WindowFlags())
        color_layout = QGridLayout()
        colorbox.setLayout(color_layout)
        color_layout.setContentsMargins(9, 0, 9, 0)
        nn = 7
        self.clrbtn = []
        for i, color in enumerate(colors):
            self.clrbtn.append(QToolButton())
            css = (f"QToolButton {{{border}background-color:{color};}}"
                   f"QToolButton:hover {{border: 1px solid red; }}")
            self.clrbtn[-1].setStyleSheet(css)
            self.clrbtn[-1].clicked.connect(
                lambda x, c=color: self.select_color_(c))
            # noinspection PyArgumentList
            color_layout.addWidget(self.clrbtn[-1], i // nn, i % nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_color_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/colorwheel")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("other colors"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self.clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(colorbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)
示例#13
0
文件: instable.py 项目: ligm74/LiGM
    def __init__(self, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)
        self._text = self.tr("Table")

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)

        b = "border: 1px solid #9b9b9b;"
        self._styles = {
            "border": b,
            "border_blue": "border: 0px solid blue;",
            "selection": f"QToolButton {{{b}background-color:#fee5e2;}}",
            "white": f"QToolButton {{{b}background-color:white;}}",
            "frame": 'QFrame[frameShape="4"]{color: #9b9b9b;}'}

        self.setStyleSheet(self._styles["frame"])

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(self._text)
        self._lbl_caption.setStyleSheet(self._styles["border_blue"])
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(
            f"background-color: {color_caption}; {self._styles['border']}")

        # -- CELLS GRID -------------------------------
        cellsbox = QFrame(self, flags=Qt.WindowFlags())
        cells = QGridLayout()
        cells.setSpacing(1)
        cellsbox.setLayout(cells)
        cells.setContentsMargins(9, 0, 9, 0)
        self._nn = 10
        self._clrbtn = []
        colors = ["white" for _ in range(self._nn ** 2)]
        cellsbox.leaveEvent = lambda x: self._leave_cell()
        for i, color in enumerate(colors):
            self._clrbtn.append(QToolButton())
            # noinspection PyPep8Naming
            self._clrbtn[-1].enterEvent = lambda x, n=i: self._enter_cell(n)
            self._clrbtn[-1].setStyleSheet(self._styles["white"])
            self._clrbtn[-1].clicked.connect(
                lambda x, n=i: self.select_size_(n))
            # noinspection PyArgumentList
            cells.addWidget(self._clrbtn[-1], i // self._nn, i % self._nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_size_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/table_gray")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("insert table"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self._clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(cellsbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)
示例#14
0
    def test_highlightBlock(self):

        self.test = QTestHelper()

        # ---------------------------------------------------------------------
        # customize editor
        text = " hello \n world1"

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

        def load():
            return text

        # ---------------------------------------------------------------------

        self.widget = TestableWidget(None)
        self.editor = TextEditor(self.widget,
                                 Config(),
                                 save=save,
                                 load=load,
                                 format="HTML",
                                 spell=SpellChecker(True))
        self.editor.load()

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

        self.test.show_and_wait_for_active(self.widget)

        idx = {
            text.index("hello"): [None, False],
            text.index("world1"): [None, True],
        }

        cursor = self.editor._view.text.textCursor()
        cursor.movePosition(QTextCursor.Start)
        self.test.sleep()
        for i in range(len(text)):
            pos_in_block = cursor.positionInBlock()
            formats = cursor.block().layout().additionalFormats()

            for fmt in formats:
                if fmt.start <= pos_in_block < fmt.start + fmt.length:
                    if i in idx:
                        idx[i][0] = fmt.format

            cursor.movePosition(QTextCursor.NextCharacter)

        self.test.sleep()

        for i in idx:
            if idx[i][1]:
                fmt = idx[i][0]
                self.assertEqual(QTextCharFormat.SpellCheckUnderline,
                                 fmt.underlineStyle())
                self.assertEqual(
                    QColor("red").name(),
                    fmt.underlineColor().name())
            else:
                self.assertIsNone(idx[i][0])