-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogs.py
145 lines (129 loc) · 4.72 KB
/
dialogs.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from kivy.properties import StringProperty, NumericProperty
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivymd.uix.list import TwoLineListItem
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton
class Content(BoxLayout):
pass
class InfoItem(TwoLineListItem):
dialog = None
def show_info_dialog(self):
if not self.dialog:
self.dialog = MDDialog(
title=self.text,
text=self.secondary_text,
buttons=[
MDFlatButton(
text='OK',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
)
],
size_hint=[.8, .5],
auto_dismiss=False
)
self.dialog.open()
def my_callback(self, popup_widget):
self.dialog.dismiss()
self.dialog = None
return popup_widget.text
class NoteItem(TwoLineListItem):
dialog = None
food_id = NumericProperty(None)
food_name = StringProperty(None)
def add_note_dialog(self):
if not self.dialog:
self.dialog = MDDialog(
title=self.text,
type='custom',
content_cls=Content(),
buttons=[
MDFlatButton(
text='CANCEL',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
),
MDFlatButton(
text='ADD',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
)
],
size_hint=[.8, 1],
auto_dismiss=False
)
self.dialog.set_normal_height()
self.dialog.open()
def view_note_dialog(self):
if not self.dialog:
self.dialog = MDDialog(
title=self.text,
text=self.secondary_text,
buttons=[
MDFlatButton(
text='CANCEL',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
),
MDFlatButton(
text='EDIT',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
)
],
size_hint=[.8, .5],
auto_dismiss=False
)
self.dialog.open()
def edit_note_dialog(self):
if not self.dialog:
self.dialog = MDDialog(
title=self.text,
type='custom',
content_cls=Content(),
buttons=[
MDFlatButton(
text='CANCEL',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
),
MDFlatButton(
text='SAVE',
text_color=self.theme_cls.primary_color,
on_release=self.my_callback
)
],
size_hint=[.8, 1],
auto_dismiss=False
)
self.dialog.content_cls.ids.note_text.text = self.secondary_text
self.dialog.set_normal_height()
self.dialog.open()
def my_callback(self, popup_widget):
app = MDApp.get_running_app()
if popup_widget.text == 'EDIT':
self.dialog.dismiss()
self.dialog = None
self.edit_note_dialog()
elif popup_widget.text == 'ADD':
query = 'UPDATE ingredients SET notes=? WHERE name1=? AND id=?;'
vals = (self.dialog.content_cls.text, self.food_name, self.food_id)
app.cursor.execute(query, vals)
app.conn.commit()
self.note_content = self.dialog.content_cls
self.secondary_text = self.dialog.content_cls.text
self.dialog.dismiss()
self.dialog = None
elif popup_widget.text == 'SAVE':
query = 'UPDATE ingredients SET notes=? WHERE name1=? AND id=?;'
vals = (self.dialog.content_cls.text, self.food_name, self.food_id)
app.cursor.execute(query, vals)
app.conn.commit()
self.secondary_text = self.dialog.content_cls.text
self.dialog.dismiss()
self.dialog = None
else:
self.dialog.dismiss()
self.dialog = None
return popup_widget.text