def ok_click(self, e):
# check for changes to cron
if self.cron_lamp_on.GetLabel() == "not found" or self.cron_lamp_off.GetLabel() == "not found":
mbox = wx.MessageDialog(None, "Add new job to cron?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
if sure == wx.ID_YES:
if self.cron_lamp_on.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_on.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_on_string_text.GetLabel(), cron_task)
if self.cron_lamp_off.GetLabel() == "not found":
cron_task = "/home/pi/Pigrow/scripts/switches/" + "lamp_off.py"
MainApp.cron_info_pannel.add_to_onetime_list("new", "True", self.new_off_string_text.GetLabel(), cron_task)
MainApp.cron_info_pannel.update_cron_click("e")
elif not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel() or not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
print(":" + self.new_on_string_text.GetLabel() + ":")
print(":" + self.cron_lamp_on.GetLabel() + ":")
mbox = wx.MessageDialog(None, "Update cron timing?", "Are you sure?", wx.YES_NO|wx.ICON_QUESTION)
sure = mbox.ShowModal()
result_on = 'done' # these are for cases when only one is changed
result_off = 'done' # if it attempts to update cron and fails it'll change to an error message
if sure == wx.ID_YES:
if not self.new_on_string_text.GetLabel() == self.cron_lamp_on.GetLabel():
result_on = self.change_cron_trigger("lamp_on.py", self.new_on_string_text.GetLabel())
if not self.new_off_string_text.GetLabel() == self.cron_lamp_off.GetLabel():
result_off = self.change_cron_trigger("lamp_off.py", self.new_off_string_text.GetLabel())
if result_on != "done" or result_off != "done":
wx.MessageBox('Cron update error, edit lamp switches in the cron pannel', 'Info', wx.OK | wx.ICON_INFORMATION)
else:
MainApp.cron_info_pannel.update_cron_click("e")
# check for changes to settings file
time_lamp_on = str(self.on_hour_spin.GetValue()) + ":" + str(self.on_min_spin.GetValue())
time_lamp_off = str(self.off_hour_spin.GetValue()) + ":" + str(self.off_min_spin.GetValue())
if not MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] == time_lamp_on or not MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] == time_lamp_off:
MainApp.config_ctrl_pannel.config_dict["time_lamp_on"] = time_lamp_on
MainApp.config_ctrl_pannel.config_dict["time_lamp_off"] = time_lamp_off
MainApp.config_ctrl_pannel.update_setting_click("e")
MainApp.config_ctrl_pannel.update_config_click("e")
self.Destroy()
评论列表
文章目录