Skip to content

Commit

Permalink
macros have search function now
Browse files Browse the repository at this point in the history
  • Loading branch information
vilemnovak committed Jan 8, 2017
1 parent 35137d3 commit 400fe9c
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 21 deletions.
103 changes: 86 additions & 17 deletions addons/macros.py
Expand Up @@ -69,6 +69,54 @@ def save_preset(text):
textblock.filepath=filepath



class VIEW3D_menu_tools_macro(bpy.types.Menu):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
bl_category = "Macro"

bl_label = "Macros menu"
bl_idname = "view3d.macromenu"
#bl_context = "objectmode"
#bl_category = "Tools"

prefix = bpy.props.StringProperty(name="text block", default='R_')
mlist=[]

def draw(self, context):
#print(dir(self))
prefix = 'R_'
layout = self.layout
col = layout.column(align=True)
#print(self.bl_label)
if self.mlist==[]:
#print( 'reload' )
self.mlist=load_presets()

for t in bpy.data.texts:


#print(dir(self.layout))
#print((self.bl_label))
#print(dir(self.path_menu))
#print((self.layout._name))
if t.name[:2]==self.prefix:
col.operator("object.run_macro", text=t.name).text=self.bl_label#t.name
col.separator()
for t in self.mlist:
dupli=False
for t1 in bpy.data.texts:
if t[0]==t1.name:
dupli=True
#continue
if not dupli:
#print(t[1][:2])
if t[0][:2]==self.prefix:
col.operator("object.run_macro", text=t[0][2:]).text=t[1]




class VIEW3D_PT_tools_macro(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
Expand All @@ -86,18 +134,29 @@ def draw(self, context):

layout = self.layout
col = layout.column(align=True)
# col.menu("view3d.macromenu", text="relief tools")
col.prop(bpy.context.scene, 'macro_search_string')
op = col.operator("wm.call_menu", text='relief tools')
col = layout.column(align=True)
op.name = 'view3d.macromenu'
#op.prefix='R_'
#print(dir(op))

if self.mlist==[]:
#print( 'reload' )
self.mlist=load_presets()

search_string = bpy.context.scene.macro_search_string

for t in bpy.data.texts:

row=col.row(align=True)
#print(self.search_string)

row.operator("object.run_macro", text=t.name).text=t.name
row.operator("object.save_macro", text='', icon='SAVE_COPY').text=t.name
row.operator("object.unlink_macro", text='', icon='X').text=t.name
if t.name.find(search_string)>-1:
row=col.row(align=True)

row.operator("object.run_macro", text=t.name).text=t.name
row.operator("object.save_macro", text='', icon='SAVE_COPY').text=t.name
row.operator("object.unlink_macro", text='', icon='X').text=t.name


col.separator()
Expand All @@ -108,9 +167,10 @@ def draw(self, context):
dupli=True
#continue
if not dupli:
row=col.row(align=True)
row.operator("object.run_macro", text=t[0]).text=t[1]
row.operator("text.open", text='', icon='FILE_TEXT').filepath=t[1]
if t[0].find(search_string)>-1:
row=col.row(align=True)
row.operator("object.run_macro", text=t[0]).text=t[1]
row.operator("text.open", text='', icon='FILE_TEXT').filepath=t[1]


class RunMacro(bpy.types.Operator):
Expand All @@ -119,9 +179,9 @@ class RunMacro(bpy.types.Operator):
bl_label = 'run macro'
bl_options = {'REGISTER', 'UNDO'}

@classmethod
def poll(cls, context):
return True
#@classmethod
#def poll(cls, context):
# return True

text = bpy.props.StringProperty(name="text block",
default='')
Expand Down Expand Up @@ -195,18 +255,24 @@ def extractProperties(self,text):
li=0
scriptonly=''
self.props=[[],[],[],[]]

text=text.split('\n')
while not end:

l=text[li]

#print(l)
l=l.replace('\\','\\\\')
if l.find('=')>-1 and defmore:
i=l.find('=')
#print(l[:i],l[i+1:])
propname=l[:i]
propvalue=eval(l[i+1:])

ptype=type(propvalue)

try:
propvalue=eval(l[i+1:])
ptype=type(propvalue)
except:
ptype = None
#print(propname,propvalue,ptype)
#print(dir(ptype))

Expand Down Expand Up @@ -329,25 +395,28 @@ class UnlinkMacro(bpy.types.Operator):
default='')

def execute(self, context):
bpy.data.texts.remove(bpy.data.texts[self.text])

bpy.data.texts.remove(bpy.data.texts[self.text], do_unlink = True)
return {'FINISHED'}



def register():

bpy.utils.register_class(RunMacro)
bpy.utils.register_class(SaveMacro)
bpy.utils.register_class(EditMacro)
bpy.utils.register_class(UnlinkMacro)
bpy.utils.register_class(VIEW3D_PT_tools_macro)

bpy.utils.register_class(VIEW3D_menu_tools_macro)
bpy.types.Scene.macro_search_string = bpy.props.StringProperty(name = 'Search' , default = '')
#set (function) – Function to be called when this value is ‘written’, This function must take 2 values (self, value)
def unregister():
bpy.utils.unregister_class(RunMacro)
bpy.utils.unregister_class(SaveMacro)
bpy.utils.unregister_class(EditMacro)
bpy.utils.unregister_class(UnlinkMacro)
bpy.utils.unregister_class(VIEW3D_PT_tools_macro)
bpy.utils.unregister_class(VIEW3D_menu_tools_macro)


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions addons/tabs_interface.py
Expand Up @@ -112,9 +112,9 @@ def buildTabDir():
exec('npanel.'+nprop+ ' = panel.'+nprop)
'''
spaces[st][rt].append(panel)

panel.realID = panel.bl_rna.identifier
try:
panel.realID = panel.bl_rna.identifier

bpy.utils.unregister_class(eval('bpy_types.bpy_types.'+panel.bl_rna.identifier))
#print('haha')
#bpy.utils.register_class(eval('bpy_types.bpy_types.'+panel.bl_rna.identifier))
Expand Down Expand Up @@ -766,8 +766,8 @@ def unregister():
if hasattr(panel, 'bl_category'):
if hasattr(panel, 'orig_category'):
panel.bl_category = panel.orig_category
panel.realID = panel.bl_rna.identifier
bpy.utils.register_class(eval('bpy_types.bpy_types.'+panel.realID))
# panel.realID = panel.bl_rna.identifier
# bpy.utils.register_class(eval('bpy_types.bpy_types.'+panel.realID))
bpy.utils.unregister_class(VIEW3D_PT_Transform)


Expand Down

0 comments on commit 400fe9c

Please sign in to comment.