import tkinter import tkintermapview import requests import skydome from PIL import Image, ImageTk #api altitude endpoint URL="https://api.open-elevation.com/api/v1/lookup" def get_api_params(coords): return {"locations":"{},{}".format(coords[0],coords[1])} # create tkinter window root_tk = tkinter.Tk() # set other tile server (standard is OpenStreetMap) # map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22) # google normal # map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22) # google satellite def printer(): print("button") environment_tk = tkinter.Tk() class renderedImageZoom: def __init__(self,root,image_window,aerosol_window): self.root = root self.root.geometry(f"{1000}x{700}") self.root.title("map_view_simple_example.py") self.aerosol_window = aerosol_window # create map widget self.map_widget = tkintermapview.TkinterMapView(self.root, width=1000, height=700, corner_radius=0) self.map_widget.pack(fill="both", expand=True) self.map_widget.add_right_click_menu_command(label="Set as observer location", command=self.add_marker_event, pass_coords=True) self.map_widget.add_right_click_menu_command(label="get altitude", command=self.get_altitude, pass_coords=True) self.image_window = image_window self.image_window.title("Simulated Sunset") self.image_window.config(width=256,height=256) #image = skydome.renderFromCamera(coords) self.canvas = tkinter.Canvas(self.image_window,bg="white") self.canvas.pack(fill=tkinter.BOTH,expand=True) self.environment_window_filler() def environment_window_filler(self): self.aerosol_window.title("options selector") environemnt_info_text = tkinter.Label(self.aerosol_window, text="Please choose in which environment the sunset is occuring") environemnt_info_text.grid(column=0,row=0,columnspan=2,pady=20,padx=10) #Continental Clean - 26e-6 g = 0.709 #Continental Average - 75e-6 g = 0.703 #Continental Polluted - 175e-6 g = 0.698 # #Urban - 353e-6 g = 0.689 # #Desert - 145e-6 g = 0.729 # #Maritime Clean - 90e-6 g = 0.772 #Maritime Polluted - 115e-6 g = 0.756 #Maritime Tropic - 43e-6 g = 0.774 # #Arctic - 23e-6 g = 0.721 # #Antarctic - 11e-6 g = 0.784 buton_cont_clean = tkinter.Button(self.aerosol_window,text="Continental Clean",command=lambda: self.env_setter(26e-6,0.709)); buton_cont_clean.grid(column=0,row=1,padx=10,pady=5) buton_cont_avr = tkinter.Button(self.aerosol_window,text="Continental Average ",command=lambda: self.env_setter(75e-6,0.793)); buton_cont_avr.grid(column=0,row=2,padx=10,pady=5) buton_cont_poll = tkinter.Button(self.aerosol_window,text="Continental Polluted ",command=lambda: self.env_setter(175e-6,0.698)); buton_cont_poll.grid(column=0,row=3,padx=10,pady=5) buton_urban = tkinter.Button(self.aerosol_window,text="Urban ",command=lambda: self.env_setter(353e-6,0.689)); buton_urban.grid(column=0,row=4,padx=10,pady=5) buton_desert = tkinter.Button(self.aerosol_window,text="Desert ",command=lambda: self.env_setter(145e-6,0.729)); buton_desert.grid(column=0,row=5,padx=10,pady=5) buton_mar_clean = tkinter.Button(self.aerosol_window,text="Maritime Clean ",command=lambda: self.env_setter(90e-6,0.772)); buton_mar_clean.grid(column=1,row=1,padx=10,pady=5) buton_mar_poll = tkinter.Button(self.aerosol_window,text="Maritime Polluted ",command=lambda: self.env_setter(115e-6,0.756)); buton_mar_poll.grid(column=1,row=2,padx=10,pady=5) buton_mar_tro = tkinter.Button(self.aerosol_window,text="Maritime Tropic ",command=lambda: self.env_setter(43e-6,0.774)); buton_mar_tro.grid(column=1,row=3,padx=10,pady=5) buton_arctic = tkinter.Button(self.aerosol_window,text="Arctic ",command=lambda: self.env_setter(23e-6,0.721)); buton_arctic.grid(column=1,row=4,padx=10,pady=5) buton_antarctic = tkinter.Button(self.aerosol_window,text="Antarctic ",command=lambda: self.env_setter(11e-6,0.784)); buton_antarctic.grid(column=1,row=5,padx=10,pady=5) environemnt_info_text = tkinter.Label(self.aerosol_window, text="Please enter the temperature and pressure (in C, and mmHg)") environemnt_info_text.grid(column=0,row=6,columnspan=2,pady=20,padx=10) t_frame = tkinter.Frame(self.aerosol_window) text_t = tkinter.Text(t_frame,height=1,width=10) submit_t_button = tkinter.Button(t_frame,text="set temperature",command=lambda: self.set_temp(text_t.get("1.0","end-1c"))) text_t.pack(side=tkinter.LEFT) submit_t_button.pack(side=tkinter.RIGHT) t_frame.grid(column=0,row=7,columnspan=2,padx=20) p_frame = tkinter.Frame(self.aerosol_window) text_p = tkinter.Text(p_frame,height=1,width=10) submit_p_button = tkinter.Button(p_frame,text="set pressure",command=lambda: self.set_press(text_p.get("1.0","end-1c"))) text_p.pack(side=tkinter.LEFT) submit_p_button.pack(side=tkinter.RIGHT) p_frame.grid(column=0,row=8,columnspan=2,padx=20) testing_info_text = tkinter.Label(self.aerosol_window, text="Change y heights between which average redness and blueness will be calculated") testing_info_text.grid(column=0,row=9,columnspan=2,pady=20,padx=10) r_frame = tkinter.Frame(self.aerosol_window) text_r_l = tkinter.Text(r_frame,height=1,width=10) text_r_u = tkinter.Text(r_frame,height=1,width=10) submit_r_button = tkinter.Button(r_frame,text="calculate_average_red",command=lambda: average_r_label.config( text=self.get_image_average("red",int(text_r_l.get("1.0","end-1c")),int(text_r_u.get("1.0","end-1c"))))) average_r_label = tkinter.Label(r_frame,text="no average yet") text_r_l.pack(side=tkinter.LEFT) text_r_u.pack(side=tkinter.LEFT) average_r_label.pack(side=tkinter.RIGHT) submit_r_button.pack(side=tkinter.RIGHT) r_frame.grid(column=0,row=10,columnspan=2,padx=20) b_frame = tkinter.Frame(self.aerosol_window) text_b_l = tkinter.Text(b_frame,height=1,width=10) text_b_u = tkinter.Text(b_frame,height=1,width=10) submit_b_button = tkinter.Button(b_frame,text="calculate_average_blue",command=lambda: average_b_label.config( text=self.get_image_average("blue",int(text_b_l.get("1.0","end-1c")),int(text_b_u.get("1.0","end-1c"))))) average_b_label = tkinter.Label(b_frame,text="no average yet") text_b_l.pack(side=tkinter.LEFT) text_b_u.pack(side=tkinter.LEFT) average_b_label.pack(side=tkinter.RIGHT) submit_b_button.pack(side=tkinter.RIGHT) b_frame.grid(column=0,row=11,columnspan=2,padx=20) #self.img = Image.fromarray(image,mode="RGB") #self.tk_image = ImageTk.PhotoImage(width=256,height=256,image=self.img) #img = ImageTk.PhotoImage(Image.open("highpress_camera.png")) #self.canvas.create_image(0,0, anchor="center", image=self.tk_image) zoom_in_button = tkinter.Button(self.image_window, text="Zoom In", command=self.zoom_in) zoom_out_button = tkinter.Button(self.image_window, text="Zoom Out", command=self.zoom_out) render_button = tkinter.Button(self.image_window,text="render",command=self.render) zoom_in_button.pack(side=tkinter.LEFT) zoom_out_button.pack(side=tkinter.LEFT) render_button.pack(side=tkinter.RIGHT) self.canvas.bind("",self.zoom_in) self.canvas.bind("", self.zoom_out) def set_temp(self,temp): if temp is None: self.temperature = 0 elif int(temp) < -270 or int(temp) > 100: print("temperature unrealistic, resetting to 0 degrees") self.temperature = 0 else: self.temperature = int(temp) def set_press(self,press): if press is None: self.pressure = 720 elif int(press) < 100 or int(press) > 1300: print("pressure unrealistic, resetting to 720 mmHg") self.pressure = 720 else: self.pressure = int(press) def get_image_average(self,color,low, high): if color == "blue": slice = self.image[:][low:high] print(slice.size) print(slice) return "{} + {}".format(low,high) else: return "red".format(low,high) def env_setter(self,environment_constant,g): self.betaM = skydome.Vec3(environment_constant,environment_constant,environment_constant) self.g = g def render(self): self.image = skydome.renderFromCamera(self.coords,self.betaM,self.g,self.altitude,self.temperature,self.pressure) self.img = Image.fromarray(self.image,mode="RGB") self.tk_image = ImageTk.PhotoImage(width=256,height=256,image=self.img) #img = ImageTk.PhotoImage(Image.open("highpress_camera.png")) self.canvas.create_image(0,0, anchor="nw", image=self.tk_image) def zoom_in(self, event=None): # Increase the image size by a factor (e.g., 1.2) self.img = self.img.resize((int(self.img.width * 1.2), int(self.img.height * 1.2))) self.tk_image = ImageTk.PhotoImage(self.img) self.canvas.delete("all") self.canvas.create_image(0, 0, anchor="nw", image=self.tk_image) def zoom_out(self, event=None): # Decrease the image size by a factor (e.g., 0.8) self.img = self.img.resize((int(self.img.width * 0.8), int(self.img.height * 0.8)))#,resampling) self.tk_image = ImageTk.PhotoImage(self.img) self.canvas.delete("all") self.canvas.create_image(0, 0, anchor="nw", image=self.tk_image) # def show_image(self,coords): # self.coords = coords #image_shower = renderedImageZoom(image_window,coords) # self.image_window.mainloop() def add_marker_event(self,coords): self.coords = coords print("marker added to {}".format(self.coords)) self.map_widget.delete_all_marker() new_marker = self.map_widget.set_marker(self.coords[0], self.coords[1], text="sunset observer") self.get_altitude(coords) def marker_click(self,marker): print(f"marker clicked - text: {marker.text} position: {marker.position}") def get_altitude(self,coords): self.coords = coords print("getting altitude for {}\n".format(self.coords)) params = get_api_params(self.coords) r = requests.get(URL,params) data = r.json() print(data['results'][0]['elevation']) self.altitude = data['results'][0]['elevation'] image_window = tkinter.Toplevel() #image_shower = renderedImageZoom(image_window,coords) image_shower = renderedImageZoom(root_tk,image_window,environment_tk) root_tk.mainloop()