Exemplo n.º 1
0
def start():
    app = QSingleApplication("zzclient", sys.argv)
    # 异常捕获
    os.makedirs(Config().except_path, exist_ok=True)
    sys.excepthook = cgitb.Hook(1, Config().except_path, 5, sys.stderr, '')
    if app.isRunning():
        # 激活窗口
        app.sendMessage('show', 1000)
    else:
        # 窗口关闭程序退出
        app.setQuitOnLastWindowClosed(True)
        # 应用图标
        app.setWindowIcon(ResourceLoader().qt_icon_project_ico)
        # 设置主题样式
        Theme.load()
        # 设置字体
        # fontDB = QFontDatabase()
        # fontDB.addApplicationFont(':/font/Roboto-Regular.ttf')
        # app.setFont(QFont('Roboto'))
        # 设置雅黑字体
        app.setFont(ResourceLoader.load_app_font())
        # 图标字体
        ResourceLoader.load_icon_font()
        # 加载模块
        ResourceLoader.load_modules()
        # 创建窗体
        window = HomePage()
        window.resize(1024 ,768)
        # 样式注入器
        ConnectStyleSheetInspector(main_window=window,
                                   shortcut=QKeySequence(Qt.Key_Tab))
        # 计算居中显示的位置
        desktop = QDesktopWidget().availableGeometry()
        width = (desktop.width() - window.width()) / 2
        height = (desktop.height() - window.height()) / 2
        app.setActivationWindow(window)
        window.show()
        window.move(width, height)
        sys.exit(app.exec_())
Exemplo n.º 2
0
class Window(QWidget):
    def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)

        self.setStyleSheet(Style)
        self.resize(1024, 768)
        self.sheet = ActionSheet(data=['电流', '电压', '电阻'], parent=self)
        self.sheet.on_item_clicked.connect(lambda item:print('选中了{item}'.format(item=item)))
        self.sheet.dialog.add_action('重置', lambda :print("点击了重置按钮"))
        # self.popup = PopupContainer(self, widget=sheet)
        self.open_drawer()

    def open_drawer(self):
        QTimer.singleShot(100, lambda :self.sheet.showSelf())

    def closeEvent(self, a0: QtGui.QCloseEvent) -> None:
        Bloc_App().app_closed.emit()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    Theme.load()
    # fontDB = QFontDatabase()
    # font_id = fontDB.addApplicationFont(':font/Microsoft-YaHei.ttf')
    # fontName = QFontDatabase.applicationFontFamilies(font_id)[0]
    # app.setFont(QFont('Microsoft YaHei'))
    window = Window()
    window.show()

    sys.exit(app.exec_())