diff --git a/bauh/api/abstract/view.py b/bauh/api/abstract/view.py index 06ead95c..b442c4e1 100644 --- a/bauh/api/abstract/view.py +++ b/bauh/api/abstract/view.py @@ -215,7 +215,8 @@ class FormComponent(ViewComponent): class FileChooserComponent(ViewComponent): def __init__(self, allowed_extensions: Set[str] = None, label: str = None, tooltip: str = None, - file_path: str = None, max_width: int = -1, id_: str = None, search_path: str = None): + file_path: str = None, max_width: int = -1, id_: str = None, search_path: str = None, capitalize_label: bool = True, + directory: bool = False): super(FileChooserComponent, self).__init__(id_=id_) self.label = label self.allowed_extensions = allowed_extensions @@ -223,6 +224,8 @@ class FileChooserComponent(ViewComponent): self.tooltip = tooltip self.max_width = max_width self.search_path = search_path + self.capitalize_label = capitalize_label + self.directory = directory def set_file_path(self, fpath: str): self.file_path = fpath @@ -231,6 +234,12 @@ class FileChooserComponent(ViewComponent): for o in self.observers: o.on_change(self.file_path) + def get_label(self) -> str: + if not self.label: + return '' + else: + return self.label.capitalize() if self.capitalize_label else self.label + class TabComponent(ViewComponent): diff --git a/bauh/gems/arch/controller.py b/bauh/gems/arch/controller.py index db615b10..51b38dc9 100644 --- a/bauh/gems/arch/controller.py +++ b/bauh/gems/arch/controller.py @@ -22,7 +22,8 @@ from bauh.api.abstract.handler import ProcessWatcher, TaskManager from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus, \ SuggestionPriority, CustomSoftwareAction from bauh.api.abstract.view import MessageType, FormComponent, InputOption, SingleSelectComponent, SelectViewType, \ - ViewComponent, PanelComponent, MultipleSelectComponent, TextInputComponent, TextComponent, TextInputType + ViewComponent, PanelComponent, MultipleSelectComponent, TextInputComponent, TextComponent, TextInputType, \ + FileChooserComponent from bauh.api.constants import TEMP_DIR from bauh.commons import user, internet from bauh.commons.category import CategoriesDownloader @@ -2415,7 +2416,7 @@ class ArchManager(SoftwareManager): def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent: local_config = read_config() - max_width = floor(screen_width * 0.22) + max_width = floor(screen_width * 0.25) db_sync_start = self._gen_bool_selector(id_='sync_dbs_start', label_key='arch.config.sync_dbs', @@ -2486,14 +2487,13 @@ class ArchManager(SoftwareManager): max_width=max_width, type_=SelectViewType.RADIO, capitalize_label=False), - TextInputComponent(id_='aur_build_dir', - label=self.i18n['arch.config.aur_build_dir'], - tooltip=self.i18n['arch.config.aur_build_dir.tip'].format(BUILD_DIR), - only_int=False, - max_width=max_width, - value=local_config.get('aur_build_dir', ''), - capitalize_label=False) - + FileChooserComponent(id_='aur_build_dir', + label=self.i18n['arch.config.aur_build_dir'], + tooltip=self.i18n['arch.config.aur_build_dir.tip'].format(BUILD_DIR), + max_width=max_width, + file_path=local_config['aur_build_dir'], + capitalize_label=False, + directory=True) ] return PanelComponent([FormComponent(fields, spaces=False)]) @@ -2513,7 +2513,7 @@ class ArchManager(SoftwareManager): config['repositories_mthread_download'] = form_install.get_component('mthread_download').get_selected() config['automatch_providers'] = form_install.get_component('autoprovs').get_selected() config['edit_aur_pkgbuild'] = form_install.get_component('edit_aur_pkgbuild').get_selected() - config['aur_build_dir'] = form_install.get_component('aur_build_dir').get_value().strip() + config['aur_build_dir'] = form_install.get_component('aur_build_dir').file_path if not config['aur_build_dir']: config['aur_build_dir'] = None diff --git a/bauh/view/qt/components.py b/bauh/view/qt/components.py index 616e754c..d6f7bdd7 100644 --- a/bauh/view/qt/components.py +++ b/bauh/view/qt/components.py @@ -768,8 +768,11 @@ class FormQt(QGroupBox): if hasattr(comp, 'size') and comp.size is not None: label_comp.setStyleSheet("QLabel { font-size: " + str(comp.size) + "px }") - attr = 'label' if hasattr(comp,'label') else 'value' - text = getattr(comp, attr) + if hasattr(comp, 'get_label'): + text = comp.get_label() + else: + attr = 'label' if hasattr(comp,'label') else 'value' + text = getattr(comp, attr) if text: if hasattr(comp, 'capitalize_label') and getattr(comp, 'capitalize_label'): @@ -868,17 +871,16 @@ class FormQt(QGroupBox): if c.file_path: chooser.setText(c.file_path) + chooser.setCursorPosition(0) c.observers.append(chooser) chooser.setPlaceholderText(self.i18n['view.components.file_chooser.placeholder']) def open_chooser(e): - options = QFileDialog.Options() - if c.allowed_extensions: exts = ';;'.join({'*.{}'.format(e) for e in c.allowed_extensions}) else: - exts = '{}} (*);;'.format(self.i18n['all_files'].capitalize()) + exts = '{} (*);;'.format(self.i18n['all_files'].capitalize()) if c.file_path and os.path.isfile(c.file_path): cur_path = c.file_path @@ -887,7 +889,10 @@ class FormQt(QGroupBox): else: cur_path = str(Path.home()) - file_path, _ = QFileDialog.getOpenFileName(self, self.i18n['file_chooser.title'], cur_path, exts, options=options) + if c.directory: + file_path = QFileDialog.getExistingDirectory(self, self.i18n['file_chooser.title'], cur_path, options=QFileDialog.Options()) + else: + file_path, _ = QFileDialog.getOpenFileName(self, self.i18n['file_chooser.title'], cur_path, exts, options=QFileDialog.Options()) if file_path: c.set_file_path(file_path)