Skip to content

Commit a039df2

Browse files
authored
Merge pull request PySimpleGUI#5068 from PySimpleGUI/Dev-latest
Dev latest
2 parents 0e2aeb3 + f523e51 commit a039df2

File tree

2 files changed

+63
-26
lines changed

2 files changed

+63
-26
lines changed

DemoPrograms/Demo_All_Elements.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ def make_window(theme):
2020
sg.theme(theme)
2121
menu_def = [['&Application', ['E&xit']],
2222
['&Help', ['&About']] ]
23-
right_click_menu_def = [[], ['Nothing','More Nothing','Exit']]
23+
right_click_menu_def = [[], ['Edit Me', 'Versions', 'Nothing','More Nothing','Exit']]
24+
graph_right_click_menu_def = [[], ['Erase','Draw Line', 'Draw',['Circle', 'Rectangle', 'Image'], 'Exit']]
2425

2526
# Table Data
2627
data = [["John", 10], ["Jen", 5]]
2728
headings = ["Name", "Score"]
2829

29-
input_layout = [[sg.Menu(menu_def, key='-MENU-')],
30+
input_layout = [
31+
32+
# [sg.Menu(menu_def, key='-MENU-')],
3033
[sg.Text('Anything that requires user-input is in this tab!')],
3134
[sg.Input(key='-INPUT-')],
3235
[sg.Slider(orientation='h', key='-SKIDER-'),
@@ -36,17 +39,22 @@ def make_window(theme):
3639
[sg.Combo(values=('Combo 1', 'Combo 2', 'Combo 3'), default_value='Combo 1', readonly=True, k='-COMBO-'),
3740
sg.OptionMenu(values=('Option 1', 'Option 2', 'Option 3'), k='-OPTION MENU-'),],
3841
[sg.Spin([i for i in range(1,11)], initial_value=10, k='-SPIN-'), sg.Text('Spin')],
39-
[sg.Multiline('Demo of a Multi-Line Text Element!\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nYou get the point.', size=(45,5), k='-MLINE-')],
42+
[sg.Multiline('Demo of a Multi-Line Text Element!\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\nLine 7\nYou get the point.', size=(45,5), expand_x=True, expand_y=True, k='-MLINE-')],
4043
[sg.Button('Button'), sg.Button('Popup'), sg.Button(image_data=sg.DEFAULT_BASE64_ICON, key='-LOGO-')]]
4144

4245
asthetic_layout = [[sg.T('Anything that you would use for asthetics is in this tab!')],
4346
[sg.Image(data=sg.DEFAULT_BASE64_ICON, k='-IMAGE-')],
44-
[sg.ProgressBar(1000, orientation='h', size=(20, 20), key='-PROGRESS BAR-'), sg.Button('Test Progress bar')]]
47+
[sg.ProgressBar(100, orientation='h', size=(20, 20), key='-PROGRESS BAR-'), sg.Button('Test Progress bar')]]
4548

46-
logging_layout = [[sg.Text("Anything printed will display here!")], [sg.Output(size=(60,15), font='Courier 8')]]
49+
logging_layout = [[sg.Text("Anything printed will display here!")],
50+
[sg.Multiline(size=(60,15), font='Courier 8', expand_x=True, expand_y=True, write_only=True,
51+
reroute_stdout=True, reroute_stderr=True, echo_stdout_stderr=True, autoscroll=True, auto_refresh=True)]
52+
# [sg.Output(size=(60,15), font='Courier 8', expand_x=True, expand_y=True)]
53+
]
4754

4855
graphing_layout = [[sg.Text("Anything you would use to graph will display here!")],
49-
[sg.Graph((200,200), (0,0),(200,200),background_color="black", key='-GRAPH-', enable_events=True)],
56+
[sg.Graph((200,200), (0,0),(200,200),background_color="black", key='-GRAPH-', enable_events=True,
57+
right_click_menu=graph_right_click_menu_def)],
5058
[sg.T('Click anywhere on graph to draw a circle')],
5159
[sg.Table(values=data, headings=headings, max_col_width=25,
5260
background_color='black',
@@ -58,9 +66,9 @@ def make_window(theme):
5866
key='-TABLE-',
5967
row_height=25)]]
6068

61-
specalty_layout = [[sg.Text("Any \"special\" elements will display here!")],
62-
[sg.Button("Open Folder")],
63-
[sg.Button("Open File")]]
69+
popup_layout = [[sg.Text("Popup Testing")],
70+
[sg.Button("Open Folder")],
71+
[sg.Button("Open File")]]
6472

6573
theme_layout = [[sg.Text("See how elements look under different themes by choosing a different theme here!")],
6674
[sg.Listbox(values = sg.theme_list(),
@@ -69,16 +77,22 @@ def make_window(theme):
6977
enable_events = True)],
7078
[sg.Button("Set Theme")]]
7179

72-
layout = [[sg.Text('Demo Of (Almost) All Elements', size=(38, 1), justification='center', font=("Helvetica", 16), relief=sg.RELIEF_RIDGE, k='-TEXT HEADING-', enable_events=True)]]
80+
layout = [ [sg.MenubarCustom(menu_def, key='-MENU-', font='Courier 15', tearoff=True)],
81+
[sg.Text('Demo Of (Almost) All Elements', size=(38, 1), justification='center', font=("Helvetica", 16), relief=sg.RELIEF_RIDGE, k='-TEXT HEADING-', enable_events=True)]]
7382
layout +=[[sg.TabGroup([[ sg.Tab('Input Elements', input_layout),
7483
sg.Tab('Asthetic Elements', asthetic_layout),
7584
sg.Tab('Graphing', graphing_layout),
76-
sg.Tab('Specialty', specalty_layout),
85+
sg.Tab('Popups', popup_layout),
7786
sg.Tab('Theming', theme_layout),
78-
sg.Tab('Output', logging_layout)]], key='-TAB GROUP-')]]
79-
80-
return sg.Window('All Elements Demo', layout, right_click_menu=right_click_menu_def)
87+
sg.Tab('Output', logging_layout)]], key='-TAB GROUP-', expand_x=True, expand_y=True),
8188

