Ejemplo n.º 1
0
 def quit(cls):
     """退出线程
     :param cls:
     """
     if hasattr(cls, '_thread'):
         cls._thread.quit()
         AppLog.info('login thread quit')
Ejemplo n.º 2
0
    def loadColourfulTheme(cls, color, widget=None, replaces={}):
        """基于当前设置主题颜色
        :param cls:
        :param color:        背景颜色
        :param widget:        指定控件
        """
        # 加载主题取样式
        path = cls.stylePath('Default')
        AppLog.info('stylePath: {}'.format(path))
        try:
            styleSheet = open(path, 'rb').read().decode(
                'utf-8', errors='ignore')
            # 需要替换部分样式
            colorstr = GradientUtils.styleSheetCode(color)
            if isinstance(color, QLinearGradient) or isinstance(color, QRadialGradient) or isinstance(color, QConicalGradient):
                color = color.stops()[0][1]
            # 替换name
            templates = StyleGradientTemplate
            for name, value in replaces.items():
                templates = templates.replace(name, value)

            styleSheet += templates.format(
                color.red(), color.green(), color.blue(), colorstr)
            widget = widget or QApplication.instance()
            widget.setStyleSheet(styleSheet)
        except Exception as e:
            AppLog.exception(e)
Ejemplo n.º 3
0
 def loadCursor(cls, widget, name='default.png'):
     # 加载光标
     path = cls.cursorPath(name)
     AppLog.info('cursorPath: {}'.format(path))
     if os.path.exists(path):
         # 设置自定义鼠标样式,并以0,0为原点
         widget.setCursor(QCursor(QPixmap(path), 0, 0))
Ejemplo n.º 4
0
    def loadPictureTheme(cls, image=None, widget=None, replaces={}):
        """设置图片背景的主题
        :param cls:
        :param image:         背景图片
        :param widget:        指定控件
        """
        # 加载主题取样式
        path = cls.stylePath('Default')
        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)))

                # 替换name
                templates = StylePictureTemplate
                for name, value in replaces.items():
                    templates = templates.replace(name, value)

                styleSheet += templates.format(os.path.abspath(
                    image).replace('\\', '/')) + StyleColorTemplate.format(*color)
            widget = widget or QApplication.instance()
            widget.setStyleSheet(styleSheet)
        except Exception as e:
            AppLog.exception(e)
Ejemplo n.º 5
0
    def run(self):
        AppLog.info('start get all colourful')
        # 午夜巴黎
        mcolor = QLinearGradient(0, 0, self.width, self.height)
        mcolor.ex = 1
        mcolor.ey = 1
        mcolor.startColor = QColor(20, 179, 255, 255)
        mcolor.endColor = QColor(226, 14, 255, 255)
        mcolor.setColorAt(0, mcolor.startColor)
        mcolor.setColorAt(1, mcolor.endColor)
        # 樱草青葱
        pcolor = QLinearGradient(0, 0, self.width, self.height)
        pcolor.ex = 1
        pcolor.ey = 1
        pcolor.startColor = QColor(0, 173, 246, 255)
        pcolor.endColor = QColor(0, 234, 155, 255)
        pcolor.setColorAt(0, pcolor.startColor)
        pcolor.setColorAt(1, pcolor.endColor)
        # 秋日暖阳
        acolor = QLinearGradient(0, 0, self.width, self.height)
        acolor.ex = 1
        acolor.ey = 1
        acolor.startColor = QColor(255, 128, 27, 255)
        acolor.endColor = QColor(255, 0, 14, 255)
        acolor.setColorAt(0, acolor.startColor)
        acolor.setColorAt(1, acolor.endColor)

        defaults = splistList(
            [
                [self.tr('MidnightParis'), mcolor],  # 午夜巴黎
                [self.tr('PrimroseGreenOnion'), pcolor],  # 樱草青葱
                [self.tr('AutumnSun'), acolor],  # 秋日暖阳
                [self.tr('LightGray'),
                 QColor(236, 236, 236)],  # 淡灰色
                [self.tr('DarkBlack'),
                 QColor(33, 33, 33)],  # 深黑色
                [self.tr('BlueGreen'),
                 QColor(0, 190, 172)],  # 蓝绿色
                [self.tr('Orange'), QColor(255, 152, 0)],  # 橙色
                [self.tr('Brown'), QColor(140, 100, 80)],  # 咖啡色
                [self.tr('Green'), QColor(121, 190, 60)],  # 绿色
                [self.tr('Pink'), QColor(236, 98, 161)],  # 粉色
                [self.tr('Purple'), QColor(103, 58, 183)],  # 紫色
                [self.tr('Blue'), QColor(0, 188, 212)],  # 蓝色
                [self.tr('GreyBlue'),
                 QColor(80, 126, 164)],  # 蓝灰色
                [self.tr('Red'), QColor(244, 94, 99)],  # 红色
            ],
            5)

        for row, default in enumerate(defaults):
            for col, (name, color) in enumerate(default):
                Signals.colourfulItemAdded.emit(row, col, name, color)
                QThread.msleep(100)
                QThread.yieldCurrentThread()

        Signals.colourfulItemAddFinished.emit()
        AppLog.info('colourful thread end')
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def _initLanguage(self):
     """加载国际化翻译
     """
     if QLocale.system().language() in (QLocale.China, QLocale.Chinese, QLocale.Taiwan, QLocale.HongKong):
         # 加载中文
         translator = QTranslator(self)
         translator.load('Resources/pyqtclient_zh_CN.qm')
         QApplication.instance().installTranslator(translator)
         AppLog.info('install local language')
