mmmrqs / bl_ui_widgets

UI Widgets for Blender 2.8 and newer versions
GNU General Public License v3.0
46 stars 5 forks source link

Add bind_operator method for button widget #13

Closed atticus-lv closed 1 year ago

atticus-lv commented 1 year ago

Mostly I need is an easy way to bind an operator, so I make this changes. It can automatically get the info from the given operator idname and bind it to the button and allow input property settings. And less code to define a simple button

Old

self.button3 = BL_UI_Button((btnX + ((btnW - 1 + btnG) * btnC)), btnY, btnW, btnH)
self.button3.style = 'RADIO'
self.button3.text = "ADD"
self.button3.text_size = 13
self.button3.rounded_corners = (0, 0, 0, 0)
self.button3.set_mouse_up(self.button3_click)
self.button3.set_button_pressed(self.button3_pressed)
self.button3.description = "Adds one little 'MONKEY' object to 3D View area"
self.button3.python_cmd = "bpy.ops.object.dp_ot_draw_operator.button3_click()"
if self.button3_pressed(self.button3):
    self.button3.state = 3

New

self.button3 = BL_UI_Button((btnX + ((btnW - 1 + btnG) * btnC)), btnY, btnW, btnH)
self.button3.bind_operator('mesh.primitive_monkey_add',text ='ADD')
# self.button3.bind_operator('mesh.primitive_monkey_add',text ='ADD',icon_path=r'ERROR PATH TEST')
self.text_size = 13
self.button3.rounded_corners = (0, 0, 0, 0)
if self.button3_pressed(self.button3):
    self.button3.state = 3
atticus-lv commented 1 year ago
image image