Skip to content

Commit

Permalink
setting crop of None to default button
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Dec 2, 2024
1 parent 5005f45 commit b19a739
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion field_friend/interface/components/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def field_setting(self) -> None:
.tooltip('Set the number of beds')
ui.separator()
with ui.column().classes('w-full').style('max-height: 500px; overflow-y: auto;'):
# if any value of bed_crops is None add a button to set the Nones to the first bed crop
if any(value is None for value in parameters['bed_crops'].values()):
ui.button('Set missing crops to first bed\'s crop',
on_click=lambda: self.set_missing_crops_to_default())
for i in range(parameters['bed_count']):
with ui.row().classes('w-full item-center'):
ui.label(f'Bed {i + 1}:').classes('text-lg')
Expand All @@ -161,7 +165,6 @@ def field_setting(self) -> None:
forward=lambda v, idx=i: {
**parameters.get('bed_crops', {}), str(idx): v},
backward=lambda v, idx=i: v.get(str(idx)))
# TODO dynamic adding and deleting the beds when the number of beds is changed
with ui.row():
ui.button('Cancel', on_click=self.edit_field_dialog.close)
ui.button('Apply', on_click=lambda: self.edit_selected_field(parameters))
Expand Down Expand Up @@ -203,3 +206,11 @@ def field_setting(self) -> None:
multiple=True, label='selected beds', clearable=True) \
.classes('grow').props('use-chips') \
.bind_value(self.field_provider, 'selected_beds')

def set_missing_crops_to_default(self):
if self.field_provider.selected_field:
if self.field_provider.selected_field.bed_crops:
first_bed_crop = next(iter(self.field_provider.selected_field.bed_crops.values()))
for i in range(self.field_provider.selected_field.bed_count):
if self.field_provider.selected_field.bed_crops[str(i)] is None:
self.field_provider.selected_field.bed_crops[str(i)] = first_bed_crop

0 comments on commit b19a739

Please sign in to comment.