[Bf-blender-cvs] [7ba1489bd72] master: Cleanup: use 'context' to make panels show in their section

Campbell Barton noreply at git.blender.org
Thu Dec 19 03:31:12 CET 2019


Commit: 7ba1489bd7235a333a4f99040b3c9e7501bf346c
Author: Campbell Barton
Date:   Thu Dec 19 13:21:41 2019 +1100
Branches: master
https://developer.blender.org/rB7ba1489bd7235a333a4f99040b3c9e7501bf346c

Cleanup: use 'context' to make panels show in their section

All panels were calling poll to draw in their section causing a lot of
repeated boiler plate poll functions.

Also rename 'PreferencePanel' to 'CenterAlignMixIn'
since this is it's purpose.

===================================================================

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/editors/space_userpref/space_userpref.c
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index fec76b045a4..9527c7f4de8 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -138,49 +138,49 @@ class USERPREF_PT_save_preferences(Panel):
 # Min-In Helpers
 
 # Panel mix-in.
-class PreferencePanel:
+class CenterAlignMixIn:
     """
     Base class for panels to center align contents with some horizontal margin.
-    Deriving classes need to implement a ``draw_props(context, layout)`` function.
+    Deriving classes need to implement a ``draw_centered(context, layout)`` function.
     """
 
-    bl_space_type = 'PREFERENCES'
-    bl_region_type = 'WINDOW'
-
     def draw(self, context):
         layout = self.layout
         width = context.region.width
         ui_scale = context.preferences.system.ui_scale
+        # No horizontal margin if region is rather small.
+        is_wide = width > (350 * ui_scale)
 
         layout.use_property_split = True
         layout.use_property_decorate = False  # No animation.
 
         row = layout.row()
-        if width > (350 * ui_scale):  # No horizontal margin if region is rather small.
+        if is_wide:
             row.label()  # Needed so col below is centered.
 
         col = row.column()
         col.ui_units_x = 50
 
-        # draw_props implemented by deriving classes.
-        self.draw_props(context, col)
+        # Implemented by sub-classes.
+        self.draw_centered(context, col)
 
-        if width > (350 * ui_scale):  # No horizontal margin if region is rather small.
+        if is_wide:
             row.label()  # Needed so col above is centered.
 
 
 # -----------------------------------------------------------------------------
 # Interface Panels
 
-class USERPREF_PT_interface_display(PreferencePanel, Panel):
-    bl_label = "Display"
+class InterfacePanel:
+    bl_space_type = 'PREFERENCES'
+    bl_region_type = 'WINDOW'
+    bl_context = "interface"
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE')
 
-    def draw_props(self, context, layout):
+class USERPREF_PT_interface_display(InterfacePanel, CenterAlignMixIn, Panel):
+    bl_label = "Display"
+
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -200,16 +200,11 @@ class USERPREF_PT_interface_display(PreferencePanel, Panel):
         flow.prop(view, "show_large_cursors")
 
 
