~k-nielsen81/npt/trunk

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
#!/usr/bin/env python
#
# autopageturner.py
#
# This program 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.
# 
# This program 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 Library General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA

import sys

import gobject
import playermodule
import time
import customexceptions
import fileIO

class NotePageTurnerCore():
    """This is the AutoPageTurner application"""

    def __init__(self, verbose=False):
        self.verbose = verbose
        self.current_position = 0.0
        self.duration = 0.0
        self.rep_interval = {'start':0.0, 'end':0.0}
        self.time = time.time()
        self.files=[]
        self.current_text_key = None
        self.current_file = None

        # Load the sound player
        self.player = playermodule.Player()

    def open(self, file_name):
        # Get file name from file dialog
        f = fileIO.FileIO()
        # Replace hardcoded filepath with the one from open dialogue
        f.set_filepath(file_name)
        f.load_file()
        self.files.append(f)
        self.current_file = 0

        # This dummy call loads a standard file to the player, and should
        # be removed later when program is more complete
        self.player.set_file('file://' + f.get_audio_file_path())
        
        # The set file function creates plays and stops the playback to test
        # whether it is playable. If it is not ot will create error. We must give
        # these time to propagate, so that we recognize that there is no file loaded
        # before we call get duration.
        self.duration_timer = gobject.timeout_add(100, self.get_duration)

    def get_duration(self):
        # Get duration and set set the scale
        self.duration = self.player.get_duration()
        # This makes the timer destroy it-self after one call
        return False

    def get_position(self):
        return 0.1
    
    def play(self):
        self.player.play()

    def pause(self):
        self.player.pause()

    def stop(self):
        self.player.stop()
        
    def get_text(self):
        return 'test'

    ### Other methods ###            
    
    def tick(self, widget=None, scrolltype=None, value=None):
        # Returns state_changed, state, err_code, err_msg
        state_changed, state, err_code, err_msg = self.player.check_for_errors()
        if state_changed or (err_code is not None):
            print state_changed, state, err_code, err_msg

        return True        

if __name__ == "__main__":
    apt = AutoPageTurner()
    gtk.main()