-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
executable file
·145 lines (120 loc) · 3.98 KB
/
main.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
#!/usr/bin/env python3
import flet as ft
from flet import (
Column,
Container,
ElevatedButton,
RoundedRectangleBorder,
Page,
Row,
Text,
UserControl,
border_radius,
colors,
)
import random
# import sqlite3
# from datetime import datetime
from util import *
from dataclasses import dataclass, field
from pathlib import Path
# from sqlmodel import Field, Session, SQLModel, create_engine, select
from typing import Optional, Dict, List, Tuple
@dataclass
class CustomButton():
text: str
style: Tuple = field(default_factory=lambda: ft.ButtonStyle(shape={
ft.MaterialState.DEFAULT: RoundedRectangleBorder(radius=2),
}))
on_click: Optional[ft.ElevatedButton().on_click] = None
def __call__(self, text):
return ft.ElevatedButton(
text=self.text,
style=self.style,
on_click=self.on_click,
)
class Lunch(UserControl):
def __init__(self, page: Page):
super().__init__()
self.page = page
self._build()
def _build(self):
page = self.page
page.title = "Lunch"
page.background_color = colors.WHITE
page.padding = 10
choice = ft.RadioGroup(
content=ft.Row([
ft.Container(ft.Radio(value="cheap", label="Cheap"), alignment=ft.alignment.center),
ft.Container(ft.Radio(value="normal", label="Normal"), alignment=ft.alignment.center),
],
alignment=ft.MainAxisAlignment.CENTER,)
)
page.add(ft.Text("Click below to find out what's for Lunch:"), choice)
row = Row(
controls=[
Container(CustomButton(text="Roll Lunch")(page), alignment=ft.alignment.center, on_click=self.button_clicked, data="roll"),
Container(CustomButton(text="Delete Restaurant")(page), alignment=ft.alignment.center, on_click=self.button_clicked, data="delete"),
Container(CustomButton(text="Add Restaurant")(page), alignment=ft.alignment.center, on_click=self.button_clicked, data="add"),
Container(CustomButton(text="List All")(page), alignment=ft.alignment.center, on_click=self.button_clicked, data="list"),
],
alignment=ft.MainAxisAlignment.CENTER,
)
page.add(row)
# TODO: connect to db; bind to buttons; create views based on button clicks
def roll_lunch(self, option):
restaurant = rng_restaurant(option)
print(restaurant)
def delete_restaurant(self):
pass
def add_restaurant(self):
pass
def list_all(self):
pass
# TODO: debug row + button click
def button_clicked(self, e):
data = e.control.data
if self.result.value == "roll" or data == "roll":
self.roll_lunch(data)
elif data == "delete":
self.delete_restaurant()
elif data == "add":
self.add_restaurant()
elif data == "list":
self.list_all()
def main(page: Page):
page.title = "Lunch"
page.window_width = 650
page.window_height = 275
page.vertical_alignment = "center"
page.horizontal_alignment = "center"
# create application instance
lunch = Lunch(page)
# add application's root control to page
page.add(lunch)
def bs_dismissed(e):
print("Dismissed!")
def show_bs(e):
bs.open = True
bs.update()
def close_bs(e):
bs.open = False
bs.update()
bs = ft.BottomSheet(
ft.Container(
ft.Column(
[
ft.Text("This is sheet's content!"),
ft.ElevatedButton("Close bottom sheet", on_click=close_bs),
],
tight=True,
),
padding=10,
),
open=True,
on_dismiss=bs_dismissed,
)
page.overlay.append(bs)
page.add(ft.ElevatedButton("Display bottom sheet", on_click=show_bs))
Lunch.button_clicked = show_bs
ft.app(target=main)