Ejemplo n.º 8
0
 def start(cls, parent=None):
     """启动自动更新线程
     :param cls:
     """
     cls._thread = QThread(parent)
     cls._worker = UpgradeThread()
     cls._worker.moveToThread(cls._thread)
     cls._thread.started.connect(cls._worker.run)
     cls._thread.finished.connect(cls._worker.deleteLater)
     cls._thread.start()
     AppLog.info('update thread started')
Ejemplo n.º 9
0
 def loadCursor(cls, widget, name='default.png'):
     # 加载光标
     path = cls.cursorPath(name)
     if path in ThemeManager.Cursors:
         widget.setCursor(ThemeManager.Cursors[path])
         return
     AppLog.info('cursorPath: {}'.format(path))
     if os.path.exists(path):
         # 设置自定义鼠标样式,并以0,0为原点
         cur = QCursor(QPixmap(path), 0, 0)
         ThemeManager.Cursors[path] = cur
         widget.setCursor(cur)
Ejemplo n.º 10
0
 def start(cls, account, password, parent=None):
     """启动登录线程
     :param cls:
     :param account:        账号
     :param password:       密码
     """
     cls._thread = QThread(parent)
     cls._worker = LoginThread(account, password)
     cls._worker.moveToThread(cls._thread)
     cls._thread.started.connect(cls._worker.run)
     cls._thread.finished.connect(cls._worker.deleteLater)
     cls._thread.start()
     AppLog.info('login thread started')
Ejemplo n.º 11
0
 def start(cls, width, height, parent=None):
     """启动线程
     :param cls:
     :param width:
     :param height:
     :param parent:
     """
     cls._thread = QThread(parent)
     cls._worker = ColourfulThread(width, height)
     cls._worker.moveToThread(cls._thread)
     cls._thread.started.connect(cls._worker.run)
     cls._thread.finished.connect(cls._worker.deleteLater)
     cls._thread.start()
     AppLog.info('colourful thread started')
Ejemplo n.º 12
0
    def run(self):
        AppLog.info('start get all theme')

        defaults = [[p.parent.name, str(p)]
                    for p in Path(DirThemes).rglob('style.qss')]

        defaults = splistList(defaults, 5)

        for row, default in enumerate(defaults):
            for col, (name, path) in enumerate(default):
                Signals.themeItemAdded.emit(row, col, name, path)
                QThread.msleep(100)
                QThread.yieldCurrentThread()

        Signals.themeItemAddFinished.emit()
        AppLog.info('theme thread end')
