예제 #1
0
 def loadUserTheme(cls, theme='Default'):
     """加载主题目录里的主题
     :param cls:
     :param theme:        文件夹名字
     """
     Setting.setValue('theme', theme)
     cls.loadTheme()
예제 #2
0
    def initAccount(self):
        # 自动填充账号密码
        self._accounts = Setting.value('accounts', {}, QVariant)
        completer = QCompleter(self._accounts.keys(), self.lineEditAccount)
        completer.setCaseSensitivity(Qt.CaseInsensitive)
        # 在内部自动填充完成
        completer.setCompletionMode(QCompleter.InlineCompletion)
        # 设置objectName用于设置样式
        # completer.popup().setObjectName('lineEditAccountAuto')
        self.lineEditAccount.setCompleter(completer)

        # 读取储存的账号密码
        account = Setting.value('account', '', str)
        self.lineEditAccount.setText(account)
예제 #3
0
 def __init__(self, *args, **kwargs):
     super(MainWindow, self).__init__(*args, **kwargs)
     Setting.init(self)
     self._initUi()
     self._initSignals()
     # 加载窗口大小并恢复
     geometry = Setting.value('geometry')
     if geometry:
         self.restoreGeometry(geometry)
     # 200毫秒后显示登录对话框
     QTimer.singleShot(200, self._initCatalog)
     # 初始化网页
     QTimer.singleShot(500, self._initWebView)
     # 检测更新
     QTimer.singleShot(5000, UpgradeThread.start)
     # 显示捐赠窗口
     QTimer.singleShot(
         randint(1000 * 60 * 5, 2000 * 60 * 5), self._initDonate)
예제 #4
0
 def loadFont(cls):
     """加载字体
     """
     ThemeManager.ThemeName = Setting.value('theme', 'Default', str)
     # 加载主题中的字体
     path = cls.fontPath()
     AppLog.info('fontPath: {}'.format(path))
     if os.path.isfile(path):
         QFontDatabase.addApplicationFont(path)
예제 #5
0
 def _initUi(self):
     """初始UI"""
     self.setupUi(self)
     # 隐藏还原按钮
     self.buttonNormal.setVisible(False)
     # 隐藏目录树的滑动条
     self.treeViewCatalogs.verticalScrollBar().setVisible(False)
     # 加载鼠标样式
     ThemeManager.loadCursor(self.widgetMain)
     ThemeManager.setPointerCursors([
         self.buttonHead,            # 主界面头像
         self.buttonClear,           # 主界面清空按钮
         self.buttonGithub,          # Github按钮
         self.buttonQQ,              # QQ按钮
         self.buttonGroup,           # 群按钮
         self.buttonBackToUp,        # 返回顶部按钮
         self.buttonHome             # 显示主页readme
     ])
     # 安装事件过滤器用于还原鼠标样式
     self.widgetMain.installEventFilter(self)
     # 绑定返回顶部提示框
     ToolTip.bind(self.buttonBackToUp)
     ToolTip.bind(self.buttonHome)
     # 头像提示控件
     ToolTip.bind(self.buttonHead)
     # 加载主题
     colourful = Setting.value('colourful')
     picture = Setting.value('picture', '', str)
     AppLog.debug('colourful: %s', str(colourful))
     AppLog.debug('picture: %s', picture)
     if picture:
         ThemeManager.loadFont()
         ThemeManager.loadPictureTheme(picture)
     elif colourful:
         ThemeManager.loadFont()
         if isinstance(picture, QColor):
             ThemeManager.loadColourfulTheme(colourful)
         else:
             # json数据转渐变
             ThemeManager.loadColourfulTheme(
                 GradientUtils.toGradient(colourful))
     else:
         ThemeManager.loadTheme()
예제 #6
0
 def onLoginSuccessed(self, uid, name):
     AppLog.debug('onLoginSuccessed')
     self._isLogin = False
     self.buttonLogin.showWaiting(False)
     self.setEnabled(True)
     # 用账号密码实例化github访问对象
     account = self.lineEditAccount.text().strip()
     password = self.lineEditPassword.text().strip()
     Constants._Account = account
     Constants._Password = password
     Constants._Username = name
     # 储存账号密码
     Setting.setValue('account', account)
     if account not in self._accounts:
         # 更新账号数组
         self._accounts[account] = [
             uid, base64.b85encode(password.encode()).decode()]
         Setting.setValue('accounts', self._accounts)
     self.accept()
예제 #7
0
 def loadTheme(cls):
     """根据配置加载主题
     :param cls:
     :param parent:
     """
     cls.ThemeName = Setting.value('theme', 'Default', str)
     # 加载主题中的字体
     path = cls.fontPath()
     AppLog.info('fontPath: {}'.format(path))
     if os.path.exists(path):
         QFontDatabase.addApplicationFont(path)
     # 加载主题取样式
     path = cls.stylePath()
     AppLog.info('stylePath: {}'.format(path))
     try:
         QApplication.instance().setStyleSheet(
             open(path, 'rb').read().decode('utf-8', errors='ignore'))
     except Exception as e:
         AppLog.error(str(e))
예제 #8
0
 def loadFestivalTheme(cls, image=None):
     """根据配置加载主题
     :param cls:
     :param parent:
     :param image:         背景图片
     """
     cls.ThemeName = Setting.value('theme', 'Default', str)
     # 加载主题取样式
     path = cls.stylePath()
     AppLog.info('stylePath: {}'.format(path))
     try:
         styleSheet = open(path, 'rb').read().decode('utf-8',
                                                     errors='ignore')
         # 需要替换部分样式
         if image and os.path.isfile(image):
             # 获取图片主色调
             color_thief = ColorThief(image)
             color = color_thief.get_color()
             AppLog.info('dominant color: {}'.format(str(color)))
             styleSheet += StyleTemplate.format(
                 os.path.abspath(image).replace('\\', '/'), *color)
         QApplication.instance().setStyleSheet(styleSheet)
     except Exception as e:
         AppLog.error(str(e))
예제 #9
0
 def closeEvent(self, event):
     # 储存窗口位置
     Setting.setValue('geometry', self.saveGeometry())
     super(MainWindow, self).closeEvent(event)
예제 #10
0
 def on_buttonPreviewApply_clicked(self):
     """设置主题
     """
     if self._which == self.Theme:
         ThemeManager.loadUserTheme(
             os.path.basename(os.path.dirname(self._poc)))
         Setting.setValue('picture', None)
         Setting.setValue('colourful', None)
     elif self._which == self.Color:
         ThemeManager.loadColourfulTheme(self._poc)
         if isinstance(self._poc, QColor):
             Setting.setValue('colourful', self._poc)
         else:
             # 渐变需要转成字典数据
             Setting.setValue('colourful', GradientUtils.toJson(self._poc))
         Setting.setValue('picture', None)
     elif self._which == self.Picture:
         ThemeManager.loadPictureTheme(self._poc)
         Setting.setValue('colourful', None)
         Setting.setValue('picture', self._poc.replace('\\', '/'))
예제 #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年1月9日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: [email protected]
@file: Test.TestSetting
@description: 
"""
import os

from PyQt5.QtCore import QVariant

from Utils.CommonUtil import Setting

__Author__ = """By: Irony
QQ: 892768447
Email: [email protected]"""
__Copyright__ = "Copyright (c) 2019 Irony"
__Version__ = "Version 1.0"

os.chdir('../')

print(Setting.value('accounts', [], QVariant))

Setting.setValue('accounts', ['*****@*****.**'])

print(Setting.value('accounts', [], QVariant))