[Bf-blender-cvs] [2eba146a887] soc-2020-custom-menus: Custom Menu: add submenu item
TempoDev
noreply at git.blender.org
Mon Jun 29 03:07:26 CEST 2020
Commit: 2eba146a8877af87ddad23f157dae5fbeede9294
Author: TempoDev
Date: Sat Jun 27 17:23:17 2020 +0200
Branches: soc-2020-custom-menus
https://developer.blender.org/rB2eba146a8877af87ddad23f157dae5fbeede9294
Custom Menu: add submenu item
===================================================================
M release/scripts/modules/rna_user_menus_ui.py
M release/scripts/startup/bl_operators/userpref.py
M source/blender/blenkernel/intern/blender_user_menu.c
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/editors/screen/screen_user_menu.c
M source/blender/makesdna/DNA_userdef_types.h
M source/blender/makesrna/intern/rna_userdef.c
===================================================================
diff --git a/release/scripts/modules/rna_user_menus_ui.py b/release/scripts/modules/rna_user_menus_ui.py
index 400f7e867d0..f9878f90c8d 100644
--- a/release/scripts/modules/rna_user_menus_ui.py
+++ b/release/scripts/modules/rna_user_menus_ui.py
@@ -26,6 +26,7 @@ import bpy
from bpy.app.translations import pgettext_iface as iface_
from bpy.app.translations import contexts as i18n_contexts
+
def draw_item(context, box, but_list):
prefs = context.preferences
um = prefs.user_menus
@@ -35,10 +36,12 @@ def draw_item(context, box, but_list):
if items.item.type == "SEPARATOR":
name = "___________"
box.prop(items, "pressed", text=name, toggle=1)
- if items.item.type == "MENU":
+ if items.item.type == "SUBMENU":
sub_box = box.box()
+ sub_box = sub_box.column(align=True)
draw_item(context, sub_box, items.subbut)
+
def draw_item_box(context, row):
prefs = context.preferences
um = prefs.user_menus
@@ -47,18 +50,11 @@ def draw_item_box(context, row):
box_col = box_line.column(align=True)
has_item = um.has_item()
- if not has_item :
+ if not has_item:
box_col.label(text="none")
- #box_col.prop(um, "item_selected", expand=True)
um.buttons_refresh()
- for items in um.buttons:
- name = items.item.name
- if items.item.type == "SEPARATOR":
- name = "___________"
- box_col.prop(items, "pressed", text=name, toggle=1)
- if items.item.type == "MENU":
- sub_box = box_col.box()
-
+ draw_item(context, box_col, um.buttons)
+
row = row.split(factor=0.9, align=True)
col = row.column(align=True)
@@ -68,6 +64,7 @@ def draw_item_box(context, row):
col.operator("preferences.menuitem_down", text="", icon='TRIA_DOWN')
row.separator()
+
def draw_item_editor(context, row):
prefs = context.preferences
um = prefs.user_menus
@@ -76,7 +73,7 @@ def draw_item_editor(context, row):
has_item = um.has_item()
current = um.active_item
- if not has_item :
+ if not has_item:
col.label(text="No item in this list.")
col.label(text="Add one or choose another list to get started")
elif current:
@@ -86,7 +83,10 @@ def draw_item_editor(context, row):
if (current.type == "OPERATOR"):
umi_op = current.get_operator()
col.prop(umi_op, "operator")
- else :
+ if (current.type == "MENU"):
+ umi_pm = current.get_menu()
+ col.prop(umi_pm, "id_name", text="ID name")
+ else:
col.label(text="No item selected.")
@@ -106,7 +106,8 @@ def draw_user_menus(context, layout):
rowsub = row.row(align=True)
rowsub.menu("USERPREF_MT_menu_select", text=menu_name_active)
rowsub.operator("wm.keyconfig_preset_add", text="", icon='ADD')
- rowsub.operator("wm.keyconfig_preset_add", text="", icon='REMOVE').remove_active = True
+ rowsub.operator("wm.keyconfig_preset_add", text="",
+ icon='REMOVE').remove_active = True
rowsub = split.row(align=True)
rowsub.prop(um, "space_selected", text="")
diff --git a/release/scripts/startup/bl_operators/userpref.py b/release/scripts/startup/bl_operators/userpref.py
index 9c5e7210a54..9182f29b562 100644
--- a/release/scripts/startup/bl_operators/userpref.py
+++ b/release/scripts/startup/bl_operators/userpref.py
@@ -51,6 +51,8 @@ def module_filesystem_remove(path_base, module_name):
# This duplicates shutil.copytree from Python 3.8, with the new dirs_exist_ok
# argument that we need. Once we upgrade to 3.8 we can remove this.
+
+
def _preferences_copytree(entries, src, dst):
import os
import shutil
@@ -85,11 +87,13 @@ def _preferences_copytree(entries, src, dst):
raise Error(errors)
return dst
+
def preferences_copytree(src, dst):
import os
with os.scandir(src) as entries:
return _preferences_copytree(entries=entries, src=src, dst=dst)
+
class PREFERENCES_OT_keyconfig_activate(Operator):
bl_idname = "preferences.keyconfig_activate"
bl_label = "Activate Keyconfig"
@@ -238,7 +242,8 @@ class PREFERENCES_OT_keyconfig_import(Operator):
config_name = basename(self.filepath)
- path = bpy.utils.user_resource('SCRIPTS', os.path.join("presets", "keyconfig"), create=True)
+ path = bpy.utils.user_resource(
+ 'SCRIPTS', os.path.join("presets", "keyconfig"), create=True)
path = os.path.join(path, config_name)
try:
@@ -457,7 +462,8 @@ class PREFERENCES_OT_addon_enable(Operator):
err_str = traceback.format_exc()
print(err_str)
- mod = addon_utils.enable(self.module, default_set=True, handle_error=err_cb)
+ mod = addon_utils.enable(
+ self.module, default_set=True, handle_error=err_cb)
if mod:
info = addon_utils.module_bl_info(mod)
@@ -541,7 +547,8 @@ class PREFERENCES_OT_theme_install(Operator):
xmlfile = self.filepath
- path_themes = bpy.utils.user_resource('SCRIPTS', "presets/interface_theme", create=True)
+ path_themes = bpy.utils.user_resource(
+ 'SCRIPTS', "presets/interface_theme", create=True)
if not path_themes:
self.report({'ERROR'}, "Failed to get themes path")
@@ -551,7 +558,8 @@ class PREFERENCES_OT_theme_install(Operator):
if not self.overwrite:
if os.path.exists(path_dest):
- self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
+ self.report(
+ {'WARNING'}, "File already installed to %r\n" % path_dest)
return {'CANCELLED'}
try:
@@ -635,7 +643,8 @@ class PREFERENCES_OT_addon_install(Operator):
if self.target == 'DEFAULT':
# don't use bpy.utils.script_paths("addons") because we may not be able to write to it.
- path_addons = bpy.utils.user_resource('SCRIPTS', "addons", create=True)
+ path_addons = bpy.utils.user_resource(
+ 'SCRIPTS', "addons", create=True)
else:
path_addons = context.preferences.filepaths.script_directory
if path_addons:
@@ -658,7 +667,8 @@ class PREFERENCES_OT_addon_install(Operator):
pyfile_dir = os.path.dirname(pyfile)
for addon_path in addon_utils.paths():
if os.path.samefile(pyfile_dir, addon_path):
- self.report({'ERROR'}, "Source file is in the add-on search path: %r" % addon_path)
+ self.report(
+ {'ERROR'}, "Source file is in the add-on search path: %r" % addon_path)
return {'CANCELLED'}
del addon_path
del pyfile_dir
@@ -681,7 +691,8 @@ class PREFERENCES_OT_addon_install(Operator):
for f in file_to_extract.namelist():
path_dest = os.path.join(path_addons, os.path.basename(f))
if os.path.exists(path_dest):
- self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
+ self.report(
+ {'WARNING'}, "File already installed to %r\n" % path_dest)
return {'CANCELLED'}
try: # extract the file to "addons"
@@ -696,7 +707,8 @@ class PREFERENCES_OT_addon_install(Operator):
if self.overwrite:
module_filesystem_remove(path_addons, os.path.basename(pyfile))
elif os.path.exists(path_dest):
- self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
+ self.report(
+ {'WARNING'}, "File already installed to %r\n" % path_dest)
return {'CANCELLED'}
# if not compressed file just copy into the addon path
@@ -706,7 +718,8 @@ class PREFERENCES_OT_addon_install(Operator):
traceback.print_exc()
return {'CANCELLED'}
- addons_new = {mod.__name__ for mod in addon_utils.modules()} - addons_old
+ addons_new = {mod.__name__ for mod in addon_utils.modules()} - \
+ addons_old
addons_new.discard("modules")
# disable any addons we may have enabled previously and removed.
@@ -776,7 +789,8 @@ class PREFERENCES_OT_addon_remove(Operator):
path, isdir = PREFERENCES_OT_addon_remove.path_from_addon(self.module)
if path is None:
- self.report({'WARNING'}, "Add-on path %r could not be found" % path)
+ self.report(
+ {'WARNING'}, "Add-on path %r could not be found" % path)
return {'CANCELLED'}
# in case its enabled
@@ -922,9 +936,11 @@ class PREFERENCES_OT_app_template_install(Operator):
module_filesystem_remove(path_app_templates, f)
else:
for f in file_to_extract.namelist():
- path_dest = os.path.join(path_app_templates, os.path.basename(f))
+ path_dest = os.path.join(
+ path_app_templates, os.path.basename(f))
if os.path.exists(path_dest):
- self.report({'WARNING'}, "File already installed to %r\n" % path_dest)
+ self.report(
+ {'WARNING'}, "File already installed to %r\n" % path_dest)
return {'CANCELLED'}
try: # extract the file to "bl_app_templates_user"
@@ -938,7 +954,8 @@ class PREFERENCES_OT_app_template_install(Operator):
self.report({'WARNING'}, "Expected a zip-file %r\n" % filepath)
return {'CANCELLED'}
- app_templates_new = set(os.listdir(path_app_templates)) - app_templates_old
+ app_templates_new = set(os.listdir(
+ path_app_templates)) - app_templates_old
# in case a new module path was created to install this addon.
bpy.utils.refresh_script_paths()
@@ -998,14 +1015,17 @@ class PREFERENCES_OT_studiolight_install(Operator):
prefs = context.preferences
path_studiolights = os.path.join("studiolights", self.type.low
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list