示例#1
0
def main_app(base_path, file, file_config):
    """Run the GUI of xBan

    The function initiates and resize the application
    """
    app = QApplication(sys.argv)

    if hasattr(QStyleFactory, "AA_UseHighDpiPixmaps"):
        app.setAttribute(Qt.AA_UseHighDpiPixmaps)

    with open(os.path.join(base_path, "xBanStyle.css"), "r") as style_sheet:
        style = style_sheet.read()

    app.setWindowIcon(QIcon(os.path.join(base_path, "xBanUI.png")))
    xBanApp = xBanWindow(base_path, file, file_config)

    xBanApp.setStyleSheet(style)

    # resize and move screen to center

    primary_screen = QGuiApplication.primaryScreen()
    if primary_screen:
        screen_size = primary_screen.availableSize()

        xBanApp.resize(screen_size.width() / 3, screen_size.height() / 2)
        xBanApp.move(
            (screen_size.width() - xBanApp.width()) / 2,
            (screen_size.height() - xBanApp.height()) / 2,
        )

        app.setStyle("Fusion")
        sys.exit(app.exec_())

    else:
        main_logger.error("Primary screen not found")
示例#2
0
def main():
    """Main Loop."""
    print(__doc__ + __version__ + __url__)
    application = QApplication(sys.argv)
    application.setApplicationName("pyvoicechanger")
    application.setOrganizationName("pyvoicechanger")
    application.setOrganizationDomain("pyvoicechanger")
    application.setWindowIcon(QIcon.fromTheme("audio-input-microphone"))
    application.aboutToQuit.connect(
        lambda: call('killall rec ; killall play', shell=True))
    mainwindow = MainWindow()
    mainwindow.show()
    sys.exit(application.exec_())
def create_gui(icon):
    """Create and show the GUI Application"""
    app = QApplication()
    app.setApplicationName('Importador BGG -> Ludopedia')
    app.setApplicationVersion('v0.4')
    app.setWindowIcon(QIcon(icon))

    importer = Importador()
    importer.show()
    importer.raise_()
    importer.setVisible(True)
    importer.resize(500, 400)

    sys.exit(app.exec_())
示例#4
0
def main():
    print(f'PySide6=={PySideVer} Qt=={QtVer}')

    parser = ArgumentParser(
        description='cappuccino: Simple image viewer with download')
    parser.add_argument('download_keyword',
                        nargs='?',
                        default='',
                        help='image keyword to download')
    args = parser.parse_args()

    download_keyword = args.download_keyword
    if not download_keyword and not exist_images():
        download_keyword = DEFAULT_KEYWORD

    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon(resource_path('cappuccino.ico')))
    window = MainWindow(download_keyword, IMAGES_DIR_NAME)
    window.show()
    sys.exit(app.exec())
示例#5
0
    def _tick(self):
        """
        Tick the world simulation.
        """
        self._ticks += 1
        self._world.update(self._ticks)
        self._wator_widget.repaint()
        self._wator_graph.repaint()

        fish, sharks = self._world.stats()
        if fish == 0 and sharks == 0:
            print("Both sharks and fish have become extinct.")
            self.pause()
        elif fish == 0 and sharks > 0:
            print("No more fish. Wa-Tor is overrun with sharks.")
            self.pause()
        elif sharks == 0:
            print("No more sharks. Wa-Tor will become overrun with fish.")
            self.pause()


if __name__ == "__main__":
    # Create the Qt Application
    APP = QApplication(sys.argv)
    APP.setWindowIcon(QIcon("res/icon_wator.png"))
    # Create and show the form
    MAIN = MainWindow()
    MAIN.show()
    # Run the main Qt loop
    sys.exit(APP.exec_())
示例#6
0
import sys

from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QApplication

from main_window import MainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('viaflash.icns'))
    window = MainWindow()
    if not window:
        print(loader.errorString())
        sys.exit(-1)
    window.show()

    sys.exit(app.exec())

        # RESIZE WINDOW
        self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
        self.sizegrip.setStyleSheet(
            "width: 20px; height: 20px; margin 0px; padding: 0px;")

        # MINIMIZE
        self.ui.minimizeAppBtn.clicked.connect(self.showMinimized)

        # MAXIMIZE/RESTORE
        self.ui.maximizeRestoreAppBtn.clicked.connect(self.maximize_restore)

        # CLOSE APPLICATION
        self.ui.closeAppBtn.clicked.connect(self.close)

    def resize_grips(self):
        if self._enable_custom_title_bar:
            self.left_grip.setGeometry(0, 10, 10, self.height())
            self.right_grip.setGeometry(self.width() - 10, 10, 10,
                                        self.height())
            self.top_grip.setGeometry(0, 0, self.width(), 10)
            self.bottom_grip.setGeometry(0,
                                         self.height() - 10, self.width(), 10)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon("icon.ico"))
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())
示例#8
0
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()
示例#9
0
def pyside6_splash_main(main_module_name: str,
                        main_func_name: str,
                        min_py_ver: Iterable,
                        requirements: Iterable,
                        splash_text: str,
                        pre_main_name: Optional[str] = None):
    """
    Splash screen & intall packages.
    1. Show PySide6 splash
    2. Check & install packages
    3. Hide splash
    4. Then run the main function.

    Text of splash screen is read from launch.json at root directory.

    Args:
        main_module_name (str):
            The module that main function exists.
        main_func_name (str):
            The name of main function.
            It will be called by this function
            if installer successfully executed.
        min_py_ver (Iterable):
            The minimum requirement of python version.
        requirements (Iterable):
            PIP names of required package.
        splash_text (str):
            The text displayed to splash screen.
        pre_main_name (str, optional):
            Function that must be called before main function run.
            Return value of function will be used
                as second argument of main function.
    """
    if _check_py_ver(min_py_ver):
        return 1

    # pylint: disable = not-callable
    if _check_imports():  # When PySide6 is not installed
        # Check missing packages and install (with PySide6)
        if IS_ZIPFILE:
            return_code = _zipapp_package_installer(requirements)
        else:
            return_code = _normal_package_checker(requirements)
        if return_code != 0:
            return return_code

        # Create Qt application & Show splash
        app = QApplication()
        icon = get_icon()
        if icon is not None:
            app.setWindowIcon(icon)

        splash = _Splash(app, splash_text)
        splash.show()
        QApplication.processEvents()
    else:  # When PySide6 is installed
        # Create Qt application & Show splash
        app = QApplication()
        icon = get_icon()
        if icon is not None:
            app.setWindowIcon(icon)

        splash = _Splash(app, splash_text)
        splash.show()
        QApplication.processEvents()

        # Check another missing packages
        if IS_ZIPFILE:
            return_code = _zipapp_package_installer(requirements)
        else:
            return_code = _normal_package_checker(requirements)
        if return_code != 0:
            splash.hide()
            return return_code
    QApplication.processEvents()

    main_module = import_module(main_module_name)
    QApplication.processEvents()
    if pre_main_name is not None:
        res = getattr(main_module, pre_main_name)()
        QApplication.processEvents()
        splash.hide()
        return getattr(main_module, main_func_name)(app, res)
    splash.hide()
    return getattr(main_module, main_func_name)(app)