~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-10-28 19:57:12 UTC
  • mto: (7.1.1 sid) (9.1.1 squeeze) (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20081028195712-e8kusg37fc1hnw0s
Tags: upstream-0.9.17
ImportĀ upstreamĀ versionĀ 0.9.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from threading import Thread
2
2
 
 
3
import time
 
4
 
3
5
import gst
4
6
import gtk
5
7
 
6
8
class RepeatSound(Thread):
7
 
        def __init__(self, howmanytimes, button, volume, PlayerInstance):
 
9
        def __init__(self, howmanytimes, button, volume, PlayerInstance, MainClass, sndfile):
8
10
 
9
11
                Thread.__init__(self)
10
12
 
11
13
                self.setDaemon(True)
12
 
 
 
14
                self.sndfile = sndfile
13
15
                self.button = button
14
 
                self.times = howmanytimes - 1
 
16
                self.times = howmanytimes
15
17
                self.bus = PlayerInstance.get_bus()
16
18
                self.bus.add_signal_watch()
17
19
                self.bus.connect('message', self.BusMessage)
20
22
                self.stop = False
21
23
                self.volume = volume / 100
22
24
                self.PlayerInstance = PlayerInstance
23
 
 
24
 
        def run(self):
25
 
                
26
25
                self.PlayerInstance.set_property("volume", self.volume)
 
26
                self.stillrun = True
 
27
                self.MainClass = MainClass
27
28
                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
 
29
                self.PlayAgain = False
 
30
        def run(self):
 
31
                while self.stillrun or self.Repeated <= self.times or self.times == -1:
 
32
                        time.sleep(0.01)
 
33
                        if self.PlayAgain:
 
34
                                if not self.Repeated < self.times - 1 and not self.times == -1: break
 
35
                                self.PlayerInstance.set_property('uri', "file://" + self.sndfile)
 
36
                                self.PlayerInstance.seek_simple(self.time_format, gst.SEEK_FLAG_FLUSH, 0)
 
37
                                self.PlayerInstance.set_state(gst.STATE_PLAYING)
 
38
                                if self.times > 0:
 
39
                                        self.Repeated += 1
 
40
                                else:
 
41
                                        self.Repeated = -2
 
42
                                        self.PlayAgain = True
 
43
                        self.PlayAgain = False
 
44
 
 
45
 
 
46
 
 
47
                        if self.PlayerInstance.get_state()[1] == gst.STATE_NULL:
 
48
                                break
 
49
 
 
50
 
 
51
 
38
52
 
39
53
                self.PlayerInstance.set_property("volume", 0)
40
54
                self.PlayerInstance.set_state(gst.STATE_NULL)
41
55
                self.Repeated = 0
42
56
 
43
57
                gtk.gdk.threads_enter()
44
 
                self.button.set_sensitive(False)
 
58
                self.MainClass.StopTheSound()
 
59
                self.PlayerInstance.set_state(gst.STATE_NULL)
45
60
                gtk.gdk.threads_leave()
 
61
                self.stillrun = False
 
62
 
46
63
 
47
64
        def BusMessage(self, Bus, Message):
 
65
                if not self.MainClass.WhatPlaying == "R": return
 
66
                if self.PlayerInstance.get_state()[1] == gst.STATE_NULL: return
48
67
                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
 
68
 
 
69
                        if self.Repeated == self.times and not self.times < 0:
 
70
                                gtk.gdk.threads_enter()
 
71
                                self.MainClass.StopTheSound()
 
72
                                gtk.gdk.threads_leave()
 
73
                                self.stillrun = False
 
74
                        self.PlayAgain = True
 
75
 
54
76
 
55
77