forked from nortikin/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuto_Perspective.py
148 lines (112 loc) · 4.68 KB
/
Auto_Perspective.py
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# -*- coding: utf-8 -*-
# ##### 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 2
# 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Auto Perspective",
"author": "Alexander Nedovizin",
"version": (0, 1, 0),
"blender": (2, 7, 0),
"location": "View3D > Auto Perspective",
"category": "3D View"
}
import bpy
def main(context):
pass
return
class ModalTimerOperator(bpy.types.Operator):
"""Operator which runs its self from a timer"""
bl_idname = "wm.modal_timer_operator"
bl_label = "Start AutoPersp"
_timer = None
frequence = bpy.props.FloatProperty(name="Frequence", default=1.0)
mode = bpy.props.BoolProperty(name="Mode", default=False)
@classmethod
def poll(cls, context):
return (context.area.type == 'VIEW_3D')
def modal(self, context, event):
config = bpy.context.window_manager.CONFIG_Z
if event.type == 'ESC' or config.label == 'Start AutoPersp':
return self.cancel(context)
if event.type == 'TIMER':
main(context)
if event.type in ['NUMPAD_1', 'NUMPAD_3', 'NUMPAD_7']:
view3d = context.space_data.region_3d
view3d.view_perspective = 'ORTHO'
view3d.update()
self.mode = True
if event.type == 'MIDDLEMOUSE':
view3d = context.space_data.region_3d
if self.mode:
view3d.view_perspective = 'PERSP'
view3d.update()
self.mode = False
return {'PASS_THROUGH'}
def invoke(self, context, event):
self._timer = context.window_manager.event_timer_add(self.frequence, context.window)
context.window_manager.modal_handler_add(self)
config = bpy.context.window_manager.CONFIG_Z
if config.label == 'Start AutoPersp':
config.label = 'Stop AutoPersp'
else:
config.label = 'Start AutoPersp'
return {'RUNNING_MODAL'}
def cancel(self, context):
context.window_manager.event_timer_remove(self._timer)
config = bpy.context.window_manager.CONFIG_Z
config.label = 'Start AutoPersp'
return {'FINISHED'}
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Auto Perspective"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
config = bpy.context.window_manager.CONFIG_Z
layout = self.layout
col = layout.column(align=True)
split = col.split(percentage=0.15)
if config.display:
split.prop(config, "display", text="", icon='DOWNARROW_HLT')
else:
split.prop(config, "display", text="", icon='RIGHTARROW')
timer_op = split.operator("wm.modal_timer_operator", text = config.label)
timer_op.frequence = config.frequence
if config.display:
box = col.column(align=True).box().column()
col_top = box.column(align=True)
row = col_top.row(align=True)
row.prop(config,'frequence')
class UIElements(bpy.types.PropertyGroup):
frequence = bpy.props.FloatProperty(name="Frequence")
label = bpy.props.StringProperty(name="label")
display = bpy.props.BoolProperty(name="display")
def register():
bpy.utils.register_class(HelloWorldPanel)
bpy.utils.register_class(ModalTimerOperator)
bpy.utils.register_class(UIElements)
bpy.types.WindowManager.CONFIG_Z = bpy.props.PointerProperty(type = UIElements)
bpy.context.window_manager.CONFIG_Z.frequence = 1.0
bpy.context.window_manager.CONFIG_Z.label = 'Start AutoPersp'
bpy.context.window_manager.CONFIG_Z.display = False
def unregister():
del bpy.types.WindowManager.CONFIG_Z
bpy.utils.unregister_class(UIElements)
bpy.utils.unregister_class(ModalTimerOperator)
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()