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

Function _error_popup_with_code

PySimpleGUI/PySimpleGUI.py:22134–22187  ·  view source on GitHub ↗

Makes the error popup window :param title: The title that will be shown in the popup's titlebar and in the first line of the window :type title: str :param filename: The filename to show.. may not be the filename that actually encountered the exception! :type filename

(title, filename, line_num, *args, emoji=None)

Source from the content-addressed store, hash-verified

22132
22133
22134def _error_popup_with_code(title, filename, line_num, *args, emoji=None):
22135 """
22136 Makes the error popup window
22137
22138 :param title: The title that will be shown in the popup's titlebar and in the first line of the window
22139 :type title: str
22140 :param filename: The filename to show.. may not be the filename that actually encountered the exception!
22141 :type filename: str
22142 :param line_num: Line number within file with the error
22143 :type line_num: int | str
22144 :param args: A variable number of lines of messages
22145 :type args: *Any
22146 :param emoji: An optional BASE64 Encoded image to shows in the error window. If set to '' (empty string) then no emoji will be shown
22147 :type emoji: bytes | str
22148 """
22149 editor_filename = execute_get_editor()
22150 if emoji is None:
22151 emoji_data = _random_error_emoji()
22152 else:
22153 emoji_data = emoji
22154
22155 layout = [[Text('ERROR'), Text(title)]]
22156 if emoji_data != '':
22157 layout += [[Image(data=emoji_data)]]
22158 lines = []
22159 for msg in args:
22160 if isinstance(msg, Exception):
22161 lines += [[f'Additional Exception info pased in by PySimpleGUI or user: Error type is: {type(msg).__name__}']]
22162 lines += [[f'In file {__file__} Line number {msg.__traceback__.tb_lineno}']]
22163 lines += [[f'{msg}']]
22164 else:
22165 lines += [str(msg).split('\n')]
22166 max_line_len = 0
22167 for line in lines:
22168 max_line_len = max(max_line_len, max([len(s) for s in line]))
22169
22170 layout += [[Text(''.join(line), size=(min(max_line_len, 90), None))] for line in lines]
22171 layout += [[Button('Close'), Button('Take me to error', disabled=True if not editor_filename else False), Button('Kill Application', button_color='white on red')]]
22172 if not editor_filename:
22173 layout += [[Text('Configure editor in the Global settings to enable "Take me to error" feature')]]
22174 window = Window(title, layout, keep_on_top=True)
22175
22176 while True:
22177 event, values = window.read()
22178 if event in ('Close', WIN_CLOSED):
22179 break
22180 if event == 'Kill Application':
22181 window.close()
22182 popup_quick_message('KILLING APP! BYE!', font='_ 18', keep_on_top=True, text_color='white', background_color='red', non_blocking=False)
22183 sys.exit()
22184 if event == 'Take me to error' and filename is not None and line_num is not None:
22185 execute_editor(filename, line_num)
22186
22187 window.close()
22188
22189
22190#####################################################################

Callers 1

Calls 10

readMethod · 0.95
closeMethod · 0.95
execute_get_editorFunction · 0.85
_random_error_emojiFunction · 0.85
TextClass · 0.85
ImageClass · 0.85
ButtonClass · 0.85
WindowClass · 0.85
popup_quick_messageFunction · 0.85
execute_editorFunction · 0.85

Tested by

no test coverage detected