Code: Alles auswählen
proc = Popen(...)
while proc.poll() is None:
gtk.main_iteration()
Vielleicht kann man das mit wx ähnlich lösen.
Code: Alles auswählen
proc = Popen(...)
while proc.poll() is None:
gtk.main_iteration()
Es klappt! Sort of... Es gibt tatsaechlich einen Befehl in wxPython genannt "wx.EnableTopLevelWindows()", der durch einen boolean definiert ist (True fuer an und False fuer aus, is klar). Das sieht dann bei mir im GUI so aus als function:ms4py hat geschrieben:Also mit GTK kann man über den Befehl `main_iteration` die GUI-Events ablaufen lassen. In Kombination mit subprocess hab ich das mit einer while Schleife folgendermaßen gelöst.
Damit wird auf den Prozess gewartet und gleichzeitig ist noch die GUI aktiv (bei mir in Form einer Progressbar).Code: Alles auswählen
proc = Popen(...) while proc.poll() is None: gtk.main_iteration()
Vielleicht kann man das mit wx ähnlich lösen.
Code: Alles auswählen
def onPlay(self, event):
d = audiere.open_device()
f = d.open_file('my/audio/file', -1) # -1 equals 'streaming', 0 is load fully into RAM prior to use
f.play()
while f.playing:
wx.EnableTopLevelWindows()
Code: Alles auswählen
Traceback (most recent call last):
File "C:\Dokumente und Einstellungen\Nebelhom\workspace\DSAMusic\src\DSAMusicGUI.py", line 159, in onPlay
wx.EnableTopLevelWindows()
File "C:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_misc.py", line 382, in EnableTopLevelWindows
return _misc_.EnableTopLevelWindows(*args, **kwargs)
TypeError: Required argument 'enable' (pos 1) not found
Code: Alles auswählen
class Audiofile:
# Amazingly, this works without locking up the GUI!!!
def __init__(self, path):
self.path = path
self.file = audiere.open_device()
self.song = self.file.open_file(path, -1) # -1 stands for streaming, tested with .mp3, .wav, .ogg
def player(self):
self.song.play()
def stopper(self):
self.song.stop()
# Excerpt from gui functions bound to buttons in wxpython
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# constructor stuffs
...
wx.EVT_BUTTON (self, ID_PLAY, self.onPlay)
wx.EVT_BUTTON (self, ID_STOP, self.onStop)
...
self.audio = Audiofile('an/audio/file')
def onPlay(self, event):
self.audio.player()
def onStop(self, event):
self.audio.stopper()
Code: Alles auswählen
def onPlay(self, event, path='my/audio/file'):
d = audiere.open_device() #defined without self
f = d.open_file(path)
f.play()
while f.playing: # leaving it out causes the audiofile not to play
time.sleep(.01)