def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]: i18n = generate_i18n(app_config, resource.get_path('locale')) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']), cleaner=cache_cleaner) icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration'])) http_client = HttpClient(logger) context = ApplicationContext(i18n=i18n, http_client=http_client, download_icons=bool(app_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(logger), logger=logger, distro=util.get_distro(), file_downloader=AdaptableFileDownloader(logger, bool(app_config['download']['multithreaded']), i18n, http_client, app_config['download']['multithreaded_client']), app_name=__app_name__, internet_checker=InternetChecker(offline=app_args.offline)) managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY) if app_args.reset: util.clean_app_files(managers) exit(0) manager = GenericSoftwareManager(managers, context=context, config=app_config) app = new_qt_application(app_config=app_config, logger=logger, quit_on_last_closed=True) if app_args.settings: # only settings window manager.cache_available_managers() return app, SettingsWindow(manager=manager, i18n=i18n, screen_size=app.primaryScreen().size(), window=None) else: manage_window = ManageWindow(i18n=i18n, manager=manager, icon_cache=icon_cache, screen_size=app.primaryScreen().size(), config=app_config, context=context, http_client=http_client, icon=util.get_default_icon()[1], logger=logger) prepare = PreparePanel(screen_size=app.primaryScreen().size(), context=context, manager=manager, i18n=i18n, manage_window=manage_window, app_config=app_config) cache_cleaner.start() return app, prepare
def main(): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) args = cli_args.read() logger = logs.new_logger(__app_name__, False) app_config = CoreConfigManager().get_config() http_client = HttpClient(logger) i18n = generate_i18n(app_config, resource.get_path('locale')) cache_factory = DefaultMemoryCacheFactory(expiration_time=0) downloader = AdaptableFileDownloader( logger=logger, multithread_enabled=app_config['download']['multithreaded'], multithread_client=app_config['download']['multithreaded_client'], i18n=i18n, http_client=http_client, check_ssl=app_config['download']['check_ssl']) context = ApplicationContext( i18n=i18n, http_client=http_client, download_icons=bool(app_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(logger), logger=logger, distro=util.get_distro(), file_downloader=downloader, app_name=__app_name__, app_version=__version__, internet_checker=InternetChecker(offline=False), suggestions_mapping=None, # TODO not needed at the moment root_user=user.is_root()) managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY, logger=logger) cli = CLIManager( GenericSoftwareManager(managers, context=context, config=app_config)) if args.command == 'updates': cli.list_updates(args.format)
def main(): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) args = cli_args.read() logger = logs.new_logger(__app_name__, False) app_config = config.read_config(update_file=True) http_client = HttpClient(logger) i18n = generate_i18n(app_config, resource.get_path('locale')) cache_factory = DefaultMemoryCacheFactory(expiration_time=0) context = ApplicationContext( i18n=i18n, http_client=http_client, download_icons=bool(app_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(logger), logger=logger, distro=util.get_distro(), file_downloader=AdaptableFileDownloader( logger, bool(app_config['download']['multithreaded']), i18n, http_client, app_config['download']['multithreaded_client']), app_name=__app_name__) managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY) cli = CLIManager( GenericSoftwareManager(managers, context=context, config=app_config)) if args.command == 'updates': cli.list_updates(args.format)
def main(): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) args = app_args.read() logger = logs.new_logger(__app_name__, bool(args.logs)) local_config = config.read_config(update_file=True) if local_config['ui']['auto_scale']: os.environ['QT_AUTO_SCREEN_SCALE_FACTOR'] = '1' logger.info("Auto screen scale factor activated") if local_config['ui']['hdpi']: logger.info("HDPI settings activated") QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) i18n_key, current_i18n = translation.get_locale_keys( local_config['locale']) default_i18n = translation.get_locale_keys( DEFAULT_I18N_KEY)[1] if i18n_key != DEFAULT_I18N_KEY else {} i18n = I18n(i18n_key, current_i18n, DEFAULT_I18N_KEY, default_i18n) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=int( local_config['memory_cache']['data_expiration']), cleaner=cache_cleaner) icon_cache = cache_factory.new( int(local_config['memory_cache']['icon_expiration'])) http_client = HttpClient(logger) context = ApplicationContext( i18n=i18n, http_client=http_client, disk_cache=bool(local_config['disk_cache']['enabled']), download_icons=bool(local_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory( disk_cache_enabled=bool(local_config['disk_cache']['enabled']), logger=logger), logger=logger, distro=util.get_distro(), file_downloader=AdaptableFileDownloader( logger, bool(local_config['download']['multithreaded']), i18n, http_client), app_name=__app_name__) managers = gems.load_managers(context=context, locale=i18n_key, config=local_config, default_locale=DEFAULT_I18N_KEY) if args.reset: util.clean_app_files(managers) exit(0) manager = GenericSoftwareManager(managers, context=context, config=local_config) manager.prepare() app = QApplication(sys.argv) app.setQuitOnLastWindowClosed( False ) # otherwise windows opened through the tray icon kill the aplication when closed app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) app_icon = util.get_default_icon()[1] app.setWindowIcon(app_icon) if local_config['ui']['style']: app.setStyle(str(local_config['ui']['style'])) else: if app.style().objectName().lower() not in {'fusion', 'breeze'}: app.setStyle('Fusion') manage_window = ManageWindow(i18n=i18n, manager=manager, icon_cache=icon_cache, screen_size=app.primaryScreen().size(), config=local_config, context=context, http_client=http_client, icon=app_icon, logger=logger) if args.tray: tray_icon = TrayIcon(i18n=i18n, manager=manager, manage_window=manage_window, screen_size=app.primaryScreen().size(), config=local_config) manage_window.set_tray_icon(tray_icon) tray_icon.show() if args.show_panel: tray_icon.show_manage_window() else: manage_window.refresh_apps() manage_window.show() cache_cleaner.start() Thread(target=config.remove_old_config, args=(logger, ), daemon=True).start() sys.exit(app.exec_())
def __init__(self, config: dict, screen_size: QSize, logger: logging.Logger, manage_process: Popen = None, settings_process: Popen = None): super(TrayIcon, self).__init__() self.app_config = config self.i18n = generate_i18n(config, resource.get_path('locale/tray')) self.screen_size = screen_size self.manage_process = manage_process self.settings_process = settings_process self.logger = logger self.http_client = HttpClient(logger=logger) if config['ui']['tray']['default_icon']: self.icon_default = QIcon(config['ui']['tray']['default_icon']) else: self.icon_default = QIcon.fromTheme('bauh_tray_default') if self.icon_default.isNull(): self.icon_default = load_resource_icon('img/logo.svg', 24) if config['ui']['tray']['updates_icon']: self.icon_updates = QIcon(config['ui']['tray']['updates_icon']) else: self.icon_updates = QIcon.fromTheme('bauh_tray_updates') if self.icon_updates.isNull(): self.icon_updates = load_resource_icon('img/logo_update.svg', 24) self.setIcon(self.icon_default) self.menu = QMenu() self.action_manage = self.menu.addAction( self.i18n['tray.action.manage']) self.action_manage.triggered.connect(self.show_manage_window) self.action_settings = self.menu.addAction( self.i18n['tray.settings'].capitalize()) self.action_settings.triggered.connect(self.show_settings_window) self.action_about = self.menu.addAction(self.i18n['tray.action.about']) self.action_about.triggered.connect(self.show_about) self.action_exit = self.menu.addAction(self.i18n['tray.action.exit']) self.action_exit.triggered.connect(lambda: QCoreApplication.exit()) self.setContextMenu(self.menu) self.manage_window = None self.dialog_about = None self.settings_window = None self.check_lock = Lock() self.check_thread = UpdateCheck(check_interval=int( config['updates']['check_interval']), check_file=False, lock=self.check_lock, logger=logger) self.check_thread.signal.connect(self.notify_updates) self.check_thread.start() self.recheck_thread = UpdateCheck(check_interval=5, check_file=True, lock=self.check_lock, logger=logger) self.recheck_thread.signal.connect(self.notify_updates) self.recheck_thread.start() self.update_thread = AppUpdateCheck(http_client=self.http_client, logger=self.logger, i18n=self.i18n) self.update_thread.start() self.last_updates = set() self.update_notification = bool(config['system']['notifications']) self.lock_notify = Lock() self.activated.connect(self.handle_click) self.set_default_tooltip()
def new_manage_panel(app_args: Namespace, app_config: dict, logger: logging.Logger) -> Tuple[QApplication, QWidget]: i18n = generate_i18n(app_config, resource.get_path('locale')) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=int(app_config['memory_cache']['data_expiration']), cleaner=cache_cleaner) icon_cache = cache_factory.new(int(app_config['memory_cache']['icon_expiration'])) http_client = HttpClient(logger) downloader = AdaptableFileDownloader(logger=logger, multithread_enabled=app_config['download']['multithreaded'], multithread_client=app_config['download']['multithreaded_client'], i18n=i18n, http_client=http_client, check_ssl=app_config['download']['check_ssl']) context = ApplicationContext(i18n=i18n, http_client=http_client, download_icons=bool(app_config['download']['icons']), app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(logger), logger=logger, distro=util.get_distro(), file_downloader=downloader, app_name=__app_name__, app_version=__version__, internet_checker=InternetChecker(offline=app_args.offline), suggestions_mapping=read_suggestions_mapping(), root_user=user.is_root()) managers = gems.load_managers(context=context, locale=i18n.current_key, config=app_config, default_locale=DEFAULT_I18N_KEY, logger=logger) if app_args.reset: util.clean_app_files(managers) exit(0) force_suggestions = bool(app_args.suggestions) manager = GenericSoftwareManager(managers, context=context, config=app_config, force_suggestions=force_suggestions) app = new_qt_application(app_config=app_config, logger=logger, quit_on_last_closed=True) screen_size = app.primaryScreen().size() context.screen_width, context.screen_height = screen_size.width(), screen_size.height() logger.info(f"Screen: {screen_size.width()} x {screen_size.height()} " f"(DPI: {int(app.primaryScreen().logicalDotsPerInch())})") if app_args.settings: # only settings window manager.cache_available_managers() return app, SettingsWindow(manager=manager, i18n=i18n, window=None) else: manage_window = ManageWindow(i18n=i18n, manager=manager, icon_cache=icon_cache, screen_size=screen_size, config=app_config, context=context, http_client=http_client, icon=util.get_default_icon()[1], force_suggestions=force_suggestions, logger=logger) prepare = PreparePanel(screen_size=screen_size, context=context, manager=manager, i18n=i18n, manage_window=manage_window, app_config=app_config, force_suggestions=force_suggestions) cache_cleaner.start() return app, prepare
def main(): if not os.getenv('PYTHONUNBUFFERED'): os.environ['PYTHONUNBUFFERED'] = '1' args = app_args.read() logger = logs.new_logger(__app_name__, bool(args.logs)) app_args.validate(args, logger) i18n_key, i18n = util.get_locale_keys(args.locale) cache_cleaner = CacheCleaner() cache_factory = DefaultMemoryCacheFactory(expiration_time=args.cache_exp, cleaner=cache_cleaner) icon_cache = cache_factory.new(args.icon_exp) context = ApplicationContext(i18n=i18n, http_client=HttpClient(logger), disk_cache=args.disk_cache, download_icons=args.download_icons, app_root_dir=ROOT_DIR, cache_factory=cache_factory, disk_loader_factory=DefaultDiskCacheLoaderFactory(disk_cache_enabled=args.disk_cache, logger=logger), logger=logger, file_downloader=AdaptableFileDownloader(logger, bool(args.download_mthread))) user_config = config.read() app = QApplication(sys.argv) app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) app.setWindowIcon(QIcon(resource.get_path('img/logo.svg'))) if user_config.style: app.setStyle(user_config.style) else: if app.style().objectName().lower() not in {'fusion', 'breeze'}: app.setStyle('Fusion') managers = gems.load_managers(context=context, locale=i18n_key, config=user_config) manager = GenericSoftwareManager(managers, context=context, app_args=args) manager.prepare() manage_window = ManageWindow(i18n=i18n, manager=manager, icon_cache=icon_cache, disk_cache=args.disk_cache, download_icons=bool(args.download_icons), screen_size=app.primaryScreen().size(), suggestions=args.sugs, display_limit=args.max_displayed, config=user_config, context=context, notifications=bool(args.system_notifications)) if args.tray: tray_icon = TrayIcon(i18n=i18n, manager=manager, manage_window=manage_window, check_interval=args.check_interval, update_notification=bool(args.system_notifications)) manage_window.set_tray_icon(tray_icon) tray_icon.show() if args.show_panel: tray_icon.show_manage_window() else: manage_window.refresh_apps() manage_window.show() cache_cleaner.start() sys.exit(app.exec_())