Ejemplo n.º 13
0
    def run(self):
        AppLog.info('start login github')
        try:
            req = requests.get(self.Url, auth=HTTPBasicAuth(
                self.account, self.password))
            retval = req.json()
            if retval.get('message', '') == 'Bad credentials':
                Signals.loginErrored.emit(QCoreApplication.translate(
                    'Repository', 'Incorrect account or password'))
                AppLog.warn('Incorrect account or password')
                LoginThread.quit()
                return
            if 'login' not in retval:
                Signals.loginErrored.emit(QCoreApplication.translate(
                    'Repository', 'Login failed, Unknown reason'))
                AppLog.warn('Login failed, Unknown reason')
                LoginThread.quit()
                return
            # 用户ID
            uid = retval.get('id', 0)
            AppLog.debug('user id: {}'.format(uid))
            # 用户昵称
            name = retval.get('name', 'Unknown')
            AppLog.debug('user name: {}'.format(name))
            # 用户头像地址
            avatar_url = retval.get('avatar_url', '')
            if avatar_url:
                # 获取头像
                self.get_avatar(uid, avatar_url)
            Signals.loginSuccessed.emit(str(uid), name)
        except ConnectTimeout as e:
            Signals.loginErrored.emit(QCoreApplication.translate(
                'Repository', 'Connect Timeout'))
            AppLog.exception(e)
        except ConnectionError as e:
            Signals.loginErrored.emit(QCoreApplication.translate(
                'Repository', 'Connection Error'))
            AppLog.exception(e)
        except Exception as e:
            Signals.loginErrored.emit(QCoreApplication.translate(
                'Repository', 'Unknown Error'))
            AppLog.exception(e)

        AppLog.info('login thread end')
        LoginThread.quit()
Ejemplo n.º 14
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))
Ejemplo n.º 15
0
 def run(self):
     show = True
     try:
         req = requests.get(self.Url)
         AppLog.info(req.text)
         if req.status_code != 200:
             AppLog.info('update thread end')
             UpgradeThread.quit()
             return
         content = req.json()
         for version, text in content:
             if Version.version < version:
                 if show:
                     Signals.updateDialogShowed.emit()
                     QThread.msleep(1000)
                 show = False
                 Signals.updateTextChanged.emit(
                     str(Version.version), str(version), text)
                 self.download(Constants.UpgradeFile.format(
                     version), self.ZipUrl.format(version))
         Signals.updateFinished.emit(self.tr('update completed'))
     except Exception as e:
         Signals.updateFinished.emit(
             self.tr('update failed: {}').format(str(e)))
         AppLog.exception(e)
     AppLog.info('update thread end')
     UpgradeThread.quit()
Ejemplo n.º 16
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))
Ejemplo n.º 17
0
    def run(self):
        try:
            path = pygit2.discover_repository(Constants.DirProjects)
            if not path:
                # 本地项目不存在
                if os.path.exists(Constants.DirProjects):
                    # 如果文件夹存在则删除
                    AppLog.info('remove dir: {}'.format(Constants.DirProjects))
                    self.remove()
                AppLog.info('clone into dir: {}'.format(Constants.DirProjects))
                self.clone()
            else:
                repo = pygit2.Repository(path)
                if repo.is_empty:  # 如果项目为空
                    if os.path.exists(Constants.DirProjects):
                        # 如果文件夹存在则删除
                        AppLog.info('remove dir: {}'.format(
                            Constants.DirProjects))
                        self.remove()
                    AppLog.info('clone into dir: {}'.format(
                        Constants.DirProjects))
                    self.clone()
                else:
                    # 重置并pull
                    AppLog.info('reset dir: {}'.format(Constants.DirProjects))
                    repo.reset(repo.head.target, pygit2.GIT_RESET_HARD)
                    Signals.progressUpdated.emit(5, 100)
                    AppLog.info('pull into dir: {}'.format(
                        Constants.DirProjects))
                    self.pull(repo)
                    Signals.progressStoped.emit()
        except Exception as e:
            AppLog.exception(e)

        AppLog.info('clone thread end')
        Signals.progressStoped.emit()
        Signals.cloneFinished.emit('')
        CloneThread.quit()