class Preferences(object): if is_macos(): QSettings.setDefaultFormat(QSettings.Format.NativeFormat) SETTINGS = QSettings(QSettings.NativeFormat, QSettings.UserScope, ORGANIZATION_DOMAIN, APPLICATION_NAME) else: QSettings.setDefaultFormat(QSettings.Format.IniFormat) SETTINGS = QSettings(QSettings.IniFormat, QSettings.UserScope, ORGANIZATION_DOMAIN, APPLICATION_NAME) def __init__(self): super(Preferences, self).__init__() @classmethod def contains(cls, key): return cls.SETTINGS.contains(key) @classmethod def get(cls, key, type=None): return cls.get_or_default(key, None, type=type) @classmethod def get_or_default(cls, key, default, type=None): if type is None: return cls.SETTINGS.value(key, default) else: return cls.SETTINGS.value(key, default, type=type) @classmethod def set(cls, key, value): cls.SETTINGS.setValue(key, value) @classmethod def remove(cls, key): cls.SETTINGS.remove(key)
def start(ctx, mock=False, clean=False): """start the w3modmanager application""" from tests.framework import _mockdata, _root import w3modmanager import w3modmanager.__main__ _testdata = _root.joinpath('testdata') if clean: print('cleaning up testdata...') rmtree(_testdata, ignore_errors=True) git = which('git') if git: hash = subprocess.run([git, 'rev-parse', '--short=7', 'HEAD'], capture_output=True).stdout if hash: w3modmanager.VERSION_HASH = str(hash, 'utf-8').strip() date = subprocess.run([git, 'show', '-s', '--format=%cI', 'HEAD'], capture_output=True).stdout if date: date = datetime.fromisoformat(str( date, 'utf-8').strip()).astimezone(timezone.utc).isoformat() date = date[:10].replace('-', '.') w3modmanager.VERSION = date if mock: from PySide2.QtCore import QSettings print('setting up testdata...') copy_tree(str(_mockdata), str(_testdata)) QSettings.setDefaultFormat(QSettings.IniFormat) QSettings.setPath(QSettings.IniFormat, QSettings.UserScope, str(_testdata.joinpath('settings'))) w3modmanager.__main__.main(_testdata.joinpath('programs'), _testdata.joinpath('documents')) else: w3modmanager.__main__.main()
def main(app_url, game_index, qt_args): logging.basicConfig(level=logging.DEBUG) logging.info("Starting QtWebEngine") browser.init() app = QApplication(["runekit", *qt_args]) app.setQuitOnLastWindowClosed(False) app.setOrganizationName("cupco.de") app.setOrganizationDomain("cupco.de") app.setApplicationName("RuneKit") signal.signal(signal.SIGINT, lambda no, frame: app.quit()) timer = QTimer() timer.start(300) timer.timeout.connect(lambda: None) QSettings.setDefaultFormat(QSettings.IniFormat) try: game_manager = get_platform_manager() host = Host(game_manager) if app_url == "settings": host.open_settings() host.setting_dialog.setAttribute(Qt.WA_DeleteOnClose) host.setting_dialog.destroyed.connect(app.quit) elif app_url: logging.info("Loading app") game_app = host.launch_app_from_url(app_url) game_app.window.destroyed.connect(app.quit) else: if not host.app_store.has_default_apps(): host.app_store.load_default_apps() app.exec_() sys.exit(0) except Exception as e: msg = QMessageBox( QMessageBox.Critical, "Oh No!", f"Fatal error: \n\n{e.__class__.__name__}: {e}", ) msg.setDetailedText(traceback.format_exc()) msg.exec_() raise finally: if game_manager is not None: logging.debug("Stopping game manager") game_manager.stop()