~ubuntu-branches/ubuntu/oneiric/alarm-clock/oneiric

« back to all changes in this revision

Viewing changes to alarm-clock/RepeatSoundThread.py

  • Committer: Bazaar Package Importer
  • Author(s): Marco Rodrigues
  • Date: 2008-07-04 22:40:34 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080704224034-ckgozkaxdrpch0a4
Tags: 0.9.10-1
* New upstream version.
* debian/rules:
  + Add python-distutils.mk include.
* Remove scripts directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from threading import Thread
 
2
 
 
3
import gst
 
4
import gtk
 
5
 
 
6
class RepeatSound(Thread):
 
7
        def __init__(self, howmanytimes, button, volume, PlayerInstance):
 
8
 
 
9
                Thread.__init__(self)
 
10
 
 
11
                self.setDaemon(True)
 
12
 
 
13
                self.button = button
 
14
                self.times = howmanytimes - 1
 
15
                self.bus = PlayerInstance.get_bus()
 
16
                self.bus.add_signal_watch()
 
17
                self.bus.connect('message', self.BusMessage)
 
18
                self.time_format = gst.Format(gst.FORMAT_TIME)
 
19
                self.Repeated = 0       
 
20
                self.stop = False
 
21
                self.volume = volume / 100
 
22
                self.PlayerInstance = PlayerInstance
 
23
 
 
24
        def run(self):
 
25
                
 
26
                self.PlayerInstance.set_property("volume", self.volume)
 
27
                self.PlayerInstance.set_state(gst.STATE_PLAYING)
 
28
 
 
29
                if self.times > -1:
 
30
                        while self.Repeated < self.times and \
 
31
                        self.PlayerInstance.get_state()[1] != gst.STATE_NULL:
 
32
                                if self.times == -1:
 
33
                                        self.Repeated = 0
 
34
                                        continue
 
35
                                continue
 
36
                else:
 
37
                        while self.PlayerInstance.get_state()[1] != gst.STATE_NULL: continue
 
38
 
 
39
                self.PlayerInstance.set_property("volume", 0)
 
40
                self.PlayerInstance.set_state(gst.STATE_NULL)
 
41
                self.Repeated = 0
 
42
 
 
43
                gtk.gdk.threads_enter()
 
44
                self.button.set_sensitive(False)
 
45
                gtk.gdk.threads_leave()
 
46
 
 
47
        def BusMessage(self, Bus, Message):
 
48
                if Message.type == gst.MESSAGE_EOS:
 
49
                        self.PlayerInstance.set_state(gst.STATE_PAUSED)
 
50
                        self.PlayerInstance.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
 
51
                        self.PlayerInstance.set_property("volume", self.volume)
 
52
                        self.PlayerInstance.set_state(gst.STATE_PLAYING)
 
53
                        self.Repeated += 1
 
54
 
 
55