addon_common icon indicating copy to clipboard operation
addon_common copied to clipboard

Full Screen Causes challenges

Open patmo141 opened this issue 6 years ago • 8 comments

I am still in the process of trying to figure out the exact criteria for failure but starting to collect thoughts here.

Desired Behavior: -Have CookieCutter ops be able to go full screen on invoke, taking entire control of the UI for a very structured workflow

Current Attempts: -Use a separate operator, a "Wizard Start" that calls bpy.ops.screen.screen_full_area() and then calls the first CookieCutter operator> Fails: rays.py and useractions.py complain about a None types not having atrirbutes "width" etc.

-Call bpy.ops.screen_full_area() in the start() or start_ui() methods Fails: rays.py and useractions.py complain about a None types not having atrirbutes "width" etc.

File "....\addon_common\common\useractions.py", line 167, in init self.size = (context.region.width,context.region.height) AttributeError: 'NoneType' object has no attribute 'width'

patmo141 avatar Jun 21 '19 12:06 patmo141

If I call bpy.ops.screen_full_area() with either ctrl + up_arrow or alt + f10, and then start CookieCutter ops by calling them with spacebar menu, they function fine.

It seems like somehow CookieCutter is maybe getting a hold on old context

patmo141 avatar Jun 21 '19 12:06 patmo141

Thanks, @patmo141. Will look into it!

vxlcoder avatar Jun 21 '19 12:06 vxlcoder

I'm looking into it too, I'll try a few things. I'm kind backing through the CookieCutter start code to see where it might fail if fullscreen happens later.

patmo141 avatar Jun 21 '19 12:06 patmo141

ok, furthermore, if I hit alt+f10 AFTER i'm already interacting with a CookieCutter op it's fine. Because it seems in the base modal of CookieCutter that self.context = context (context is being update). So the hangup seems somehwere in the middle

patmo141 avatar Jun 21 '19 12:06 patmo141

So, the cascade is

` self.context = context

    self.fsm_init()
    self.ui_init()
    self.actions_init()

    try:
        self.start()
    except Exception as e:
        print('Caught exception while trying to start')
        print(e)
        raise e

    self.ui_start()`

My guess is the problem is that changing blender context in ui_init() before actions_init() causes problems beacuse actions_init references self.context which may be stale.

patmo141 avatar Jun 21 '19 12:06 patmo141

I've never fully understood the context. I often wonder if simply using bpy.context would just work instead, since we only work in one area

vxlcoder avatar Jun 21 '19 12:06 vxlcoder

Because alt + F10 works fine while interacting with a CookieCutter op, I think the problem is more of my placement of "fullscreen" in the cascade rather than a deficiency in how CookieCutter is structured.

patmo141 avatar Jun 21 '19 12:06 patmo141

From CookieCutterUI ui_init and ui_start reference self.context, and grab context area. My first attempt will just be recapturing self.context = context right after the full_screen() call.

[edit, I give up with inserting code]

` def ui_init(self): self._area = self.context.area self._space = self.context.space_data self.wm = UI_WindowManager() self.drawing = Drawing.get_instance() self.drawing.set_region(bpy.context.space_data, bpy.context.region, bpy.context.space_data.region_3d, bpy.context.window) self._manipulator = self.drawing.space.show_manipulator fns = {'pre3d':[], 'post3d':[], 'post2d':[]} for m,fn in self.find_fns('drawmode'): fns[m].append(fn) def draw(fns): for fn in fns: fn(self) self._draw_pre3d = lambda:draw(fns['pre3d']) self._draw_post3d = lambda:draw(fns['post3d']) self._draw_post2d = lambda:draw(fns['post2d']) self._area.tag_redraw()

def ui_start(self):
    def preview():
        self._draw_pre3d()
    def postview():
        self._draw_post3d()
    def postpixel():
        bgl.glEnable(bgl.GL_MULTISAMPLE)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_POINT_SMOOTH)

        self._draw_post2d()

        try:
            self.wm.draw_postpixel(self.context)
        except Exception as e:
            print('Caught exception while trying to draw window UI')
            debugger.print_exception()
            print(e)

    self._handle_preview = self._space.draw_handler_add(preview, tuple(), 'WINDOW', 'PRE_VIEW')
    self._handle_postview = self._space.draw_handler_add(postview, tuple(), 'WINDOW', 'POST_VIEW')
    self._handle_postpixel = self._space.draw_handler_add(postpixel, tuple(), 'WINDOW', 'POST_PIXEL')
    self._area.tag_redraw()`

patmo141 avatar Jun 21 '19 12:06 patmo141