Skip to content

Commit f2ac7d3

Browse files
Rework of Demo Debugger Integration + New Demo Debugger Button (experimental only)
1 parent fc4e996 commit f2ac7d3

2 files changed

Lines changed: 83 additions & 21 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import PySimpleGUI as sg
2+
# import imwatchingyou # STEP 1
3+
4+
"""
5+
Demo program that shows you how to integrate the PySimpleGUI Debugger
6+
into your program.
7+
This particular program is a GUI based program simply to make it easier for you to interact and change
8+
things.
9+
10+
In this example, the debugger is not started initiallly. You click the "Debug" button to launch it
11+
There are THREE steps, and they are copy and pastes.
12+
1. At the top of your app to debug add
13+
import imwatchingyou
14+
2. When you want to show a debug window, call one of two functions:
15+
imwatchingyou.show_debug_window()
16+
imwatchingyou.show_popout_window()
17+
3. You must find a location in your code to "refresh" the debugger. Some loop that's executed often.
18+
In this loop add this call:
19+
imwatchingyou.refresh()
20+
"""
21+
22+
layout = [
23+
[sg.T('A typical PSG application')],
24+
[sg.In(key='_IN_')],
25+
[sg.T(' ', key='_OUT_', size=(45,1))],
26+
[sg.CBox('Checkbox 1'), sg.CBox('Checkbox 2')],
27+
[sg.Radio('a',1, key='_R1_'), sg.Radio('b',1, key='_R2_'), sg.Radio('c',1, key='_R3_')],
28+
[sg.Combo(['c1', 'c2', 'c3'], size=(6,3), key='_COMBO_')],
29+
[sg.Output(size=(50,6))],
30+
[sg.Ok(), sg.Exit(), sg.Button('Enable'), sg.Debug(key='Debug')],
31+
]
32+
33+
window = sg.Window('This is your Application Window', layout, debugger_enabled=False)
34+
35+
counter = 0
36+
timeout = 100
37+
38+
while True: # Your Event Loop
39+
event, values = window.Read(timeout=timeout)
40+
if event in (None, 'Exit'):
41+
break
42+
elif event == 'Enable':
43+
window.EnableDebugger()
44+
counter += 1
45+
# to prove window is operating, show the input in another area in the window.
46+
window.Element('_OUT_').Update(values['_IN_'])
47+
48+
window.Close()
Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
import PySimpleGUI as sg
2-
import PySimpleGUIdebugger # STEP 1
2+
import imwatchingyou # STEP 1
33

44
"""
55
Demo program that shows you how to integrate the PySimpleGUI Debugger
66
into your program.
7+
This particular program is a GUI based program simply to make it easier for you to interact and change
8+
things.
9+
710
In this example, the debugger is not started initiallly. You click the "Debug" button to launch it
811
There are THREE steps, and they are copy and pastes.
912
1. At the top of your app to debug add
10-
import PySimpleGUIdebugger
11-
2. Initialize the debugger at the start of your program by calling:
12-
PySimpleGUIdebugger.initialize()
13-
3. At the top of your app's Event Loop add:
14-
PySimpleGUIdebugger.refresh(locals(), globals())
13+
import imwatchingyou
14+
2. When you want to show a debug window, call one of two functions:
15+
imwatchingyou.show_debug_window()
16+
imwatchingyou.show_popout_window()
17+
3. You must find a location in your code to "refresh" the debugger. Some loop that's executed often.
18+
In this loop add this call:
19+
imwatchingyou.refresh()
1520
"""
1621

1722
layout = [
18-
[sg.T('A typical PSG application')],
19-
[sg.In(key='_IN_')],
20-
[sg.T(' ', key='_OUT_')],
21-
[sg.Radio('a',1, key='_R1_'), sg.Radio('b',1, key='_R2_'), sg.Radio('c',1, key='_R3_')],
22-
[sg.Combo(['c1', 'c2', 'c3'], size=(6,3), key='_COMBO_')],
23-
[sg.Output(size=(50,6))],
24-
[sg.Ok(), sg.Exit(), sg.B('Debug')],
25-
]
23+
[sg.T('A typical PSG application')],
24+
[sg.In(key='_IN_')],
25+
[sg.T(' ', key='_OUT_', size=(30, 1))],
26+
[sg.Radio('a', 1, key='_R1_'),
27+
sg.Radio('b', 1, key='_R2_'),
28+
sg.Radio('c', 1, key='_R3_')],
29+
[sg.Combo(['c1', 'c2', 'c3'], size=(6, 3), key='_COMBO_')],
30+
[sg.Output(size=(50, 6))],
31+
[sg.Ok(), sg.Exit(), sg.Button('Debugg'), sg.Button('Popout')],
32+
]
2633

2734
window = sg.Window('This is your Application Window', layout)
2835

2936
counter = 0
3037
timeout = 100
31-
debug_started = False
3238

33-
while True: # Your Event Loop
34-
if debug_started:
35-
debug_started = PySimpleGUIdebugger.refresh(locals(), globals()) # STEP 3 - refresh debugger
39+
# Start the program with the popout window showing so you can immediately start debugging!
40+
imwatchingyou.show_debugger_popout_window()
41+
42+
while True: # Your Event Loop
3643
event, values = window.Read(timeout=timeout)
3744
if event in (None, 'Exit'):
3845
break
3946
elif event == 'Ok':
4047
print('You clicked Ok.... this is where print output goes')
41-
elif event == 'Debug' and not debug_started:
42-
PySimpleGUIdebugger.initialize() # STEP 2
43-
debug_started = True
48+
imwatchingyou.show_debugger_popout_window() # STEP 2 also
49+
elif event == 'Debugg':
50+
imwatchingyou.show_debugger_window() # STEP 2
51+
elif event == 'Popout':
52+
imwatchingyou.show_debugger_popout_window() # STEP 2
4453
counter += 1
54+
# to prove window is operating, show the input in another area in the window.
4555
window.Element('_OUT_').Update(values['_IN_'])
56+
57+
# don't worry about the "state" of things, just call this function "frequently"
58+
imwatchingyou.refresh_debugger() # STEP 3 - refresh debugger
59+
4660
window.Close()

0 commit comments

Comments
 (0)