Auto-set parameters when panel opens
Spit data from draw method to a draw call back.

When playing around with draw callbacks noticed that can modify objects, whereas you cannot from a panel draw method.
Here is an example Is automatic &quot;Reload from disk&quot; confirmation in Text Editor possible?
A panel can be registered as default closed. In this case only the poll and draw header method will be called.  When it is expanded we see the content of the draw method. Explained here.
For convenience the drawing class is added to the driver namespace. As explained in How do you remove a draw handler after it&#39;s been added?  See also answer to operator error when open a new file re setting up a  on the window manager.
Test script: defines a draw callback class and a panel (default closed). The drawing class has a list being fed from the poll and draw methods of the panel. The list is kept to 5 members. If the panel is being drawn it sees this and sets the active object to 'TEXTURED' else to 'WIRE'.
import bpy
import blf


class DrawingClass:
    def __init__(self, context, prop):
        self.status = [prop]
        self.prop = prop
        self.handle = bpy.types.SpaceView3D.draw_handler_add(
                   self.draw_text_callback,(context,),
                   'WINDOW', 'POST_PIXEL')

    def draw_text_callback(self, context):
        font_id = 0  # XXX, need to find out how best to get this.

        # draw some text
        blf.position(font_id, 15, 50, 0)
        blf.size(font_id, 20, 72)
        blf.draw(font_id, &quot;%s %s&quot; % (context.scene.name, &quot;,&quot;.join(self.status)))
        ob = context.object
        if ob:
            ob.display_type = 'TEXTURED' if &quot;Open&quot; in self.status else 'WIRE'

    def remove_handle(self):
        bpy.types.SpaceView3D.draw_handler_remove(self.handle, 'WINDOW')         

class HelloWorldPanel(bpy.types.Panel):
    &quot;&quot;&quot;Creates a Panel in the Object properties window&quot;&quot;&quot;
    bl_label = &quot;Hello World Panel&quot;
    bl_idname = &quot;OBJECT_PT_hello&quot;
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_options = {'DEFAULT_CLOSED'}

    def __init__(self):
        print(&quot;init&quot;)

    @classmethod 
    def poll(self, context):
        print(&quot;poll&quot;)

        dc = dns.get(&quot;dc&quot;)
        if dc:
            while len(dc.status) &gt; 4:
                dc.status.pop()
            dc.status.insert(0, &quot;Closed&quot;)

        return True    
        
    def draw(self, context):
        print(&quot;draw&quot;)
        layout = self.layout
        dc = dns.get(&quot;dc&quot;)
        if dc:
            dc.status.insert(0, &quot;Open&quot;)
        layout.label(text=&quot;Open&quot;)

def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == &quot;__main__&quot;:
    register()
    

    context = bpy.context             
    dns = bpy.app.driver_namespace
    dc = dns.get(&quot;dc&quot;)
    if not dc:
        dns[&quot;dc&quot;] = DrawingClass(context, &quot;Closed&quot;)

Have used similar for a panel &quot;heat&quot; addon, where a counter is added to the panel class for every draw call. After a while &quot;cold&quot; panels, are closed, moved or unregistered.