How do I, with python, select the sequencer area which has a view type as preview, to make it active/context? (And not select the "strip" window)

EDIT: My overall goal is to add a windowless, fullscreen, correctly scaled video-preview function to the VSE view menu(shortcuts: alt+F10, alt+F11 and home). In the video-editing workspace, there are two areas which are sequencer areas. One is the view type: sequencer(with strips) and one is view type: preview. When adding the function to the menu with SEQUENCER_MT_view, it is added to both areas, but I only want to make the preview area full screen, not the strip area. So I need help to make sure that the full-screen functions only will make the preview area full screen. How do I do that?

TrueFullScreen

Where I am now(after help from SNU) - But get the working code from Snu further down:

import bpy

class SEQUENCE_MT_true_fullscreen(bpy.types.Operator):
    """True fullscreen preview. Close in upper right corner"""
    bl_label = "True Fullscreen"
    bl_idname = "sequencer.true_fullscreen"
    bl_options = {'REGISTER', 'UNDO'}

    def execute(self, context):
        scene=bpy.context.scene

        if not bpy.context.scene.sequence_editor: #create sequence, if missing
            bpy.context.scene.sequence_editor_create()   

        context = bpy.context
        for area in bpy.context.screen.areas:
            if area.type == 'SEQUENCE_EDITOR':
                if area.spaces[0].view_type == 'PREVIEW':  
                   override = bpy.context.copy()
                   override['space_data'] = area.spaces.active
                   override['region'] = area.regions[-1]
                   override['area'] = area
                   override['screen'] = context.screen
                   bpy.ops.screen.screen_full_area(override, use_hide_panels=True)
                   bpy.ops.wm.window_fullscreen_toggle()
                   #bpy.ops.sequencer.view_all_preview() #uncomment this to crash
                   break    

        return {'FINISHED'}

def menu_append(self, context):
    self.layout.operator(SEQUENCE_MT_true_fullscreen.bl_idname)

def register():
    bpy.utils.register_class(SEQUENCE_MT_true_fullscreen)
    bpy.types.SEQUENCER_MT_view.append(menu_append) # add to "view" vse header menu

def unregister():
    bpy.utils.unregister_class(SEQUENCE_MT_true_fullscreen)
    bpy.types.SEQUENCER_MT_view.remove(menu_append)

if __name__ == "__main__":
    register() 
  • The question is unclear. What are you trying to achieve? What are you doing to achieve it? What results do you expect? What results do you get? You cannot select a screen area or region or make it active - it does not make sense. The question needs to be rephrased. – Martin Z Sep 19 at 15:43
  • My overall goal is to add a windowless, fullscreen, correctly scaled video-preview function to the VSE view menu(shortcuts: alt+F10, alt+f11 and home). In the video-editing workspace there are two areas which are sequencer areas. One is the view type: sequencer(with strips) and one is view type: preview. When adding the function to the menu with SEQUENCER_MT_view, it is added to both areas, but I only want to make the preview area full screen, not the strip area. So I need help to make sure that the full screen functions only will make the preview area full screen. How do I do that? – tintwotin Sep 19 at 18:05
  • Small note: When context is an argument of an operator method use it, not bpy.context. Lets say for argument sake we wanted to override context in your operator above, bpy.context would override the overridden context. PS: this is a good q&a and as such hopefully will gain more UVs. – batFINGER Sep 21 at 8:49
up vote 2 down vote accepted

After realizing I wanted this feature as well, I have been giving this some thought. The script shouldn't be trying to figure out which preview to full-screen (there may be more than one preview), it should let the user decide that. This can be accomplished by moving the check for the space view_type into the menu_append function, and having the operator just use the passed in context.

I was also thinking about how to close this preview, and I think the best way to do so would be to just use a modal operator for the whole thing, and revert everything once it ends.

So, after some reworking, here's the code I came up with:

import bpy

