Defines the layout and creates the window for the main window If the parm test_window is True, then a simplified, and EASY to close version is shown :param location: (x,y) location to create the window :type location: Tuple[int, int] :param test_window: If True, then this is a
(location, test_window=False)
| 65 | |
| 66 | |
| 67 | def make_window(location, test_window=False): |
| 68 | """ |
| 69 | Defines the layout and creates the window for the main window |
| 70 | If the parm test_window is True, then a simplified, and EASY to close version is shown |
| 71 | |
| 72 | :param location: (x,y) location to create the window |
| 73 | :type location: Tuple[int, int] |
| 74 | :param test_window: If True, then this is a test window & will close by clicking on it |
| 75 | :type test_window: bool |
| 76 | :return: newly created window |
| 77 | :rtype: sg.Window |
| 78 | """ |
| 79 | title = sg.user_settings_get_entry('-title-', '') |
| 80 | if not test_window: |
| 81 | theme = sg.user_settings_get_entry('-theme-', THEME) |
| 82 | sg.theme(theme) |
| 83 | main_info_font = sg.user_settings_get_entry('-main info font-', 'Courier 60') |
| 84 | |
| 85 | # ------------------- Window Layout ------------------- |
| 86 | initial_text = get_date_string() |
| 87 | if test_window: |
| 88 | title_element = sg.Text('Click to close', font=title_font, enable_events=True) |
| 89 | right_click_menu = [[''], ['Exit', ]] |
| 90 | else: |
| 91 | title_element = sg.pin(sg.Text(title, size=(20, 1), font=title_font, justification='c', k='-TITLE-')) |
| 92 | right_click_menu = [[''], |
| 93 | ['Choose Title', 'Edit Me', 'New Theme', 'Save Location', 'Font', 'Refresh', 'Set Refresh Rate', 'Show Refresh Info', 'Hide Refresh Info', |
| 94 | 'Alpha', [str(x) for x in range(1, 11)], 'Exit', ]] |
| 95 | |
| 96 | |
| 97 | layout = [[title_element], |
| 98 | [sg.Text(initial_text, size=(len(initial_text)+2, 1), font=main_info_font, k='-MAIN INFO-', justification='c', enable_events=test_window)], |
| 99 | [sg.pin( |
| 100 | sg.Text(size=(15, 2), font=refresh_font, k='-REFRESHED-', justification='c', visible=sg.user_settings_get_entry('-show refresh-', True)))]] |
| 101 | |
| 102 | # ------------------- Window Creation ------------------- |
| 103 | try: |
| 104 | window = sg.Window('Desktop Widget Template', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_justification='c', element_padding=(0, 0), alpha_channel=sg.user_settings_get_entry('-alpha-', ALPHA), finalize=True, right_click_menu=right_click_menu, right_click_menu_tearoff=False) |
| 105 | except Exception as e: |
| 106 | if sg.popup_yes_no('Error creating the window', e, 'Do you want to delete your settings file to fix?') == 'Yes': |
| 107 | sg.user_settings_delete_filename() |
| 108 | sg.popup('Settings file deleted. Please restart your program.') |
| 109 | exit() |
| 110 | return window |
| 111 | |
| 112 | def get_date_string(): |
| 113 | dtime_here = datetime.utcnow() + timedelta(hours=-5) |
no test coverage detected