89+
]]
90+
layout[-1].append(sg.Sizegrip())
91+
window = sg.Window('All Elements Demo', layout, right_click_menu=right_click_menu_def, right_click_menu_tearoff=True, grab_anywhere=True, resizable=True, margins=(0,0), use_custom_titlebar=True, finalize=True, keep_on_top=True,
92+
# scaling=2.0,
93+
)
94+
window.set_min_size(window.size)
95+
return window
8296

8397
def main():
8498
window = make_window(sg.theme())
@@ -102,41 +116,49 @@ def main():
102116
'Right click anywhere to see right click menu',
103117
'Visit each of the tabs to see available elements',
104118
'Output of event and values can be see in Output tab',
105-
'The event and values dictionary is printed after every event')
119+
'The event and values dictionary is printed after every event', keep_on_top=True)
106120
elif event == 'Popup':
107121
print("[LOG] Clicked Popup Button!")
108-
sg.popup("You pressed a button!")
122+
sg.popup("You pressed a button!", keep_on_top=True)
109123
print("[LOG] Dismissing Popup!")
110124
elif event == 'Test Progress bar':
111125
print("[LOG] Clicked Test Progress Bar!")
112126
progress_bar = window['-PROGRESS BAR-']
113-
for i in range(1000):
127+
for i in range(100):
114128
print("[LOG] Updating progress bar by 1 step ("+str(i)+")")
115-
progress_bar.UpdateBar(i + 1)
129+
progress_bar.update(current_count=i + 1)
116130
print("[LOG] Progress bar complete!")
117131
elif event == "-GRAPH-":
118132
graph = window['-GRAPH-'] # type: sg.Graph
119133
graph.draw_circle(values['-GRAPH-'], fill_color='yellow', radius=20)
120134
print("[LOG] Circle drawn at: " + str(values['-GRAPH-']))
121135
elif event == "Open Folder":
122136
print("[LOG] Clicked Open Folder!")
123-
folder_or_file = sg.popup_get_folder('Choose your folder')
124-
sg.popup("You chose: " + str(folder_or_file))
137+
folder_or_file = sg.popup_get_folder('Choose your folder', keep_on_top=True)
138+
sg.popup("You chose: " + str(folder_or_file), keep_on_top=True)
125139
print("[LOG] User chose folder: " + str(folder_or_file))
126140
elif event == "Open File":
127141
print("[LOG] Clicked Open File!")
128-
folder_or_file = sg.popup_get_file('Choose your file')
129-
sg.popup("You chose: " + str(folder_or_file))
142+
folder_or_file = sg.popup_get_file('Choose your file', keep_on_top=True)
143+
sg.popup("You chose: " + str(folder_or_file), keep_on_top=True)
130144
print("[LOG] User chose file: " + str(folder_or_file))
131145
elif event == "Set Theme":
132146
print("[LOG] Clicked Set Theme!")
133147
theme_chosen = values['-THEME LISTBOX-'][0]
134148
print("[LOG] User Chose Theme: " + str(theme_chosen))
135149
window.close()
136150
window = make_window(theme_chosen)
151+
elif event == 'Edit Me':
152+
sg.execute_editor(__file__)
153+
elif event == 'Versions':
154+
sg.popup(sg.get_versions(), keep_on_top=True)
137155

138156
window.close()
139157
exit(0)
140158

