~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-12-12 16:06:12 UTC
  • mfrom: (7.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081212160612-1260171ufoj0v3ww
Tags: 0.9.18-2
* debian/control:
  + Add gstreamer0.10-plugins-base to
    Depends. Closes: #485386.
* debian/watch:
  + Fix URL to new hosting address.

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.PlayerInstance.set_state(gst.STATE_NULL)
45
59
                gtk.gdk.threads_leave()
 
60
                self.stillrun = False
 
61
 
46
62
 
47
63
        def BusMessage(self, Bus, Message):
 
64
                if not self.MainClass.WhatPlaying == "R": return
 
65
                if self.PlayerInstance.get_state()[1] == gst.STATE_NULL: return
48
66
                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
 
67
 
 
68
                        if self.Repeated == self.times and not self.times < 0:
 
69
                                gtk.gdk.threads_enter()
 
70
                                self.MainClass.StopTheSound()
 
71
                                gtk.gdk.threads_leave()
 
72
                                self.stillrun = False
 
73
                        self.PlayAgain = True
 
74
 
54
75
 
55
76