Floating toolbar, Cookbook update
This commit is contained in:
parent
080450c691
commit
ef8c1a2857
3 changed files with 183 additions and 36 deletions
|
@ -988,7 +988,7 @@ Use the upper half to generate your hash code. Then paste it into the code in t
|
|||
password_hash = sha1hash.hexdigest()
|
||||
if password_hash == hash:
|
||||
return True
|
||||
else:
|
||||
else:
|
||||
return False
|
||||
|
||||
login_password_hash = '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
|
||||
|
@ -1089,6 +1089,81 @@ You can easily change colors to match your background by changing a couple of pa
|
|||
Launcher()
|
||||
|
||||
|
||||
|
||||
|
||||
## Desktop Floating Widget
|
||||
|
||||
This is a little widget you can leave running on your desktop. Will hopefully see more of these for things like checking email, checking server pings, displaying system information, dashboards, etc
|
||||
.
|
||||
Much of the code is handling the button states in a fancy way. It could be much simpler if you don't change the button text based on state.
|
||||
|
||||
|
||||
import PySimpleGUI as sg
|
||||
import time
|
||||
|
||||
"""
|
||||
Timer Desktop Widget Creates a floating timer that is always on top of other windows You move it by grabbing anywhere on the window Good example of how to do a non-blocking, polling program using PySimpleGUI Can be used to poll hardware when running on a Pi NOTE - you will get a warning message printed when you exit using exit button.
|
||||
It will look something like: invalid command name "1616802625480StopMove""""
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
sg.ChangeLookAndFeel('Black')
|
||||
sg.SetOptions(element_padding=(0,0))
|
||||
# Make a form, but don't use context manager
|
||||
# Create the form layout
|
||||
form_rows = [[sg.Text('')],
|
||||
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
|
||||
[sg.ReadFormButton('Pause', key='button', button_color=('white', '#001480')), sg.ReadFormButton('Reset', button_color=('white', '#007339')), sg.Exit(button_color=('white','firebrick4'))]]
|
||||
# Layout the rows of the form and perform a read. Indicate the form is non-blocking!
|
||||
form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True)
|
||||
form.Layout(form_rows)
|
||||
#
|
||||
# ---------------- main loop ----------------
|
||||
current_time = 0
|
||||
paused = False
|
||||
start_time = int(round(time.time()*100))
|
||||
while (True):
|
||||
# --------- Read and update window --------
|
||||
if not paused:
|
||||
button, values = form.ReadNonBlocking()
|
||||
current_time = int(round(time.time()*100)) - start_time
|
||||
else:
|
||||
button, values = form.Read()
|
||||
# --------- Do Button Operations --------
|
||||
if values is None or button == 'Exit':
|
||||
break
|
||||
if button is 'Reset':
|
||||
start_time = int(round(time.time()*100))
|
||||
current_time = 0
|
||||
paused_time = start_time
|
||||
elif button == 'Pause':
|
||||
paused = True
|
||||
paused_time = int(round(time.time()*100))
|
||||
element = form.FindElement('button')
|
||||
element.Update(new_text='Run')
|
||||
elif button == 'Run':
|
||||
paused = False
|
||||
start_time = start_time + int(round(time.time()*100)) - paused_time
|
||||
element = form.FindElement('button')
|
||||
element.Update(new_text='Pause')
|
||||
|
||||
# --------- Display timer in window --------
|
||||
form.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((current_time // 100) // 60,
|
||||
(current_time // 100) % 60,
|
||||
current_time % 100))
|
||||
time.sleep(.01)
|
||||
|
||||
|
||||
# --------- After loop --------
|
||||
|
||||
# Broke out of main loop. Close the window.
|
||||
form.CloseNonBlockingForm()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Menus
|
||||
|
||||
Menus are nothing more than buttons that live in a menu-bar. When you click on a menu item, you get back a "button" with that menu item's text, just as you would had that text been on a button.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue