-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertToMP3GUI.py
More file actions
executable file
·128 lines (112 loc) · 4.79 KB
/
Copy pathConvertToMP3GUI.py
File metadata and controls
executable file
·128 lines (112 loc) · 4.79 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
#!/usr/bin/python
#
# Copyright (C) Brad Smith 2008
#
# This file is part of ConvertToMP3GUI
#
# ConvertToMP3GUI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ConvertToMP3GUI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ConvertToMP3GUI. If not, see <http://www.gnu.org/licenses/>.
import wxversion
try:
wxversion.select('2.8')
except wxversion.VersionError:
wxversion.select('2.6')
import wx
import os, sys, subprocess, fcntl
from wxConvertToMP3GUI import MainFrame, ConvertFrame
class ConvertGUIStatusFrame(ConvertFrame):
def __init__(self, *args, **kwds):
ConvertFrame.__init__(self, *args, **kwds)
self.process = None
self.Bind(wx.EVT_CLOSE, self.onClose)
self.Bind(wx.EVT_BUTTON, self.onExitButton, self.exitButton)
wx.CallLater(1000, self.idleLoop)
def onClose(self, _event):
self.GetParent().Close()
def onExitButton(self, _event):
self.Close()
def beginConversion(self, sourceDir, destDir):
convToMP3Path = os.path.join(os.path.dirname(__file__),
u'ConvertToMP3.py')
cmd = [unicode(sys.executable, 'UTF-8'), u'-u',
convToMP3Path, sourceDir, destDir]
fse = sys.getfilesystemencoding()
cmd = [arg.encode(fse) if isinstance(arg, unicode) else arg for arg in cmd]
self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
env=os.environ, cwd=os.getcwd())
flags = fcntl.fcntl(self.process.stdout, fcntl.F_GETFL)
fcntl.fcntl(self.process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
def idleLoop(self):
if self.process is not None:
output_stream = self.process.stdout
try:
text = output_stream.read()
self.progress.AppendText(text + '\n')
except IOError, e:
if e.errno == 11:
pass
else:
raise
if self.process.poll() != None:
self.processEnded()
wx.CallLater(1000, self.idleLoop)
def processEnded(self):
self.process = None
self.status.SetForegroundColour(wx.Colour(0, 255, 0))
self.status.SetLabel("Conversion process complete")
class ConvertGUIMainFrame(MainFrame):
def __init__(self, *args, **kwds):
MainFrame.__init__(self, *args, **kwds)
self.Bind(wx.EVT_BUTTON, self.onBeginConvert, self.beginConvert)
self.Bind(wx.EVT_BUTTON, self.onToConvertBrowse, self.toConvertBrowse)
self.Bind(wx.EVT_TEXT, self.onToConvertText, self.toConvert)
def onToConvertBrowse(self, _event):
dd = wx.DirDialog(None, style=wx.DD_DIR_MUST_EXIST)
if dd.ShowModal() == wx.ID_OK:
self.toConvert.SetValue(dd.GetPath())
def onToConvertText(self, _event):
if self.toConvert.GetValue() != "":
self.status.SetForegroundColour(wx.Colour(0, 255, 0))
self.destination.Enable()
self.destinationBrowse.Enable()
self.beginConvert.Enable()
self.status.SetLabel("Ready to begin conversion")
src = self.toConvert.GetValue()
if src[-1] == "/":
src = src[:-1]
self.destination.SetValue(src + "_mp3")
else:
self.status.SetForegroundColour(wx.Colour(255, 0, 0))
self.destination.Enable(False)
self.destinationBrowse.Enable(False)
self.beginConvert.Enable(False)
self.status.SetLabel("Please select a directory " \
"containing music files")
self.destination.SetValue("")
def onBeginConvert(self, _event):
self.Hide()
statusFrame = ConvertGUIStatusFrame(self, -1, "")
statusFrame.SetSize(self.GetSize())
statusFrame.SetPosition(self.GetPosition())
statusFrame.Show()
statusFrame.beginConversion(self.toConvert.GetValue(),
self.destination.GetValue())
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
ConvertToMP3 = ConvertGUIMainFrame(None, -1, "")
app.SetTopWindow(ConvertToMP3)
ConvertToMP3.Show()
app.MainLoop()