1#  This program is free software; you can redistribute it and/or
2#  modify it under the terms of the GNU General Public License
3#  as published by the Free Software Foundation; either version 2
4#  of the License, or (at your option) any later version.
5#
6#  This program is distributed in the hope that it will be useful,
7#  but WITHOUT ANY WARRANTY; without even the implied warranty of
8#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9#  GNU General Public License for more details.
10#
11#  You should have received a copy of the GNU General Public License
12#  along with this program; if not, write to the Free Software Foundation,
13#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14"""
15Timeline Extra Info
16
17Display amount of frames left until Frame End, very handy especially when
18rendering an animation or OpenGL preview.
19Display current/end time on SMPTE. Find it on the Timeline header.
20"""
21
22import bpy
23
24
25def label_timeline_extra_info(self, context):
26    get_addon = "amaranth" in context.preferences.addons.keys()
27    if not get_addon:
28        return
29
30    layout = self.layout
31    scene = context.scene
32
33    if context.preferences.addons["amaranth"].preferences.use_timeline_extra_info:
34        row = layout.row(align=True)
35
36        # Check for preview range
37        frame_start = scene.frame_preview_start if scene.use_preview_range else scene.frame_start
38        frame_end = scene.frame_preview_end if scene.use_preview_range else scene.frame_end
39
40        row.label(
41            text="%s / %s" %
42            (bpy.utils.smpte_from_frame(
43                scene.frame_current -
44                frame_start),
45                bpy.utils.smpte_from_frame(
46                    frame_end -
47                    frame_start)))
48
49        if (scene.frame_current > frame_end):
50            row.label(text="%s Frames Ahead" %
51                      ((frame_end - scene.frame_current) * -1))
52        elif (scene.frame_current == frame_start):
53            row.label(text="Start Frame (%s left)" %
54                      (frame_end - scene.frame_current))
55        elif (scene.frame_current == frame_end):
56            row.label(text="%s End Frame" % scene.frame_current)
57        else:
58            row.label(text="%s Frames Left" %
59                      (frame_end - scene.frame_current))
60
61
62def register():
63    bpy.types.STATUSBAR_HT_header.append(label_timeline_extra_info)
64
65
66def unregister():
67    bpy.types.STATUSBAR_HT_header.remove(label_timeline_extra_info)
68