Amaranth Addon
[blender-addons-contrib.git] / amaranth / scene / refresh.py
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 """
15 Refresh Scene
16
17 Refresh the current scene, useful when working with libraries or drivers.
18 Could also add an option to refresh the VSE maybe? Usage: Hit F5 or find
19 it on the Specials menu W.
20 """
21
22 import bpy
23
24
25 KEYMAPS = list()
26
27
28 class AMTH_SCENE_OT_refresh(bpy.types.Operator):
29
30     """Refresh the current scene"""
31     bl_idname = "scene.refresh"
32     bl_label = "Refresh!"
33
34     def execute(self, context):
35         preferences = context.user_preferences.addons["amaranth"].preferences
36         scene = context.scene
37
38         if preferences.use_scene_refresh:
39             # Changing the frame is usually the best way to go
40             scene.frame_current = scene.frame_current
41             self.report({"INFO"}, "Scene Refreshed!")
42
43         return {"FINISHED"}
44
45
46 def button_refresh(self, context):
47     preferences = context.user_preferences.addons["amaranth"].preferences
48
49     if preferences.use_scene_refresh:
50         self.layout.separator()
51         self.layout.operator(AMTH_SCENE_OT_refresh.bl_idname,
52                              text="Refresh!",
53                              icon="FILE_REFRESH")
54
55
56 def register():
57     bpy.utils.register_class(AMTH_SCENE_OT_refresh)
58     bpy.types.VIEW3D_MT_object_specials.append(button_refresh)
59     kc = bpy.context.window_manager.keyconfigs.addon
60     km = kc.keymaps.new(name="Window")
61     kmi = km.keymap_items.new("scene.refresh", "F5", "PRESS",
62                               alt=True)
63     KEYMAPS.append((km, kmi))
64
65
66 def unregister():
67     bpy.utils.unregister_class(AMTH_SCENE_OT_refresh)
68     bpy.types.VIEW3D_MT_object_specials.remove(button_refresh)
69     for km, kmi in KEYMAPS:
70         km.keymap_items.remove(kmi)
71     KEYMAPS.clear()