def buildWindow(self, window: QWidget): window.resize(self.newSizeX, self.newSizeY) font = QFont() font.setBold(False) font.setUnderline(False) font.setKerning(False) font.setWeight(QFont.Weight.Normal) window.setFont(font) window.setObjectName(u"background") window.setStyleSheet("QWidget#background {background-color: gray}")
def __init__(self, tab, config_path, options): self.options = options self.selected = [] super().__init__(tab, config_path, defer_initial_ui_update=True) self.selectionMode = self.MultiSelection # add options for opt in options: if isinstance(opt, str): self.addItem(QListWidgetItem(opt)) else: group_header = QListWidgetItem(opt["group"]) group_header.setFlags(Qt.ItemFlag.NoItemFlags) group_header.setForeground(Qt.black) header_font = QFont() header_font.setWeight(QFont.Bold) group_header.setFont(header_font) self.addItem(group_header) for group_opt in opt["entries"]: self.addItem(QListWidgetItem(group_opt)) self.on_config_changed(self.main_window.config)
def main(gamePath: Optional[str] = None, configPath: Optional[str] = None, startupMode: StartupMode = StartupMode.Main) -> NoReturn: from w3modmanager.util.util import getRuntimePath from w3modmanager.core.model import Model from w3modmanager.core.errors import OtherInstanceError, InvalidGamePath, InvalidConfigPath from w3modmanager.ui.graphical.mainwindow import MainWindow from w3modmanager.domain.web.nexus import closeSession from w3modmanager.domain.system.permissions import \ getWritePermissions, setWritePermissions from PySide6.QtCore import Qt, QSettings from PySide6.QtWidgets import QApplication, QMessageBox from PySide6.QtGui import QIcon, QPalette, QFont from qasync import QEventLoop QApplication.setOrganizationName(w3modmanager.ORG_NAME) QApplication.setOrganizationDomain(w3modmanager.ORG_URL) QApplication.setApplicationName(w3modmanager.TITLE) QApplication.setApplicationVersion(w3modmanager.VERSION) QApplication.setApplicationDisplayName('') QApplication.setAttribute(Qt.AA_NativeWindows) app = QApplication(sys.argv) app.setStyleSheet(''' Link { text-decoration: none; } ''') eventloop = QEventLoop(app) asyncio.set_event_loop(eventloop) palette = QPalette(QApplication.palette()) palette.setColor(QPalette.Link, Qt.red) palette.setColor(QPalette.LinkVisited, Qt.red) palette.setColor(QPalette.PlaceholderText, Qt.gray) app.setPalette(palette) font = QFont('Segoe UI') font.setStyleHint(QFont.System) font.setWeight(QFont.Normal) font.setStyleStrategy(QFont.PreferDevice) font.setPointSize(9) app.setFont(font) icon = QIcon() icon.addFile(str(getRuntimePath('resources/icons/w3b.ico'))) app.setWindowIcon(icon) pool = ThreadPoolExecutor() asyncio.get_running_loop().set_default_executor(pool) # configure startup overrides settings = QSettings() if gamePath: settings.setValue('gamePath', gamePath) if configPath: settings.setValue('configPath', configPath) if startupMode == StartupMode.About: MainWindow.showAboutDialog(None).exec_() sys.exit() if startupMode == StartupMode.Settings: MainWindow.showSettingsDialog(None).exec_() sys.exit() exception_hook_set = False def createModel(ignorelock: bool = False) -> Model: nonlocal settings return Model( Path(str(settings.value('gamePath'))), Path(str(settings.value('configPath'))), Path( appdirs.user_data_dir(w3modmanager.NAME, w3modmanager.ORG_NAME)), ignorelock) try: # try to initialize the mod management model try: model = createModel() # if another instance is already open, inform and ask to open anyway except OtherInstanceError as e: if MainWindow.showOtherInstanceDialog( None).exec_() == QMessageBox.Yes: model = createModel(True) else: raise e # if game path or config path is invalid or not set, # show a special settings dialog and retry except (InvalidGamePath, InvalidConfigPath): MainWindow.showSettingsDialog(None, True).exec_() model = createModel() # check for write access to the game and config directories for path in ( model.gamepath, model.configpath, model.cachepath, ): if not getWritePermissions(path): if MainWindow.showInvalidPermissionsDialog(None, path).exec_() != QMessageBox.Yes \ or not setWritePermissions(path): raise PermissionError(f'Not enough permissions for {path}') window = MainWindow(model) app.setActiveWindow(window) def show_exception_hook(exctype, value, tb) -> None: # noqa nonlocal window MainWindow.showCritcalErrorDialog( window, value, ''.join(traceback.format_exception(exctype, value, tb))).exec_() exception_hook(exctype, value, tb) sys.excepthook = show_exception_hook exception_hook_set = True with eventloop: status = eventloop.run_forever() eventloop.run_until_complete(closeSession()) sys.exit(status) except OtherInstanceError as e: sys.exit(f'error: {str(e)}') except (InvalidGamePath, InvalidConfigPath) as e: MainWindow.showInvalidConfigErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except PermissionError as e: MainWindow.showInvalidPermissionsErrorDialog(None).exec_() sys.exit(f'error: {str(e)}') except Exception as e: if not exception_hook_set: MainWindow.showCritcalErrorDialog(None, str(e)).exec_() raise e sys.exit()
def __init__(self, persepolis_setting): super().__init__() self.persepolis_setting = persepolis_setting # add support for other languages locale = str(self.persepolis_setting.value('settings/locale')) QLocale.setDefault(QLocale(locale)) self.translator = QTranslator() if self.translator.load(':/translations/locales/ui_' + locale, 'ts'): QCoreApplication.installTranslator(self.translator) # set ui direction ui_direction = self.persepolis_setting.value('ui_direction') if ui_direction == 'rtl': self.setLayoutDirection(Qt.RightToLeft) elif ui_direction in 'ltr': self.setLayoutDirection(Qt.LeftToRight) icons = ':/' + \ str(self.persepolis_setting.value('settings/icons')) + '/' self.setMinimumSize(QSize(545, 375)) self.setWindowIcon(QIcon.fromTheme('persepolis', QIcon(':/persepolis.svg'))) verticalLayout = QVBoxLayout(self) self.about_tabWidget = QTabWidget(self) # about tab self.about_tab = QWidget(self) about_tab_horizontalLayout = QHBoxLayout(self.about_tab) about_tab_verticalLayout = QVBoxLayout() # persepolis icon if qtsvg_available: persepolis_icon_verticalLayout = QVBoxLayout() self.persepolis_icon = QtSvgWidget.QSvgWidget(':/persepolis.svg') self.persepolis_icon.setFixedSize(QSize(64, 64)) persepolis_icon_verticalLayout.addWidget(self.persepolis_icon) persepolis_icon_verticalLayout.addStretch(1) about_tab_horizontalLayout.addLayout(persepolis_icon_verticalLayout) self.title_label = QLabel(self.about_tab) font = QFont() font.setBold(True) font.setWeight(QFont.Weight.Bold) self.title_label.setFont(font) self.title_label.setAlignment(Qt.AlignCenter) about_tab_verticalLayout.addWidget(self.title_label) self.version_label = QLabel(self.about_tab) self.version_label.setAlignment(Qt.AlignCenter) about_tab_verticalLayout.addWidget(self.version_label) self.site2_label = QLabel(self.about_tab) self.site2_label.setTextFormat(Qt.RichText) self.site2_label.setAlignment(Qt.AlignCenter) self.site2_label.setOpenExternalLinks(True) self.site2_label.setTextInteractionFlags( Qt.TextBrowserInteraction) about_tab_verticalLayout.addWidget(self.site2_label) self.telegram_label = QLabel(self.about_tab) self.telegram_label.setTextFormat(Qt.RichText) self.telegram_label.setAlignment(Qt.AlignCenter) self.telegram_label.setOpenExternalLinks(True) self.telegram_label.setTextInteractionFlags( Qt.TextBrowserInteraction) about_tab_verticalLayout.addWidget(self.telegram_label) self.twitter_label = QLabel(self.about_tab) self.twitter_label.setTextFormat(Qt.RichText) self.twitter_label.setAlignment(Qt.AlignCenter) self.twitter_label.setOpenExternalLinks(True) self.twitter_label.setTextInteractionFlags( Qt.TextBrowserInteraction) about_tab_verticalLayout.addWidget(self.twitter_label) about_tab_verticalLayout.addStretch(1) about_tab_horizontalLayout.addLayout(about_tab_verticalLayout) # developers_tab # developers self.developers_tab = QWidget(self) developers_verticalLayout = QVBoxLayout(self.developers_tab) self.developers_title_label = QLabel(self.developers_tab) font.setBold(True) font.setWeight(QFont.Weight.Bold) self.developers_title_label.setFont(font) self.developers_title_label.setAlignment(Qt.AlignCenter) developers_verticalLayout.addWidget(self.developers_title_label) self.name_label = QLabel(self.developers_tab) self.name_label.setAlignment(Qt.AlignCenter) developers_verticalLayout.addWidget(self.name_label) # contributors self.contributors_thank_label = QLabel(self.developers_tab) self.contributors_thank_label.setFont(font) self.contributors_thank_label.setAlignment(Qt.AlignCenter) developers_verticalLayout.addWidget(self.contributors_thank_label) self.contributors_link_label = QLabel(self.developers_tab) self.contributors_link_label.setTextFormat(Qt.RichText) self.contributors_link_label.setAlignment(Qt.AlignCenter) self.contributors_link_label.setOpenExternalLinks(True) self.contributors_link_label.setTextInteractionFlags( Qt.TextBrowserInteraction) developers_verticalLayout.addWidget(self.contributors_link_label) developers_verticalLayout.addStretch(1) # translators tab self.translators_tab = QWidget(self) translators_tab_verticalLayout = QVBoxLayout(self.translators_tab) # translators self.translators_textEdit = QTextEdit(self.translators_tab) self.translators_textEdit.setReadOnly(True) translators_tab_verticalLayout.addWidget(self.translators_textEdit) # License tab self.license_tab = QWidget(self) license_tab_verticalLayout = QVBoxLayout(self.license_tab) self.license_text = QTextEdit(self.license_tab) self.license_text.setReadOnly(True) license_tab_verticalLayout.addWidget(self.license_text) verticalLayout.addWidget(self.about_tabWidget) # buttons button_horizontalLayout = QHBoxLayout() button_horizontalLayout.addStretch(1) self.pushButton = QPushButton(self) self.pushButton.setIcon(QIcon(icons + 'ok')) self.pushButton.clicked.connect(self.close) button_horizontalLayout.addWidget(self.pushButton) verticalLayout.addLayout(button_horizontalLayout) self.setWindowTitle(QCoreApplication.translate("about_ui_tr", "About Persepolis")) # about_tab self.title_label.setText(QCoreApplication.translate("about_ui_tr", "Persepolis Download Manager")) self.version_label.setText(QCoreApplication.translate("about_ui_tr", "Version 3.2.0")) self.site2_label.setText(QCoreApplication.translate("about_ui_tr", "<a href=https://persepolisdm.github.io>https://persepolisdm.github.io</a>", "TRANSLATORS NOTE: YOU REALLY DON'T NEED TO TRANSLATE THIS PART!")) self.telegram_label.setText(QCoreApplication.translate("about_ui_tr", "<a href=https://telegram.me/persepolisdm>https://telegram.me/persepolisdm</a>", "TRANSLATORS NOTE: YOU REALLY DON'T NEED TO TRANSLATE THIS PART!")) self.twitter_label.setText(QCoreApplication.translate("about_ui_tr", "<a href=https://twitter.com/persepolisdm>https://twitter.com/persepolisdm</a>", "TRANSLATORS NOTE: YOU REALLY DON'T NEED TO TRANSLATE THIS PART!")) # developers_tab self.developers_title_label.setText(QCoreApplication.translate('about_ui_tr', 'Developers:')) self.name_label.setText(QCoreApplication.translate("about_ui_tr", "\nAliReza AmirSamimi\nMohammadreza Abdollahzadeh\nSadegh Alirezaie\nMostafa Asadi\nMohammadAmin Vahedinia\nJafar Akhondali\nH.Rostami\nEhsan Titish", "TRANSLATORS NOTE: YOU REALLY DON'T NEED TO TRANSLATE THIS PART!")) self.contributors_thank_label.setText(QCoreApplication.translate('about_ui_tr', 'Special thanks to:')) self.contributors_link_label.setText( "<a href=https://github.com/persepolisdm/persepolis/graphs/contributors>our contributors</a>") # License self.license_text.setPlainText(""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. """) # tabs self.about_tabWidget.addTab(self.about_tab, QCoreApplication.translate("about_ui_tr", "About Persepolis")) self.about_tabWidget.addTab(self.developers_tab, QCoreApplication.translate("about_ui_tr", "Developers")) self.about_tabWidget.addTab(self.translators_tab, QCoreApplication.translate("about_ui_tr", "Translators")) self.about_tabWidget.addTab(self.license_tab, QCoreApplication.translate("about_ui_tr", "License")) # button self.pushButton.setText(QCoreApplication.translate("about_ui_tr", "OK"))