filter by app name

This commit is contained in:
Vinicius Moreira
2019-08-31 23:32:31 -03:00
parent 1c1527a5cd
commit b15420625e
6 changed files with 41 additions and 6 deletions

View File

@@ -42,7 +42,7 @@ def read() -> Namespace:
parser.add_argument('--tray', action="store", default=os.getenv('BAUH_TRAY', 0), choices=[0, 1], type=int, 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') 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('--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() args = parser.parse_args()
if args.cache_exp < 0: if args.cache_exp < 0:

View File

@@ -98,3 +98,4 @@ cancel=cancel
status.caching_data=Caching {} data to disk status.caching_data=Caching {} data to disk
action.run.tooltip=Click here to launch this application action.run.tooltip=Click here to launch this application
any=any any=any
manage_window.name_filter.tooltip=Escriba aquí para encontrar una aplicación por su nombre

View File

@@ -99,4 +99,5 @@ ask.continue=¿Continuar ?
cancel=cancelar cancel=cancelar
status.caching_data=Cacheando los datos de {} para el disco status.caching_data=Cacheando los datos de {} para el disco
action.run.tooltip=Haces clic aqui para iniciar este aplicativo action.run.tooltip=Haces clic aqui para iniciar este aplicativo
any=cualquier any=cualquier
manage_window.name_filter.tooltip=Digite aqui para encontrar um aplicativo pelo nome

View File

@@ -99,4 +99,5 @@ ask.continue=Continuar ?
cancel=cancelar cancel=cancelar
status.caching_data=Cacheando dados de {} para o disco status.caching_data=Cacheando dados de {} para o disco
action.run.tooltip=Clique aqui para iniciar esse aplicativo action.run.tooltip=Clique aqui para iniciar esse aplicativo
any=qualquer any=qualquer
manage_window.name_filter.tooltip=Digite aqui para encontrar um aplicativo pelo nome

View File

@@ -1,5 +1,6 @@
from PyQt5.QtCore import QEvent, Qt
from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \ 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 from bauh_api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType
@@ -126,6 +127,18 @@ class MultipleSelectQt(QGroupBox):
col += 1 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): def new_single_select(model: SingleSelectComponent):
if model.type == SelectViewType.RADIO: if model.type == SelectViewType.RADIO:
return RadioSelectQt(model) return RadioSelectQt(model)

View File

@@ -16,7 +16,7 @@ from bauh.util import util
from bauh.view.qt import dialog from bauh.view.qt import dialog
from bauh.view.qt.about import AboutDialog from bauh.view.qt.about import AboutDialog
from bauh.view.qt.apps_table import AppsTable, UpdateToggleButton 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.confirmation import ConfirmationDialog
from bauh.view.qt.history import HistoryDialog from bauh.view.qt.history import HistoryDialog
from bauh.view.qt.info import InfoDialog 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.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.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.toolbar.addWidget(new_spacer())
self.bt_installed = QPushButton() self.bt_installed = QPushButton()
@@ -238,6 +246,9 @@ class ManageWindow(QWidget):
self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys) self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys)
self.thread_warnings.signal_warnings.connect(self._show_warnings) 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: def _bind_async_action(self, action: AsyncAction, finished_call, only_finished: bool = False) -> AsyncAction:
action.signal_finished.connect(finished_call) action.signal_finished.connect(finished_call)
@@ -447,6 +458,7 @@ class ManageWindow(QWidget):
if self.pkgs_available: if self.pkgs_available:
pkgs_displayed = [] pkgs_displayed = []
displayed = 0 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): for idx, app_v in enumerate(self.pkgs_available):
hidden = self.filter_only_apps and not app_v.model.is_application() 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: if not hidden and self.filter_updates:
hidden = not app_v.model.update 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 app_v.visible = not hidden
if not hidden and displayed < self.display_limit: if not hidden and displayed < self.display_limit:
@@ -464,6 +478,7 @@ class ManageWindow(QWidget):
displayed += 1 displayed += 1
self.pkgs = pkgs_displayed self.pkgs = pkgs_displayed
self.table_apps.update_apps(pkgs_displayed, update_check_enabled=update_check_enabled) self.table_apps.update_apps(pkgs_displayed, update_check_enabled=update_check_enabled)
self.change_update_state(change_filters=False) self.change_update_state(change_filters=False)
@@ -599,6 +614,9 @@ class ManageWindow(QWidget):
self.checkbox_only_apps.setCheckable(True) self.checkbox_only_apps.setCheckable(True)
self.checkbox_only_apps.setChecked(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._update_type_filters(pkgs_info['available_types'])
self.apply_filters(update_check_enabled=update_check_enabled) self.apply_filters(update_check_enabled=update_check_enabled)
self.change_update_state() self.change_update_state()
@@ -693,6 +711,7 @@ class ManageWindow(QWidget):
self.textarea_output.appendPlainText(output) self.textarea_output.appendPlainText(output)
def _begin_action(self, action_label: str, keep_search: bool = False, clear_filters: bool = False): 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_combo_filter_type.setVisible(False)
self.ref_bt_about.setVisible(False) self.ref_bt_about.setVisible(False)
self.ref_label_updates.setVisible(False) self.ref_label_updates.setVisible(False)