-class USERPREF_PT_interface_text(PreferencePanel, Panel):
+class USERPREF_PT_interface_text(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Text Rendering"
     bl_options = {'DEFAULT_CLOSED'}
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE')
-
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -224,14 +219,13 @@ class USERPREF_PT_interface_text(PreferencePanel, Panel):
         flow.prop(view, "font_path_ui_mono")
 
 
-class USERPREF_PT_interface_translation(PreferencePanel, Panel):
+class USERPREF_PT_interface_translation(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Translation"
     bl_translation_context = i18n_contexts.id_windowmanager
 
     @classmethod
     def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE') and bpy.app.build_options.international
+        return bpy.app.build_options.international
 
     def draw_header(self, context):
         prefs = context.preferences
@@ -239,7 +233,7 @@ class USERPREF_PT_interface_translation(PreferencePanel, Panel):
 
         self.layout.prop(view, "use_international_fonts", text="")
 
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -254,15 +248,10 @@ class USERPREF_PT_interface_translation(PreferencePanel, Panel):
         flow.prop(view, "use_translate_new_dataname", text="New Data")
 
 
-class USERPREF_PT_interface_editors(PreferencePanel, Panel):
+class USERPREF_PT_interface_editors(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Editors"
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE')
-
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
         system = prefs.system
@@ -277,17 +266,12 @@ class USERPREF_PT_interface_editors(PreferencePanel, Panel):
         flow.prop(view, "factor_display_type")
 
 
-class USERPREF_PT_interface_temporary_windows(PreferencePanel, Panel):
+class USERPREF_PT_interface_temporary_windows(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Temporary Windows"
     bl_parent_id = "USERPREF_PT_interface_editors"
     bl_options = {'DEFAULT_CLOSED'}
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE')
-
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -297,22 +281,15 @@ class USERPREF_PT_interface_temporary_windows(PreferencePanel, Panel):
         flow.prop(view, "filebrowser_display_type", text="File Browser")
 
 
-class USERPREF_PT_interface_menus(Panel):
-    bl_space_type = 'PREFERENCES'
-    bl_region_type = 'WINDOW'
+class USERPREF_PT_interface_menus(InterfacePanel, Panel):
     bl_label = "Menus"
     bl_options = {'DEFAULT_CLOSED'}
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'INTERFACE')
-
     def draw(self, context):
         pass
 
 
-class USERPREF_PT_interface_menus_mouse_over(PreferencePanel, Panel):
+class USERPREF_PT_interface_menus_mouse_over(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Open on Mouse Over"
     bl_parent_id = "USERPREF_PT_interface_menus"
 
@@ -322,7 +299,7 @@ class USERPREF_PT_interface_menus_mouse_over(PreferencePanel, Panel):
 
         self.layout.prop(view, "use_mouse_over_open", text="")
 
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -334,11 +311,11 @@ class USERPREF_PT_interface_menus_mouse_over(PreferencePanel, Panel):
         flow.prop(view, "open_sublevel_delay", text="Sub Level")
 
 
-class USERPREF_PT_interface_menus_pie(PreferencePanel, Panel):
+class USERPREF_PT_interface_menus_pie(InterfacePanel, CenterAlignMixIn, Panel):
     bl_label = "Pie Menus"
     bl_parent_id = "USERPREF_PT_interface_menus"
 
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         view = prefs.view
 
@@ -355,25 +332,24 @@ class USERPREF_PT_interface_menus_pie(PreferencePanel, Panel):
 # -----------------------------------------------------------------------------
 # Editing Panels
 
-class USERPREF_PT_edit_objects(Panel):
-    bl_label = "Objects"
+class EditingPanel:
     bl_space_type = 'PREFERENCES'
     bl_region_type = 'WINDOW'
+    bl_context = "editing"
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'EDITING')
+
+class USERPREF_PT_edit_objects(EditingPanel, Panel):
+    bl_label = "Objects"
 
     def draw(self, context):
         pass
 
 
-class USERPREF_PT_edit_objects_new(PreferencePanel, Panel):
+class USERPREF_PT_edit_objects_new(EditingPanel, CenterAlignMixIn, Panel):
     bl_label = "New Objects"
     bl_parent_id = "USERPREF_PT_edit_objects"
 
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         edit = prefs.edit
 
@@ -384,11 +360,11 @@ class USERPREF_PT_edit_objects_new(PreferencePanel, Panel):
         flow.prop(edit, "use_enter_edit_mode", text="Enter Edit Mode")
 
 
-class USERPREF_PT_edit_objects_duplicate_data(PreferencePanel, Panel):
+class USERPREF_PT_edit_objects_duplicate_data(EditingPanel, CenterAlignMixIn, Panel):
     bl_label = "Duplicate Data"
     bl_parent_id = "USERPREF_PT_edit_objects"
 
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         edit = prefs.edit
 
@@ -413,15 +389,10 @@ class USERPREF_PT_edit_objects_duplicate_data(PreferencePanel, Panel):
         col.prop(edit, "use_duplicate_grease_pencil", text="Grease Pencil")
 
 
-class USERPREF_PT_edit_cursor(PreferencePanel, Panel):
+class USERPREF_PT_edit_cursor(EditingPanel, CenterAlignMixIn, Panel):
     bl_label = "3D Cursor"
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'EDITING')
-
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         edit = prefs.edit
 
@@ -431,16 +402,11 @@ class USERPREF_PT_edit_cursor(PreferencePanel, Panel):
         flow.prop(edit, "use_cursor_lock_adjust")
 
 
-class USERPREF_PT_edit_gpencil(PreferencePanel, Panel):
+class USERPREF_PT_edit_gpencil(EditingPanel, CenterAlignMixIn, Panel):
     bl_label = "Grease Pencil"
     bl_options = {'DEFAULT_CLOSED'}
 
-    @classmethod
-    def poll(cls, context):
-        prefs = context.preferences
-        return (prefs.active_section == 'EDITING')
-
-    def draw_props(self, context, layout):
+    def draw_centered(self, context, layout):
         prefs = context.preferences
         edit = prefs.edit
 
@@ -450,15 +416,10 @@ class USERPREF_PT_edit_gpencil(PreferencePanel, Panel):
         flow.prop(edit, "grease_pencil_euclidean_distance", text="Euclidean Distance")
 
 
-class USERPREF_PT_edit_annotations(PreferencePanel, Panel):
+class USERPREF_PT_edit_annotations(Editing

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list