1import pyatspi
2import orca.script_utilities as script_utilities
3
4class Utilities(script_utilities.Utilities):
5
6    def __init__(self, script):
7        """Creates an instance of the Utilities class.
8
9        Arguments:
10        - script: the script with which this instance is associated.
11        """
12
13        script_utilities.Utilities.__init__(self, script)
14
15    def _formatDuration(self, s):
16        seconds = '%02d' % (s%60)
17        minutes = '%02d' % (s/60)
18        hours = '%02d' % (s/3600)
19
20        duration = [minutes, seconds]
21
22        if hours != '00':
23            duration.insert(0, hours)
24
25        return ':'.join(duration)
26
27    def isSeekSlider(self, obj):
28        return bool(pyatspi.findAncestor(
29                obj, lambda x: x.getRole() == pyatspi.ROLE_TOOL_BAR))
30
31    def textForValue(self, obj):
32        if not self.isSeekSlider(obj):
33            return script_utilities.Utilities.textForValue(self, obj)
34
35        try:
36            value = obj.queryValue()
37        except NotImplementedError:
38            return script_utilities.Utilities.textForValue(self, obj)
39        else:
40            return self._formatDuration(int(value.currentValue)/1000)
41