space_time.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. import bpy
  20. from bpy.types import Header, Menu, Panel
  21. # Header buttons for timeline header (play, etc.)
  22. class TIME_HT_editor_buttons(Header):
  23. bl_idname = "TIME_HT_editor_buttons"
  24. bl_space_type = 'DOPESHEET_EDITOR'
  25. bl_label = ""
  26. def draw(self, context):
  27. pass
  28. @staticmethod
  29. def draw_header(context, layout):
  30. scene = context.scene
  31. tool_settings = context.tool_settings
  32. screen = context.screen
  33. layout.separator_spacer()
  34. layout.prop(tool_settings, "use_keyframe_insert_auto", text="", toggle=True)
  35. row = layout.row(align=True)
  36. row.operator("screen.frame_jump", text="", icon='REW').end = False
  37. row.operator("screen.keyframe_jump", text="", icon='PREV_KEYFRAME').next = False
  38. if not screen.is_animation_playing:
  39. # if using JACK and A/V sync:
  40. # hide the play-reversed button
  41. # since JACK transport doesn't support reversed playback
  42. if scene.sync_mode == 'AUDIO_SYNC' and context.preferences.system.audio_device == 'JACK':
  43. sub = row.row(align=True)
  44. sub.scale_x = 1.4
  45. sub.operator("screen.animation_play", text="", icon='PLAY')
  46. else:
  47. row.operator("screen.animation_play", text="", icon='PLAY_REVERSE').reverse = True
  48. row.operator("screen.animation_play", text="", icon='PLAY')
  49. else:
  50. sub = row.row(align=True)
  51. sub.scale_x = 1.4
  52. sub.operator("screen.animation_play", text="", icon='PAUSE')
  53. row.operator("screen.keyframe_jump", text="", icon='NEXT_KEYFRAME').next = True
  54. row.operator("screen.frame_jump", text="", icon='FF').end = True
  55. layout.separator_spacer()
  56. row = layout.row()
  57. row.scale_x = 0.95
  58. if scene.show_subframe:
  59. row.prop(scene, "frame_float", text="")
  60. else:
  61. row.prop(scene, "frame_current", text="")
  62. row = layout.row(align=True)
  63. row.prop(scene, "use_preview_range", text="", toggle=True)
  64. sub = row.row(align=True)
  65. sub.scale_x = 0.8
  66. if not scene.use_preview_range:
  67. sub.prop(scene, "frame_start", text="Start")
  68. sub.prop(scene, "frame_end", text="End")
  69. else:
  70. sub.prop(scene, "frame_preview_start", text="Start")
  71. sub.prop(scene, "frame_preview_end", text="End")
  72. class TIME_MT_editor_menus(Menu):
  73. bl_idname = "TIME_MT_editor_menus"
  74. bl_label = ""
  75. def draw(self, _context):
  76. layout = self.layout
  77. horizontal = (layout.direction == 'VERTICAL')
  78. if horizontal:
  79. row = layout.row()
  80. sub = row.row(align=True)
  81. else:
  82. sub = layout
  83. sub.popover(
  84. panel="TIME_PT_playback",
  85. text="Playback",
  86. )
  87. sub.popover(
  88. panel="TIME_PT_keyframing_settings",
  89. text="Keying",
  90. )
  91. if horizontal:
  92. sub = row.row(align=True)
  93. sub.menu("TIME_MT_view")
  94. sub.menu("TIME_MT_marker")
  95. class TIME_MT_marker(Menu):
  96. bl_label = "Marker"
  97. def draw(self, context):
  98. layout = self.layout
  99. marker_menu_generic(layout, context)
  100. class TIME_MT_view(Menu):
  101. bl_label = "View"
  102. def draw(self, context):
  103. layout = self.layout
  104. scene = context.scene
  105. st = context.space_data
  106. layout.prop(st, "show_seconds")
  107. layout.prop(st, "show_locked_time")
  108. layout.separator()
  109. layout.prop(st, "show_marker_lines")
  110. layout.prop(st, "show_frame_indicator")
  111. layout.prop(scene, "show_keys_from_selected_only")
  112. layout.separator()
  113. layout.menu("TIME_MT_cache")
  114. layout.separator()
  115. # NOTE: "action" now, since timeline is in the dopesheet editor, instead of as own editor
  116. layout.operator("action.view_all")
  117. layout.operator("action.view_frame")
  118. layout.separator()
  119. layout.menu("INFO_MT_area")
  120. class TIME_MT_cache(Menu):
  121. bl_label = "Cache"
  122. def draw(self, context):
  123. layout = self.layout
  124. st = context.space_data
  125. layout.prop(st, "show_cache")
  126. layout.separator()
  127. col = layout.column()
  128. col.enabled = st.show_cache
  129. col.prop(st, "cache_softbody")
  130. col.prop(st, "cache_particles")
  131. col.prop(st, "cache_cloth")
  132. col.prop(st, "cache_smoke")
  133. col.prop(st, "cache_dynamicpaint")
  134. col.prop(st, "cache_rigidbody")
  135. def marker_menu_generic(layout, context):
  136. # layout.operator_context = 'EXEC_REGION_WIN'
  137. layout.column()
  138. layout.operator("marker.add", text="Add Marker")
  139. layout.operator("marker.duplicate", text="Duplicate Marker")
  140. if len(bpy.data.scenes) > 10:
  141. layout.operator_context = 'INVOKE_DEFAULT'
  142. layout.operator("marker.make_links_scene", text="Duplicate Marker to Scene...", icon='OUTLINER_OB_EMPTY')
  143. else:
  144. layout.operator_menu_enum("marker.make_links_scene", "scene", text="Duplicate Marker to Scene")
  145. layout.operator("marker.delete", text="Delete Marker")
  146. layout.separator()
  147. layout.operator("marker.rename", text="Rename Marker")
  148. layout.operator("marker.move", text="Move Marker")
  149. layout.separator()
  150. layout.operator("marker.camera_bind")
  151. layout.separator()
  152. layout.operator("screen.marker_jump", text="Jump to Next Marker").next = True
  153. layout.operator("screen.marker_jump", text="Jump to Previous Marker").next = False
  154. layout.separator()
  155. tool_settings = context.tool_settings
  156. layout.prop(tool_settings, "lock_markers")
  157. ###################################
  158. class TimelinePanelButtons:
  159. bl_space_type = 'DOPESHEET_EDITOR'
  160. bl_region_type = 'UI'
  161. @staticmethod
  162. def has_timeline(context):
  163. return context.space_data.mode == 'TIMELINE'
  164. class TIME_PT_playback(TimelinePanelButtons, Panel):
  165. bl_label = "Playback"
  166. bl_region_type = 'HEADER'
  167. def draw(self, context):
  168. layout = self.layout
  169. screen = context.screen
  170. scene = context.scene
  171. layout.prop(scene, "sync_mode", text="")
  172. layout.prop(scene, "use_audio_scrub")
  173. layout.prop(scene, "use_audio", text="Mute Audio")
  174. layout.prop(scene, "show_subframe", text="Subframes")
  175. layout.prop(scene, "lock_frame_selection_to_range", text="Limit Playhead to Frame Range")
  176. layout.prop(screen, "use_follow", text="Follow Playhead")
  177. layout.separator()
  178. col = layout.column()
  179. col.label(text="Play Animation In:")
  180. layout.prop(screen, "use_play_top_left_3d_editor", text="Active Editor Only")
  181. layout.prop(screen, "use_play_3d_editors")
  182. layout.prop(screen, "use_play_animation_editors")
  183. layout.prop(screen, "use_play_properties_editors")
  184. layout.prop(screen, "use_play_image_editors")
  185. layout.prop(screen, "use_play_sequence_editors")
  186. layout.prop(screen, "use_play_node_editors")
  187. layout.prop(screen, "use_play_clip_editors")
  188. layout.separator()
  189. row = layout.row(align=True)
  190. row.operator("anim.start_frame_set")
  191. row.operator("anim.end_frame_set")
  192. class TIME_PT_keyframing_settings(TimelinePanelButtons, Panel):
  193. bl_label = "Keyframing Settings"
  194. bl_options = {'HIDE_HEADER'}
  195. bl_region_type = 'HEADER'
  196. @classmethod
  197. def poll(cls, context):
  198. # only for timeline editor
  199. return cls.has_timeline(context)
  200. def draw(self, context):
  201. layout = self.layout
  202. scene = context.scene
  203. tool_settings = context.tool_settings
  204. prefs = context.preferences
  205. col = layout.column(align=True)
  206. col.label(text="Active Keying Set:")
  207. row = col.row(align=True)
  208. row.prop_search(scene.keying_sets_all, "active", scene, "keying_sets_all", text="")
  209. row.operator("anim.keyframe_insert", text="", icon='KEY_HLT')
  210. row.operator("anim.keyframe_delete", text="", icon='KEY_DEHLT')
  211. col = layout.column(align=True)
  212. col.label(text="New Keyframe Type:")
  213. col.prop(tool_settings, "keyframe_type", text="")
  214. col = layout.column(align=True)
  215. col.label(text="Auto Keyframing:")
  216. row = col.row()
  217. row.prop(tool_settings, "auto_keying_mode", text="")
  218. row.prop(tool_settings, "use_keyframe_insert_keyingset", text="")
  219. if not prefs.edit.use_keyframe_insert_available:
  220. col.prop(tool_settings, "use_record_with_nla", text="Layered Recording")
  221. layout.prop(tool_settings, "use_keyframe_cycle_aware")
  222. ###################################
  223. classes = (
  224. TIME_HT_editor_buttons,
  225. TIME_MT_editor_menus,
  226. TIME_MT_marker,
  227. TIME_MT_view,
  228. TIME_MT_cache,
  229. TIME_PT_playback,
  230. TIME_PT_keyframing_settings,
  231. )
  232. if __name__ == "__main__": # only for live edit.
  233. from bpy.utils import register_class
  234. for cls in classes:
  235. register_class(cls)