示例#1
0
def main():
    global win
    signal.signal(signal.SIGINT, exit)
    args = parse_arguments()
    appKey = "scudcloud.pid"
    socket = QLocalSocket()
    socket.connectToServer(appKey)
    if socket.isOpen():
        socket.close()
        socket.deleteLater()
        return 0
    socket.deleteLater()
    app = QtWidgets.QApplication(sys.argv)
    app.setApplicationName(Resources.APP_NAME + ' Slack')
    app.setWindowIcon(QtGui.QIcon(Resources.get_path('scudcloud.png')))
    try:
        settings_path, cache_path = load_settings(args.confdir, args.cachedir)
    except:
        print("Data directories " + args.confdir + " and " + args.cachedir +
              " could not be created! Exiting...")
        raise SystemExit()
    minimized = True if args.minimized is True else None
    urgent_hint = True if args.urgent_hint is True else None

    # Let's move the CSS to cachedir to enable additional actions
    copyfile(Resources.get_path('resources.css'),
             os.path.join(cache_path, 'resources.css'))

    # If there is an qt4 config and not a qt5, let's copy the old one
    qt4_config = os.path.join(settings_path, 'scudcloud.cfg')
    qt5_config = os.path.join(settings_path, 'scudcloud_qt5.cfg')
    if os.path.exists(qt4_config) and not os.path.exists(qt5_config):
        copyfile(qt4_config, qt5_config)

    win = sca.ScudCloud(debug=args.debug,
                        minimized=minimized,
                        urgent_hint=urgent_hint,
                        settings_path=settings_path,
                        cache_path=cache_path)
    app.commitDataRequest.connect(win.setForceClose,
                                  type=QtCore.Qt.DirectConnection)

    server = QLocalServer()
    server.newConnection.connect(restore)
    server.listen(appKey)
    win.restore()
    if win.minimized is None:
        win.show()
    sys.exit(app.exec_())
    def start(cls, path, image, widget=None, single=False, name=None,
              above=False, alignment=None, color=None):
        """
        :param path: 客户端路径
        :param image: 背景图片
        :param widget: 自定义的UI层
        :param single: 是否单实例,默认 False
        :param name: 单实例唯一名
        :param above: 是否置顶
        :param alignment: 文字对齐位置
        :param color: 文本颜色
        """
        name = cls.getName(name)
        os.environ['SplashConnectName'] = name

        # 单实例检测
        if single:
            s = QLocalSocket()
            s.connectToServer(name)
            if s.waitForConnected():
                # 应用已经启动则退出
                s.close()
                s.deleteLater()
                print('application is already running')
                sys.exit(0)

        app = QApplication(sys.argv)
        # 启动客户端并将参数传递
        QProcess.startDetached(path, sys.argv[1:])

        # 显示启动界面
        w = SplashScreen(name, image, widget, above)
        w.setAlignment(alignment)
        w.setColor(color)
        w.show()

        sys.exit(app.exec_())