code cleansing

This commit is contained in:
2026-05-12 14:49:27 +02:00
parent 76b81316c2
commit 4befb8e3c5

View File

@@ -55,106 +55,6 @@ QSS = """
"""
@dc.dataclass(slots=True)
class Address:
name: str
street: str
number: int
zip_code: str
city: str
def export(self):
data = {}
for f in dc.fields(self):
data[f.name] = str(getattr(self, f.name))
return data
# added search field
class AddressForm(QWidget):
def __init__(self):
super().__init__()
main_layout = QVBoxLayout(self)
form_layout = QFormLayout()
form_layout.setSpacing(15)
# --- 1. Einfaches Feld: Firmenname ---
self.company_input = QLineEdit(placeholderText="Name des Partners")
form_layout.addRow("Name Unternehmen/Netzwerkpartner:", self.company_input)
# --- 2. Kombinierte Zeile: Straße & Hausnummer ---
street_layout = QHBoxLayout()
street_layout.setContentsMargins(0, 0, 0, 0) # Wichtig: Verhindert doppelte Abstände!
street_layout.setSpacing(10)
self.street_input = QLineEdit(placeholderText="Straße")
self.number_input = QLineEdit(placeholderText="Nr.")
# Optik-Trick: Hausnummern-Feld begrenzen, damit es nicht so breit wie die Straße wird
self.number_input.setMaximumWidth(80)
# Mit "stretch" definieren wir das Breitenverhältnis (Straße nimmt restlichen Platz)
street_layout.addWidget(self.street_input, stretch=3)
street_layout.addWidget(self.number_input, stretch=1)
form_layout.addRow("Straße / Nr.:", street_layout)
# --- 3. Kombinierte Zeile: PLZ & Ort ---
city_layout = QHBoxLayout()
city_layout.setContentsMargins(0, 0, 0, 0)
city_layout.setSpacing(10)
self.zip_input = QLineEdit(placeholderText="PLZ")
self.city_input = QLineEdit(placeholderText="Ort")
self.zip_input.setMaximumWidth(100) # PLZ ist immer relativ kurz
city_layout.addWidget(self.zip_input, stretch=1)
city_layout.addWidget(self.city_input, stretch=3)
form_layout.addRow("PLZ / Ort:", city_layout)
main_layout.addLayout(form_layout)
self.autofilled_fields = (
self.street_input,
self.number_input,
self.zip_input,
self.city_input,
)
for field in self.autofilled_fields:
field.setReadOnly(True)
field.setStyleSheet("""
QLineEdit {
background-color: #f1f5f9; /* Helles System-Grau */
color: #333D4B; /* Etwas blassere Schrift */
border: 1px dashed #cbd5e1; /* Ein gestrichelter Rand wirkt oft wie ein "Stempel" */
border-radius: 4px;
padding: 5px;
}
/* Wenn das Feld fokussiert wird, keinen blauen Rand anzeigen */
QLineEdit:focus {
border: 1px dashed #cbd5e1;
}
""")
def fill_out(self, address: Address):
addr_ = address.export()
for field, value in zip(self.autofilled_fields, addr_.values()):
field.setText(value)
ADDRESSES = [
Address("Test UG", "Teststraße", 1, "09111", "Chemnitz"),
Address("Max Mustermann GmbH", "Teststraße", 2, "09112", "Chemnitz"),
Address("Mustergruppe GbR", "Teststraße", 3, "09113", "Chemnitz"),
Address("Lorem Ipsum AG", "Teststraße", 4, "09114", "Chemnitz"),
]
class CompanyForm_Search(QWidget):
company_selected = Signal(int)
@@ -165,54 +65,48 @@ class CompanyForm_Search(QWidget):
main_layout.setContentsMargins(0, 0, 0, 0)
form_layout = QFormLayout()
form_layout.setSpacing(10)
# TODO: remove title
title = QLabel("--- Suche Unternehmen ---")
title.setStyleSheet("font-size: 14px; font-style: italic;") # font-weight: bold;
main_layout.addWidget(title)
# --- SEARCH ---
self.search_input = QLineEdit(placeholderText="Tippen zum Suchen...")
form_layout.addRow("Suche:", self.search_input)
self.completer = QCompleter()
self.completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
self.completer.setFilterMode(Qt.MatchFlag.MatchContains)
self.search_input.setCompleter(self.completer)
self.completer.activated[QModelIndex].connect(self.search_result_selected) # type: ignore
# --- 1. Einfaches Feld: Firmenname ---
# --- FILLED FIELDS ---
# name
self.company_input = QLineEdit(placeholderText="Name des Partners")
form_layout.addRow("Name Unternehmen/Netzwerkpartner:", self.company_input)
# street
street_layout = QHBoxLayout()
street_layout.setContentsMargins(0, 0, 0, 0) # Wichtig: Verhindert doppelte Abstände!
street_layout.setSpacing(10)
self.street_input = QLineEdit(placeholderText="Straße")
self.number_input = QLineEdit(placeholderText="Nr.")
self.number_input.setMaximumWidth(80)
# Mit "stretch" definieren wir das Breitenverhältnis (Straße nimmt restlichen Platz)
street_layout.addWidget(self.street_input, stretch=3)
street_layout.addWidget(self.number_input, stretch=1)
form_layout.addRow("Straße / Nr.:", street_layout)
# ZIP, city
# --- 3. Kombinierte Zeile: PLZ & Ort ---
city_layout = QHBoxLayout()
city_layout.setContentsMargins(0, 0, 0, 0)
city_layout.setSpacing(10)
self.zip_input = QLineEdit(placeholderText="PLZ")
self.city_input = QLineEdit(placeholderText="Ort")
self.zip_input.setMaximumWidth(100) # PLZ ist immer relativ kurz
city_layout.addWidget(self.zip_input, stretch=1)
city_layout.addWidget(self.city_input, stretch=3)
form_layout.addRow("PLZ / Ort:", city_layout)
# add fom layout
main_layout.addLayout(form_layout)
self.autofilled_fields = (
self.autofilled_fields: tuple[QLineEdit, ...] = (
self.company_input,
self.street_input,
self.number_input,
@@ -221,19 +115,7 @@ class CompanyForm_Search(QWidget):
)
for field in self.autofilled_fields:
field.setReadOnly(True)
field.setStyleSheet("""
QLineEdit {
background-color: #f1f5f9; /* Helles System-Grau */
color: #333D4B; /* Etwas blassere Schrift */
border: 1px dashed #cbd5e1; /* Ein gestrichelter Rand wirkt oft wie ein "Stempel" */
border-radius: 4px;
padding: 5px;
}
/* Wenn das Feld fokussiert wird, keinen blauen Rand anzeigen */
QLineEdit:focus {
border: 1px dashed #cbd5e1;
}
""")
field.setProperty("styleClass", "stempel")
self.update_search_data()
@@ -244,13 +126,13 @@ class CompanyForm_Search(QWidget):
self.zip_input.setText(comp_info["ma_plz"])
self.city_input.setText(comp_info["ma_ort"])
def clear_fields(self) -> None:
def clear_autofilled_fields(self) -> None:
self.search_input.clear()
for field in self.autofilled_fields:
field.clear()
def update_search_data(self) -> None:
self.clear_fields()
self.clear_autofilled_fields()
search_items = QStandardItemModel()
search_choices = be_init_rec.comp_search_choices()
for item, db_index in search_choices:
@@ -277,56 +159,49 @@ class ContactPersonForm_Search(QWidget):
main_layout.setContentsMargins(0, 0, 0, 0)
form_layout = QFormLayout()
form_layout.setSpacing(10)
# TODO: remove title
title = QLabel("--- Suche Nutzer ---")
title.setStyleSheet("font-size: 14px; font-style: italic;") # font-weight: bold;
main_layout.addWidget(title)
# --- SEARCH ---
self.search_input = QComboBox(placeholderText="Tippen zum Suchen...")
self.search_input.setEditable(True)
self.search_input.setInsertPolicy(QComboBox.InsertPolicy.NoInsert)
line_edit = self.search_input.lineEdit()
assert line_edit
line_edit.setPlaceholderText("Suchen...")
# --- FILLED FIELDS ---
form_layout.addRow("Suche Ansprechpartner:", self.search_input)
# self.completer = QCompleter()
self.completer = self.search_input.completer()
assert self.completer
self.completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
self.completer.setFilterMode(Qt.MatchFlag.MatchContains)
self.completer.setCompletionMode(QCompleter.CompletionMode.PopupCompletion)
self.search_input.activated.connect(self.search_result_selected)
# salutation
self.gui_titel = QLineEdit()
self.gui_anrede = QLineEdit()
hor_layout = QHBoxLayout()
hor_layout.addWidget(self.gui_anrede, stretch=1)
hor_layout.addWidget(self.gui_titel, stretch=1)
form_layout.addRow("Anrede / Titel:", hor_layout)
# form_layout.addRow("Titel:", self.gui_titel)
# form_layout.addRow("Anrede", self.gui_anrede)
# names
self.gui_nachname = QLineEdit()
# form_layout.addRow("Nachname", self.gui_nachname)
self.gui_vorname = QLineEdit()
# form_layout.addRow("Vorname", self.gui_vorname)
hor_layout = QHBoxLayout()
hor_layout.addWidget(self.gui_nachname, stretch=1)
hor_layout.addWidget(self.gui_vorname, stretch=1)
form_layout.addRow("Nachname / Vorname:", hor_layout)
# phones
phone_layout = QHBoxLayout()
phone_layout.setContentsMargins(0, 0, 0, 0)
phone_layout.setSpacing(10)
self.gui_landline_number = QLineEdit()
self.gui_mobile_number = QLineEdit()
# Mit "stretch" definieren wir das Breitenverhältnis
phone_layout.addWidget(self.gui_landline_number, stretch=1)
phone_layout.addWidget(self.gui_mobile_number, stretch=1)
form_layout.addRow("Telefon Festnetz / Mobil:", phone_layout)
# additional
self.gui_email = QLineEdit()
form_layout.addRow("E-Mail:", self.gui_email)
self.gui_funktion = QLineEdit()
@@ -334,7 +209,8 @@ class ContactPersonForm_Search(QWidget):
main_layout.addLayout(form_layout)
self.autofilled_fields = (
# auto-filled fields are readonly
self.autofilled_fields: tuple[QLineEdit, ...] = (
self.gui_titel,
self.gui_anrede,
self.gui_nachname,
@@ -346,19 +222,7 @@ class ContactPersonForm_Search(QWidget):
)
for field in self.autofilled_fields:
field.setReadOnly(True)
field.setStyleSheet("""
QLineEdit {
background-color: #f1f5f9; /* Helles System-Grau */
color: #333D4B; /* Etwas blassere Schrift */
border: 1px dashed #cbd5e1; /* Ein gestrichelter Rand wirkt oft wie ein "Stempel" */
border-radius: 4px;
padding: 5px;
}
/* Wenn das Feld fokussiert wird, keinen blauen Rand anzeigen */
QLineEdit:focus {
border: 1px dashed #cbd5e1;
}
""")
field.setProperty("styleClass", "stempel")
self.update_search_data(None)
@@ -382,7 +246,7 @@ class ContactPersonForm_Search(QWidget):
)
self.fill_out(comp_info)
def clear_fields(self) -> None:
def clear_autofilled_fields(self) -> None:
self.search_input.clear()
for field in self.autofilled_fields:
field.clear()
@@ -391,7 +255,7 @@ class ContactPersonForm_Search(QWidget):
self,
company_id: int | None,
) -> None:
self.clear_fields()
self.clear_autofilled_fields()
search_choices = be_init_rec.contact_person_search_choices(company_id, True)
for item, db_index in search_choices:
self.search_input.addItem(item, db_index)
@@ -444,16 +308,10 @@ class FormFieldDynList:
fields: Sequence[FormField]
@dc.dataclass(slots=True)
class FormFieldGroup:
label: str | None
fields: Sequence[FormField] | FormFieldDynList
# @dc.dataclass(slots=True)
# class FormFieldRegistry:
# widget: QWidget
# form_field: FormField
# class FormFieldGroup:
# label: str | None
# fields: Sequence[FormField] | FormFieldDynList
class WidgetRegistryEntry(TypedDict):
@@ -1015,22 +873,8 @@ FORM_FIELDS_LANGUAGES = [
),
]
# FORM_DYN_LIST = FormFieldDynList("Dynamische Liste", FORM_FIELDS_SCHOOL)
FORM_FIELDS = [
# FormFieldGroup(
# "Status && Projektrelevanz",
# [
# FormField(
# "Projektrelevanz",
# FormFieldType.DROPDOWN,
# required=True,
# options=["ja", "nein"],
# fill_value="nein",
# ),
# ],
# ),
FormField(
"Status && Projektrelevanz",
FormFieldType.GROUP,
@@ -1304,7 +1148,6 @@ class AutoForm(QWidget):
margin-top: 15px; /* Platz für die Überschrift schaffen */
padding-top: 15px; /* Abstand zwischen Rahmen und erstem Feld */
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left; /* Überschrift oben links */
@@ -1842,19 +1685,7 @@ class SearchFormPage(QWidget):
field = QLineEdit(placeholderText="...")
field.setText("22.04.2026")
field.setReadOnly(True)
field.setStyleSheet("""
QLineEdit {
background-color: #f1f5f9; /* Helles System-Grau */
color: #333D4B; /* Etwas blassere Schrift */
border: 1px dashed #cbd5e1; /* Ein gestrichelter Rand wirkt oft wie ein "Stempel" */
border-radius: 4px;
padding: 5px;
}
/* Wenn das Feld fokussiert wird, keinen blauen Rand anzeigen */
QLineEdit:focus {
border: 1px #cbd5e1;
}
""")
field.setProperty("styleClass", "stempel")
field.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
inf_block_1.addWidget(label)
inf_block_1.addWidget(field)