-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedkgen.pyw
104 lines (78 loc) · 2.66 KB
/
edkgen.pyw
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
#!/usr/bin/env python
# author:kernel@verycd.com
# created at 02/01/2007
from ed2k import *
from wx import *
import threading
import os.path
class Working(threading.Thread):
def __init__(self,dlg):
threading.Thread.__init__(self)
self.dlg = dlg
self.f = PartFile()
self.f.Attach(dlg.filepath)
def run(self):
s = self.f.Go()
v = True
while(v):
v = s.next()
if(v):
self.dlg.process.SetValue(int(v*100))
print str(v * 100)+'% Finished'
if self.f.IsFinished():
pass
self.dlg.start.Enable()
self.dlg.cancel.Disable()
ed2k = "ed2k://|file|"+self.f.GetNAME()+"|"+self.f.GetSIZE()+"|"+self.f.GetED2K()+"|h="+self.f.GetAICH()+"|/"
self.dlg.result.SetValue(ed2k)
def cancel(self):
self.f.cancel = True
class ED2KDialog(Dialog):
def __init__(self, parent, id, title):
Dialog.__init__(self, parent, id, title)
self.OnInit()
self.filepath = None
def OnInit(self):
self.start = Button(self, 101, 'Start', (10,50))
self.start.Disable()
EVT_BUTTON(self, 101, self.OnStartClick)
self.cancel = Button(self, 102, 'Cancel', (90,50))
self.cancel.Disable()
EVT_BUTTON(self,102, self.OnCancelClick)
self.open = Button(self, 100, 'Open', (170,50))
self.open.Enable()
EVT_BUTTON(self, 100, self.OnOpenClick)
self.process = Gauge(self,-1,100,(10,20),(240,20))
self.process.SetValue(0)
self.result = TextCtrl(self, -1, '', (10,100), (240,50))
self.result.SetEditable(False)
self.result.SelectAll()
def OnOpenClick(self,event):
filedlg = FileDialog(self,message='Select File', style=wx.FD_OPEN)
filedlg.ShowModal()
self.filepath = filedlg.GetDirectory() + u'/' + filedlg.GetFilename()
if(os.path.isfile(self.filepath)):
self.start.Enable()
self.result.SetValue('')
else:
self.filepath = ''
self.start.Disable()
self.cancel.Disable()
def OnStartClick(self,event):
self.start.Disable()
self.cancel.Enable()
self.workthread = Working(self)
self.workthread.start()
def OnCancelClick(self,event):
if self.workthread:
self.workthread.cancel()
self.start.Enable()
self.cancel.Disable()
class ED2KApp(App):
def __init__(self):
App.__init__(self, redirect=False)
def OnInit(self):
self.dlg = ED2KDialog(None, -1, "ED2K Link Creator")
self.dlg.ShowModal()
return True
app = ED2KApp()