-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtkmain.py-old
More file actions
293 lines (246 loc) · 12.1 KB
/
Copy pathtkmain.py-old
File metadata and controls
293 lines (246 loc) · 12.1 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import os
import sys
import time
from tkinter.ttk import Combobox
from typing import List
from geopy import Nominatim
from parsedata.parse_json import ParseJson
from tkinter import *
import tkintermapview
import uuid
from PIL import Image, ImageTk
from itertools import count, cycle
import random
from domain.user import AddressUser
from domain.data import SellPoint
from domain.logic import address_to_coord
# Importing the PIL library
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
EVENT_TIMEOUT = .01 # A very short timeout - seconds.
POLLING_DELAY = 1000 # How often to check search status - millisecs.
locator = Nominatim(user_agent="low-fuel")
def center(win):
"""
centers a tkinter window
:param win: the main window or Toplevel window to center
"""
win.update_idletasks()
width = win.winfo_width()
frm_width = win.winfo_rootx() - win.winfo_x()
win_width = width + 2 * frm_width
height = win.winfo_height()
titlebar_height = win.winfo_rooty() - win.winfo_y()
win_height = height + titlebar_height + frm_width
x = win.winfo_screenwidth() // 2 - win_width // 2
y = win.winfo_screenheight() // 2 - win_height // 2
win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
win.deiconify()
'''
def set_appwindow(mainWindow): # Pour afficher l'icon dans la barre des taches
GWL_EXSTYLE = -20
WS_EX_APPWINDOW = 0x00040000
WS_EX_TOOLWINDOW = 0x00000080
# Magic
hwnd = windll.user32.GetParent(mainWindow.winfo_id())
stylew = windll.user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
stylew = stylew & ~WS_EX_TOOLWINDOW
stylew = stylew | WS_EX_APPWINDOW
windll.user32.SetWindowLongW(hwnd, GWL_EXSTYLE, stylew)
mainWindow.wm_withdraw()
mainWindow.after(10, mainWindow.wm_deiconify)
'''
class Main(Tk):
def __init__(self):
super().__init__()
self.geometry(f"{1150}x{800}")
self.title("Carte des stations à proximité")
#icon application
if sys.platform == 'win32':
icon_app = os.path.join(os.getcwd(), "petrol_pump.ico")
icon_app = "petrol_pump.ico"
self.iconbitmap(icon_app)
# create map widget
self.map_widget = tkintermapview.TkinterMapView(self, width=1150, height=800, corner_radius=0)
self.map_widget.place(relx=.5, rely=.5, anchor=CENTER)
# random position
Nord = 51.08916667
Sud = 42.33277778
Ouest = -4.79555556
Est = 8.23055556
random_latitude = random.uniform(Sud, Nord)
random_longitude = random.uniform(Ouest, Est)
# set current widget position and zoom
self.map_widget.set_position(random_latitude, random_longitude) # Domicile
self.map_widget.set_zoom(13)
self.frame = Frame(self)
self.frame.pack(expand=YES)
# Définition de variable simple
self.name_entry: str = ""
self.street_entry: str = ""
self.post_code_entry: int = 0
self.city_entry: str = ""
self.radius_entry: float = 0.0
self.labl_0 = Label(self.frame, text="Vos Infos Personnelles",width=20,font=("bold", 20))
self.labl_0.place(x=240,y=53)
self.labl_0.pack()
self.street_label = Label(self.frame, text = "Numéro et nom de rue", font=("bold", 10))
self.street_entry = Entry(self.frame)
self.street_label.place(x=200,y=230)
self.street_entry.place(x=500,y=230)
self.street_label.pack()
self.street_entry.pack()
self.post_code_label = Label(self.frame, text = "Code Postal", font=("bold", 10))
self.post_code_entry = Entry(self.frame)
self.post_code_label.place(x=200,y=280)
self.post_code_entry.place(x=500,y=280)
self.post_code_label.pack()
self.post_code_entry.pack()
self.city_label = Label(self.frame, text = "Ville", font=("bold", 10))
self.city_entry = Entry(self.frame)
self.city_label.place(x=200,y=330)
self.city_entry.place(x=500,y=330)
self.city_label.pack()
self.city_entry.pack()
self.radius_label = Label(self.frame, text = "Rayon d'action", font=("bold", 10))
self.radius_entry = Spinbox(self.frame, from_=1, to=10)
self.radius_label.place(x=200,y=380)
self.radius_entry.place(x=500,y=380)
self.radius_label.pack()
self.radius_entry.pack()
self.list_fuel = ["SP95", "E85","Gazole","SP98","GPLc","E10"]
self.fuel_label = Label(self.frame, text = "Choix du Carburant", font=("bold", 10))
self.fuel_entry = Combobox(self.frame, values=self.list_fuel)
self.fuel_entry.current(0)
self.fuel_label.place(x=200,y=430)
self.fuel_entry.place(x=500,y=430)
self.fuel_label.pack()
self.fuel_entry.pack()
self.submit = Button(self.frame ,text="Envoyer...",width=20,bg='brown',fg='white',command=self.printValue)
self.submit.place(x=320,y=550)
self.submit.pack()
# Affichage fenêtre
center(self)
#set_appwindow(self)
self.mainloop()
#self.map_widget()
def printValue(self):
self.street_entry = self.street_entry.get()
self.post_code_entry = self.post_code_entry.get()
self.city_entry = self.city_entry.get()
self.radius_entry = self.radius_entry.get()
self.fuel_entry = self.fuel_entry.get()
self.frame.pack_forget()
self.test()
def test(self):
self.frame = Frame(self)
file_gif='image/KSYL.gif'
self.gif = PhotoImage(file=file_gif, format="gif -index 2") # Convert to tkinter PhotoImage.
self.frame = Label(image=self.gif) # Put it on a Label.
self.frame.img = self.gif # Attach reference to image to prevent its deletion.
self.frame.pack(expand=YES)
idClient = uuid.uuid1()
user_address = AddressUser(idClient, str(self.street_entry), str(self.post_code_entry), str(self.city_entry), str(self.radius_entry))
location = address_to_coord(user_address.street + ' ' + user_address.post_code + ' ' + user_address.city)
user_address = AddressUser(idClient, str(self.street_entry), str(self.post_code_entry), str(self.city_entry), str(self.radius_entry), location[0],location[1])
if location[1] > 0:
location_1 = '+' + str(location[1])
else:
location_1 = str(location[1])
radius = '+' + str(float(self.radius_entry) * 1000)
url_data : str = 'https://data.economie.gouv.fr/explore/dataset/prix-carburants-fichier-instantane-test-ods-copie/download/?format=json&q=&refine.prix_nom=' + self.fuel_entry + '&geofilter.distance=' + str(location[0]) + ',' + location_1 + ',' + radius + '&timezone=Europe/Berlin&lang=fr'
path_of_file : str = 'info.gouv/prix-carburants.json'
parsejson = ParseJson(url_data, path_of_file, user_address)
my_sell_points: List[SellPoint] = parsejson.station_list()
pdv: SellPoint
# set current widget position and zoom
self.map_widget.set_position(location[0], location[1]) # Domicile
self.map_widget.set_zoom(13)
#set_first_marker
marker_1 = self.map_widget.set_position(location[0], location[1], marker=True, marker_color_circle = '#396D46', marker_color_outside = '#0C9F31', text_color = '#3F6990')
print(marker_1.position, marker_1.text)
marker_1.set_text("Point de départ")
i = 0
self.frame.pack_forget()
for pdv in my_sell_points:
print('\n')
print("------------------------------------------------------------")
print(pdv.idSP)
text1 = pdv.name
print(text1)
text2 = str(pdv.address[0]) + ' ' + str(pdv.address[1]) + ' ' + str(pdv.address[2]) + ' ' + str(pdv.address[3]) + ' ' + str(pdv.address[4])
print(text2)
text2 = str(pdv.address[0]) + ' ' + str(pdv.address[1]) + ' ' + str(pdv.address[2])
text3 = ""
text5 = ""
text6 = ""
text7 = ""
if pdv.week_hours.is_24_24:
text3 = "pompe(s) ouverte(s) 24h/24"
print(text3)
else:
if pdv.week_hours.day_hours[0][0][0] == "horaire non précisé":
text3 = "horaire non précisé"
print("horaire non précisé")
else:
text5 = ""
text6 = ""
text7 = ""
for jour in range(0, 6):
jour_en_lettre = str(pdv.week_hours.day_hours[0][jour][0])
if pdv.week_hours.day_hours[0][jour][1]:
text5 += '\n' + jour_en_lettre + " pas d'horaire spécifiée"
else:
opening = pdv.week_hours.day_hours[0][jour][2][0]
closing = pdv.week_hours.day_hours[0][jour][2][1]
if opening.__len__() == 2:
text6 += '\n' + jour_en_lettre + " ouverture le matin de " + opening[0].replace('.', 'h') + " à " + opening[1].replace('.', 'h') + " et l'après midi' de " + closing[0].replace('.', 'h') + " à " + closing[1].replace('.', 'h')
else:
text7 += '\n' + jour_en_lettre + " ouverture de " + opening.replace('.', 'h') + " à " + closing.replace('.', 'h')
print(text5)
print(text6)
print(text7)
prices_txt: str = ""
prices_txt_geo: str = ""
print("\n")
for price in pdv.prices:
if price != []:
prices_txt += "\nCarburant " + str(price[1]) + " à " + str(price[3]).replace('.', ',') + "€/L\nDernière mise à jour du prix :" + "\n" + str(price[2]) + "\n"
prices_txt_geo += str(price[1]) + " à " + str(price[3]).replace('.', ',') + "€/L\n"
print(prices_txt)
proposed_services: str = ""
for service in pdv.services:
proposed_services += str(service) + '\n'
print(str(proposed_services))
text8 = "Station à " + str(round(pdv.distance,2)).replace('.', ',') + ' km'
print(text8)
print("------------------------------------------------------------")
data_text = text1 + '\n' + text2 + '\n' + text3 + '\n' + text5 + '\n' + text6 + '\n' + text7 + '\n' + prices_txt + '\n' + proposed_services + '\n' + text8
# Open an Image
img = Image.open('image/fuel_gauge_texts.jpg')
# Call draw Method to add 2D graphics in an image
I1 = ImageDraw.Draw(img)
# Custom font style and font size
myFont = ImageFont.truetype('AcariSans-Regular.ttf', 12)
# Add Text to an image
I1.text((5, 5), data_text, font=myFont, fill =(255, 255, 255))
# Save the edited image
low_fuel_image = f'image/imagecard/fuel_gauge_texts_{i}.jpg'
img.save(low_fuel_image)
time_to_wait = 10
time_counter = 0
while not os.path.exists(low_fuel_image):
time.sleep(1)
time_counter += 1
if time_counter > time_to_wait:break
im = Image.open(low_fuel_image)
ph = ImageTk.PhotoImage(im)
if pdv.name == parsejson.get_low_price_name():
new_marker = self.map_widget.set_marker(pdv.address[3], pdv.address[4], marker_color_circle = '#736A7C', marker_color_outside = '#8551BF', text=pdv.name + '\n' + prices_txt_geo + '\n', text_color = '#FF0000', image = ph, image_zoom_visibility=(15, float("inf")))
#new_marker.hide_image(True)
else:
new_marker = self.map_widget.set_marker(pdv.address[3], pdv.address[4], text=pdv.name + '\n' + prices_txt_geo + '\n', text_color = '#3F6990', image = ph, image_zoom_visibility=(15, float("inf")))
#new_marker.hide_image(True)
i += 1
Main()