fixed setting pressure and save image button
This commit is contained in:
parent
5ecade7cb0
commit
10ead4e3a8
1 changed files with 50 additions and 10 deletions
60
app.py
60
app.py
|
@ -3,6 +3,7 @@ import tkintermapview
|
|||
import requests
|
||||
import skydome
|
||||
import math
|
||||
import imageio
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
|
||||
|
@ -25,6 +26,20 @@ def printer():
|
|||
environment_tk = tkinter.Tk()
|
||||
|
||||
|
||||
class EnvButton(tkinter.Button):
|
||||
def __init__(self,*args,**kwargs):
|
||||
tkinter.Button.__init__(self, *args, **kwargs)
|
||||
self.default_bg_color = self.cget('bg')
|
||||
self['activebackground'] = 'cadetblue2'
|
||||
|
||||
def switch(self):
|
||||
print(self.cget('bg'))
|
||||
if self.cget('bg') == self.default_bg_color:
|
||||
self['bg'] = 'cadetblue1'
|
||||
else:
|
||||
self['bg'] = self.default_bg_color
|
||||
|
||||
|
||||
|
||||
class renderedImageZoom:
|
||||
def __init__(self,root,image_window,aerosol_window):
|
||||
|
@ -35,6 +50,8 @@ class renderedImageZoom:
|
|||
self.pressure = 720
|
||||
self.set_sun(90)
|
||||
self.fisheye = False
|
||||
self.curr_env = 0
|
||||
self.env_list = ["cont_clean","cont_avr","cont_poll","urban","desert","mar_clean","mar_poll","mar_tro","arctic","antarctic"]
|
||||
|
||||
self.aerosol_window = aerosol_window
|
||||
# create map widget
|
||||
|
@ -83,36 +100,51 @@ class renderedImageZoom:
|
|||
#
|
||||
#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));
|
||||
|
||||
# button_list = [buton_cont_clean,buton_cont_avr,buton_cont_poll,buton_urban,buton_desert,buton_mar_clean,buton_mar_poll,button_mar_tro,button_arctic,buton_antarctic]
|
||||
|
||||
def set_active(index):
|
||||
|
||||
if index != self.curr_env:
|
||||
button_list[index].switch()
|
||||
button_list[self.curr_env].switch()
|
||||
self.curr_env = index
|
||||
|
||||
buton_cont_clean = EnvButton(self.aerosol_window,text="Continental Clean",command=lambda: [self.env_setter(26e-6,0.709),set_active(0)]);
|
||||
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_clean['bg'] = 'cadetblue1'
|
||||
self.env_setter(26e-6,0.709)
|
||||
|
||||
|
||||
buton_cont_avr = EnvButton(self.aerosol_window,text="Continental Average ",command=lambda: [self.env_setter(75e-6,0.793),set_active(1)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Continental Polluted ",command=lambda:[ self.env_setter(175e-6,0.698),set_active(2)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Urban ",command=lambda: [self.env_setter(353e-6,0.689),set_active(3)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Desert ",command=lambda: [self.env_setter(145e-6,0.729),set_active(4)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Maritime Clean ",command=lambda: [self.env_setter(90e-6,0.772),set_active(5)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Maritime Polluted ",command=lambda: [self.env_setter(115e-6,0.756),set_active(6)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Maritime Tropic ",command=lambda: [self.env_setter(43e-6,0.774),set_active(7)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Arctic ",command=lambda: [self.env_setter(23e-6,0.721),set_active(8)]);
|
||||
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 = EnvButton(self.aerosol_window,text="Antarctic ",command=lambda:[ self.env_setter(11e-6,0.784),set_active(9)]);
|
||||
buton_antarctic.grid(column=1,row=5,padx=10,pady=5)
|
||||
|
||||
button_list = [buton_cont_clean,buton_cont_avr,buton_cont_poll,buton_urban,buton_desert,buton_mar_clean,buton_mar_poll,buton_mar_tro,buton_arctic,buton_antarctic]
|
||||
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)
|
||||
|
||||
|
@ -203,8 +235,10 @@ class renderedImageZoom:
|
|||
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)
|
||||
cam_fish_toggle = tkinter.Button(self.image_window,text="cam view", command=cam_toggle)
|
||||
save_button = tkinter.Button(self.image_window,text="Save image",command=self.save_image)
|
||||
zoom_in_button.pack(side=tkinter.LEFT)
|
||||
zoom_out_button.pack(side=tkinter.LEFT)
|
||||
save_button.pack(side=tkinter.LEFT)
|
||||
render_button.pack(side=tkinter.RIGHT)
|
||||
cam_fish_toggle.pack(side=tkinter.RIGHT)
|
||||
|
||||
|
@ -242,6 +276,8 @@ class renderedImageZoom:
|
|||
pressure = sorted([400,int(press),900])[1]
|
||||
print("pressure unrealistic, resetting to clamped value {}".format(pressure))
|
||||
self.pressure = pressure
|
||||
else:
|
||||
self.pressure = int(press)
|
||||
|
||||
|
||||
def get_image_average(self,color,low, high):
|
||||
|
@ -286,6 +322,10 @@ class renderedImageZoom:
|
|||
self.canvas.create_image(0,0, anchor="nw", image=self.tk_image)
|
||||
|
||||
|
||||
def save_image(self):
|
||||
imageio.imwrite("./sunset_t{}_p{}_env_{}_alt{}_ang{}.png".format(self.temperature,self.pressure,self.env_list[self.curr_env],self.altitude
|
||||
,math.degrees(math.acos(self.sunDir.v[1]))), self.img)
|
||||
|
||||
|
||||
def zoom_in(self, event=None):
|
||||
# Increase the image size by a factor (e.g., 1.2)
|
||||
|
|
Loading…
Reference in a new issue