[arch] -> improvement: 'aur_build_dir' property rendered as a file chooser

This commit is contained in:
Vinicius Moreira
2020-08-18 18:41:27 -03:00
parent befcc79cb0
commit e20bfe461b
3 changed files with 32 additions and 18 deletions

View File

@@ -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):

View File

@@ -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

View File

@@ -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)