diff --git a/DemoPrograms/Demo_Desktop_Widget_Postit.py b/DemoPrograms/Demo_Desktop_Widget_Postit.py index edffb800..c9f29e0f 100644 --- a/DemoPrograms/Demo_Desktop_Widget_Postit.py +++ b/DemoPrograms/Demo_Desktop_Widget_Postit.py @@ -3,28 +3,67 @@ import PySimpleGUI as sg """ Demo Desktop Widget Postit - Sizegrip Element is used to make a window without a titlebar be resizable. - - There are 3 lines - 1. Make the window - 2. Set initial size of window as the minimum - 3. Read any event from the window which will close the window and return + This is the longer version as it adds a lot to the right click menu to make it like + the other more complete desktop widgets. Note that while the window has no scrollbar, you can still use the mousewheel to scroll - + Copyright 2021 PySimpleGUI """ # ----- Make the window ----- -window = sg.Window('Postit', [[sg.T('Postit Note', text_color='black', background_color='#FFFF88')], - [sg.ML(size=(30,5), background_color='#FFFF88', no_scrollbar=True, k='-ML-', border_width=0, expand_y=True, expand_x=True), sg.Sizegrip(background_color='#FFFF88')]], - no_titlebar=True, grab_anywhere=True, margins=(0,0), background_color='#FFFF88', element_padding=(0,0), - right_click_menu=sg.MENU_RIGHT_CLICK_EXIT, keep_on_top=True, font='_ 20', resizable=True, finalize=True) +def make_window(loc): + text_font = sg.user_settings_get_entry('-font-', '_ 20') + text = sg.user_settings_get_entry('-text-', '') + alpha = sg.user_settings_get_entry('-alpha-', 1.0) + title = sg.user_settings_get_entry('-title-', 'Postit') + + layout = [[sg.T(title, text_color='black', background_color='#FFFF88', k='-TITLE-')], + [sg.ML(text, size=(30, 5), background_color='#FFFF88', no_scrollbar=True, k='-ML-', border_width=0, expand_y=True, expand_x=True, font=text_font), + sg.Sizegrip(background_color='#FFFF88')]] + window = sg.Window('Postit',layout, + no_titlebar=True, grab_anywhere=True, margins=(0, 0), background_color='#FFFF88', element_padding=(0, 0), location=loc, + right_click_menu=[[''], ['Edit Me', 'Change Font', 'Save Location', 'Alpha', [str(x) for x in range(1, 11)], 'Choose Title', 'Exit', ]], keep_on_top=True, + font='_ 20', right_click_menu_font=text_font, resizable=True, finalize=True, alpha_channel=alpha) + window.set_min_size(window.size) + + return window # ----- Make sure it doesn't get any smaller than it is initially ----- -window.set_min_size(window.size) -# ----- Read the window and wait for any event. -# ----- Any event will cause the read to return -# ----- Has a right click menu that can be used to choose exit -window.read(close=True) +def main(): + loc = sg.user_settings_get_entry('-location-', (None, None)) + window = make_window(loc) + + while True: # Event Loop + event, values = window.read() + print(event, values) + if event == sg.WIN_CLOSED or event == 'Exit': + break + if event == 'Edit Me': + sg.execute_editor(__file__) + elif event == 'Change Font': + font = sg.popup_get_text('Main Information Font and Size (e.g. courier 70)', default_text=sg.user_settings_get_entry('-font-'), keep_on_top=True, location=window.current_location()) + if font: + sg.user_settings_set_entry('-font-', font) + _, window = window.close(), make_window(loc) + elif event == 'Save Location': + sg.user_settings_set_entry('-location-', window.current_location()) + elif event in [str(x) for x in range(1,11)]: + window.set_alpha(int(event)/10) + sg.user_settings_set_entry('-alpha-', int(event)/10) + elif event == 'Choose Title': + new_title = sg.popup_get_text('Choose a title for your date', default_text=sg.user_settings_get_entry('-title-', 'Postit'), location=window.current_location(), keep_on_top=True) + if new_title is not None: + window['-TITLE-'].update(new_title) + sg.user_settings_set_entry('-title-', new_title) + sg.user_settings_set_entry('-text-', window['-ML-'].get().rstrip()) + + window.close() + + +if __name__ == '__main__': + # To start the window at a specific location, get this location on the command line + # The location should be in form x,y with no spaces + + main() \ No newline at end of file diff --git a/DemoPrograms/Demo_Desktop_Widget_Postit_3_Lines.py b/DemoPrograms/Demo_Desktop_Widget_Postit_3_Lines.py new file mode 100644 index 00000000..c4e4e889 --- /dev/null +++ b/DemoPrograms/Demo_Desktop_Widget_Postit_3_Lines.py @@ -0,0 +1,31 @@ +import PySimpleGUI as sg + +""" + Demo Desktop Widget Postit + + Sizegrip Element is used to make a window without a titlebar be resizable. + + There are 3 lines + 1. Make the window + 2. Set initial size of window as the minimum + 3. Read any event from the window which will close the window and return + + Note that while the window has no scrollbar, you can still use the mousewheel to scroll + + Copyright 2021 PySimpleGUI +""" + +# ----- Make the window ----- +window = sg.Window('Postit', [[sg.T('Postit Note', text_color='black', background_color='#FFFF88')], + [sg.ML(size=(30, 5), background_color='#FFFF88', no_scrollbar=True, k='-ML-', border_width=0, expand_y=True, expand_x=True), + sg.Sizegrip(background_color='#FFFF88')]], + no_titlebar=True, grab_anywhere=True, margins=(0, 0), background_color='#FFFF88', element_padding=(0, 0), + right_click_menu=sg.MENU_RIGHT_CLICK_EXIT, keep_on_top=True, font='_ 20', resizable=True, finalize=True) + +# ----- Make sure it doesn't get any smaller than it is initially ----- +window.set_min_size(window.size) + +# ----- Read the window and wait for any event. +# ----- Any event will cause the read to return +# ----- Has a right click menu that can be used to choose exit +window.read(close=True)