Removed last of Context Manager from Popups. Added Underscore to Menu Examples, Updated Templates, Better Popup examples
This commit is contained in:
parent
96635ef5a2
commit
d1773e6447
|
@ -8,9 +8,9 @@ else:
|
|||
sg.ChangeLookAndFeel('GreenTan')
|
||||
|
||||
# ------ Menu Definition ------ #
|
||||
menu_def = [['File', ['Open', 'Save', 'Exit', 'Properties']],
|
||||
['Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
|
||||
['Help', 'About...'], ]
|
||||
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
|
||||
['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
|
||||
['&Help', '&About...'], ]
|
||||
|
||||
# ------ Column Definition ------ #
|
||||
column1 = [[sg.Text('Column 1', background_color='#F7F3EC', justification='center', size=(10, 1))],
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
import PySimpleGUI_mod as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
"""
|
||||
|
@ -26,9 +26,10 @@ def TestMenus():
|
|||
sg.SetOptions(element_padding=(0, 0))
|
||||
|
||||
# ------ Menu Definition ------ #
|
||||
menu_def = [['File', ['O_&pen', 'Save', '---', 'Properties']],
|
||||
['Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
|
||||
['Help', 'About...'],]
|
||||
menu_def = [['&File', ['&Open', '&Save', '---', 'Properties', 'E&xit' ]],
|
||||
['&Edit', ['Paste', ['Special', 'Normal',], 'Undo'],],
|
||||
[''
|
||||
'&Help', '&About...'],]
|
||||
|
||||
# ------ GUI Defintion ------ #
|
||||
layout = [
|
||||
|
@ -48,9 +49,9 @@ def TestMenus():
|
|||
print('Button = ', button)
|
||||
# ------ Process menu choices ------ #
|
||||
if button == 'About...':
|
||||
window.Disable()
|
||||
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...')
|
||||
window.Enable()
|
||||
window.Hide()
|
||||
sg.Popup('About this program','Version 1.0', 'PySimpleGUI rocks...', grab_anywhere=True)
|
||||
window.UnHide()
|
||||
elif button == 'Open':
|
||||
filename = sg.PopupGetFile('file to open', no_window=True)
|
||||
print(filename)
|
||||
|
|
|
@ -6,18 +6,23 @@ else:
|
|||
import PySimpleGUI27 as sg
|
||||
|
||||
# Here, have some windows on me....
|
||||
[sg.PopupNoWait(location=(10*x,0)) for x in range(10)]
|
||||
[sg.PopupNoWait(location=(500+100*x,500)) for x in range(10)]
|
||||
|
||||
print (sg.PopupYesNo('Yes No'))
|
||||
answer = sg.PopupYesNo('Do not worry about all those open windows... they will disappear at the end', 'Are you OK with that?')
|
||||
|
||||
print(sg.PopupGetText('Get text', location=(1000,200)))
|
||||
print(sg.PopupGetFile('Get file'))
|
||||
print(sg.PopupGetFolder('Get folder'))
|
||||
if answer == 'No':
|
||||
sg.PopupCancel('OK, we will destroy those windows as soon as you close this window')
|
||||
sys.exit()
|
||||
|
||||
sg.PopupNonBlocking('Your answer was',answer, location=(1000,600))
|
||||
|
||||
text = sg.PopupGetText('This is a call to PopopGetText', location=(1000,200))
|
||||
sg.PopupGetFile('Get file')
|
||||
sg.PopupGetFolder('Get folder')
|
||||
|
||||
|
||||
sg.Popup('Simple popup')
|
||||
|
||||
sg.PopupNonBlocking('Non Blocking', location=(500,500))
|
||||
sg.PopupNoTitlebar('No titlebar')
|
||||
sg.PopupNoBorder('No border')
|
||||
sg.PopupNoFrame('No frame')
|
||||
|
|
|
@ -10,7 +10,8 @@ if sys.version_info[0] >= 3:
|
|||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
layout = [[ sg.Text('My layout') ],
|
||||
[ sg.Button('Next Window')]]
|
||||
|
||||
window = sg.Window('My window').Layout(layout)
|
||||
button, value = window.Read()
|
||||
|
@ -26,11 +27,13 @@ if sys.version_info[0] >= 3:
|
|||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
layout = [[ sg.Text('My layout') ]]
|
||||
layout = [[ sg.Text('My layout') ],
|
||||
[ sg.RButton('Read The Window')]]
|
||||
|
||||
window = sg.Window('My new window').Layout(layout)
|
||||
|
||||
while True: # Event Loop
|
||||
button, value = window.Read()
|
||||
if button is None:
|
||||
break
|
||||
break
|
||||
print(button, value)
|
|
@ -3873,35 +3873,35 @@ def ScrolledTextBox(*args, button_color=None, yes_no=False, auto_close=False, au
|
|||
if not args: return
|
||||
width, height = size
|
||||
width = width if width else MESSAGE_BOX_LINE_WIDTH
|
||||
with Window(args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration) as form:
|
||||
max_line_total, max_line_width, total_lines, height_computed = 0,0,0,0
|
||||
complete_output = ''
|
||||
for message in args:
|
||||
# fancy code to check if string and convert if not is not need. Just always convert to string :-)
|
||||
# if not isinstance(message, str): message = str(message)
|
||||
message = str(message)
|
||||
longest_line_len = max([len(l) for l in message.split('\n')])
|
||||
width_used = min(longest_line_len, width)
|
||||
max_line_total = max(max_line_total, width_used)
|
||||
max_line_width = width
|
||||
lines_needed = _GetNumLinesNeeded(message, width_used)
|
||||
height_computed += lines_needed
|
||||
complete_output += message + '\n'
|
||||
total_lines += lines_needed
|
||||
height_computed = MAX_SCROLLED_TEXT_BOX_HEIGHT if height_computed > MAX_SCROLLED_TEXT_BOX_HEIGHT else height_computed
|
||||
if height:
|
||||
height_computed = height
|
||||
form.AddRow(Multiline(complete_output, size=(max_line_width, height_computed)))
|
||||
pad = max_line_total-15 if max_line_total > 15 else 1
|
||||
# show either an OK or Yes/No depending on paramater
|
||||
if yes_no:
|
||||
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Yes(), No())
|
||||
button, values = form.Read()
|
||||
return button
|
||||
else:
|
||||
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), SimpleButton('OK', size=(5, 1), button_color=button_color))
|
||||
form = Window(args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration)
|
||||
max_line_total, max_line_width, total_lines, height_computed = 0,0,0,0
|
||||
complete_output = ''
|
||||
for message in args:
|
||||
# fancy code to check if string and convert if not is not need. Just always convert to string :-)
|
||||
# if not isinstance(message, str): message = str(message)
|
||||
message = str(message)
|
||||
longest_line_len = max([len(l) for l in message.split('\n')])
|
||||
width_used = min(longest_line_len, width)
|
||||
max_line_total = max(max_line_total, width_used)
|
||||
max_line_width = width
|
||||
lines_needed = _GetNumLinesNeeded(message, width_used)
|
||||
height_computed += lines_needed
|
||||
complete_output += message + '\n'
|
||||
total_lines += lines_needed
|
||||
height_computed = MAX_SCROLLED_TEXT_BOX_HEIGHT if height_computed > MAX_SCROLLED_TEXT_BOX_HEIGHT else height_computed
|
||||
if height:
|
||||
height_computed = height
|
||||
form.AddRow(Multiline(complete_output, size=(max_line_width, height_computed)))
|
||||
pad = max_line_total-15 if max_line_total > 15 else 1
|
||||
# show either an OK or Yes/No depending on paramater
|
||||
if yes_no:
|
||||
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Yes(), No())
|
||||
button, values = form.Read()
|
||||
return button
|
||||
else:
|
||||
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Button('OK', size=(5, 1), button_color=button_color))
|
||||
button, values = form.Read()
|
||||
return button
|
||||
|
||||
|
||||
PopupScrolled = ScrolledTextBox
|
||||
|
|
Loading…
Reference in New Issue