Пример #1
0
 def on_custom_clicked(self):
     where = Globals.config.get(Globals.UserData.custom_dir)
     url, types = QFileDialog().getOpenFileName(
         dir=where, filter="Font Files Only (*.ttf)")
     if url is not None and url != "":
         QFontDatabase.addApplicationFont(url)
         names = get_font_name(url)
         self.custom_font_path = url
         self.custom_family = names[0][0]
         self.custom_edit.setText(self.custom_family)
         Globals.config.set(Globals.UserData.custom_dir,
                            os.path.abspath(os.path.dirname(url)))
         self.refresh_font()
     else:
         self.custom_edit.setText("")
         self.custom_font_path = None
         self.custom_family = None
         self.refresh_font()
Пример #2
0
    def setup_product_table(self):
        # Setup table
        table = self.window.ui.productTableView
        table.setModel(self.product_model)

        # Use monospace font for table contents.
        # TODO: Break these out into one common font for the controller.
        font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
        font.setPointSize(14)
        table.setFont(font)

        # Setup header
        header = table.horizontalHeader()
        header.setSectionResizeMode(QHeaderView.ResizeToContents)
        header.setStretchLastSection(True)
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(TitleBar, self).__init__(*args, **kwargs)

        # Поддержка настройки фона qss
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.mPos = None
        self.iconSize = 20  # Размер значка по умолчанию

        # Установите цвет фона по умолчанию, иначе он будет прозрачным из-за влияния родительского окна
        self.setAutoFillBackground(True)
        palette = self.palette()
        palette.setColor(palette.Window, QColor(240, 240, 240))
        self.setPalette(palette)
        # Подключение стиля
        self.setStyleSheet('Titlebar.qss')
        self.setStyleSheet(open("Titlebar.qss", "r").read())
        # макет
        layout = QHBoxLayout(self)
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)

        # значок окна

        # название окна
        self.titleLabel = QLabel(self)
        self.titleLabel.setMargin(2)
        self.font_id = QFontDatabase.addApplicationFont(
            "Roboto/Roboto-Bold.ttf")
        font = QFont("Roboto-Bold", 12)
        font.setFamily(u"Roboto")
        font.setBold(True)
        self.buttonMy = QPushButton(self,
                                    clicked=self.showButtonMy,
                                    objectName='buttonMy')
        self.buttonMy.setIcon(QIcon('icon-white.ico'))

        layout.addWidget(self.buttonMy)
        layout.addStretch()

        self.titleLabel.setFont(font)

        layout.addStretch()
        layout.addWidget(self.titleLabel, alignment=Qt.AlignCenter)

        # Средний телескопический бар
        layout.addSpacerItem(
            QSpacerItem(40, 100, QSizePolicy.Expanding, QSizePolicy.Minimum))

        # Использовать шрифты Webdings для отображения значков
        font = self.font() or QFont()
        font.setFamily('Webdings')

        # Своя Кнопка

        # Свернуть кнопку
        self.buttonMinimum = QPushButton('0',
                                         self,
                                         clicked=self.windowMinimumed.emit,
                                         font=font,
                                         objectName='buttonMinimum')
        layout.addWidget(self.buttonMinimum)

        # Кнопка Max / restore
        self.buttonMaximum = QPushButton('1',
                                         self,
                                         clicked=self.showMaximized,
                                         font=font,
                                         objectName='buttonMaximum')
        layout.addWidget(self.buttonMaximum)

        # Кнопка закрытия
        self.buttonClose = QPushButton('r',
                                       self,
                                       clicked=self.windowClosed.emit,
                                       font=font,
                                       objectName='buttonClose')
        layout.addWidget(self.buttonClose)

        # начальная высота
        self.setHeight()
