mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 19:04:15 +02:00
[wgem] custom icon selector
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
from pathlib import Path
|
||||
from typing import Tuple
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QIcon, QPixmap
|
||||
from PyQt5.QtWidgets import QRadioButton, QGroupBox, QCheckBox, QComboBox, QGridLayout, QWidget, \
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout
|
||||
QLabel, QSizePolicy, QLineEdit, QToolButton, QHBoxLayout, QFormLayout, QFileDialog
|
||||
|
||||
from bauh.api.abstract.view import SingleSelectComponent, InputOption, MultipleSelectComponent, SelectViewType, \
|
||||
TextInputComponent, FormComponent
|
||||
TextInputComponent, FormComponent, FileChooserComponent
|
||||
from bauh.view.qt import css
|
||||
from bauh.view.util import resource
|
||||
from bauh.view.util.translation import I18n
|
||||
|
||||
|
||||
class RadioButtonQt(QRadioButton):
|
||||
@@ -257,9 +259,10 @@ class IconButton(QWidget):
|
||||
|
||||
class FormQt(QGroupBox):
|
||||
|
||||
def __init__(self, model: FormComponent):
|
||||
def __init__(self, model: FormComponent, i18n: I18n):
|
||||
super(FormQt, self).__init__(model.label if model.label else '')
|
||||
self.model = model
|
||||
self.i18n = i18n
|
||||
self.setLayout(QFormLayout())
|
||||
self.setStyleSheet(css.GROUP_BOX)
|
||||
|
||||
@@ -273,6 +276,9 @@ class FormQt(QGroupBox):
|
||||
label = QLabel(c.label.capitalize() if c.label else '')
|
||||
field = ComboBoxQt(c)
|
||||
self.layout().addRow(label, field)
|
||||
elif isinstance(c, FileChooserComponent):
|
||||
label, field = self._new_file_chooser(c)
|
||||
self.layout().addRow(label, field)
|
||||
else:
|
||||
raise Exception('Unsupported component type {}'.format(c.__class__.__name__))
|
||||
|
||||
@@ -300,6 +306,35 @@ class FormQt(QGroupBox):
|
||||
line_edit.textChanged.connect(update_model)
|
||||
return QLabel(c.label.capitalize() if c.label else ''), line_edit
|
||||
|
||||
def _new_file_chooser(self, c: FileChooserComponent) -> Tuple[QLabel, QLineEdit]:
|
||||
chooser = QLineEdit()
|
||||
chooser.setReadOnly(True)
|
||||
|
||||
chooser.setPlaceholderText(self.i18n['view.components.file_chooser.placeholder'])
|
||||
|
||||
def open_chooser(e):
|
||||
options = QFileDialog.Options()
|
||||
|
||||
if c.allowed_extensions:
|
||||
exts = ';;'.join({'{} {} (*.{})'.format(self.i18n['files'].capitalize(), e.upper(), e) for e in c.allowed_extensions})
|
||||
else:
|
||||
exts = '{}} (*);;'.format(self.i18n['all_files'].capitalize())
|
||||
|
||||
file_path, _ = QFileDialog.getOpenFileName(self, self.i18n['file_chooser.title'], str(Path.home()), exts, options=options)
|
||||
|
||||
if file_path:
|
||||
c.file_path = file_path
|
||||
chooser.setText(file_path)
|
||||
else:
|
||||
c.file_path = None
|
||||
chooser.setText('')
|
||||
|
||||
chooser.setCursorPosition(0)
|
||||
|
||||
chooser.mousePressEvent = open_chooser
|
||||
|
||||
return QLabel(c.label if c.label else ''), chooser
|
||||
|
||||
|
||||
def new_single_select(model: SingleSelectComponent):
|
||||
if model.type == SelectViewType.RADIO:
|
||||
|
||||
@@ -48,7 +48,7 @@ class ConfirmationDialog(QMessageBox):
|
||||
elif isinstance(comp, TextInputComponent):
|
||||
inst = TextInputQt(comp)
|
||||
elif isinstance(comp, FormComponent):
|
||||
inst = FormQt(comp)
|
||||
inst = FormQt(comp, i18n)
|
||||
else:
|
||||
raise Exception("Cannot render instances of " + comp.__class__.__name__)
|
||||
|
||||
|
||||
@@ -208,4 +208,8 @@ details=detalls
|
||||
communication=comunicació
|
||||
administration=administració
|
||||
settings=configuració
|
||||
address=adreça
|
||||
address=adreça
|
||||
view.components.file_chooser.placeholder=Feu clic aquí per seleccionar
|
||||
files=fitxers
|
||||
all_files=tots els fitxers
|
||||
file_chooser.title=Selector de fitxers
|
||||
@@ -162,4 +162,8 @@ details=details
|
||||
communication=Kommunikation
|
||||
administration=Verwaltung
|
||||
settings=Einstellungen
|
||||
address=Adresse
|
||||
address=Adresse
|
||||
view.components.file_chooser.placeholder=Klicken Sie hier, um auszuwählen
|
||||
files=Dateien
|
||||
all_files=Alle Dateien
|
||||
file_chooser.title=Dateiauswahl
|
||||
@@ -166,4 +166,8 @@ administration=administration
|
||||
audio=audio
|
||||
video=video
|
||||
settings=settings
|
||||
address=address
|
||||
address=address
|
||||
view.components.file_chooser.placeholder=Click here to select
|
||||
files=files
|
||||
all_files=all files
|
||||
file_chooser.title=File selector
|
||||
@@ -207,4 +207,8 @@ details=detalles
|
||||
communication=comunicación
|
||||
administration=administración
|
||||
settings=configuraciones
|
||||
address=dirección
|
||||
address=dirección
|
||||
view.components.file_chooser.placeholder=Pulse aquí para seleccionar
|
||||
files=archivos
|
||||
all_files=todos los archivos
|
||||
file_chooser.title=Selector de archivos
|
||||
@@ -163,4 +163,8 @@ details=dettagli
|
||||
communication=comunicazione
|
||||
administration=amministrazione
|
||||
settings=impostazioni
|
||||
address=indirizzo
|
||||
address=indirizzo
|
||||
view.components.file_chooser.placeholder=Fai clic qui per selezionare
|
||||
files=files
|
||||
all_files=tutti i files
|
||||
file_chooser.title=Selettore file
|
||||
@@ -210,4 +210,8 @@ details=detalhes
|
||||
communication=comunicação
|
||||
messaging=mensagem
|
||||
administration=administração
|
||||
address=endereço
|
||||
address=endereço
|
||||
view.components.file_chooser.placeholder=Clique aqui para selecionar
|
||||
files=arquivos
|
||||
all_files=todos os arquivos
|
||||
file_chooser.title=Seletor arquivos
|
||||
Reference in New Issue
Block a user