From b15420625ee3ff63ab570c7eee4caf6e9a50233f Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Sat, 31 Aug 2019 23:32:31 -0300 Subject: [PATCH] filter by app name --- bauh/app_args.py | 2 +- bauh/resources/locale/en | 1 + bauh/resources/locale/es | 3 ++- bauh/resources/locale/pt | 3 ++- bauh/view/qt/components.py | 15 ++++++++++++++- bauh/view/qt/window.py | 23 +++++++++++++++++++++-- 6 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bauh/app_args.py b/bauh/app_args.py index 5de076a7..be69a314 100644 --- a/bauh/app_args.py +++ b/bauh/app_args.py @@ -42,7 +42,7 @@ def read() -> Namespace: parser.add_argument('--tray', action="store", default=os.getenv('BAUH_TRAY', 0), choices=[0, 1], type=int, help='If the tray icon and update-check daemon should be created. Default: %(default)s') parser.add_argument('--sugs', action="store", default=os.getenv('BAUH_SUGGESTIONS', 1), choices=[0, 1], type=int, help='If app suggestions should be displayed if no application package is installed (runtimes / libraries do not count as apps). Default: %(default)s') - parser.add_argument('-md', '--max-displayed', action="store", default=os.getenv('BAUH_MAX_DISPLAYED', 200), choices=[0, 1], type=int, help='Maximum number of displayed packages in the management panel table. Default: %(default)s') + parser.add_argument('-md', '--max-displayed', action="store", default=os.getenv('BAUH_MAX_DISPLAYED', 100), choices=[0, 1], type=int, help='Maximum number of displayed packages in the management panel table. Default: %(default)s') args = parser.parse_args() if args.cache_exp < 0: diff --git a/bauh/resources/locale/en b/bauh/resources/locale/en index a853af1c..34824305 100644 --- a/bauh/resources/locale/en +++ b/bauh/resources/locale/en @@ -98,3 +98,4 @@ cancel=cancel status.caching_data=Caching {} data to disk action.run.tooltip=Click here to launch this application any=any +manage_window.name_filter.tooltip=Escriba aquí para encontrar una aplicación por su nombre diff --git a/bauh/resources/locale/es b/bauh/resources/locale/es index b99e1422..abd6965f 100644 --- a/bauh/resources/locale/es +++ b/bauh/resources/locale/es @@ -99,4 +99,5 @@ ask.continue=¿Continuar ? cancel=cancelar status.caching_data=Cacheando los datos de {} para el disco action.run.tooltip=Haces clic aqui para iniciar este aplicativo -any=cualquier \ No newline at end of file +any=cualquier +manage_window.name_filter.tooltip=Digite aqui para encontrar um aplicativo pelo nome \ No newline at end of file diff --git a/bauh/resources/locale/pt b/bauh/resources/locale/pt index 08c134ba..d157b45a 100644 --- a/bauh/resources/locale/pt +++ b/bauh/resources/locale/pt @@ -99,4 +99,5 @@ ask.continue=Continuar ? cancel=cancelar status.caching_data=Cacheando dados de {} para o disco action.run.tooltip=Clique aqui para iniciar esse aplicativo -any=qualquer \ No newline at end of file +any=qualquer +manage_window.name_filter.tooltip=Digite aqui para encontrar um aplicativo pelo nome \ No newline at end of file diff --git a/bauh/view/qt/components.py b/bauh/view/qt/components.py index 1721653f..7005736f 100644 --- a/bauh/view/qt/components.py +++ b/bauh/view/qt/components.py @@ -1,5 +1,6 @@ +from PyQt5.QtCore import QEvent, Qt from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \ - QLabel, QSizePolicy + QLabel, QSizePolicy, QLineEdit from bauh_api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType @@ -126,6 +127,18 @@ class MultipleSelectQt(QGroupBox): col += 1 +class InputFilter(QLineEdit): + + def __init__(self, on_key_press): + super(InputFilter, self).__init__() + self.on_key_press = on_key_press + + def keyPressEvent(self, event): + super(InputFilter, self).keyPressEvent(event) + if event.key() != Qt.EnterKeyReturn: + self.on_key_press(self.text()) + + def new_single_select(model: SingleSelectComponent): if model.type == SelectViewType.RADIO: return RadioSelectQt(model) diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 3f308c08..88a0c876 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -16,7 +16,7 @@ from bauh.util import util from bauh.view.qt import dialog from bauh.view.qt.about import AboutDialog from bauh.view.qt.apps_table import AppsTable, UpdateToggleButton -from bauh.view.qt.components import new_spacer +from bauh.view.qt.components import new_spacer, InputFilter from bauh.view.qt.confirmation import ConfirmationDialog from bauh.view.qt.history import HistoryDialog from bauh.view.qt.info import InfoDialog @@ -119,6 +119,14 @@ class ManageWindow(QWidget): self.combo_filter_type.addItem(load_icon(resource.get_path('img/logo.svg'), 14), self.locale_keys[self.any_type_filter].capitalize(), self.any_type_filter) self.ref_combo_filter_type = self.toolbar.addWidget(self.combo_filter_type) + self.input_name_filter = InputFilter(self._filter_by_name) + self.input_name_filter.setMaxLength(10) + self.input_name_filter.setPlaceholderText(self.locale_keys['name'].capitalize() + ',,,') + self.input_name_filter.setToolTip(self.locale_keys['manage_window.name_filter.tooltip']) + self.input_name_filter.setStyleSheet("QLineEdit { background-color: white; color: gray;}") + self.input_name_filter.setMaximumWidth(120) + self.ref_input_name_filter = self.toolbar.addWidget(self.input_name_filter) + self.toolbar.addWidget(new_spacer()) self.bt_installed = QPushButton() @@ -238,6 +246,9 @@ class ManageWindow(QWidget): self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys) self.thread_warnings.signal_warnings.connect(self._show_warnings) + def _filter_by_name(self, words: str): + self.apply_filters() + def _bind_async_action(self, action: AsyncAction, finished_call, only_finished: bool = False) -> AsyncAction: action.signal_finished.connect(finished_call) @@ -447,6 +458,7 @@ class ManageWindow(QWidget): if self.pkgs_available: pkgs_displayed = [] displayed = 0 + starts_with_lower = self.input_name_filter.text().lower() if self.input_name_filter.text() else None for idx, app_v in enumerate(self.pkgs_available): hidden = self.filter_only_apps and not app_v.model.is_application() @@ -456,7 +468,9 @@ class ManageWindow(QWidget): if not hidden and self.filter_updates: hidden = not app_v.model.update - # self.table_apps.setRowHidden(idx, hidden) + if not hidden and starts_with_lower: + hidden = not app_v.model.base_data.name.lower().startswith(starts_with_lower) + app_v.visible = not hidden if not hidden and displayed < self.display_limit: @@ -464,6 +478,7 @@ class ManageWindow(QWidget): displayed += 1 self.pkgs = pkgs_displayed + self.table_apps.update_apps(pkgs_displayed, update_check_enabled=update_check_enabled) self.change_update_state(change_filters=False) @@ -599,6 +614,9 @@ class ManageWindow(QWidget): self.checkbox_only_apps.setCheckable(True) self.checkbox_only_apps.setChecked(True) + if self.pkgs: + self.ref_input_name_filter.setVisible(True) + self._update_type_filters(pkgs_info['available_types']) self.apply_filters(update_check_enabled=update_check_enabled) self.change_update_state() @@ -693,6 +711,7 @@ class ManageWindow(QWidget): self.textarea_output.appendPlainText(output) def _begin_action(self, action_label: str, keep_search: bool = False, clear_filters: bool = False): + self.ref_input_name_filter.setVisible(False) self.ref_combo_filter_type.setVisible(False) self.ref_bt_about.setVisible(False) self.ref_label_updates.setVisible(False)