Skip to content

Commit f523e51

Browse files
committed
Swapped out Output element for Multiline. Includes the Titilebar, CustomMenubar, Sizegrip and standard "Edit Me" and "Versions" right click setting and numerous smaller changes
1 parent ef3746c commit f523e51

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
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()

0 commit comments

Comments
 (0)