Renamed postit to 3-line postit. Added new postit with expanded right click menu (a fuller desktop widget)

This commit is contained in:
PySimpleGUI 2021-08-08 13:14:08 -04:00
parent 17fbd31dce
commit 9d39fad480
2 changed files with 86 additions and 16 deletions

View File

@ -3,12 +3,8 @@ import PySimpleGUI as sg
""" """
Demo Desktop Widget Postit Demo Desktop Widget Postit
Sizegrip Element is used to make a window without a titlebar be resizable. 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.
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 Note that while the window has no scrollbar, you can still use the mousewheel to scroll
@ -16,15 +12,58 @@ import PySimpleGUI as sg
""" """
# ----- Make the window ----- # ----- Make the window -----
window = sg.Window('Postit', [[sg.T('Postit Note', text_color='black', background_color='#FFFF88')], def make_window(loc):
[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')]], text_font = sg.user_settings_get_entry('-font-', '_ 20')
no_titlebar=True, grab_anywhere=True, margins=(0,0), background_color='#FFFF88', element_padding=(0,0), text = sg.user_settings_get_entry('-text-', '')
right_click_menu=sg.MENU_RIGHT_CLICK_EXIT, keep_on_top=True, font='_ 20', resizable=True, finalize=True) alpha = sg.user_settings_get_entry('-alpha-', 1.0)
title = sg.user_settings_get_entry('-title-', 'Postit')
# ----- Make sure it doesn't get any smaller than it is initially ----- 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) window.set_min_size(window.size)
# ----- Read the window and wait for any event. return window
# ----- Any event will cause the read to return
# ----- Has a right click menu that can be used to choose exit # ----- Make sure it doesn't get any smaller than it is initially -----
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()

View File

@ -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)