class SEQUENCE_MT_true_fullscreen(bpy.types.Operator):
    """True fullscreen preview"""
    bl_label = "True Fullscreen"
    bl_idname = "sequencer.true_fullscreen"

    runs = 0
    original_area = None

    def invoke(self, context, event):
        self.original_area = context.area
        bpy.ops.wm.window_fullscreen_toggle()
        self.runs = 0
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}

    def modal(self, context, event):
        if self.runs == 0:
            override = context.copy()
            bpy.ops.screen.screen_full_area(override, use_hide_panels=True) #This has to be delayed because if it is run in the invoke function, it crashes blender...
        if self.runs == 1:
            bpy.ops.sequencer.view_all_preview() #This has to be delayed because if it is run right after the screen_full_area, it crashes blender...
        self.runs = self.runs + 1
        if event.type in {'RIGHTMOUSE', 'ESC'}:
            bpy.ops.wm.window_fullscreen_toggle()
            bpy.ops.screen.header()
            bpy.ops.screen.back_to_previous()
            override = context.copy()
            area = self.original_area
            override['area'] = area
            override['space_data'] = area.spaces.active
            for region in area.regions:
                if region.type == 'PREVIEW':
                    break
            override['region'] = region
            bpy.ops.sequencer.view_all_preview(override)
            return {'FINISHED'}
        return {'PASS_THROUGH'}

def true_fullscreen_menu(self, context):
    if context.area.spaces[0].view_type == 'PREVIEW':
        self.layout.operator(SEQUENCE_MT_true_fullscreen.bl_idname)

def register():
    bpy.utils.register_class(SEQUENCE_MT_true_fullscreen)
    bpy.types.SEQUENCER_MT_view.append(true_fullscreen_menu) # add to "view" vse header menu

def unregister():
    bpy.utils.unregister_class(SEQUENCE_MT_true_fullscreen)
    bpy.types.SEQUENCER_MT_view.remove(true_fullscreen_menu)

if __name__ == "__main__":
    register()

Note that I had to use the modal operator to delay a couple operators, or blender crashed -_-

edit: fixed that last issue!

  • Perhaps a modal timer would give more scope for handling a delay. – batFINGER Sep 21 at 8:57
  • Wow, that's just brilliant! You did it!!! – tintwotin Sep 21 at 9:52
  • @batFINGER I originally had put in a timer as well, but it seems to work fine without it (both run 0 and run 1 are triggered every time) The first is triggered by a 'MOUSEMOVE' (which im assuming is the button releasing, since the mouse isnt actually moved...?) And the second is 'INBETWEEN_MOUSEMOVE'. Right... ok. Well, it works, is there a particular reason to have the timer? – Snu Sep 21 at 19:40
  • Nevermind. If it works it works. Using the timer gives a known delay between calls is all. – batFINGER Sep 22 at 7:42

This is kinda two problems. The first: you need to find the area that needs to be full-screened, second: you need to be able to full screen an arbitrary area.

For the first, the easiest way is to iterate through all areas and find the one that matches your conditions:

for area in bpy.context.screen.areas:
    if area.type == 'SEQUENCE_EDITOR':

this will find all areas of the sequencer type, now you need to check if its in preview mode:

        if area.spaces[0].view_type == 'PREVIEW':

now, it should have found the preview area, but we need to make it full screen. For this there is an operator, but the operator has no idea what area to work with (the second problem). So, we need to override it's context, and pass in a dictionary telling it to use the area we just found:

            bpy.ops.screen.screen_full_area({'area': area}, use_hide_panels=True)
            bpy.ops.wm.window_fullscreen_toggle()
            break

...and that break is there to just ensure it doesnt try to fullscreen multiple previews if there is such a thing in the current layout.

only problem i have with the script, next it needs to call bpy.ops.sequencer.view_all_preview() (the 'home' key shortcut), and it should be good enough with the same context override, but nothing happens when that operator is run.

  • Thank you. The "strip" sequencer menu entry will not make the "preview" area fullscreen this way(for me?). Looking at this override example: blender.stackexchange.com/questions/107438/… there is a way to force preview fullscreen no matter what menu it is called from. I updated the code above. py.ops.sequencer.view_all_preview() will make 2.79b crash and so does .view_frame(), .view_ghost_border, .view_zoom_ratio(, And apparently isn't the close full screen icon added by calling bpy.ops.wm.window_fullscreen_toggle(). Does the header need to be updated? – tintwotin Sep 20 at 10:03
  • 1
    I tried out your edited script, and it seems to make the preview fullscreen when called from the sequencer view, not sure why it isnt on your system. My guess on the cause for the crash is that the previous operator changed the current areas, but bpy.context hasnt yet updated to reflect this... I tried a couple things, but couldn't get it to work... Tho, overriding it's context prevents blender from crashing at least, but it still bugs out with an incorrect context error. Also, you can delete the "override['screen'] = context.screen", it serves no purpose since that was already copied. – Snu Sep 21 at 4:10

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.