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

Function update_window

DemoPrograms/Demo_Desktop_Widget_Drive_Usage.py:33–56  ·  view source on GitHub ↗
(window)

Source from the content-addressed store, hash-verified

31
32
33def update_window(window):
34 drive_list = []
35 particians = psutil.disk_partitions()
36 all_ok = True
37 for count, part in enumerate(particians):
38 mount = part[0]
39 try:
40 usage = psutil.disk_usage(mount)
41 window[('-NAME-', mount)].update(mount)
42 window[('-PROG-', mount)].update_bar(int(usage.percent))
43 window[('-%-', mount)].update(f'{usage.percent}%')
44 window[('-STATS-', mount)].update(f'{human_size(usage.used)} / {human_size(usage.total)} = {human_size(usage.free)} free')
45 drive_list.append(str(mount))
46 except KeyError as e: # A key error means a new drive was added
47 all_ok = False
48 except Exception as e:
49 pass
50 all_ok = Globals.drive_list == drive_list and all_ok
51 Globals.drive_list = drive_list
52
53 return all_ok
54
55
56 # ---------------- Create Layout ----------------
57def create_window(location):
58 layout = [[sg.Text('Drive Status', font='Any 16')]]
59

Callers 1

mainFunction · 0.70

Calls 3

update_barMethod · 0.80
human_sizeFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected