Shorten edit name, passthrough kwargs to adder methods

win_fixes
Tyler Goodlet 2021-09-23 10:10:59 -04:00
parent 7cbcfc5525
commit d7cfe4dcb3
3 changed files with 14 additions and 9 deletions

View File

@ -48,7 +48,7 @@ from ._style import hcolor, _font, _font_small, DpiAwareFont
from ._label import FormatLabel
class FontAndChartAwareLineEdit(QLineEdit):
class Edit(QLineEdit):
def __init__(
@ -369,13 +369,14 @@ class FieldsForm(QWidget):
key: str,
label_name: str,
value: str,
readonly: bool = False,
) -> FontAndChartAwareLineEdit:
) -> Edit:
# TODO: maybe a distint layout per "field" item?
label = self.add_field_label(label_name)
edit = FontAndChartAwareLineEdit(
edit = Edit(
parent=self,
# width_in_chars=6,
)
@ -386,6 +387,7 @@ class FieldsForm(QWidget):
}}
"""
)
edit.setReadOnly(readonly)
edit.setText(str(value))
self.form.addRow(label, edit)
@ -478,13 +480,15 @@ def mk_form(
for key, conf in fields_schema.items():
wtype = conf['type']
label = str(conf.get('label', key))
kwargs = conf.get('kwargs', {})
# plain (line) edit field
if wtype == 'edit':
w = form.add_edit_field(
key,
label,
conf['default_value']
conf['default_value'],
**kwargs,
)
# drop-down selection
@ -493,7 +497,8 @@ def mk_form(
w = form.add_select_field(
key,
label,
values
values,
**kwargs,
)
w._key = key

View File

@ -36,7 +36,7 @@ from PyQt5.QtWidgets import (
from ._forms import (
# FontScaledDelegate,
FontAndChartAwareLineEdit,
Edit,
)
@ -97,7 +97,7 @@ class Selection(Field[DataType], Generic[DataType]):
class Edit(Field[DataType], Generic[DataType]):
'''An edit field which takes a number.
'''
widget_factory = FontAndChartAwareLineEdit
widget_factory = Edit
class AllocatorPane(BaseModel):

View File

@ -72,7 +72,7 @@ from ._style import (
_font,
hcolor,
)
from ._forms import FontAndChartAwareLineEdit, FontScaledDelegate
from ._forms import Edit, FontScaledDelegate
log = get_logger(__name__)
@ -407,7 +407,7 @@ class CompleterView(QTreeView):
self.resize()
class SearchBar(FontAndChartAwareLineEdit):
class SearchBar(Edit):
mode_name: str = 'search'