141159
if __name__ == '__main__':
160+
sg.theme('black')
161+
sg.theme('dark red')
162+
sg.theme('dark green 7')
163+
# sg.theme('DefaultNoMoreNagging')
142164
main()

PySimpleGUI.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/python3
2-
version = __version__ = "4.56.0 Released 5-Jan-2022"
2+
version = __version__ = "4.56.0.1 Uneleased"
33

44
_change_log = """
55
Changelog since 4.56.0 released to PyPI on 5-Jan-2022
66

7-
7+
4.56.0.1
8+
set_options - added disable_modal_windows option to provide a single call to disable the modal feature globally (including popups)
89
"""
910

1011
__version__ = version.split()[0] # For PEP 396 and PEP 345
@@ -516,6 +517,7 @@ def running_replit():
516517
TABLE_SELECT_MODE_EXTENDED = tk.EXTENDED
517518
DEFAULT_TABLE_SELECT_MODE = TABLE_SELECT_MODE_EXTENDED
518519

520+
DEFAULT_MODAL_WINDOWS_ENABLED = True
519521

520522
TAB_LOCATION_TOP = 'top'
521523
TAB_LOCATION_TOP_LEFT = 'topleft'
@@ -3920,6 +3922,7 @@ class Output(Element):
39203922

39213923
The Multiline Element is the superior and recommended method for showing the output of stdout.
39223924
The Multiline Element has been added to significantly while the Output element has not.
3925+
If you choose to use a Multiline element to replace an Output element, be sure an turn on the write_only paramter in the Multline
39233926

39243927
Of course, Output Element continues to operate and be backwards compatible, but you're missing out on
39253928
features such as routing the cprint output to the element.
@@ -10691,6 +10694,10 @@ def make_modal(self):
1069110694
if running_mac() and ENABLE_MAC_MODAL_DISABLE_PATCH:
1069210695
return
1069310696

10697+
# if modal windows have been disabled globally
10698+
if not DEFAULT_MODAL_WINDOWS_ENABLED:
10699+
return
10700+
1069410701
try:
1069510702
self.TKroot.transient()
1069610703
self.TKroot.grab_set()
@@ -16617,7 +16624,8 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
1661716624
window_location=(None, None), error_button_color=(None, None), tooltip_time=None, tooltip_font=None, use_ttk_buttons=None, ttk_theme=None,
1661816625
suppress_error_popups=None, suppress_raise_key_errors=None, suppress_key_guessing=None,warn_button_key_duplicates=False, enable_treeview_869_patch=None,
1661916626
enable_mac_notitlebar_patch=None, use_custom_titlebar=None, titlebar_background_color=None, titlebar_text_color=None, titlebar_font=None,
16620-
titlebar_icon=None, user_settings_path=None, pysimplegui_settings_path=None, pysimplegui_settings_filename=None, keep_on_top=None, dpi_awareness=None, scaling=None):
16627+
titlebar_icon=None, user_settings_path=None, pysimplegui_settings_path=None, pysimplegui_settings_filename=None, keep_on_top=None, dpi_awareness=None, scaling=None,
16628+
disable_modal_windows=None):
1662116629
"""
1662216630
:param icon: Can be either a filename or Base64 value. For Windows if filename, it MUST be ICO format. For Linux, must NOT be ICO. Most portable is to use a Base64 of a PNG file. This works universally across all OS's
1662316631
:type icon: bytes | str
@@ -16724,7 +16732,9 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
1672416732
:param dpi_awareness: If True then will turn on DPI awareness (Windows only at the moment)
1672516733
:type dpi_awareness: (bool)
1672616734
:param scaling: Sets the default scaling for all windows including popups, etc.
16727-
:type scaling: (float)
16735+
:type scaling: (float)
16736+
:param disable_modal_windows: If True then all windows, including popups, will not be modal windows
16737+
:type disable_modal_windows: (bool)
1672816738
:return: None
1672916739
:rtype: None
1673016740
"""
@@ -16780,6 +16790,7 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
1678016790
global DEFAULT_USER_SETTINGS_PYSIMPLEGUI_FILENAME
1678116791
global DEFAULT_KEEP_ON_TOP
1678216792
global DEFAULT_SCALING
16793+
global DEFAULT_MODAL_WINDOWS_ENABLED
1678316794
global _pysimplegui_user_settings
1678416795
# global _my_windows
1678516796

@@ -16955,6 +16966,10 @@ def set_options(icon=None, button_color=None, element_size=(None, None), button_
1695516966
if scaling is not None:
1695616967
DEFAULT_SCALING = scaling
1695716968

16969+
if disable_modal_windows is not None:
16970+
DEFAULT_MODAL_WINDOWS_ENABLED = not disable_modal_windows
16971+
16972+
1695816973
return True
1695916974

1696016975

0 commit comments

Comments
 (0)