Results 1 to 5 of 5
  1. #1

    Desynchronization of areas

    Good behavior.
    All areas can have it own active tab



    Bad behavior.
    Switch tab in one Area also change tab in other.



    How Desynchronize Tabs and its content in single Area type, single Tab Panel?
    Last edited by RADIOFARO; 18-Mar-17 at 14:15.



  2. #2
    Ok. Solved.

    I done it with region id. And if use UI elements which dont change his visual states (menu)

    Code:
    import bpy
    from bpy.props import IntProperty
    
    global reg_map
    reg_map = {}
    
    def map_region(id, item = 1):
        reg_map[id] = item
        return    
    
    class tabs_switch(bpy.types.Operator):
        bl_idname = "tabs.switch"
        bl_label = "Tabs Switch"
    
        menu_item = bpy.props.IntProperty(name="Menu item", default = 1)
    
        def execute(self, context):
    
            if bpy.context.area.type != "VIEW_3D":
                return {'FINISHED'}
    
            reg_id = bpy.context.area.regions[1].id
    
            if not reg_id in reg_map:
                map_region(id = reg_id)
            else:
                reg_map[reg_id] = self.menu_item
    
            return{'FINISHED'}
    
    
    class tabs_menu(bpy.types.Menu):
        bl_label = "Switch Tab"
    
        def draw(self, context):
            layout = self.layout
            layout.operator("tabs.switch", text="Open Tab 1", icon='COLOR_RED')
            layout.operator("tabs.switch", text="Open Tab 2", icon='COLOR_GREEN').menu_item = 2
            layout.operator("tabs.switch", text="Open Tab 3", icon='COLOR_BLUE').menu_item = 3
            layout.separator()
            layout.operator("wm.splash", icon='BLENDER')
    
    
    class TabsPanel(bpy.types.Panel):
        bl_label = "Menu"
        bl_space_type = 'VIEW_3D'
        bl_region_type = 'TOOLS'
        selected = 1
    
        def draw(self, context):
            layout = self.layout
    
            reg_id = bpy.context.area.regions[1].id
            if not reg_id in reg_map:
                map_region(id = reg_id)
                return
            else:
                self.selected = reg_map[reg_id]
    
            a_type = bpy.context.area.type
            r_type = bpy.context.area.regions[1].type
            r_id = bpy.context.area.regions[1].id  
    
            layout.menu("tabs_menu")
    
            if self.selected == 1:
    
                row = layout.row()
                row.label(icon='COLOR_RED', text ='TAB 1')
                row = layout.row()
                row.label('area type: '+ a_type)
                row = layout.row()
                row.label('region type: ' + r_type)
                row = layout.row()
                row.label('region id: ' + str(r_id))
    
            elif self.selected == 2:
    
                row = layout.row(align=True)
                row.label(icon='COLOR_GREEN', text ='TAB 2')
                row = layout.row()
                row.label('area type: '+ a_type)
                row = layout.row()
                row.label('region type: ' + r_type)
                row = layout.row()
                row.label('region id: ' + str(r_id))
    
            elif self.selected == 3:
    
                row = layout.row(align=True)
                row.label(icon='COLOR_BLUE', text ='TAB 3')
                row = layout.row()
                row.label('area type: '+ a_type)
                row = layout.row()
                row.label('region type: ' + r_type)
                row = layout.row()
                row.label('region id: ' + str(r_id))
            else:
                row = layout.row()
                row.label('Unknown TAB selected!')
    
    
    def register():
        bpy.utils.register_class(tabs_switch)
        bpy.utils.register_class(tabs_menu)
        bpy.utils.register_class(TabsPanel)
    
    def unregister():
        bpy.utils.unregister_class(tabs_switch)
        bpy.utils.register_class(tabs_menu)
        bpy.utils.unregister_class(TabsPanel)
    
    if __name__ == "__main__":
        register()
    Last edited by RADIOFARO; 18-Mar-17 at 14:13.



  3. #3
    Anybody know how get Area identificator?
    In old Blender was GetAreaID() function
    Last edited by RADIOFARO; 20-Apr-17 at 12:15.



  4. #4
    It usable without Area ID

    You can replace this:
    Code:
        reg_id = bpy.context.area.regions[1].id
    
        if not reg_id in reg_map:
            map_region(id = reg_id)
        else:
            reg_map[reg_id] = self.menu_item
    To this:
    Code:
        ar = bpy.context.area
    
        if not ar in reg_map:
            map_region(id = ar)
        else:
            reg_map[ar] = self.menu_item



  5. #5
    Experiments with this metod

    Remember selected Editor and Tools in dictionary and use Area as identificator.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •