MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_System_Tray_Reminder.py:43–80  ·  view source on GitHub ↗

Function with all the good stuff. Creates the System Tray and processes all events

()

Source from the content-addressed store, hash-verified

41
42
43def main():
44 """
45 Function with all the good stuff. Creates the System Tray and processes all events
46 """
47 delay = frequency_in_seconds = STARTING_FREQUENCY
48
49 tray_icon = resize_base64_image(icon, (64,64)) if sg.port == 'PySimpleGUI' else icon
50
51 menu_def = ['UNUSED', ['Change Frequency', '---', 'Exit']]
52
53 tray = sg.SystemTray(menu=menu_def, data_base64=tray_icon, tooltip=f'Reminder every {frequency_in_seconds/60} minutes')
54
55 starting_seconds = time()
56
57 while True:
58 event = tray.read(timeout=delay*1000)
59 if event == 'Exit':
60 break
61
62 delta_from_last = time() - starting_seconds
63 if delta_from_last >= frequency_in_seconds:
64 starting_seconds = time()
65 delta_from_last = 0
66 sg.popup_no_wait('Reminder!', f'It has been {frequency_in_seconds/60} minutes since your last reminder', background_color=POPUP_BACKGROUND_COLOR, text_color=POPUP_TEXT_COLOR, font=POPUP_FONT)
67
68 if event == 'Change Frequency': # Change how often a reminder should be shown
69 freq = sg.popup_get_text(f'Currently you will be reminded every {frequency_in_seconds/60} minutes\n'+
70 'Enter new frequency in minutes', 'Change Timer Frequency')
71 try:
72 frequency_in_seconds = int(float(freq)*60)
73 starting_seconds = time()
74 delta_from_last = 0
75 tray.update(tooltip=f'Reminder every {frequency_in_seconds/60} minutes')
76 except:
77 sg.popup_error(f'Invalid value: {freq}', f'Keeping old frequency of {frequency_in_seconds/60} minutes')
78
79 delay = frequency_in_seconds - delta_from_last
80 tray.close()
81
82if __name__ == '__main__':
83 icon = \

Callers 1

Calls 4

readMethod · 0.95
updateMethod · 0.95
closeMethod · 0.95
resize_base64_imageFunction · 0.70

Tested by

no test coverage detected