forked from brendonbeebe/AutoMovieArchive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriveGrab.py
96 lines (79 loc) · 2.75 KB
/
DriveGrab.py
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
import clr
clr.AddReference('System.Drawing')
clr.AddReference('System.Windows.Forms')
from System.Drawing import *
from System.Windows.Forms import *
from System.IO import *
import string
from ctypes import windll
class DriveGrab(Form):
def __init__(self):
self.Text = 'Select default drive'
self.Height = 225
self.Width = 250
self.PATH = "C:/Movies"
self.label = Label()
self.label.Text = "Default Save Directory: C:\Movies"
self.label.Location = Point(50, 20)
self.label.Height = 30
self.label.Width = 200
#self.drives = self.get_drives()
self.drives = DriveInfo.GetDrives()
#combo box
cb = ComboBox()
cb.Parent = self
cb.Location = Point(50, 50)
cb.SelectionChangeCommitted += self.OnChanged
for drive in self.drives:
if drive.IsReady:
desc = drive.Name
desc += self.convertBytes(drive.AvailableFreeSpace) + ' Free'
cb.Items.Add(desc)
#browse button
browse = Button()
browse.Text = "Browse for Directory"
browse.Location = Point(50,80)
browse.Click += self.browsePressed
browse.AutoSize = True
#OK button
okbutton = Button()
okbutton.Text = "OK"
okbutton.Location = Point(150,150)
okbutton.Click += self.okPressed
self.Controls.Add(self.label)
self.Controls.Add(browse)
self.Controls.Add(okbutton)
def convertBytes(self, bytes):
gb = bytes / 1073741824.0
if gb < 1:
mb = bytes / 1048576.0
return '%(number).2fMB' % {'number': mb}
else:
return '%(number).2fGB' % {'number': gb}
def OnChanged(self, sender, args):
self.PATH = "%s:\Movies" % sender.SelectedItem
self.label.Text = "Default Save Directory: %s" % self.PATH
def browsePressed(self, sender, args):
dialogf = FolderBrowserDialog()
if dialogf.ShowDialog(self) == DialogResult.OK:
self.PATH = dialogf.SelectedPath
self.label.Text = "Default Save Directory: %s" % self.PATH
def okPressed(self, sender, args):
cnfg = open("settings.conf","w")
cnfg.write("PATH-%s" % self.PATH)
cnfg.close()
self.Close()
Application.Exit()
def get_drives(self):
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
if bitmask & 1:
drives.append(letter)
bitmask >>= 1
return drives
if __name__ == '__main__':
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
form = DriveGrab()
Application.Run(form)