-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface_project_timer.py
More file actions
127 lines (104 loc) · 3.88 KB
/
interface_project_timer.py
File metadata and controls
127 lines (104 loc) · 3.88 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# ***** BEGIN GPL LICENSE BLOCK *****
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# The Original Code is Copyright (C) 2013 by Marcin Zielinski
# All rights reserved.
#
# Contact: martin.zielinsky@gmail.com
# Information: http://<domain>.<ext> ###
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL LICENSE BLOCK *****
bl_info = {
"name": "Project Timer",
"author": "Martin Zielinski",
"version": (1, 4, 2),
"blender": (3, 0, 0),
"location": "Info",
"description": "Show time spent on project",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Interface"}
# Is this script helpful? Please donate
# BTC 19pXNYUaktXE2MXK37gVEZkrVjL3TwZhF
import bpy
import time
from bpy.app.handlers import persistent
class ProjectTimerReset(bpy.types.Operator):
bl_idname = "poject_timer.reset"
bl_label = "Reset Project Timer"
bl_options = {'INTERNAL'}
def execute(self, context):
bpy.projectTime = 0
return {'FINISHED'}
class ProjectTimerPreferences(bpy.types.AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __name__
def draw(self, context):
layout = self.layout
layout.operator("poject_timer.reset")
bpy.types.Scene.projectTime = bpy.props.IntProperty(
name = "Project Time",
description='All time spent on project',
default = 0)
def draw_counter(self, context):
projectTimerUpdate(context.scene)
layout = self.layout
region = context.region
if region.alignment == 'RIGHT':
seconds = bpy.projectTime
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
layout.label(text=str(h)+':'+format(m, '02d')+':'+format(s, '02d'))
def projectTimerUpdate(scene):
if not hasattr(bpy, 'projectTimestamp'): #first open
bpy.projectTime = scene.projectTime
bpy.projectTimestamp = int(time.time())
print('Project Time: ', bpy.projectTime)
print('Project Timestamp: ', bpy.projectTimestamp)
delta = int(time.time()) - bpy.projectTimestamp
if delta < 30:
bpy.projectTime += delta
bpy.projectTimestamp = int(time.time())
@persistent
def projectTimerSave(scene):
projectTimerUpdate(scene)
bpy.context.scene.projectTime = bpy.projectTime
print('Project Time saved', bpy.projectTime)
@persistent
def projectTimerLoad(scene):
bpy.projectTime = bpy.context.scene.projectTime
bpy.projectTimestamp = int(time.time())
print('Project Time loaded', bpy.projectTime)
# Registration
def register():
bpy.app.handlers.load_post.append(projectTimerLoad)
bpy.app.handlers.save_pre.append(projectTimerSave)
bpy.utils.register_class(ProjectTimerReset)
bpy.utils.register_class(ProjectTimerPreferences)
bpy.types.TOPBAR_HT_upper_bar.append(draw_counter)
def unregister():
bpy.app.handlers.load_post.remove(projectTimerLoad)
bpy.app.handlers.save_pre.remove(projectTimerSave)
bpy.utils.unregister_class(ProjectTimerReset)
bpy.utils.unregister_class(ProjectTimerPreferences)
bpy.types.TOPBAR_HT_upper_bar.remove(draw_counter)
if __name__ == "__main__":
register()