Skip to content
Snippets Groups Projects
Commit 9298c1a8 authored by Campbell Barton's avatar Campbell Barton
Browse files

fix for filter

parent 5908a1b3
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,7 @@ def create_icon_list_all(): ...@@ -48,6 +48,7 @@ def create_icon_list_all():
return icons return icons
def create_icon_list(): def create_icon_list():
icons = create_icon_list_all() icons = create_icon_list_all()
search = bpy.context.scene.icon_props.search.lower() search = bpy.context.scene.icon_props.search.lower()
...@@ -66,46 +67,32 @@ class WM_OT_icon_info(bpy.types.Operator): ...@@ -66,46 +67,32 @@ class WM_OT_icon_info(bpy.types.Operator):
bl_description = "Click to copy this icon name to the clipboard" bl_description = "Click to copy this icon name to the clipboard"
icon = bpy.props.StringProperty() icon = bpy.props.StringProperty()
icon_scroll = bpy.props.IntProperty() icon_scroll = bpy.props.IntProperty()
def invoke(self, context, event): def invoke(self, context, event):
bpy.data.window_managers['WinMan'].clipboard = self.icon bpy.data.window_managers['WinMan'].clipboard = self.icon
self.report({'INFO'}, "Icon ID: %s" % self.icon) self.report({'INFO'}, "Icon ID: %s" % self.icon)
return {'FINISHED'} return {'FINISHED'}
class WM_OT_icon_prop_update(bpy.types.Operator):
bl_idname = "wm.icon_prop_update"
bl_label = "Icon Search"
bl_description = "Update icon_prop values"
def execute(self, context):
props = context.scene.icon_props
# set old values to new values
props.search_old = props.search
return {'FINISHED'}
class OBJECT_PT_icons(bpy.types.Panel): class OBJECT_PT_icons(bpy.types.Panel):
bl_space_type = "TEXT_EDITOR" bl_space_type = "TEXT_EDITOR"
bl_region_type = "UI" bl_region_type = "UI"
bl_label = "All icons" bl_label = "All icons"
def __init__(self, x): def __init__(self, x):
self.amount = 10 self.amount = 10
self.icon_list = create_icon_list() self.icon_list = create_icon_list()
def draw(self, context): def draw(self, context):
props = context.scene.icon_props props = context.scene.icon_props
# polling for updates # polling for updates
if props.search != props.search_old: if props.search != CONSOLE_HT_icons._search_old:
bpy.ops.wm.icon_prop_update()
self.icon_list = create_icon_list() self.icon_list = create_icon_list()
# adjusting max value of scroller # adjusting max value of scroller
IconProps.scroll = bpy.props.IntProperty(default=1, min=1, IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
max=max(1, len(self.icon_list) - self.amount + 1), max=max(1, len(self.icon_list) - self.amount + 1),
description="Drag to scroll icons") description="Drag to scroll icons")
box = self.layout.box() box = self.layout.box()
# scroll view # scroll view
if not props.expand: if not props.expand:
...@@ -120,21 +107,21 @@ class OBJECT_PT_icons(bpy.types.Panel): ...@@ -120,21 +107,21 @@ class OBJECT_PT_icons(bpy.types.Panel):
row = toprow.row() row = toprow.row()
row.active = props.bl_rna.scroll[1]['max'] > 1 row.active = props.bl_rna.scroll[1]['max'] > 1
row.prop(props, "scroll") row.prop(props, "scroll")
# icons # icons
row = box.row(align=True) row = box.row(align=True)
if len(self.icon_list) == 0: if len(self.icon_list) == 0:
row.label("No icons found") row.label("No icons found")
else: else:
for icon in self.icon_list[props.scroll-1: for icon in self.icon_list[props.scroll - 1:
props.scroll-1+self.amount]: props.scroll - 1 + self.amount]:
row.operator("wm.icon_info", text=" ", icon=icon, row.operator("wm.icon_info", text=" ", icon=icon,
emboss=False).icon = icon emboss=False).icon = icon
if len(self.icon_list) < self.amount: if len(self.icon_list) < self.amount:
for i in range(self.amount - len(self.icon_list) \ for i in range(self.amount - len(self.icon_list) \
% self.amount): % self.amount):
row.label("") row.label("")
# expanded view # expanded view
else: else:
# expand button # expand button
...@@ -148,7 +135,7 @@ class OBJECT_PT_icons(bpy.types.Panel): ...@@ -148,7 +135,7 @@ class OBJECT_PT_icons(bpy.types.Panel):
row = toprow.row() row = toprow.row()
row.active = False row.active = False
row.prop(props, "scroll") row.prop(props, "scroll")
# icons # icons
col = box.column(align=True) col = box.column(align=True)
if len(self.icon_list) == 0: if len(self.icon_list) == 0:
...@@ -166,22 +153,23 @@ class OBJECT_PT_icons(bpy.types.Panel): ...@@ -166,22 +153,23 @@ class OBJECT_PT_icons(bpy.types.Panel):
class CONSOLE_HT_icons(bpy.types.Header): class CONSOLE_HT_icons(bpy.types.Header):
bl_space_type = 'CONSOLE' bl_space_type = 'CONSOLE'
_search_old = ""
def __init__(self, x): def __init__(self, x):
self.amount = 10 self.amount = 10
self.icon_list = create_icon_list() self.icon_list = create_icon_list()
def draw(self, context): def draw(self, context):
props = context.scene.icon_props props = context.scene.icon_props
# polling for updates # polling for updates
if props.search != props.search_old: if props.search != __class__._search_old:
bpy.ops.wm.icon_prop_update() __class__._search_old = props.search
self.icon_list = create_icon_list() self.icon_list = create_icon_list()
# adjusting max value of scroller # adjusting max value of scroller
IconProps.scroll = bpy.props.IntProperty(default=1, min=1, IconProps.scroll = bpy.props.IntProperty(default=1, min=1,
max=max(1, len(self.icon_list) - self.amount + 1), max=max(1, len(self.icon_list) - self.amount + 1),
description="Drag to scroll icons") description="Drag to scroll icons")
# scroll view # scroll view
if props.console: if props.console:
layout = self.layout layout = self.layout
...@@ -193,14 +181,14 @@ class CONSOLE_HT_icons(bpy.types.Header): ...@@ -193,14 +181,14 @@ class CONSOLE_HT_icons(bpy.types.Header):
row = layout.row() row = layout.row()
row.active = props.bl_rna.scroll[1]['max'] > 1 row.active = props.bl_rna.scroll[1]['max'] > 1
row.prop(props, "scroll") row.prop(props, "scroll")
# icons # icons
row = layout.row(align=True) row = layout.row(align=True)
if len(self.icon_list) == 0: if len(self.icon_list) == 0:
row.label("No icons found") row.label("No icons found")
else: else:
for icon in self.icon_list[props.scroll-1: for icon in self.icon_list[props.scroll - 1:
props.scroll-1+self.amount]: props.scroll - 1 + self.amount]:
row.operator("wm.icon_info", text="", icon=icon, row.operator("wm.icon_info", text="", icon=icon,
emboss=False).icon = icon emboss=False).icon = icon
...@@ -210,6 +198,8 @@ def menu_func(self, context): ...@@ -210,6 +198,8 @@ def menu_func(self, context):
def register(): def register():
global IconProps
icons_total = len(create_icon_list_all()) icons_total = len(create_icon_list_all())
icons_per_row = 10 icons_per_row = 10
...@@ -223,17 +213,15 @@ def register(): ...@@ -223,17 +213,15 @@ def register():
expand = bpy.props.BoolProperty(default=False, expand = bpy.props.BoolProperty(default=False,
description="Expand, to display all icons at once") description="Expand, to display all icons at once")
search = bpy.props.StringProperty(default="", search = bpy.props.StringProperty(default="",
description = "Search for icons by name") description="Search for icons by name")
search_old = bpy.props.StringProperty(default="",
description = "Used to keep track of changes in IconProps.search")
scroll = bpy.props.IntProperty(default=1, min=1, scroll = bpy.props.IntProperty(default=1, min=1,
max=max(1, icons_total - icons_per_row + 1), max=max(1, icons_total - icons_per_row + 1),
description="Drag to scroll icons") description="Drag to scroll icons")
bpy.utils.register_module(__name__) bpy.utils.register_module(__name__)
bpy.types.Scene.icon_props = bpy.props.PointerProperty(type = IconProps) bpy.types.Scene.icon_props = bpy.props.PointerProperty(type=IconProps)
bpy.types.CONSOLE_MT_console.append(menu_func) bpy.types.CONSOLE_MT_console.append(menu_func)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment