MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Sort_Visualizer.py:38–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36
37
38def main():
39 sg.theme('LightGreen')
40 # Make list to sort
41 num_bars = DATA_SIZE[0]//(BAR_WIDTH+1)
42 list_to_sort = [DATA_SIZE[1]//num_bars*i for i in range(1, num_bars)]
43 random.shuffle(list_to_sort)
44
45 # define window layout
46 graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE)
47 layout = [[graph],
48 [sg.Text('Speed Faster'), sg.Slider((0, 20), orientation='h', default_value=10, key='-SPEED-'), sg.Text('Slower')]]
49
50 window = sg.Window('Sort Demonstration', layout, finalize=True)
51 # draw the initial window's bars
52 draw_bars(graph, list_to_sort)
53
54 sg.popup('Click OK to begin Bubblesort') # Wait for user to start it up
55 bsort = bubble_sort(list_to_sort) # get an iterator for the sort
56 timeout = 10 # start with 10ms delays between draws
57 while True: # ----- The event loop -----
58 event, values = window.read(timeout=timeout)
59 if event == sg.WIN_CLOSED:
60 break
61 try:
62 partially_sorted_list = bsort.__next__()
63 except:
64 sg.popup('Sorting done!')
65 break
66 graph.erase()
67 draw_bars(graph, partially_sorted_list)
68 timeout = int(values['-SPEED-'])
69
70 window.close()
71
72
73main()

Callers 1

Calls 5

readMethod · 0.95
eraseMethod · 0.95
closeMethod · 0.95
draw_barsFunction · 0.85
bubble_sortFunction · 0.85

Tested by

no test coverage detected