'I am not able to get any output on the browser
This piece of code calculates the shift that the user will be on a given date. 3 x Shifts (Morning, Evening, Night) rotating every 5 weeks. Each shift has 2 x teams of techs. 1st team works on a Sun-Thu rotation 2nd team works on a Tue-Sat rotation
A GUI has been implemented with PySimpleGUI in order to make the code more user friendly. I tried running this in my web browser using PySipmleGUIWeb.
Starting the app in the browser I have no issues choosing the Day, shift etc. As soon as I hit the submit button nothing happens actually and I get the following output in the Pycharm console:
Returned from Remi Start command... now sending None event
Tried to get rid of the popup windows for the results and tried to just print them. I got no error but only the results in the PyCharm console instead of the web browser.
Any idea on how to make this work using the PySimpleGUIWeb?
Thanks a lot in advance.
import datetime
import math
import calendar
import PySimpleGUIWeb as sg
import traceback
layout = [
[sg.Text("Please enter your Current Shift and the date you would like to check what rotation you will be.")],
[sg.Text("Current Shift", size=(15, 1)), sg.Checkbox("Morning", key="morning"), sg.Checkbox("Evening", key="evening"), sg.Checkbox("Night", key="night")],
[sg.Text("First day Off", size=(15, 1)), sg.Combo(["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], key="Day_Off")],
[sg.Text("Date YYYY.MM.DD", size=(18, 1)), sg.InputText("Date in YYYY.MM.DD format", key="Date")],
[sg.Submit(), sg.Cancel()]
]
window = sg.Window("Shift Rotation", layout=layout, background_color="#272533", size=(600, 150), web_start_browser=True)
try:
while True:
event, values = window.read()
window.close()
if event is None:
break
if event == "Cancel":
break
if event == "Submit":
def Days_Off():
week = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
Dayoff2 = week[week.index(Dayoff1.lower())+1]
DayOffCheck = calendar.day_name[date1.weekday()]
if Dayoff1.lower() == DayOffCheck.lower() or Dayoff2.lower() == DayOffCheck.lower():
sg.popup("Hey it is {}! You got the day off!".format(DayOffCheck))
else:
sg.popup("It is {}! You are working on that day!".format(DayOffCheck))
def Morning():
Morning = []
Evening = []
Night = []
x = 1
y = 2
z = 3
for i in range(99999):
Morning.append(float(x + 3 * i))
Evening.append(float(y + 3 * i))
Night.append(float(z + 3 * i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))
def Evening():
Evening = []
Night = []
Morning = []
x=1
y=2
z=3
for i in range(99999):
Evening.append(float(x+3*i))
Night.append(float(y+3*i))
Morning.append(float(z+3*i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))
def Night():
x = 1
y = 2
z = 3
Night = [x]
Morning = [y]
Evening = [z]
for i in range(1, 99999):
Night.append(int(x + 3 * i))
Morning.append(int(y + 3 * i))
Evening.append(int(z + 3 * i))
if ShiftC in Morning:
sg.popup("You will be on Morning shift at requested date: {}".format(date_entry))
elif ShiftC in Evening:
sg.popup("You will be on Evening shift at requested date: {}".format(date_entry))
elif ShiftC in Night:
sg.popup("You will be on Night shift at requested date: {}".format(date_entry))
if values["morning"] == True:
SelectShift = "morning"
elif values["evening"] == True:
SelectShift = "evening"
elif values["night"] == True:
SelectShift = "night"
date_entry = values["Date"]
Dayoff1 = values["Day_Off"]
year, month, day = map(int, date_entry.split('.'))
date1 = datetime.date(year, month, day)
TotalD = (datetime.date(2021, 1, 9).toordinal() - date1.toordinal()) * -1
ShiftC = math.ceil(TotalD / 35)
if SelectShift.lower() == "morning":
Morning()
Days_Off()
elif SelectShift.lower() == "evening":
Evening()
Days_Off()
elif SelectShift.lower() == "night":
Night()
Days_Off()
except Exception as e:
tb = traceback.format_exc()
sg.Print(f'An error happened. Here is the info:', e, tb)
sg.popup_error(f'AN EXCEPTION OCCURRED!', e, tb)
Solution 1:[1]
The issue was the
window.close()
used in line 24. Moved it in line 111 and this works like a charm right now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | theo_gd |