示例#1
0
    def draw(self, context):
        layout = self.layout

        userpref = context.user_preferences
        used_ext = {ext.module for ext in userpref.addons}

        # collect the categories that can be filtered on
        addons = [(mod, addon_utils.module_bl_info(mod)) for mod in addon_utils.modules(addon_utils.addons_fake_modules)]

        split = layout.split(percentage=0.2)
        col = split.column()
        col.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM')
        col.label(text="Categories")
        col.prop(context.window_manager, "addon_filter", expand=True)

        col.label(text="Supported Level")
        col.prop(context.window_manager, "addon_support", expand=True)

        col = split.column()

        # set in addon_utils.modules(...)
        if addon_utils.error_duplicates:
            self.draw_error(col,
                            "Multiple addons using the same name found!\n"
                            "likely a problem with the script search path.\n"
                            "(see console for details)",
                            )

        if addon_utils.error_encoding:
            self.draw_error(col,
                            "One or more addons do not have UTF-8 encoding\n"
                            "(see console for details)",
                            )

        filter = context.window_manager.addon_filter
        search = context.window_manager.addon_search.lower()
        support = context.window_manager.addon_support

        # initialized on demand
        user_addon_paths = []

        for mod, info in addons:
            module_name = mod.__name__

            is_enabled = module_name in used_ext

            if info["support"] not in support:
                continue

            # check if add-on should be visible with current filters
            if (filter == "All") or \
                    (filter == info["category"]) or \
                    (filter == "Enabled" and is_enabled) or \
                    (filter == "Disabled" and not is_enabled):

                if search and search not in info["name"].lower():
                    if info["author"]:
                        if search not in info["author"].lower():
                            continue
                    else:
                        continue

                # Addon UI Code
                box = col.column().box()
                colsub = box.column()
                row = colsub.row()

                row.operator("wm.addon_expand", icon='TRIA_DOWN' if info["show_expanded"] else 'TRIA_RIGHT', emboss=False).module = module_name

                rowsub = row.row()
                rowsub.active = is_enabled
                rowsub.label(text='%s: %s' % (info['category'], info["name"]))
                if info["warning"]:
                    rowsub.label(icon='ERROR')
                # icon showing depedencies (child or parent).
                disable_check = module_name
                if info["dependencies"] :
                    rowsub.label(icon='LINKED')

                # icon showing support level.
                if info["support"] == 'OFFICIAL':
                    rowsub.label(icon='FILE_BLEND')
                elif info["support"] == 'COMMUNITY':
                    rowsub.label(icon='POSE_DATA')
                else:
                    rowsub.label(icon='QUESTION')

                if info["childs"] and is_enabled :
                    row.label(icon='LINKED')
                elif is_enabled:
                    row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
                else:
                    row.operator("wm.addon_enable", icon='CHECKBOX_DEHLT', text="", emboss=False).module = module_name

                # Expanded UI (only if additional infos are available)
                if info["show_expanded"]:
                    if info["description"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Description:")
                        split.label(text=info["description"])
                    if info["location"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Location:")
                        split.label(text=info["location"])
                    if info["author"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Author:")
                        split.label(text=info["author"])
                    if info["version"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Version:")
                        split.label(text='.'.join(str(x) for x in info["version"]))
                    if info["dependencies"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text='Dependencies:')
                        parent_list, msg = addon_utils.parent_list(info["dependencies"])
                        if parent_list :
                            txt = ''
                            for n,v in parent_list : txt += '%s v%s, '%(n,'.'.join(str(x) for x in v) )
                        else :
                            txt = msg
                        split.label(text=txt[:-2])
                    if info["childs"] :
                        split = colsub.row().split(percentage=0.15)
                        split.label(text='In use by:')
                        txt = ''
                        for n in info["childs"] : txt += '%s, '%(n)
                        split.label(text=txt[:-2])
                    if info["warning"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Warning:")
                        split.label(text='  ' + info["warning"], icon='ERROR')

                    user_addon = USERPREF_PT_addons.is_user_addon(mod, user_addon_paths)
                    tot_row = bool(info["wiki_url"]) + bool(info["tracker_url"]) + bool(user_addon)

                    if tot_row:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Internet:")
                        if info["wiki_url"]:
                            split.operator("wm.url_open", text="Link to the Wiki", icon='HELP').url = info["wiki_url"]
                        if info["tracker_url"]:
                            split.operator("wm.url_open", text="Report a Bug", icon='URL').url = info["tracker_url"]
                        if user_addon:
                            split.operator("wm.addon_remove", text="Remove", icon='CANCEL').module = mod.__name__

                        for i in range(4 - tot_row):
                            split.separator()

        # Append missing scripts
        # First collect scripts that are used but have no script file.
        module_names = {mod.__name__ for mod, info in addons}
        missing_modules = {ext for ext in used_ext if ext not in module_names}

        if missing_modules and filter in {"All", "Enabled"}:
            col.column().separator()
            col.column().label(text="Missing script files")

            module_names = {mod.__name__ for mod, info in addons}
            for module_name in sorted(missing_modules):
                is_enabled = module_name in used_ext
                # Addon UI Code
                box = col.column().box()
                colsub = box.column()
                row = colsub.row()

                row.label(text=module_name, icon='ERROR')

                if is_enabled:
                    row.operator("wm.addon_disable", icon='CHECKBOX_HLT', text="", emboss=False).module = module_name
    def draw(self, context):
        layout = self.layout

        userpref = context.user_preferences
        used_ext = {ext.module for ext in userpref.addons}

        # collect the categories that can be filtered on
        addons = [
            (mod, addon_utils.module_bl_info(mod))
            for mod in addon_utils.modules(addon_utils.addons_fake_modules)
        ]

        split = layout.split(percentage=0.2)
        col = split.column()
        col.prop(context.window_manager,
                 "addon_search",
                 text="",
                 icon='VIEWZOOM')
        col.label(text="Categories")
        col.prop(context.window_manager, "addon_filter", expand=True)

        col.label(text="Supported Level")
        col.prop(context.window_manager, "addon_support", expand=True)

        col = split.column()

        # set in addon_utils.modules(...)
        if addon_utils.error_duplicates:
            self.draw_error(
                col,
                "Multiple addons using the same name found!\n"
                "likely a problem with the script search path.\n"
                "(see console for details)",
            )

        if addon_utils.error_encoding:
            self.draw_error(
                col,
                "One or more addons do not have UTF-8 encoding\n"
                "(see console for details)",
            )

        filter = context.window_manager.addon_filter
        search = context.window_manager.addon_search.lower()
        support = context.window_manager.addon_support

        # initialized on demand
        user_addon_paths = []

        for mod, info in addons:
            module_name = mod.__name__

            is_enabled = module_name in used_ext

            if info["support"] not in support:
                continue

            # check if add-on should be visible with current filters
            if (filter == "All") or \
                    (filter == info["category"]) or \
                    (filter == "Enabled" and is_enabled) or \
                    (filter == "Disabled" and not is_enabled):

                if search and search not in info["name"].lower():
                    if info["author"]:
                        if search not in info["author"].lower():
                            continue
                    else:
                        continue

                # Addon UI Code
                box = col.column().box()
                colsub = box.column()
                row = colsub.row()

                row.operator("wm.addon_expand",
                             icon='TRIA_DOWN'
                             if info["show_expanded"] else 'TRIA_RIGHT',
                             emboss=False).module = module_name

                rowsub = row.row()
                rowsub.active = is_enabled
                rowsub.label(text='%s: %s' % (info['category'], info["name"]))
                if info["warning"]:
                    rowsub.label(icon='ERROR')
                # icon showing depedencies (child or parent).
                disable_check = module_name
                if info["dependencies"]:
                    rowsub.label(icon='LINKED')

                # icon showing support level.
                if info["support"] == 'OFFICIAL':
                    rowsub.label(icon='FILE_BLEND')
                elif info["support"] == 'COMMUNITY':
                    rowsub.label(icon='POSE_DATA')
                else:
                    rowsub.label(icon='QUESTION')

                if info["childs"] and is_enabled:
                    row.label(icon='LINKED')
                elif is_enabled:
                    row.operator("wm.addon_disable",
                                 icon='CHECKBOX_HLT',
                                 text="",
                                 emboss=False).module = module_name
                else:
                    row.operator("wm.addon_enable",
                                 icon='CHECKBOX_DEHLT',
                                 text="",
                                 emboss=False).module = module_name

                # Expanded UI (only if additional infos are available)
                if info["show_expanded"]:
                    if info["description"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Description:")
                        split.label(text=info["description"])
                    if info["location"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Location:")
                        split.label(text=info["location"])
                    if info["author"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Author:")
                        split.label(text=info["author"])
                    if info["version"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Version:")
                        split.label(text='.'.join(
                            str(x) for x in info["version"]))
                    if info["dependencies"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text='Dependencies:')
                        parent_list, msg = addon_utils.parent_list(
                            info["dependencies"])
                        if parent_list:
                            txt = ''
                            for n, v in parent_list:
                                txt += '%s v%s, ' % (n, '.'.join(
                                    str(x) for x in v))
                        else:
                            txt = msg
                        split.label(text=txt[:-2])
                    if info["childs"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text='In use by:')
                        txt = ''
                        for n in info["childs"]:
                            txt += '%s, ' % (n)
                        split.label(text=txt[:-2])
                    if info["warning"]:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Warning:")
                        split.label(text='  ' + info["warning"], icon='ERROR')

                    user_addon = USERPREF_PT_addons.is_user_addon(
                        mod, user_addon_paths)
                    tot_row = bool(info["wiki_url"]) + bool(
                        info["tracker_url"]) + bool(user_addon)

                    if tot_row:
                        split = colsub.row().split(percentage=0.15)
                        split.label(text="Internet:")
                        if info["wiki_url"]:
                            split.operator("wm.url_open",
                                           text="Link to the Wiki",
                                           icon='HELP').url = info["wiki_url"]
                        if info["tracker_url"]:
                            split.operator(
                                "wm.url_open", text="Report a Bug",
                                icon='URL').url = info["tracker_url"]
                        if user_addon:
                            split.operator("wm.addon_remove",
                                           text="Remove",
                                           icon='CANCEL').module = mod.__name__

                        for i in range(4 - tot_row):
                            split.separator()

        # Append missing scripts
        # First collect scripts that are used but have no script file.
        module_names = {mod.__name__ for mod, info in addons}
        missing_modules = {ext for ext in used_ext if ext not in module_names}

        if missing_modules and filter in {"All", "Enabled"}:
            col.column().separator()
            col.column().label(text="Missing script files")

            module_names = {mod.__name__ for mod, info in addons}
            for module_name in sorted(missing_modules):
                is_enabled = module_name in used_ext
                # Addon UI Code
                box = col.column().box()
                colsub = box.column()
                row = colsub.row()

                row.label(text=module_name, icon='ERROR')

                if is_enabled:
                    row.operator("wm.addon_disable",
                                 icon='CHECKBOX_HLT',
                                 text="",
                                 emboss=False).module = module_name