More Form removal. New CloseNonBlocking method instead of CloseNonBlockingForm

This commit is contained in:
MikeTheWatchGuy 2018-09-23 18:04:32 -04:00
parent 828274af3f
commit eb72181182
2 changed files with 22 additions and 17 deletions

View File

@ -1829,9 +1829,9 @@ class Table(Element):
# ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- #
# FlexForm CLASS # # Window CLASS #
# ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- #
class FlexForm: class Window:
''' '''
Display a user defined for and return the filled in data Display a user defined for and return the filled in data
''' '''
@ -2124,7 +2124,7 @@ class FlexForm:
self.RootNeedsDestroying = True self.RootNeedsDestroying = True
return None return None
def CloseNonBlockingForm(self): def CloseNonBlocking(self):
if self.TKrootDestroyed: if self.TKrootDestroyed:
return return
try: try:
@ -2132,6 +2132,8 @@ class FlexForm:
_my_windows.Decrement() _my_windows.Decrement()
except: pass except: pass
CloseNonBlockingForm = CloseNonBlocking
def OnClosingCallback(self): def OnClosingCallback(self):
return return
@ -2151,6 +2153,9 @@ class FlexForm:
# except: # except:
# pass # pass
FlexForm = Window
# ------------------------------------------------------------------------- # # ------------------------------------------------------------------------- #
# UberForm CLASS # # UberForm CLASS #
# Used to make forms into TABS (it's trick) # # Used to make forms into TABS (it's trick) #

View File

@ -236,7 +236,7 @@ The architecture of some programs works better with button callbacks instead of
# Layout the design of the GUI # Layout the design of the GUI
layout = [[sg.Text('Please click a button', auto_size_text=True)], layout = [[sg.Text('Please click a button', auto_size_text=True)],
[sg.ReadFormButton('1'), sg.ReadFormButton('2'), sg.Quit()]] [sg.ReadButton('1'), sg.ReadButton('2'), sg.Quit()]]
# Show the Window to the user # Show the Window to the user
window = sg.Window('Button callback example').Layout(layout) window = sg.Window('Button callback example').Layout(layout)
@ -289,7 +289,7 @@ This recipe implements a remote control interface for a robot. There are 4 dire
if button == 'Quit' or values is None: if button == 'Quit' or values is None:
break break
window.CloseNonBlockingForm() # Don't forget to close your window! window.CloseNonBlocking() # Don't forget to close your window!
--------- ---------
@ -499,7 +499,7 @@ Perhaps you don't want all the statistics that the EasyProgressMeter provides an
# update bar with loop value +1 so that bar eventually reaches the maximum # update bar with loop value +1 so that bar eventually reaches the maximum
window.FindElement('progbar').UpdateBar(i + 1) window.FindElement('progbar').UpdateBar(i + 1)
# done with loop... need to destroy the window as it's still open # done with loop... need to destroy the window as it's still open
window.CloseNonBlockingForm() window.CloseNonBlocking()
---- ----
@ -650,7 +650,7 @@ Just like you can draw on a tkinter widget, you can also draw on a Graph Element
layout = [ layout = [
[sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')], [sg.Graph(canvas_size=(400, 400), graph_bottom_left=(0,0), graph_top_right=(400, 400), background_color='red', key='graph')],
[sg.T('Change circle color to:'), sg.ReadFormButton('Red'), sg.ReadFormButton('Blue'), sg.ReadFormButton('Move')] [sg.T('Change circle color to:'), sg.ReadButton('Red'), sg.ReadButton('Blue'), sg.ReadButton('Move')]
] ]
window = sg.Window('Graph test') window = sg.Window('Graph test')
@ -820,10 +820,10 @@ In other GUI frameworks this program would be most likely "event driven" with ca
layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))], layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))],
[sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))], [sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))],
[sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')], [sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')],
[sg.ReadFormButton('Start', button_color=('white', 'black'), key='Start'), [sg.ReadButton('Start', button_color=('white', 'black'), key='Start'),
sg.ReadFormButton('Stop', button_color=('white', 'black'), key='Stop'), sg.ReadButton('Stop', button_color=('white', 'black'), key='Stop'),
sg.ReadFormButton('Reset', button_color=('white', 'firebrick3'), key='Reset'), sg.ReadButton('Reset', button_color=('white', 'firebrick3'), key='Reset'),
sg.ReadFormButton('Submit', button_color=('white', 'springgreen4'), key='Submit')] sg.ReadButton('Submit', button_color=('white', 'springgreen4'), key='Submit')]
] ]
window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
@ -883,7 +883,7 @@ Use the upper half to generate your hash code. Then paste it into the code in t
1. Choose a password 1. Choose a password
2. Generate a hash code for your chosen password by running program and entering 'gui' as the password 2. Generate a hash code for your chosen password by running program and entering 'gui' as the password
3. Type password into the GUI 3. Type password into the GUI
4. Copy and paste hash code form GUI into variable named login_password_hash 4. Copy and paste hash code Window GUI into variable named login_password_hash
5. Run program again and test your login! 5. Run program again and test your login!
''' '''
@ -1104,7 +1104,7 @@ Much of the code is handling the button states in a fancy way. It could be much
# --------- After loop -------- # --------- After loop --------
# Broke out of main loop. Close the window. # Broke out of main loop. Close the window.
window.CloseNonBlockingForm() window.CloseNonBlocking()
## Desktop Floating Widget - CPU Utilization ## Desktop Floating Widget - CPU Utilization
@ -1119,12 +1119,12 @@ The spinner changes the number of seconds between reads. Note that you will get
import PySimpleGUI as sg import PySimpleGUI as sg
import psutil import psutil
# ---------------- Create Form ---------------- # ---------------- Create Window ----------------
sg.ChangeLookAndFeel('Black') sg.ChangeLookAndFeel('Black')
layout = [[sg.Text('')], layout = [[sg.Text('')],
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')], [sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')]] [sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')]]
# Layout the rows of the window and perform a read. Indicate the window is non-blocking!
window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout) window = sg.Window('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True).Layout(layout)
@ -1148,7 +1148,7 @@ The spinner changes the number of seconds between reads. Note that you will get
window.FindElement('text').Update(f'CPU {cpu_percent:02.0f}%') window.FindElement('text').Update(f'CPU {cpu_percent:02.0f}%')
# Broke out of main loop. Close the window. # Broke out of main loop. Close the window.
window.CloseNonBlockingForm() window.CloseNonBlocking()
## Menus ## Menus