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

Method notify

PySimpleGUI/PySimpleGUI.py:13049–13127  ·  view source on GitHub ↗

Displays a "notification window", usually in the bottom right corner of your display. Has an icon, a title, and a message The window will slowly fade in and out if desired. Clicking on the window will cause it to move through the end the current "phase". For example, if the window

(cls, title, message, icon=_tray_icon_success, display_duration_in_ms=SYSTEM_TRAY_MESSAGE_DISPLAY_DURATION_IN_MILLISECONDS,
               fade_in_duration=SYSTEM_TRAY_MESSAGE_FADE_IN_DURATION, alpha=0.9, location=None)

Source from the content-addressed store, hash-verified

13047
13048 @classmethod
13049 def notify(cls, title, message, icon=_tray_icon_success, display_duration_in_ms=SYSTEM_TRAY_MESSAGE_DISPLAY_DURATION_IN_MILLISECONDS,
13050 fade_in_duration=SYSTEM_TRAY_MESSAGE_FADE_IN_DURATION, alpha=0.9, location=None):
13051 """
13052 Displays a "notification window", usually in the bottom right corner of your display. Has an icon, a title, and a message
13053 The window will slowly fade in and out if desired. Clicking on the window will cause it to move through the end the current "phase". For example, if the window was fading in and it was clicked, then it would immediately stop fading in and instead be fully visible. It's a way for the user to quickly dismiss the window.
13054 :param title: Text to be shown at the top of the window in a larger font
13055 :type title: (str)
13056 :param message: Text message that makes up the majority of the window
13057 :type message: (str)
13058 :param icon: A base64 encoded PNG/GIF image or PNG/GIF filename that will be displayed in the window
13059 :type icon: bytes | str
13060 :param display_duration_in_ms: Number of milliseconds to show the window
13061 :type display_duration_in_ms: (int)
13062 :param fade_in_duration: Number of milliseconds to fade window in and out
13063 :type fade_in_duration: (int)
13064 :param alpha: Alpha channel. 0 - invisible 1 - fully visible
13065 :type alpha: (float)
13066 :param location: Location on the screen to display the window
13067 :type location: (int, int)
13068 :return: (int) reason for returning
13069 :rtype: (int)
13070 """
13071
13072 messages = message.split('\n')
13073 full_msg = ''
13074 for m in messages:
13075 m_wrap = textwrap.fill(m, SYSTEM_TRAY_MESSAGE_MAX_LINE_LENGTH)
13076 full_msg += m_wrap + '\n'
13077 message = full_msg[:-1]
13078
13079 win_msg_lines = message.count("\n") + 1
13080 max_line = max(message.split('\n'))
13081
13082 screen_res_x, screen_res_y = Window.get_screen_size()
13083 win_margin = SYSTEM_TRAY_WIN_MARGINS # distance from screen edges
13084 win_width, win_height = 364, 66 + (14.8 * win_msg_lines)
13085
13086 layout = [[Graph(canvas_size=(win_width, win_height), graph_bottom_left=(0, win_height), graph_top_right=(win_width, 0), key="-GRAPH-",
13087 background_color=SYSTEM_TRAY_MESSAGE_WIN_COLOR, enable_events=True)]]
13088
13089 win_location = location if location is not None else (screen_res_x - win_width - win_margin[0], screen_res_y - win_height - win_margin[1])
13090 window = Window(title, layout, background_color=SYSTEM_TRAY_MESSAGE_WIN_COLOR, no_titlebar=True,
13091 location=win_location, keep_on_top=True, alpha_channel=0, margins=(0, 0), element_padding=(0, 0), grab_anywhere=True, finalize=True)
13092
13093 window["-GRAPH-"].draw_rectangle((win_width, win_height), (-win_width, -win_height), fill_color=SYSTEM_TRAY_MESSAGE_WIN_COLOR,
13094 line_color=SYSTEM_TRAY_MESSAGE_WIN_COLOR)
13095 if type(icon) is bytes:
13096 window["-GRAPH-"].draw_image(data=icon, location=(20, 20))
13097 elif icon is not None:
13098 window["-GRAPH-"].draw_image(filename=icon, location=(20, 20))
13099 window["-GRAPH-"].draw_text(title, location=(64, 20), color=SYSTEM_TRAY_MESSAGE_TEXT_COLOR, font=("Helvetica", 12, "bold"),
13100 text_location=TEXT_LOCATION_TOP_LEFT)
13101 window["-GRAPH-"].draw_text(message, location=(64, 44), color=SYSTEM_TRAY_MESSAGE_TEXT_COLOR, font=("Helvetica", 9),
13102 text_location=TEXT_LOCATION_TOP_LEFT)
13103 window["-GRAPH-"].set_cursor('hand2')
13104
13105 if fade_in_duration:
13106 for i in range(1, int(alpha * 100)): # fade in

Callers 2

show_messageMethod · 0.95
popup_notifyFunction · 0.80

Calls 11

set_alphaMethod · 0.95
readMethod · 0.95
closeMethod · 0.95
GraphClass · 0.85
WindowClass · 0.85
get_screen_sizeMethod · 0.80
draw_rectangleMethod · 0.80
draw_imageMethod · 0.80
draw_textMethod · 0.80
fillMethod · 0.45
set_cursorMethod · 0.45

Tested by

no test coverage detected