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

Function create_window

DemoPrograms/Demo_Desktop_Widget_Drive_Usage.py:57–80  ·  view source on GitHub ↗
(location)

Source from the content-addressed store, hash-verified

55
56 # ---------------- Create Layout ----------------
57def create_window(location):
58 layout = [[sg.Text('Drive Status', font='Any 16')]]
59
60 # Add a row for every partician that has a bar graph and text stats
61 particians = psutil.disk_partitions()
62 for count, part in enumerate(particians):
63 mount = part[0]
64 try:
65 bar_color = sg.theme_progress_bar_color()
66 this_color = BAR_COLORS[count % len(BAR_COLORS)]
67 usage = psutil.disk_usage(mount)
68 stats_info = f'{human_size(usage.used)} / {human_size(usage.total)} = {human_size(usage.free)} free'
69 layout += [[sg.Text(mount, size=(5, 1), key=('-NAME-', mount)),
70 sg.ProgressBar(100, 'h', size=(10, 15), key=('-PROG-', mount), bar_color=(this_color, bar_color[1])),
71 sg.Text(f'{usage.percent}%', size=(6, 1), key=('-%-', mount)), sg.T(stats_info, size=(30, 1), key=('-STATS-', mount))]]
72 except:
73 pass
74 layout += [[sg.Text('Refresh', font='Any 8', key='-REFRESH-', enable_events=True)]]
75
76 # ---------------- Create Window ----------------
77 window = sg.Window('Drive Status Widget', layout, location=location, keep_on_top=True, grab_anywhere=True, no_titlebar=True, alpha_channel=ALPHA, use_default_focus=False,right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT,
78 finalize=True, enable_close_attempted_event=True)
79
80 return window
81
82def main(location):
83 # we rely on a key error to tell us if a drive was added. So.... we don't want pesky popups or other key erros to be shown

Callers 1

mainFunction · 0.70

Calls 1

human_sizeFunction · 0.70

Tested by

no test coverage detected