Пример #4
0
    def data(self, index: QModelIndex, role: Qt.ItemDataRole = Qt.DisplayRole) -> Any:
        if not index.isValid():
            return None
        col = self.getColumnKey(index.column())
        if not col:
            return None

        if role == Qt.FontRole:
            if col in ('datatype', 'size',):
                return QFontDatabase.systemFont(QFontDatabase.FixedFont)
            return None

        if role == Qt.CheckStateRole:
            if col in ('enabled',):
                mod = self.modmodel[index.row()]
                val = mod[col]
                return Qt.Checked if val else Qt.Unchecked
            return None

        if role == Qt.BackgroundRole:
            mod = self.modmodel[index.row()]
            if not mod.enabled:
                return self._colorDisabled
            if col in ('priority',) and mod.datatype not in ('mod', 'udf',):
                return self._colorUnavailable
            if mod.installdate > self._lastUpdate:
                return self._colorNewest
            if mod.installdate > self._lastInitialization:
                return self._colorRecent
            if not mod.installed:
                return self._colorUnmanaged
            return None

        if role == Qt.ForegroundRole:
            mod = self.modmodel[index.row()]
            if not mod.enabled:
                return QColor(60, 60, 60)
            elif col in ('scriptFiles',):
                if mod.filename in self.modmodel.conflicts.scripts \
                and self.modmodel.conflicts.scripts[mod.filename]:
                    return QColor('#E55934')
            elif col in ('bundledFiles',):
                if mod.filename in self.modmodel.conflicts.bundled \
                and self.modmodel.conflicts.bundled[mod.filename]:
                    return QColor('#b08968')
            return None

        if role == Qt.DecorationRole:
            if col in ('datatype',):
                mod = self.modmodel[index.row()]
                val = mod[col]
                return self._icons[val] if val in self._icons else self._icons['udf']
            return None

        if role == Qt.ToolTipRole:
            mod = self.modmodel[index.row()]
            if col in ('datatype',):
                val = mod[col]
                return self._datatypes[val] if val in self._datatypes else self._datatypes['udf']
            if col in ('enabled',):
                val = mod[col]
                return 'Enabled' if val else 'Disabled'
            return str(mod[col])

        if role == Qt.TextAlignmentRole:
            if col in ('size',):
                # Right|VCenter
                return 0x0082
            if col in ('priority', 'installdate', 'binFiles', 'menuFiles', 'settings',
                       'inputs', 'contentFiles', 'scriptFiles', 'bundledFiles',):
                # HCenter|VCenter
                return 0x0084
            # Left|VCenter
            return 0x0081

        if role == Qt.EditRole:
            if col in ('package', 'filename', 'category', 'priority',):
                mod = self.modmodel[index.row()]
                return str(mod[col])
            return None

        # role used for sorting
        if role == Qt.UserRole:
            mod = self.modmodel[index.row()]
            if col in ('priority',):
                return f'{"-" if int(mod[col]) < 0 else "+"}{abs(int(mod[col])): >20} {mod["filename"]}'
            if col in ('size',):
                return int(mod[col])
            if col in ('binFiles', 'menuFiles', 'contentFiles', \
                       'scriptFiles', 'settings', 'inputs', 'bundledFiles',):
                return len(mod[col])
            return str(mod[col])

        if role == Qt.DisplayRole:
            if col in ('enabled',):
                return None
            mod = self.modmodel[index.row()]
            if col in ('datatype',):
                return str(mod[col]).upper()
            if col in ('priority',):
                val = mod[col]
                if val < 0:
                    return 'none'
                return val
            if col in ('installdate',):
                return mod[col].astimezone(tz=None).strftime('%Y-%m-%d %H:%M:%S')
            if col in ('size',):
                val = mod[col]
                frm = 'b'
                val /= 1024
                frm = 'K'
                if val // 1024:
                    val /= 1024
                    frm = 'M'
                return '%.1f %s' % (val, frm)
            if col in ('inputs', 'settings',):
                val = 0
                for s in mod[col]:
                    for n in s.config.sections():
                        val += len(s.config.items(n))
                return val if val else None

            if col in ('binFiles', 'menuFiles', 'contentFiles', 'scriptFiles', 'bundledFiles',):
                val = len(mod[col])
                if val < 1:
                    return ''
                return val
            return str(mod[col])

        return None
Пример #5
0
########################################################################
class RuntimeStylesheets(QMainWindow, QtStyleTools):
    # ----------------------------------------------------------------------
    def __init__(self):
        """"""
        super().__init__()
        self.main = QUiLoader().load('main_window.ui', self)

        self.main.pushButton.clicked.connect(
            lambda: self.apply_stylesheet(self.main, 'dark_teal.xml'))
        self.main.pushButton_2.clicked.connect(lambda: self.apply_stylesheet(
            self.main, 'light_red.xml', extra={
                'font_family': 'mono',
            }))
        self.main.pushButton_3.clicked.connect(lambda: self.apply_stylesheet(
            self.main, 'light_blue.xml', extra={
                'font_family': 'Raleway',
            }))


if __name__ == "__main__":
    app = QApplication()

    # Local file
    QFontDatabase.addApplicationFont('Raleway-Regular.ttf')

    frame = RuntimeStylesheets()
    frame.main.show()

    app.exec_()
Пример #6
0
 def __init__(self):
     super(PatternDelegate, self).__init__()
     self.font = QFontDatabase.systemFont(QFontDatabase.FixedFont)
Пример #7
0
        self.addSubWindow(self.content)
        self.addSubWindow(self.overlay)
        self.addSubWindow(self.menu)

    def resizeEvent(self, event):
        self.content.resize(self.width(), self.height())
        self.overlay.resize(self.width(), self.height())
        self.menu.resize(270, self.height())


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.mdi = MdiArea()
        self.setCentralWidget(self.mdi)


if __name__ == "__main__":
    import sys

    app = QApplication([])

    font_db = QFontDatabase()
    font_db.addApplicationFont("res/fonts/Roboto-Black.ttf")
    font_db.addApplicationFont("res/fonts/Roboto-Light.ttf")

    w = MainWindow()
    w.resize(800, 600)
    w.show()

    sys.exit(app.exec_())