more bpy.context removal, menus are working again (check it)
[blender-addons-contrib.git] / sequencer_extra_actions / ui.py
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
19 import bpy
20
21
22 # UI
23 class SEQUENCER_EXTRA_MT_input(bpy.types.Menu):
24     bl_label = "Input"
25
26     def draw(self, context):
27         self.layout.operator_context = 'INVOKE_REGION_WIN'
28         self.layout.operator('sequencerextra.striprename',
29         text='File Name to Strip Name', icon='PLUGIN')
30         self.layout.operator('sequencerextra.editexternally',
31         text='Open with External Editor', icon='PLUGIN')
32         self.layout.operator('sequencerextra.edit',
33         text='Open with Editor', icon='PLUGIN')
34         self.layout.operator('sequencerextra.createmovieclip',
35         text='Create Movieclip strip', icon='PLUGIN')
36
37
38 def sequencer_add_menu_func(self, context):
39     self.layout.operator('sequencerextra.recursiveload', 
40     text='recursive load from browser', icon='PLUGIN')
41     self.layout.separator()
42
43
44 def sequencer_select_menu_func(self, context):
45     self.layout.operator_menu_enum('sequencerextra.select_all_by_type',
46     'type', text='All by Type', icon='PLUGIN')
47     self.layout.separator()
48     self.layout.operator('sequencerextra.selectcurrentframe',
49     text='Before Current Frame', icon='PLUGIN').mode = 'BEFORE'
50     self.layout.operator('sequencerextra.selectcurrentframe',
51     text='After Current Frame', icon='PLUGIN').mode = 'AFTER'
52     self.layout.operator('sequencerextra.selectcurrentframe',
53     text='On Current Frame', icon='PLUGIN').mode = 'ON'
54     self.layout.separator()
55
56
57 def sequencer_strip_menu_func(self, context):
58     self.layout.operator('sequencerextra.extendtofill',
59     text='Extend to Fill', icon='PLUGIN')
60     self.layout.operator('sequencerextra.distribute',
61     text='Distribute', icon='PLUGIN')
62     self.layout.operator_menu_enum('sequencerextra.fadeinout',
63     'mode', text='Fade', icon='PLUGIN')
64     self.layout.operator_menu_enum('sequencerextra.copyproperties',
65     'prop', icon='PLUGIN')
66     self.layout.operator('sequencerextra.slidegrab',
67     text='Slide Grab', icon='PLUGIN')
68     self.layout.operator_menu_enum('sequencerextra.slide',
69     'mode', icon='PLUGIN')
70     self.layout.operator('sequencerextra.insert',
71     text='Insert (Single Channel)', icon='PLUGIN').singlechannel = True
72     self.layout.operator('sequencerextra.insert',
73     text='Insert', icon='PLUGIN').singlechannel = False
74     self.layout.operator('sequencerextra.ripplecut',
75     text='Ripple Cut', icon='PLUGIN')
76     self.layout.operator('sequencerextra.rippledelete',
77     text='Ripple Delete', icon='PLUGIN')
78     self.layout.separator()
79
80
81 def sequencer_header_func(self, context):
82     self.layout.menu("SEQUENCER_EXTRA_MT_input")
83     if context.space_data.view_type in ('PREVIEW', 'SEQUENCER_PREVIEW'):
84         self.layout.operator('sequencerextra.jogshuttle',
85         text='Jog/Shuttle', icon='NDOF_TURN')
86     if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
87         self.layout.operator('sequencerextra.navigateup',
88         text='Navigate Up', icon='FILE_PARENT')
89     if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
90         self.layout.operator('sequencerextra.placefromfilebrowser',
91         text='File Place', icon='TRIA_DOWN').insert = False
92     if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
93         self.layout.operator('sequencerextra.placefromfilebrowser',
94         text='File Insert', icon='TRIA_RIGHT').insert = True
95     if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
96         self.layout.operator('sequencerextra.placefromfilebrowserproxy',
97         text='Proxy Place', icon='TRIA_DOWN')
98     if context.space_data.view_type in ('SEQUENCER', 'SEQUENCER_PREVIEW'):
99         self.layout.operator('sequencerextra.placefromfilebrowserproxy',
100         text='Proxy Insert', icon='TRIA_RIGHT').insert = True
101
102
103 def time_frame_menu_func(self, context):
104     self.layout.operator('timeextra.trimtimelinetoselection',
105     text='Trim to Selection', icon='PLUGIN')
106     self.layout.operator('timeextra.trimtimeline',
107     text='Trim to Timeline Content', icon='PLUGIN')
108     self.layout.separator()
109     self.layout.operator('screenextra.frame_skip',
110     text='Skip Forward One Second', icon='PLUGIN').back = False
111     self.layout.operator('screenextra.frame_skip',
112     text='Skip Back One Second', icon='PLUGIN').back = True
113     self.layout.separator()
114
115
116 def time_header_func(self, context):
117     self.layout.operator('sequencerextra.jogshuttle',
118     text='Jog/Shuttle', icon='NDOF_TURN')
119
120
121 def clip_header_func(self, context):
122     self.layout.operator('sequencerextra.jogshuttle',
123     text='Jog/Shuttle', icon='NDOF_TURN')
124
125
126 def clip_clip_menu_func(self, context):
127     self.layout.operator('clipextra.openactivestrip',
128     text='Open Active Strip', icon='PLUGIN')
129     self.layout.operator('clipextra.openfromfilebrowser',
130     text='Open from File Browser', icon='PLUGIN')
131     self.layout.separator()
132
133
134 class ExifInfoPanel(bpy.types.Panel):
135     """Creates a Panel in the Object properties window"""
136     bl_label = "EXIF Info Panel"
137     bl_space_type = 'SEQUENCE_EDITOR'
138     bl_region_type = 'UI'
139
140     @staticmethod
141     def has_sequencer(context):
142         return (context.space_data.view_type\
143         in {'SEQUENCER', 'SEQUENCER_PREVIEW'})
144
145     @classmethod
146     def poll(cls, context):
147         return cls.has_sequencer(context)
148
149     def draw_header(self, context):
150         layout = self.layout
151         layout.label(text="", icon="NLA")
152
153     def draw(self, context):
154         layout = self.layout
155         sce = context.scene
156         row = layout.row()
157         row.operator("sequencerextra.read_exif")
158         row = layout.row()
159         row.label(text="Exif Data", icon='RENDER_REGION')
160         row = layout.row()
161
162         try:
163             strip = context.scene.sequence_editor.active_strip
164
165             f = strip.frame_start
166             frame = sce.frame_current
167             try:
168                 if len(sce['metadata']) == 1:
169                     for d in sce['metadata'][0]:
170                         split = layout.split(percentage=0.5)
171                         col = split.column()
172                         row = col.row()
173                         col.label(text=d)
174                         col = split.column()
175                         col.label(str(sce['metadata'][0][d]))
176                 else:
177                     for d in sce['metadata'][frame - f]:
178                         split = layout.split(percentage=0.5)
179                         col = split.column()
180                         row = col.row()
181                         col.label(text=d)
182                         col = split.column()
183                         col.label(str(sce['metadata'][frame - f][d]))
184             except KeyError:
185                 pass
186         except AttributeError:
187             pass