-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI.pyw
130 lines (104 loc) · 4.43 KB
/
GUI.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
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
import wx
import os.path as op
import os
import pyBinder as pb
FRAME_OPACITY=200
DEFAULT_IMAGE_NAME='Folder.jpg'
def fProcessTracks(lFileNames, wFrame):
'''????????? ?????? ??????'''
#???? ? ?????? ?????? mp3-????...
for sSongLocation in lFileNames:
if op.splitext(sSongLocation)[-1].lower()=='.mp3': break
#...? ???????? ??? ???? ??????? ???????
wFrame.fSetGauge('Getting song info...', 20)
tSongInfo= pb.fGetSongInfo(sSongLocation)
sImageLocation=op.join(op.dirname(sSongLocation), DEFAULT_IMAGE_NAME)
wFrame.fSetGauge('Creating Last.FM request...', 40)
sLfmQuery=pb.fCreateLfmRequest(tSongInfo)
wFrame.fSetGauge('Getting data from Last.FM...', 60)
sLfmResult=pb.fQueryLfm(sLfmQuery)
wFrame.fSetGauge('Analysing Last.FM request...', 80)
sImgUrl=pb.fUnparseImgUrl(sLfmResult, pb.SIZE_RAW)
if sImgUrl == u'':
wFrame.fSetGauge('Sorry, image not found', 100)
return
wFrame.fSetGauge('Downloading image...', 90)
pb.fDownload(sImgUrl, sImageLocation)
wFrame.fSetGauge('Almost ready.', 100)
wFrame.fSetImage(sImageLocation)
#????????? ???? mp3-?????? ? ?????? ?????????? ????????
#(??????????????, ??? ??? ????? ?? ?????? ???????)
nGaugeStep=int(100/len(lFileNames))
nGaugeValue=0
for sFileName in lFileNames:
if op.isfile(sFileName) and (op.splitext(sFileName)[-1].lower() == '.mp3'):
nGaugeValue+=nGaugeStep
wFrame.fSetGauge(op.basename(sFileName), nGaugeValue)
pb.fBindArtwork(sFileName, sImageLocation)
#??????.
wFrame.fSetGauge('Ready', 100)
class CDropTarget(wx.FileDropTarget):
'''????? ??? Drag and Drop'''
def __init__(self, wTargetWidget):
wx.FileDropTarget.__init__(self)
self.window=wTargetWidget
self.wFrame=self.window.GetParent()
def OnDropFiles(self, x, y, lDroppedContent):
#??????? ????????? ?????!
lFileNames=[]
for sPath in lDroppedContent:
if op.isdir(sPath):
lInnerFileNames=[op.join(sPath, sFileName) for sFileName in os.listdir(sPath)]
fProcessTracks(lInnerFileNames, self.wFrame)
if op.isfile(sPath):
lFileNames.append(sPath)
if lFileNames!=[]:
fProcessTracks(lFileNames, self.wFrame)
class CDropFrame(wx.Frame):
'''?????? ??????????'''
def __init__(self, nSize):
wx.Frame.__init__(self, None, title='pyBinder',
style=wx.STAY_ON_TOP|wx.FRAME_TOOL_WINDOW|wx.CLOSE_BOX|wx.CAPTION|wx.SYSTEM_MENU)
#??? ?????? size - ??? ?????? ???? ?????? ? ??????????,
#??????? ??? ???????? ??????????? ?????? ?????? clientSize ?????? size
self.SetClientSize((nSize,)*2)
self.nSize=nSize
#wPanel ????????? Drag'????? ???????
self.wPanel=wx.Panel(self,pos=(0,0), size=(nSize,)*2)
self.wPanel.SetBackgroundColour('#FFFFFF')
wDropTarget=CDropTarget(self.wPanel)
self.wPanel.SetDropTarget(wDropTarget)
#???????? ??? ???????.
#????? ?????????? ?? ??????? ??????? ???????? fProcessTracks()
self.wBgFrame=wx.StaticBitmap(self.wPanel)
self.fSetImage('Backgrounds\\Background2.jpg')
#????????? ???? ProgressBar
self.wText=wx.StaticText(self.wBgFrame, -1, 'Drop some mp3 files here...', (0,(nSize/2)-15), (nSize,35), wx.ALIGN_CENTER)
self.wText.SetBackgroundColour('#000000')
self.wText.SetForegroundColour('#FFFFFF')
self.wGauge=wx.Gauge(self.wText, -1, 100, (5,20), (nSize-10,10))
self.wGauge.SetValue(0)
#??????????? ?????? ? ?????? ?????? ???? ??????
tScreenSize=wx.ScreenDC().GetSize()
tFrameSize=self.GetSize()
self.SetPosition(tuple(tScreenSize-tFrameSize))
#?????? ???????????? ??? ?????
self.SetTransparent(FRAME_OPACITY)
#??????!
self.Show()
#????????? ???????? ???????????
def fSetImage(self, sImgSrc):
wImage=wx.Image(sImgSrc)
wImage.Rescale(self.nSize, self.nSize)
wImage=wImage.ConvertToBitmap()
self.wBgFrame.SetBitmap(wImage)
#?????????? ?????? ? ??????-????
def fSetGauge(self, sMessage, nValue):
self.wText.SetLabel(sMessage)
#?????? ?????????? ???? ?????????? ?????? ??? ????????? =\
self.wText.SetSize((self.nSize,35))
self.wGauge.SetValue(nValue)
if __name__=='__main__':
aApp=wx.PySimpleApp()
wDropFrame=CDropFrame(180)
aApp.MainLoop()