def get_locale_keys(key: str = None): locale_path = None if key is None: current_locale = locale.getdefaultlocale() else: current_locale = [key.strip().lower()] if current_locale: current_locale = current_locale[0] locale_dir = resource.get_path('locale') for locale_file in glob.glob(locale_dir + '/*'): name = locale_file.split('/')[-1] if current_locale == name or current_locale.startswith(name + '_'): locale_path = locale_file break if not locale_path: locale_path = resource.get_path('locale/en') with open(locale_path, 'r') as f: locale_keys = f.readlines() locale_obj = {} for line in locale_keys: if line: keyval = line.strip().split('=') locale_obj[keyval[0].strip()] = keyval[1].strip() return locale_obj
def show_app_settings(self, app: ApplicationView): menu_row = QMenu() if app.model.installed: if app.model.can_be_refreshed(): action_history = QAction(self.window.locale_keys[ "manage_window.apps_table.row.actions.refresh"]) action_history.setIcon( QIcon(resource.get_path('img/refresh.svg'))) def refresh(): self.window.refresh(app) action_history.triggered.connect(refresh) menu_row.addAction(action_history) if app.model.has_history(): action_history = QAction(self.window.locale_keys[ "manage_window.apps_table.row.actions.history"]) action_history.setIcon( QIcon(resource.get_path('img/history.svg'))) def show_history(): self.window.get_app_history(app) action_history.triggered.connect(show_history) menu_row.addAction(action_history) if app.model.can_be_downgraded(): action_downgrade = QAction(self.window.locale_keys[ "manage_window.apps_table.row.actions.downgrade"]) def downgrade(): if dialog.ask_confirmation( title=self.window.locale_keys[ 'manage_window.apps_table.row.actions.downgrade'], body=self.window.locale_keys[ 'manage_window.apps_table.row.actions.downgrade.popup.body'] .format(app.model.base_data.name), locale_keys=self.window.locale_keys): self.window.downgrade_app(app) action_downgrade.triggered.connect(downgrade) action_downgrade.setIcon( QIcon(resource.get_path('img/downgrade.svg'))) menu_row.addAction(action_downgrade) menu_row.adjustSize() menu_row.popup(QCursor.pos()) menu_row.exec_()
def __init__(self, app_view: ApplicationView, root: QWidget, locale_keys: dict, checked: bool = True): super(UpdateToggleButton, self).__init__() self.app_view = app_view self.root = root layout = QHBoxLayout() layout.setContentsMargins(2, 2, 2, 0) layout.setAlignment(Qt.AlignCenter) self.setLayout(layout) self.bt = QToolButton() self.bt.setCheckable(True) self.bt.clicked.connect(self.change_state) self.bt.setIcon(QIcon(resource.get_path('img/app_update.svg'))) self.bt.setStyleSheet('QToolButton { background: #4EC306 } ' + 'QToolButton:checked { background: gray }') layout.addWidget(self.bt) self.setToolTip( locale_keys['manage_window.apps_table.upgrade_toggle.tooltip']) if not checked: self.bt.click()
def _set_col_installed(self, idx: int, app_v: ApplicationView): if app_v.model.installed: if app_v.model.can_be_uninstalled(): def uninstall(): self._uninstall_app(app_v) col = self._gen_row_button( self.window.locale_keys['uninstall'].capitalize(), INSTALL_BT_STYLE.format(back='#cc0000'), uninstall) else: col = QLabel() col.setPixmap((QPixmap(resource.get_path('img/checked.svg')))) col.setAlignment(Qt.AlignCenter) col.setToolTip(self.window.locale_keys['installed']) elif app_v.model.can_be_installed(): def install(): self._install_app(app_v) col = self._gen_row_button( self.window.locale_keys['install'].capitalize(), INSTALL_BT_STYLE.format(back='#088A08'), install) else: col = None self.setCellWidget(idx, 4, col)
def __init__(self, locale_keys: dict): super(AboutDialog, self).__init__() self.setWindowTitle(locale_keys['tray.action.about']) layout = QVBoxLayout() self.setLayout(layout) label_logo = QLabel(self) label_logo.setPixmap(QPixmap(resource.get_path('img/logo.svg'))) label_logo.setAlignment(Qt.AlignCenter) layout.addWidget(label_logo) label_name = QLabel('{} ( {} {} )'.format( __app_name__, locale_keys['flatpak.info.version'].lower(), __version__)) label_name.setStyleSheet('font-weight: bold;') label_name.setAlignment(Qt.AlignCenter) layout.addWidget(label_name) layout.addWidget(QLabel('')) line_desc = QLabel(self) line_desc.setStyleSheet('font-size: 10px; font-weight: bold;') line_desc.setText(locale_keys['about.info.desc']) line_desc.setAlignment(Qt.AlignCenter) line_desc.setMinimumWidth(400) layout.addWidget(line_desc) layout.addWidget(QLabel('')) label_more_info = QLabel() label_more_info.setStyleSheet('font-size: 9px;') label_more_info.setText(locale_keys['about.info.link'] + ": <a href='{url}'>{url}</a>".format( url=PROJECT_URL)) label_more_info.setOpenExternalLinks(True) label_more_info.setAlignment(Qt.AlignCenter) layout.addWidget(label_more_info) label_license = QLabel() label_license.setStyleSheet('font-size: 9px;') label_license.setText("<a href='{}'>{}</a>".format( LICENSE_URL, locale_keys['about.info.license'])) label_license.setOpenExternalLinks(True) label_license.setAlignment(Qt.AlignCenter) layout.addWidget(label_license) layout.addWidget(QLabel('')) label_rate = QLabel() label_rate.setStyleSheet('font-size: 9px; font-weight: bold;') label_rate.setText(locale_keys['about.info.rate'] + ' :)') label_rate.setOpenExternalLinks(True) label_rate.setAlignment(Qt.AlignCenter) layout.addWidget(label_rate) layout.addWidget(QLabel('')) self.adjustSize() self.setFixedSize(self.size())
def show_error(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))): error_msg = QMessageBox() error_msg.setIcon(QMessageBox.Critical) error_msg.setWindowTitle(title) error_msg.setText(body) if icon: error_msg.setWindowIcon(icon) error_msg.exec_()
def show_warning(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))): msg = QMessageBox() msg.setIcon(QMessageBox.Warning) msg.setWindowTitle(title) msg.setText(body) if icon: msg.setWindowIcon(icon) msg.exec_()
def __init__(self, parent: QWidget, icon_cache: Cache, disk_cache: bool, download_icons: bool): super(AppsTable, self).__init__() self.setParent(parent) self.window = parent self.disk_cache = disk_cache self.download_icons = download_icons self.column_names = ['' for _ in range(7)] self.setColumnCount(len(self.column_names)) self.setFocusPolicy(Qt.NoFocus) self.setShowGrid(False) self.verticalHeader().setVisible(False) self.horizontalHeader().setVisible(False) self.setSelectionBehavior(QTableView.SelectRows) self.setHorizontalHeaderLabels(self.column_names) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.icon_flathub = QIcon(resource.get_path('img/flathub.svg')) self.icon_logo = QIcon(resource.get_path('img/logo.svg')) self.network_man = QNetworkAccessManager() self.network_man.finished.connect(self._load_icon_and_cache) self.icon_cache = icon_cache self.lock_async_data = Lock()
def _set_col_settings(self, idx: int, app_v: ApplicationView): tb = QToolBar() if app_v.model.has_info(): def get_info(): self.window.get_app_info(app_v) tb.addWidget( IconButton(icon_path=resource.get_path('img/app_info.svg'), action=get_info, background='#2E68D3')) def handle_click(): self.show_app_settings(app_v) if self.has_any_settings(app_v): bt = IconButton( icon_path=resource.get_path('img/app_settings.svg'), action=handle_click, background='#12ABAB') tb.addWidget(bt) self.setCellWidget(idx, 5, tb)
def __init__(self, locale_keys: dict, manager: ApplicationManager, manage_window: ManageWindow, check_interval: int = 60, update_notification: bool = True): super(TrayIcon, self).__init__() self.locale_keys = locale_keys self.manager = manager self.icon_default = QIcon(resource.get_path('img/logo.png')) self.icon_update = QIcon(resource.get_path('img/logo_update.png')) self.setIcon(self.icon_default) self.menu = QMenu() self.action_manage = self.menu.addAction(self.locale_keys['tray.action.manage']) self.action_manage.triggered.connect(self.show_manage_window) self.action_about = self.menu.addAction(self.locale_keys['tray.action.about']) self.action_about.triggered.connect(self.show_about) self.action_exit = self.menu.addAction(self.locale_keys['tray.action.exit']) self.action_exit.triggered.connect(lambda: QCoreApplication.exit()) self.setContextMenu(self.menu) self.manage_window = None self.dialog_about = None self.check_thread = UpdateCheck(check_interval=check_interval, manager=self.manager) self.check_thread.signal.connect(self.notify_updates) self.check_thread.start() self.last_updates = set() self.update_notification = update_notification self.lock_notify = Lock() self.activated.connect(self.handle_click) self.set_default_tooltip() self.manage_window = manage_window
def change_update_state(self, change_filters: bool = True): enable_bt_update = False app_updates, library_updates, not_installed = 0, 0, 0 for app_v in self.apps: if app_v.model.update: if app_v.model.runtime: library_updates += 1 else: app_updates += 1 if not app_v.model.installed: not_installed += 1 for app_v in self.apps: if not_installed == 0 and app_v.visible and app_v.update_checked: enable_bt_update = True break self.bt_upgrade.setEnabled(enable_bt_update) total_updates = app_updates + library_updates if total_updates > 0: self.label_updates.setPixmap( QPixmap(resource.get_path('img/exclamation.svg')).scaled( 16, 16, Qt.KeepAspectRatio, Qt.SmoothTransformation)) self.label_updates.setToolTip('{}: {} ( {} {} | {} {} )'.format( self.locale_keys['manage_window.label.updates'], total_updates, app_updates, self.locale_keys['manage_window.checkbox.only_apps'].lower(), library_updates, self.locale_keys['others'].lower())) if not_installed == 0: if not self.ref_checkbox_updates.isVisible(): self.ref_checkbox_updates.setVisible(True) if change_filters and not self.checkbox_updates.isChecked(): self.checkbox_updates.setChecked(True) if change_filters and library_updates > 0 and self.checkbox_only_apps.isChecked( ): self.checkbox_only_apps.setChecked(False) else: self.checkbox_updates.setChecked(False) self.ref_checkbox_updates.setVisible(False) self.label_updates.setPixmap(QPixmap())
def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))): dialog_confirmation = QMessageBox() dialog_confirmation.setIcon(QMessageBox.Question) dialog_confirmation.setWindowTitle(title) dialog_confirmation.setText(body) dialog_confirmation.setStyleSheet('QLabel { margin-right: 25px; }') bt_yes = dialog_confirmation.addButton(locale_keys['popup.button.yes'], QMessageBox.YesRole) dialog_confirmation.addButton(locale_keys['popup.button.no'], QMessageBox.NoRole) if icon: dialog_confirmation.setWindowIcon(icon) dialog_confirmation.exec_() return dialog_confirmation.clickedButton() == bt_yes
Path(SNAP_CACHE_PATH).mkdir(parents=True, exist_ok=True) icon_cache = Cache(expiration_time=args.icon_exp) caches.append(icon_cache) disk_loader_factory = DiskCacheLoaderFactory(disk_cache=args.disk_cache, cache_map=cache_map) manager = GenericApplicationManager(managers, disk_loader_factory=disk_loader_factory, app_args=args) manager.prepare() app = QApplication(sys.argv) app.setApplicationName(__app_name__) app.setApplicationVersion(__version__) app.setWindowIcon(QIcon(resource.get_path('img/logo.svg'))) screen_size = app.primaryScreen().size() manage_window = ManageWindow(locale_keys=locale_keys, manager=manager, icon_cache=icon_cache, disk_cache=args.disk_cache, download_icons=bool(args.download_icons), screen_size=screen_size, suggestions=args.sugs) if args.tray: trayIcon = TrayIcon(locale_keys=locale_keys, manager=manager, manage_window=manage_window,
def get_default_icon_path(self): return resource.get_path('img/flathub.svg')
def __init__(self, locale_keys: dict, icon_cache: Cache, manager: ApplicationManager, disk_cache: bool, download_icons: bool, screen_size, suggestions: bool, tray_icon=None): super(ManageWindow, self).__init__() self.locale_keys = locale_keys self.manager = manager self.tray_icon = tray_icon self.working = False # restrict the number of threaded actions self.apps = [] self.label_flatpak = None self.icon_cache = icon_cache self.disk_cache = disk_cache self.download_icons = download_icons self.screen_size = screen_size self.icon_flathub = QIcon(resource.get_path('img/logo.svg')) self.resize(ManageWindow.__BASE_HEIGHT__, ManageWindow.__BASE_HEIGHT__) self.setWindowIcon(self.icon_flathub) self.layout = QVBoxLayout() self.setLayout(self.layout) self.toolbar_top = QToolBar() self.toolbar_top.addWidget(self._new_spacer()) self.label_status = QLabel() self.label_status.setText('') self.label_status.setStyleSheet("font-weight: bold") self.toolbar_top.addWidget(self.label_status) self.toolbar_search = QToolBar() self.toolbar_search.setStyleSheet("spacing: 0px;") self.toolbar_search.setContentsMargins(0, 0, 0, 0) label_pre_search = QLabel() label_pre_search.setStyleSheet( "background: white; border-top-left-radius: 5px; border-bottom-left-radius: 5px;" ) self.toolbar_search.addWidget(label_pre_search) self.input_search = QLineEdit() self.input_search.setMaxLength(20) self.input_search.setFrame(False) self.input_search.setPlaceholderText( self.locale_keys['window_manage.input_search.placeholder'] + "...") self.input_search.setToolTip( self.locale_keys['window_manage.input_search.tooltip']) self.input_search.setStyleSheet( "QLineEdit { background-color: white; color: gray; spacing: 0;}") self.input_search.returnPressed.connect(self.search) self.toolbar_search.addWidget(self.input_search) label_pos_search = QLabel() label_pos_search.setPixmap(QPixmap( resource.get_path('img/search.svg'))) label_pos_search.setStyleSheet( "background: white; padding-right: 10px; border-top-right-radius: 5px; border-bottom-right-radius: 5px;" ) self.toolbar_search.addWidget(label_pos_search) self.ref_toolbar_search = self.toolbar_top.addWidget( self.toolbar_search) self.toolbar_top.addWidget(self._new_spacer()) self.layout.addWidget(self.toolbar_top) toolbar = QToolBar() self.checkbox_updates = QCheckBox() self.checkbox_updates.setText(self.locale_keys['updates'].capitalize()) self.checkbox_updates.stateChanged.connect(self._handle_updates_filter) self.ref_checkbox_updates = toolbar.addWidget(self.checkbox_updates) self.checkbox_only_apps = QCheckBox() self.checkbox_only_apps.setText( self.locale_keys['manage_window.checkbox.only_apps']) self.checkbox_only_apps.setChecked(True) self.checkbox_only_apps.stateChanged.connect( self._handle_filter_only_apps) self.ref_checkbox_only_apps = toolbar.addWidget( self.checkbox_only_apps) self.extra_filters = QWidget() self.extra_filters.setLayout(QHBoxLayout()) toolbar.addWidget(self.extra_filters) toolbar.addWidget(self._new_spacer()) self.bt_refresh = QToolButton() self.bt_refresh.setToolTip( locale_keys['manage_window.bt.refresh.tooltip']) self.bt_refresh.setIcon(QIcon(resource.get_path('img/refresh.svg'))) self.bt_refresh.clicked.connect( lambda: self.refresh_apps(keep_console=False)) toolbar.addWidget(self.bt_refresh) self.bt_upgrade = QToolButton() self.bt_upgrade.setToolTip( locale_keys['manage_window.bt.upgrade.tooltip']) self.bt_upgrade.setIcon( QIcon(resource.get_path('img/update_green.svg'))) self.bt_upgrade.setEnabled(False) self.bt_upgrade.clicked.connect(self.update_selected) self.ref_bt_upgrade = toolbar.addWidget(self.bt_upgrade) self.layout.addWidget(toolbar) self.table_apps = AppsTable(self, self.icon_cache, disk_cache=self.disk_cache, download_icons=self.download_icons) self.table_apps.change_headers_policy() self.layout.addWidget(self.table_apps) toolbar_console = QToolBar() self.checkbox_console = QCheckBox() self.checkbox_console.setText( self.locale_keys['manage_window.checkbox.show_details']) self.checkbox_console.stateChanged.connect(self._handle_console) self.checkbox_console.setVisible(False) self.ref_checkbox_console = toolbar_console.addWidget( self.checkbox_console) toolbar_console.addWidget(self._new_spacer()) self.layout.addWidget(toolbar_console) self.textarea_output = QPlainTextEdit(self) self.textarea_output.resize(self.table_apps.size()) self.textarea_output.setStyleSheet("background: black; color: white;") self.layout.addWidget(self.textarea_output) self.textarea_output.setVisible(False) self.textarea_output.setReadOnly(True) self.thread_update = UpdateSelectedApps(self.manager) self.thread_update.signal_output.connect(self._update_action_output) self.thread_update.signal_finished.connect( self._finish_update_selected) self.thread_update.signal_status.connect( self._change_updating_app_status) self.thread_refresh = RefreshApps(self.manager) self.thread_refresh.signal.connect(self._finish_refresh_apps) self.thread_uninstall = UninstallApp(self.manager, self.icon_cache) self.thread_uninstall.signal_output.connect(self._update_action_output) self.thread_uninstall.signal_finished.connect(self._finish_uninstall) self.thread_downgrade = DowngradeApp(self.manager, self.locale_keys) self.thread_downgrade.signal_output.connect(self._update_action_output) self.thread_downgrade.signal_finished.connect(self._finish_downgrade) self.thread_get_info = GetAppInfo(self.manager) self.thread_get_info.signal_finished.connect(self._finish_get_info) self.thread_get_history = GetAppHistory(self.manager, self.locale_keys) self.thread_get_history.signal_finished.connect( self._finish_get_history) self.thread_search = SearchApps(self.manager) self.thread_search.signal_finished.connect(self._finish_search) self.thread_install = InstallApp(manager=self.manager, disk_cache=self.disk_cache, icon_cache=self.icon_cache, locale_keys=self.locale_keys) self.thread_install.signal_output.connect(self._update_action_output) self.thread_install.signal_finished.connect(self._finish_install) self.thread_animate_progress = AnimateProgress() self.thread_animate_progress.signal_change.connect( self._update_progress) self.thread_verify_models = VerifyModels() self.thread_verify_models.signal_updates.connect( self._notify_model_data_change) self.thread_refresh_app = RefreshApp(manager=self.manager) self.thread_refresh_app.signal_finished.connect(self._finish_refresh) self.thread_refresh_app.signal_output.connect( self._update_action_output) self.thread_suggestions = FindSuggestions(man=self.manager) self.thread_suggestions.signal_finished.connect(self._finish_search) self.toolbar_bottom = QToolBar() self.toolbar_bottom.setIconSize(QSize(16, 16)) self.label_updates = QLabel() self.ref_label_updates = self.toolbar_bottom.addWidget( self.label_updates) self.toolbar_bottom.addWidget(self._new_spacer()) self.progress_bar = QProgressBar() self.progress_bar.setTextVisible(False) self.ref_progress_bar = self.toolbar_bottom.addWidget( self.progress_bar) self.toolbar_bottom.addWidget(self._new_spacer()) bt_about = QToolButton() bt_about.setStyleSheet('QToolButton { border: 0px; }') bt_about.setIcon(QIcon(resource.get_path('img/about.svg'))) bt_about.clicked.connect(self._show_about) bt_about.setToolTip(self.locale_keys['manage_window.bt_about.tooltip']) self.ref_bt_about = self.toolbar_bottom.addWidget(bt_about) self.layout.addWidget(self.toolbar_bottom) self.centralize() self.filter_only_apps = True self.filter_types = set() self.filter_updates = False self._maximized = False self.dialog_about = None self.first_refresh = suggestions self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys) self.thread_warnings.signal_warnings.connect(self._show_warnings)
def get_default_icon_path(self): return resource.get_path('img/logo.svg')
def get_default_icon_path(self): return resource.get_path('img/snapcraft.png')
def notify_user(msg: str, icon_path: str = resource.get_path('img/logo.svg')): os.system("notify-send -a {} {} '{}'".format(__app_name__, "-i {}".format(icon_path) if icon_path else '', msg))