def __init__(self, *args): super().__init__(*args) from shared.config import SettingsAccessorBase from Settings import DEFAULT_SETTINGS self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel from Schedule.model import SchedulerModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel=self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) from Tasks.action import TaskCreationAgent self.taskCreationAgent = TaskCreationAgent(self) self.taskCreationAgent.available.connect(self.slotCreateTask) self.taskCreationDlg = None from Services import SessionService self.sessionService = SessionService(self) from Widgets.Main import QmlMain self.qmlWin = QmlMain(None) self.qmlWin.show() self.aboutToQuit.connect(lambda: self.qmlWin.deleteLater())
class DummyApp(QApplication): def __init__(self, *args): super().__init__(*args) from shared.config import SettingsAccessorBase from Settings import DEFAULT_SETTINGS self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) from models import TaskModel, AdapterManager, ProxyModel from Schedule.model import SchedulerModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager() for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) self.qmlWin = QmlMain(None) self.qmlWin.show() self.aboutToQuit.connect(lambda: self.qmlWin.deleteLater())
def __init__(self, *args): super().__init__(*args) from shared.config import SettingsAccessorBase from Settings import DEFAULT_SETTINGS self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel from Schedule.model import SchedulerModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel = self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) from Tasks.action import TaskCreationAgent self.taskCreationAgent = TaskCreationAgent(self) self.taskCreationAgent.available.connect(self.slotCreateTask) self.taskCreationDlg = None from Services import SessionService self.sessionService = SessionService(self) from Widgets.Main import QmlMain self.qmlWin = QmlMain(None) self.qmlWin.show() self.aboutToQuit.connect(lambda: self.qmlWin.deleteLater())
def __init__(self, *args): super().__init__(*args) logging.info("XWARE DESKTOP STARTS") self.setApplicationName("XwareDesktop") self.setApplicationVersion(__version__) os.chdir(os.path.dirname(os.path.abspath(__file__))) self.checkOneInstance() font = QFont() font.setPointSize(10) self.setFont(font) QIcon.setThemeName("") # Compat for Ubuntu 14.04: A magical fix for #102 from Settings import DEFAULT_SETTINGS from shared.config import SettingsAccessorBase self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel = self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) # components from Services import SessionService self.sessionService = SessionService(self) from Widgets.systray import Systray from Notify import Notifier from Schedule.model import SchedulerModel from Tasks.action import TaskCreationAgent self.systray = Systray(self) self.notifier = Notifier(taskModel = self.taskModel, frontendSettings = self.settings["frontend"], parent = self) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.taskCreationAgent = TaskCreationAgent(self) self.monitorWin = None self.applySettings.connect(self.slotCreateCloseMonitorWindow) # Legacy parts from legacy import main from legacy.frontendpy import FrontendPy self.mainWin = main.MainWindow(adapter = self.adapterManager[0], taskCreationAgent = self.taskCreationAgent, frontendSettings = self.settings["frontend"], app = self) self.mainWin.show() self.frontendpy = FrontendPy(taskCreationAgent = self.taskCreationAgent, legacySettings = self.settings["legacy"], adapterSettings = self.settings["adapter-legacy"], adapter = self.adapterManager[0], mainWin = self.mainWin, parent = self) self.sigMainWinLoaded.emit() self.applySettings.emit() upgradeGuide = None if self.settings.myGet("internal", "previousversion") == "0.8": # upgraded or fresh installed upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/使用说明" else: previousdate = self.settings.getfloat("internal", "previousdate") if previousdate == 0: # upgrade from pre-0.12 upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/升级到0.12" if upgradeGuide: from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices QDesktopServices.openUrl(QUrl(upgradeGuide)) self.settings.set("internal", "previousversion", __version__) self.settings.setfloat("internal", "previousdate", DATE)
class XwareDesktop(QApplication): sigMainWinLoaded = pyqtSignal() applySettings = pyqtSignal() toggleMinimized = pyqtSignal() def __init__(self, *args): super().__init__(*args) logging.info("XWARE DESKTOP STARTS") self.setApplicationName("XwareDesktop") self.setApplicationVersion(__version__) os.chdir(os.path.dirname(os.path.abspath(__file__))) self.checkOneInstance() font = QFont() font.setPointSize(10) self.setFont(font) QIcon.setThemeName("") # Compat for Ubuntu 14.04: A magical fix for #102 from Settings import DEFAULT_SETTINGS from shared.config import SettingsAccessorBase self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel = self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) # components from Services import SessionService self.sessionService = SessionService(self) from Widgets.systray import Systray from Notify import Notifier from Schedule.model import SchedulerModel from Tasks.action import TaskCreationAgent self.systray = Systray(self) self.notifier = Notifier(taskModel = self.taskModel, frontendSettings = self.settings["frontend"], parent = self) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.taskCreationAgent = TaskCreationAgent(self) self.monitorWin = None self.applySettings.connect(self.slotCreateCloseMonitorWindow) # Legacy parts from legacy import main from legacy.frontendpy import FrontendPy self.mainWin = main.MainWindow(adapter = self.adapterManager[0], taskCreationAgent = self.taskCreationAgent, frontendSettings = self.settings["frontend"], app = self) self.mainWin.show() self.frontendpy = FrontendPy(taskCreationAgent = self.taskCreationAgent, legacySettings = self.settings["legacy"], adapterSettings = self.settings["adapter-legacy"], adapter = self.adapterManager[0], mainWin = self.mainWin, parent = self) self.sigMainWinLoaded.emit() self.applySettings.emit() upgradeGuide = None if self.settings.myGet("internal", "previousversion") == "0.8": # upgraded or fresh installed upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/使用说明" else: previousdate = self.settings.getfloat("internal", "previousdate") if previousdate == 0: # upgrade from pre-0.12 upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/升级到0.12" if upgradeGuide: from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices QDesktopServices.openUrl(QUrl(upgradeGuide)) self.settings.set("internal", "previousversion", __version__) self.settings.setfloat("internal", "previousdate", DATE) @staticmethod def checkOneInstance(): fd = os.open(constants.FRONTEND_LOCK, os.O_RDWR | os.O_CREAT) alreadyRunning = False if os.name == "posix": import fcntl try: fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: alreadyRunning = True elif os.name == "nt": import msvcrt try: msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) except PermissionError: alreadyRunning = True else: raise NotImplementedError("Xware Desktop doesn't support {}".format(os.name)) if alreadyRunning: def showStartErrorAndExit(): from PyQt5.QtWidgets import QMessageBox QMessageBox.warning(None, "Xware Desktop 启动失败", "Xware Desktop已经运行,或其没有正常退出。\n" "请检查:\n" " 1. 没有Xware Desktop正在运行\n" " 2. 上次运行的Xware Desktop没有残留" "(使用进程管理器查看名为python3或xware-desktop或launcher.py的进程)\n", QMessageBox.Ok, QMessageBox.Ok) sys.exit(-1) tasks = sys.argv[1:] if len(tasks) == 0: showStartErrorAndExit() else: from Tasks import CommandlineClient try: CommandlineClient(tasks) except FileNotFoundError: showStartErrorAndExit() except ConnectionRefusedError: showStartErrorAndExit() sys.exit(0) @pyqtSlot() def slotCreateCloseMonitorWindow(self): logging.debug("slotCreateCloseMonitorWindow") show = self.settings.getbool("frontend", "showmonitorwindow") from Widgets import monitor if show: if self.monitorWin: pass # already shown, do nothing else: self.monitorWin = monitor.MonitorWindow(None) self.monitorWin.show() else: if self.monitorWin: logging.debug("close monitorwin") self.monitorWin.close() del self.monitorWin self.monitorWin = None else: pass # not shown, do nothing @property def autoStart(self): return os.path.lexists(constants.DESKTOP_AUTOSTART_FILE) @autoStart.setter def autoStart(self, on): if on: # mkdir if autostart dir doesn't exist misc.tryMkdir(os.path.dirname(constants.DESKTOP_AUTOSTART_FILE)) misc.trySymlink(constants.DESKTOP_FILE, constants.DESKTOP_AUTOSTART_FILE) else: misc.tryRemove(constants.DESKTOP_AUTOSTART_FILE)
def __init__(self, *args): super().__init__(*args) logging.info("XWARE DESKTOP STARTS") self.setApplicationName("XwareDesktop") self.setApplicationVersion(__version__) os.chdir(os.path.dirname(os.path.abspath(__file__))) self.checkOneInstance() font = QFont() font.setPointSize(10) self.setFont(font) QIcon.setThemeName( "") # Compat for Ubuntu 14.04: A magical fix for #102 from Settings import DEFAULT_SETTINGS from shared.config import SettingsAccessorBase self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel=self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) # components from Services import SessionService self.sessionService = SessionService(self) from Widgets.systray import Systray from Notify import Notifier from Schedule.model import SchedulerModel from Tasks.action import TaskCreationAgent self.systray = Systray(self) self.notifier = Notifier(taskModel=self.taskModel, frontendSettings=self.settings["frontend"], parent=self) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.taskCreationAgent = TaskCreationAgent(self) self.monitorWin = None self.applySettings.connect(self.slotCreateCloseMonitorWindow) # Legacy parts from legacy import main from legacy.frontendpy import FrontendPy self.mainWin = main.MainWindow( adapter=self.adapterManager[0], taskCreationAgent=self.taskCreationAgent, frontendSettings=self.settings["frontend"], app=self) self.mainWin.show() self.frontendpy = FrontendPy( taskCreationAgent=self.taskCreationAgent, legacySettings=self.settings["legacy"], adapterSettings=self.settings["adapter-legacy"], adapter=self.adapterManager[0], mainWin=self.mainWin, parent=self) self.sigMainWinLoaded.emit() self.applySettings.emit() upgradeGuide = None if self.settings.myGet("internal", "previousversion") == "0.8": # upgraded or fresh installed upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/使用说明" else: previousdate = self.settings.getfloat("internal", "previousdate") if previousdate == 0: # upgrade from pre-0.12 upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/升级到0.12" if upgradeGuide: from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices QDesktopServices.openUrl(QUrl(upgradeGuide)) self.settings.set("internal", "previousversion", __version__) self.settings.setfloat("internal", "previousdate", DATE)
class XwareDesktop(QApplication): sigMainWinLoaded = pyqtSignal() applySettings = pyqtSignal() toggleMinimized = pyqtSignal() def __init__(self, *args): super().__init__(*args) logging.info("XWARE DESKTOP STARTS") self.setApplicationName("XwareDesktop") self.setApplicationVersion(__version__) os.chdir(os.path.dirname(os.path.abspath(__file__))) self.checkOneInstance() font = QFont() font.setPointSize(10) self.setFont(font) QIcon.setThemeName( "") # Compat for Ubuntu 14.04: A magical fix for #102 from Settings import DEFAULT_SETTINGS from shared.config import SettingsAccessorBase self.settings = SettingsAccessorBase(constants.FRONTEND_CONFIG_FILE, DEFAULT_SETTINGS) self.aboutToQuit.connect(lambda: self.settings.save()) from models import TaskModel, AdapterManager, ProxyModel self.taskModel = TaskModel() self.proxyModel = ProxyModel() self.proxyModel.setSourceModel(self.taskModel) self.adapterManager = AdapterManager(taskModel=self.taskModel) for name, item in self.settings.itr_sections_with_prefix("adapter"): self.adapterManager.loadAdapter(item) # components from Services import SessionService self.sessionService = SessionService(self) from Widgets.systray import Systray from Notify import Notifier from Schedule.model import SchedulerModel from Tasks.action import TaskCreationAgent self.systray = Systray(self) self.notifier = Notifier(taskModel=self.taskModel, frontendSettings=self.settings["frontend"], parent=self) self.schedulerModel = SchedulerModel(self) self.schedulerModel.setSourceModel(self.taskModel) self.taskCreationAgent = TaskCreationAgent(self) self.monitorWin = None self.applySettings.connect(self.slotCreateCloseMonitorWindow) # Legacy parts from legacy import main from legacy.frontendpy import FrontendPy self.mainWin = main.MainWindow( adapter=self.adapterManager[0], taskCreationAgent=self.taskCreationAgent, frontendSettings=self.settings["frontend"], app=self) self.mainWin.show() self.frontendpy = FrontendPy( taskCreationAgent=self.taskCreationAgent, legacySettings=self.settings["legacy"], adapterSettings=self.settings["adapter-legacy"], adapter=self.adapterManager[0], mainWin=self.mainWin, parent=self) self.sigMainWinLoaded.emit() self.applySettings.emit() upgradeGuide = None if self.settings.myGet("internal", "previousversion") == "0.8": # upgraded or fresh installed upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/使用说明" else: previousdate = self.settings.getfloat("internal", "previousdate") if previousdate == 0: # upgrade from pre-0.12 upgradeGuide = "https://github.com/Xinkai/XwareDesktop/wiki/升级到0.12" if upgradeGuide: from PyQt5.QtCore import QUrl from PyQt5.QtGui import QDesktopServices QDesktopServices.openUrl(QUrl(upgradeGuide)) self.settings.set("internal", "previousversion", __version__) self.settings.setfloat("internal", "previousdate", DATE) @staticmethod def checkOneInstance(): fd = os.open(constants.FRONTEND_LOCK, os.O_RDWR | os.O_CREAT) alreadyRunning = False if os.name == "posix": import fcntl try: fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: alreadyRunning = True elif os.name == "nt": import msvcrt try: msvcrt.locking(fd, msvcrt.LK_NBLCK, 1) except PermissionError: alreadyRunning = True else: raise NotImplementedError( "Xware Desktop doesn't support {}".format(os.name)) if alreadyRunning: def showStartErrorAndExit(): from PyQt5.QtWidgets import QMessageBox QMessageBox.warning( None, "Xware Desktop 启动失败", "Xware Desktop已经运行,或其没有正常退出。\n" "请检查:\n" " 1. 没有Xware Desktop正在运行\n" " 2. 上次运行的Xware Desktop没有残留" "(使用进程管理器查看名为python3或xware-desktop或launcher.py的进程)\n", QMessageBox.Ok, QMessageBox.Ok) sys.exit(-1) tasks = sys.argv[1:] if len(tasks) == 0: showStartErrorAndExit() else: from Tasks import CommandlineClient try: CommandlineClient(tasks) except FileNotFoundError: showStartErrorAndExit() except ConnectionRefusedError: showStartErrorAndExit() sys.exit(0) @pyqtSlot() def slotCreateCloseMonitorWindow(self): logging.debug("slotCreateCloseMonitorWindow") show = self.settings.getbool("frontend", "showmonitorwindow") from Widgets import monitor if show: if self.monitorWin: pass # already shown, do nothing else: self.monitorWin = monitor.MonitorWindow(None) self.monitorWin.show() else: if self.monitorWin: logging.debug("close monitorwin") self.monitorWin.close() del self.monitorWin self.monitorWin = None else: pass # not shown, do nothing @property def autoStart(self): return os.path.lexists(constants.DESKTOP_AUTOSTART_FILE) @autoStart.setter def autoStart(self, on): if on: # mkdir if autostart dir doesn't exist misc.tryMkdir(os.path.dirname(constants.DESKTOP_AUTOSTART_FILE)) misc.trySymlink(constants.DESKTOP_FILE, constants.DESKTOP_AUTOSTART_FILE) else: misc.tryRemove(constants.DESKTOP_AUTOSTART_FILE)