mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 23:34:17 +02:00
[arch] -> improvement: 'aur_build_dir' property rendered as a file chooser
This commit is contained in:
@@ -215,7 +215,8 @@ class FormComponent(ViewComponent):
|
|||||||
class FileChooserComponent(ViewComponent):
|
class FileChooserComponent(ViewComponent):
|
||||||
|
|
||||||
def __init__(self, allowed_extensions: Set[str] = None, label: str = None, tooltip: str = None,
|
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_)
|
super(FileChooserComponent, self).__init__(id_=id_)
|
||||||
self.label = label
|
self.label = label
|
||||||
self.allowed_extensions = allowed_extensions
|
self.allowed_extensions = allowed_extensions
|
||||||
@@ -223,6 +224,8 @@ class FileChooserComponent(ViewComponent):
|
|||||||
self.tooltip = tooltip
|
self.tooltip = tooltip
|
||||||
self.max_width = max_width
|
self.max_width = max_width
|
||||||
self.search_path = search_path
|
self.search_path = search_path
|
||||||
|
self.capitalize_label = capitalize_label
|
||||||
|
self.directory = directory
|
||||||
|
|
||||||
def set_file_path(self, fpath: str):
|
def set_file_path(self, fpath: str):
|
||||||
self.file_path = fpath
|
self.file_path = fpath
|
||||||
@@ -231,6 +234,12 @@ class FileChooserComponent(ViewComponent):
|
|||||||
for o in self.observers:
|
for o in self.observers:
|
||||||
o.on_change(self.file_path)
|
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):
|
class TabComponent(ViewComponent):
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ from bauh.api.abstract.handler import ProcessWatcher, TaskManager
|
|||||||
from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus, \
|
from bauh.api.abstract.model import PackageUpdate, PackageHistory, SoftwarePackage, PackageSuggestion, PackageStatus, \
|
||||||
SuggestionPriority, CustomSoftwareAction
|
SuggestionPriority, CustomSoftwareAction
|
||||||
from bauh.api.abstract.view import MessageType, FormComponent, InputOption, SingleSelectComponent, SelectViewType, \
|
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.api.constants import TEMP_DIR
|
||||||
from bauh.commons import user, internet
|
from bauh.commons import user, internet
|
||||||
from bauh.commons.category import CategoriesDownloader
|
from bauh.commons.category import CategoriesDownloader
|
||||||
@@ -2415,7 +2416,7 @@ class ArchManager(SoftwareManager):
|
|||||||
|
|
||||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||||
local_config = read_config()
|
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',
|
db_sync_start = self._gen_bool_selector(id_='sync_dbs_start',
|
||||||
label_key='arch.config.sync_dbs',
|
label_key='arch.config.sync_dbs',
|
||||||
@@ -2486,14 +2487,13 @@ class ArchManager(SoftwareManager):
|
|||||||
max_width=max_width,
|
max_width=max_width,
|
||||||
type_=SelectViewType.RADIO,
|
type_=SelectViewType.RADIO,
|
||||||
capitalize_label=False),
|
capitalize_label=False),
|
||||||
TextInputComponent(id_='aur_build_dir',
|
FileChooserComponent(id_='aur_build_dir',
|
||||||
label=self.i18n['arch.config.aur_build_dir'],
|
label=self.i18n['arch.config.aur_build_dir'],
|
||||||
tooltip=self.i18n['arch.config.aur_build_dir.tip'].format(BUILD_DIR),
|
tooltip=self.i18n['arch.config.aur_build_dir.tip'].format(BUILD_DIR),
|
||||||
only_int=False,
|
max_width=max_width,
|
||||||
max_width=max_width,
|
file_path=local_config['aur_build_dir'],
|
||||||
value=local_config.get('aur_build_dir', ''),
|
capitalize_label=False,
|
||||||
capitalize_label=False)
|
directory=True)
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
return PanelComponent([FormComponent(fields, spaces=False)])
|
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['repositories_mthread_download'] = form_install.get_component('mthread_download').get_selected()
|
||||||
config['automatch_providers'] = form_install.get_component('autoprovs').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['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']:
|
if not config['aur_build_dir']:
|
||||||
config['aur_build_dir'] = None
|
config['aur_build_dir'] = None
|
||||||
|
|||||||
@@ -768,8 +768,11 @@ class FormQt(QGroupBox):
|
|||||||
if hasattr(comp, 'size') and comp.size is not None:
|
if hasattr(comp, 'size') and comp.size is not None:
|
||||||
label_comp.setStyleSheet("QLabel { font-size: " + str(comp.size) + "px }")
|
label_comp.setStyleSheet("QLabel { font-size: " + str(comp.size) + "px }")
|
||||||
|
|
||||||
attr = 'label' if hasattr(comp,'label') else 'value'
|
if hasattr(comp, 'get_label'):
|
||||||
text = getattr(comp, attr)
|
text = comp.get_label()
|
||||||
|
else:
|
||||||
|
attr = 'label' if hasattr(comp,'label') else 'value'
|
||||||
|
text = getattr(comp, attr)
|
||||||
|
|
||||||
if text:
|
if text:
|
||||||
if hasattr(comp, 'capitalize_label') and getattr(comp, 'capitalize_label'):
|
if hasattr(comp, 'capitalize_label') and getattr(comp, 'capitalize_label'):
|
||||||
@@ -868,17 +871,16 @@ class FormQt(QGroupBox):
|
|||||||
|
|
||||||
if c.file_path:
|
if c.file_path:
|
||||||
chooser.setText(c.file_path)
|
chooser.setText(c.file_path)
|
||||||
|
chooser.setCursorPosition(0)
|
||||||
|
|
||||||
c.observers.append(chooser)
|
c.observers.append(chooser)
|
||||||
chooser.setPlaceholderText(self.i18n['view.components.file_chooser.placeholder'])
|
chooser.setPlaceholderText(self.i18n['view.components.file_chooser.placeholder'])
|
||||||
|
|
||||||
def open_chooser(e):
|
def open_chooser(e):
|
||||||
options = QFileDialog.Options()
|
|
||||||
|
|
||||||
if c.allowed_extensions:
|
if c.allowed_extensions:
|
||||||
exts = ';;'.join({'*.{}'.format(e) for e in c.allowed_extensions})
|
exts = ';;'.join({'*.{}'.format(e) for e in c.allowed_extensions})
|
||||||
else:
|
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):
|
if c.file_path and os.path.isfile(c.file_path):
|
||||||
cur_path = c.file_path
|
cur_path = c.file_path
|
||||||
@@ -887,7 +889,10 @@ class FormQt(QGroupBox):
|
|||||||
else:
|
else:
|
||||||
cur_path = str(Path.home())
|
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:
|
if file_path:
|
||||||
c.set_file_path(file_path)
|
c.set_file_path(file_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user