-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepresourcelisteditor.py
78 lines (68 loc) · 2.75 KB
/
stepresourcelisteditor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Builds and handles the list of resources in a Step.
Use the dialog property to access the dialog control.
"""
import copy
import flet as ft
from model import Step
from ingredidentlisteditor import IngredientListEditor
class StepResourceListEditor():
"""Builds and handles the list of resources in a Step.
"""
dialog: ft.AlertDialog
original_step: dict
def __init__(self, mfgdocsapp: 'MFGDocsApp', step: Step, itemlist: dict, resource_type: str, title: str, is_inputpart: bool = False):
self.is_inputpart = is_inputpart
self.itemlist = itemlist
self.title = title
self.resource_type = resource_type
self.mfgdocsapp = mfgdocsapp
self.step = step
self.original_step = copy.deepcopy(step.to_dict())
self.dialog = ft.AlertDialog(modal=False)
self.dialog.title = ft.Text(title)
self.dialog.content = self.build()
self.dialog.actions = [ft.TextButton('Cancel', on_click=self.dialog_cancel),
ft.TextButton('Save', on_click=self.dialog_save)]
self.dialog.actions_alignment = 'end'
self.dialog.shape = ft.BeveledRectangleBorder()
self.dialog.visible = True
def build(self) -> ft.Control: # pylint: disable=too-many-locals
"""Builds the dialog content."""
return ft.Container(
expand=True,
content=ft.Column(
expand=True, scroll=ft.ScrollMode.ALWAYS, width=800,
controls=[
IngredientListEditor(
'',
self.itemlist,
resource_type=self.resource_type,
storage=self.mfgdocsapp.storage,
is_inputpart=self.is_inputpart
)
]
)
)
def dialog_cancel(self, e):
"""Closes the dialog without saving changes."""
del e
self.dialog.open = False
self.step.from_dict(self.original_step)
self.parent_search_update()
self.parent_markdown_update()
self.mfgdocsapp.page.update()
def dialog_save(self, e):
"""Closes the dialog and saves changes."""
del e
self.mfgdocsapp.storage.save_resources()
self.dialog.open = False
self.parent_search_update()
self.parent_markdown_update()
self.mfgdocsapp.page.update()
def parent_markdown_update(self):
"""Updates the markdown in the main view."""
self.mfgdocsapp.load_mainmarkdown_step(self.step.key)
def parent_search_update(self):
"""Updates the search results in the main view."""
if self.mfgdocsapp.ctrl['panel_searchresults_container'].visible:
self.mfgdocsapp.search(None)