コード例 #1
0
ファイル: qt_commands.py プロジェクト: wrapperband/leo-editor
def showFonts(self, event=None):
    """Open a tab in the log pane showing a font picker."""
    c = self.c
    p = c.p

    picker = QtWidgets.QFontDialog()
    if p.h.startswith('@font'):
        (name, family, weight, slant, size) = leoConfig.parseFont(p.b)
    else:
        name, family, weight, slant, size = None, None, False, False, 12
    try:
        font = QtGui.QFont()
        if family: font.setFamily(family)
        font.setBold(weight)
        font.setItalic(slant)
        font.setPointSize(size)
        picker.setCurrentFont(font)
    except ValueError:
        pass
    if not picker.exec_():
        g.es("No font selected")
    else:
        font = picker.selectedFont()
        udata = c.undoer.beforeChangeNodeContents(p)
        comments = [x for x in g.splitLines(p.b) if x.strip().startswith('#')]
        defs = [
            '\n' if comments else '',
            '%s_family = %s\n' % (name, font.family()),
            '%s_weight = %s\n' % (name, 'bold' if font.bold() else 'normal'),
            '%s_slant = %s\n' % (name, 'italic' if font.italic() else 'roman'),
            '%s_size = %s\n' % (name, font.pointSizeF())
        ]
        p.b = ''.join(comments + defs)
        c.undoer.afterChangeNodeContents(p, 'change-font', udata)
コード例 #2
0
 def init(self, font, position, stylesheet):
     '''Set the attributes of the widget.'''
     demo, w = g.app.demo, self
     stylesheet = stylesheet or '''\
         QLabel {
             border: 2px solid black;
             background-color : lightgrey;
             color : black;
         }'''
     demo.set_position(w, position or 'center')
     w.setStyleSheet(stylesheet)
     w.setFont(font or QtGui.QFont('DejaVu Sans Mono', 16))
コード例 #3
0
    def create_frame(self, filename, filenames, window):

        QLabel = QtWidgets.QLabel
        # Create the frame.
        frame = QtWidgets.QFrame(parent=window)
        # Create the vertical layout.
        layout = QtWidgets.QVBoxLayout()
        frame.setLayout(layout)
        # Set the font.
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(12)
        # Create the labels..
        ctime = time.ctime(os.path.getctime(filename))
        struct_time = time.strptime(ctime)
        creation_time = time.strftime('%Y %m %d', struct_time)
        file_label = QLabel(text=filename, parent=frame)
        file_label.setFont(font)
        layout.addWidget(file_label)
        size = os.path.getsize(filename) / 1000
        info_label = QLabel(text=f"size: {size} KB date: {creation_time}")
        info_label.setFont(font)
        layout.addWidget(info_label)
        # Create the delete button, centered.
        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addStretch()
        delete_button = QtWidgets.QPushButton(text='Delete', parent=frame)
        button_layout.addWidget(delete_button)
        button_layout.addStretch()
        layout.addLayout(button_layout)

        # Set the button action.

        def delete_action(arg):
            self.delete_file(filename)

        delete_button.clicked.connect(delete_action)
        # Create the picture area.
        picture = QtWidgets.QLabel('picture', parent=frame)
        layout.addWidget(picture)
        # Display the picture.
        pixmap = QtGui.QPixmap(filename)
        try:
            TransformationMode = QtCore.Qt if isQt5 else QtCore.Qt.TransformationMode
            image = pixmap.scaledToHeight(
                self.window_height, TransformationMode.SmoothTransformation)  # pylint: disable=no-member
            picture.setPixmap(image)
            picture.adjustSize()
            return frame
        except Exception:
            g.trace('Bad image')
            g.es_exception()
            return None
コード例 #4
0
def showFonts(self, event=None):
    '''Open a tab in the log pane showing a font picker.'''
    picker = QtWidgets.QFontDialog()
    text = QtWidgets.QApplication.clipboard().text()
    try:
        font = QtGui.QFont(text)
        picker.setCurrentFont(font)
    except ValueError:
        pass
    if not picker.exec_():
        g.es("No font selected")
    else:
        text = picker.selectedFont().family()
        g.es('copied to clipboard:', text)
        QtWidgets.QApplication.clipboard().setText(text)
コード例 #5
0
    def create_window(self, filenames):
        # Create the widget.
        global gWindow
        gWindow = window = QtWidgets.QWidget()
        window.setWindowTitle(f"{len(filenames)} duplicates of {filenames[0]}")
        window.setMinimumHeight(self.window_height)
        # Move the window.
        window.move(50, 50)
        # Init the layouts.
        outer_layout = QtWidgets.QVBoxLayout()
        window.setLayout(outer_layout)
        button_layout = QtWidgets.QHBoxLayout()
        frame_layout = QtWidgets.QHBoxLayout()
        outer_layout.addLayout(button_layout)
        outer_layout.addLayout(frame_layout)
        # Set the font.
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(12)
        # Create the common buttons, left aligned.
        next_button = QtWidgets.QPushButton(text='Next', parent=window)
        quit_button = QtWidgets.QPushButton(text='Quit', parent=window)
        next_button.setFont(font)
        quit_button.setFont(font)
        button_layout.addWidget(next_button)
        button_layout.addWidget(quit_button)
        button_layout.addStretch()
        # Create the actions.
        next_button.clicked.connect(window.close)
        quit_button.clicked.connect(self.quit)
        # Create the subframes and add them to the frame_layout.
        for filename in filenames:
            frame = self.create_frame(filename, filenames[:], window)
            if frame:
                frame_layout.addWidget(frame)
        # Handle close events.
        def closeEvent(*args, **kwargs):
            window.close()
            self.next_window()

        window.closeEvent = closeEvent
        # Show the window.
        window.show()
コード例 #6
0
    def __init__(self, c=None, lep=None, *args, **kwargs):
        """set up"""
        super(LEP_VanillaScintilla, self).__init__(*args, **kwargs)
        self.c = c
        self.lep = lep
        self.textChanged.connect(self.text_changed)

        font = QtGui.QFont()
        font.setFamily('Courier')
        font.setFixedPitch(True)
        font.setPointSize(14)

        lexer = Qsci.QsciLexerPython()
        lexer.setDefaultFont(font)
        self.setLexer(lexer)
        # self.SendScintilla(Qsci.QsciScintilla.SCI_STYLESETFONT, 1, 'Courier')

        self.setCaretLineVisible(True)
        self.setCaretLineBackgroundColor(QtGui.QColor("#ffe4e4"))
コード例 #7
0
ファイル: demo.py プロジェクト: ATikhonov2/leo-editor
 def init(self, font, position, size, stylesheet):
     '''Init the Text widget.'''
     demo, w = g.app.demo, self
     demo.set_position(w, position)
     if size:
         try:
             height, width = size
             height = demo.get_int(height)
             width = demo.get_int(width)
             w.resize(width, height)
         except ValueError:
             g.trace('invalid size', repr(size))
     else:
         geom = self._parent.geometry()
         w.resize(geom.width(), min(150, geom.height() / 2))
     if stylesheet:
         w.setStyleSheet(stylesheet)
     else:
         w.setFont(font or QtGui.QFont('Verdana', 14))