keyword : active_section
Steps:
Replicate the following sRNA fragment from makesrna/rna_userdef.c
to rna_space.c
:
prop = RNA_def_property(srna, "active_section", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "userpref");
RNA_def_property_enum_items(prop, user_pref_sections);
RNA_def_property_ui_text(prop, "Active Section",
"Active section of the user preferences shown in the user interface");
//RNA_def_property_update(prop, 0, "rna_userdef_update");
Then reverse transcript it into makesdna/DNA_Space_types.h
:
/* User Preferences View */
typedef struct SpaceUserPref {
short userpref; //new field
short padpad;
……
} SpaceUserPref;
as field short userpref
. Refer to the original UserDef structure.
By above two steps, we have replicated active_section
property for the python type SpaceUserPreferences
.
On the python side, by using this property instead of UserPreferences.active_section
, the beheaviour of tab selection is now independent for each instances :
space_userpref.py
class USERPREF_PT_tabs(Panel):
……
def draw(self, context):
st = context.space_data
if not hasattr(st, 'active_section'):
st = context.user_preferences
self.layout.row().prop(st, "active_section", expand=True)
def getContextualSection(context):
st = context.space_data
if not hasattr(st, 'active_section'):
st = context.user_preferences
return st.active_section
# edit poll method for every tab:
@classmethod
def poll(cls, context):
userpref = context.user_preferences
return (getContextualSection(context) == 'INTERFACE')
docs:
bpy.types.SpaceUserPreferences
bpy.types.UserPreferences