-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyComputer.py
More file actions
137 lines (92 loc) · 3.45 KB
/
MyComputer.py
File metadata and controls
137 lines (92 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from tkinter.ttk import *
from tkinter import *
from PIL import Image, ImageTk
import subprocess
import sys
import os
import re
MAX_DRIVES_IN_A_ROW = 2
def extract_details_from_line(line):
file_system, total_size, used_size, available_size, percentage_used, mount_location = line.split()
percentage_used = percentage_used.replace('%', '')
drive_name = mount_location.split('/')[-1]
if drive_name == '':
drive_name = 'Root'
return drive_name, percentage_used, available_size, total_size, mount_location
def binder(obj, path):
obj.bind('<Double-Button-1>', lambda event: os.system('xdg-open "' + path + '"'))
class GridHandler:
row = 0
column = 0
def get_row_and_column():
if GridHandler.column < MAX_DRIVES_IN_A_ROW:
return GridHandler.column, GridHandler.row
else:
GridHandler.row += 1
GridHandler.column = 0
return GridHandler.column, GridHandler.row
def get_drive_frame(root, line):
drive_name, percentage_used, available_size, total_size, mount_location = extract_details_from_line(line)
## image = Image.open("drive_icon.png")
## image = image.resize((86, 44))
## photo = ImageTk.PhotoImage(image)
## photo_list.append(photo)
main_frame = Frame(root, highlightthickness=2)
drive_icon = Label(main_frame, image=photo)
drive_icon.pack(side = LEFT, pady=14, padx=6)
binder(drive_icon, mount_location)
# Details frame
details_frame = Frame(main_frame)
drive_name_label = Label(details_frame, text=drive_name)
drive_name_label.pack()
binder(drive_name_label, mount_location)
progress_bar = Progressbar(details_frame, orient = HORIZONTAL, length = 200,
mode = 'determinate')
progress_bar['value'] = percentage_used
binder(progress_bar, mount_location)
progress_bar.pack()
space_label = Label(details_frame, text=available_size + ' free of ' + total_size)
space_label.pack()
binder(space_label, mount_location)
details_frame.pack(side = LEFT, padx=8)
# main_frame.pack(side = LEFT, padx=10)
column, row = GridHandler.get_row_and_column()
# print(column, row)
main_frame.grid(column=column, row=row, pady = 10, padx = 20)
GridHandler.column += 1
binder(main_frame, mount_location)
binder(details_frame, mount_location)
main_frame.config(highlightbackground = "steel blue")
def main():
script_location = sys.argv[0].split('/')
script_location.pop(-1)
cwd = '/'.join(script_location)
os.chdir(cwd)
call = subprocess.Popen(['df', '-h'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
output = call.communicate()[0].decode().splitlines()
#return output[-3]
#print(output)
#print()
# creating tkinter window
root = Tk()
root.title('My Computer')
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
global photo
image = Image.open("drive_icon.png")
image = image.resize((86, 44))
photo = ImageTk.PhotoImage(image)
#root.geometry(str(w) + 'x' + str(h))
for line in output:
if 'sda' in line:
get_drive_frame(root, line)
#break
root.update_idletasks()
root.update()
print('---End---')
root.mainloop()
if __name__ == '__main__':
main()