-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI_CTK.py
More file actions
231 lines (189 loc) · 9.01 KB
/
UI_CTK.py
File metadata and controls
231 lines (189 loc) · 9.01 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
'''import customtkinter as ctk
from tkinter import messagebox
class ByteBungalowUI:
def __init__(self, root):
self.root = root
self.root.title("ByteBungalow")
# main windowframes
self.main_frame = ctk.CTkFrame(self.root)
self.main_frame.pack(fill="both", expand=True)
self.top_frame = ctk.CTkFrame(self.main_frame)
self.top_frame.pack(fill="x")
self.middle_frame = ctk.CTkFrame(self.main_frame)
self.middle_frame.pack(fill="both", expand=True)
self.bottom_frame = ctk.CTkFrame(self.main_frame)
self.bottom_frame.pack(fill="x")
# top widgets
self.search_label = ctk.CTkLabel(self.top_frame, text="Search by:")
self.search_label.pack(side="left")
self.search_entry = ctk.CTkEntry(self.top_frame)
self.search_entry.pack(side="left")
self.search_button = ctk.CTkButton(self.top_frame, text="Search")
self.search_button.pack(side="left")
# middle widgets
self.listings_label = ctk.CTkLabel(self.middle_frame, text="Rental Listings:")
self.listings_label.pack(side="top")
self.listings_tab = ctk.CTkTabview(self.middle_frame)
self.listings_tab.pack(side="top", fill="both", expand=True)
# bottom widgets
self.stats_label = ctk.CTkLabel(self.bottom_frame, text="Statistics:")
self.stats_label.pack(side="left")
self.stats_button = ctk.CTkButton(self.bottom_frame, text="View Statistics")
self.stats_button.pack(side="left")
def run(self):
self.root.mainloop()
if __name__ == "__main__":
root = ctk.CTk()
ui = ByteBungalowUI(root)
ui.run()
'''
import sys
sys.path.append('C:/Users/cheap/ByteBungalow/ByteBungalow/')
from DataStructures.Listings import Listing
from BBDatabase import ListingDatabase
from BBSearch import LstSearch
import dash
from dash import dcc
from dash import html
import dash_ag_grid as dag
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
#import plotly.graph_objs as go
import matplotlib.pyplot as plt
import io
import base64
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP]) # create app
db = ListingDatabase("listings.db") #database obj
graph_data = []
for listing in db.getAllListings(): #pass from BBDatabase
graph_data.append(listing.unitIndex)
graph_data.append(listing.name)
graph_data.append(listing.rentAmt) #data to plot for graph
graph_data.append(listing.numRooms)
plt.figure(figsize=(10, 6))
plt.bar(graph_data[2], graph_data[3])
plt.xlabel("Number of Rooms")
plt.ylabel("Rental Price")
plt.title("Listing Data")
plt.xticks(rotation=90)
plt.tight_layout()
img= io.BytesIO() #save plot to image
plt.savefig(img, format='png')
img.seek(0)
chart= base64.b64encode(img.getvalue()).decode() #encode image
"data:image/png;base64,".format(chart)
# app.layout = html.Div([
# html.H1("Listing Database WebUI"), # main title
# html.Div([
# html.Div([
# html.H2("Search Listings"),
# dcc.Input(id="search-input", type="text", placeholder="Search by name, address, or host site"),
# html.Button("Search", id="search-button", n_clicks=0)
# ]),
# html.H2("Listings"), #section 1 header
# html.Table([
# html.Thead([
# html.Tr([
# html.Th("Unit Index"),
# html.Th("Name"),
# html.Th("Address"),
# html.Th("Num Rooms"),
# html.Th("Utils Included"),
# html.Th("Rent Amt"),
# html.Th("Listing URL"),
# html.Th("Host Site"),
# html.Th("Notes"),
# html.Th("Favorited")
# ])
# ]),
# html.Tbody([
# html.Tr([ #populate table
# html.Td(listing.unitIndex),
# html.Td(listing.name),
# html.Td(listing.address),
# html.Td(listing.numRooms),
# html.Td(listing.utilsIncluded),
# html.Td(listing.rentAmt),
# html.Td(listing.listingURL),
# html.Td(listing.hostSite),
# html.Td(listing.notes),
# html.Td(listing.favorited)
# ]) for listing in db.getAllListings() # get listings from db
# ])
# ]),
# html.Div([
# html.H2("Add Listing"),
# dcc.Input(id="unit-index", type="number", placeholder="Unit Index"),
# dcc.Input(id="name", type="text", placeholder="Name"),
# dcc.Input(id="address", type="text", placeholder="Address"),
# dcc.Input(id="num-rooms", type="number", placeholder="Num Rooms"),
# dcc.Input(id="utils-included", type="checkbox", placeholder="Utils Included"),
# dcc.Input(id="rent-amt", type="number", placeholder="Rent Amt"),
# dcc.Input(id="listing-url", type="text", placeholder="Listing URL"),
# dcc.Input(id="host-site", type="text", placeholder="Host Site"),
# dcc.Input(id="notes", type="text", placeholder="Notes"),
# dcc.Input(id="favorited", type="checkbox", placeholder="Favorited"),
# html.Button("Add Listing", id="add-listing-button", n_clicks=0)
# ]),
# html.Div([
# html.H2("Update Listing"),
# dcc.Input(id="update-unit-index", type="number", placeholder="Unit Index"),
# dcc.Input(id="update-name", type="text", placeholder="Name"),
# dcc.Input(id="update-address", type="text", placeholder="Address"),
# dcc.Input(id="update-num-rooms", type="number", placeholder="Num Rooms"),
# dcc.Input(id="update-utils-included", type="checkbox", placeholder="Utils Included"),
# dcc.Input(id="update-rent-amt", type="number", placeholder="Rent Amt"),
# dcc.Input(id="update-listing-url", type="text", placeholder="Listing URL"),
# dcc.Input(id="update-host-site", type="text", placeholder="Host Site"),
# dcc.Input(id="update-notes", type="text", placeholder="Notes"),
# dcc.Input(id="update-favorited", type="checkbox", placeholder="Favorited"),
# html.Button("Update Listing", id="update-listing-button", n_clicks=0)
# ]),
# html.Div([
# html.H2("Delete Listing"),
# dcc.Input(id="delete-unit-index", type="number", placeholder="Unit Index"),
# html.Button("Delete Listing", id="delete-listing-button", n_clicks=0)
# ]),
# html.Div([ #display graph
# html.H2("Plot Listings"),
# dcc.Dropdown(id="plot-type", options=[
# {"label": "Bar Chart", "value": "bar"},
# {"label": "Scatter Plot", "value": "scatter"}
# ], value="bar"),
# html.Img(src="data:image/png;base64,{}".format(chart))
# ])
# ])
# ])
@app.callback(
Output("listings-table", "children"),
[Input("add-listing-button", "n_clicks")],
[dash.dependencies.State("unit-index", "value"),
dash.dependencies.State("name", "value"),
dash.dependencies.State("address", "value"),
dash.dependencies.State("num-rooms", "value"),
dash.dependencies.State("utils-included", "value"),
dash.dependencies.State("rent-amt", "value"),
dash.dependencies.State("listing-url", "value"),
dash.dependencies.State("host-site", "value"),
dash.dependencies.State("notes", "value"),
dash.dependencies.State("favorited", "value")],
)
def search_listings(n_clicks, search_value):
if n_clicks > 0:
search_ = LstSearch()
search_.setRent(0,1500) #default range
search_results = search_.getResults()
if search_results:
return html.Div([html.P(f"Results for '{search_value}':"),
html.Ul([html.Li(f"{listing.name} - {listing.address}") for listing in search_results])])
else:
return html.P(f"No results found for '{search_value}'")
return ""
def add_listing(n_clicks, unit_index, name, address, num_rooms, utils_included, rent_amt, listing_url, host_site, notes, favorited):
if n_clicks > 0:
listing = Listing(unit_index, name, address, num_rooms, utils_included, rent_amt, listing_url, host_site, notes, favorited)
db.addListing(listing)
return "Listing added successfully!"
return ""
if __name__ == "__main__":
app.run()