How can the text, icon, and a button state (toggle high or low) be changed when a button is clicked? Just for understanding the mechanics, I wanted to know the most verbose and least verbose way to change text on a button, text on a label, an icon, and a button state (toggle up/ down) from a single button click from a button that contains the said text, icon, toggle state, and visually associated label.
import bpy
from bpy.props import *
def initSceneProperties(scn):
stin = bpy.types.Scene
stin.MyString1 = BoolProperty(
name = "String")
scn['MyString1'] = "Test 1"
stin.MyString2 = BoolProperty(
name = "String")
scn['MyString2'] = "Test 2"
return
initSceneProperties(bpy.context.scene)
# Layout panel
class LayoutPanel(bpy.types.Panel):
bl_label = "Hide Tools"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOL_PROPS"
def draw(self, context):
layout = self.layout
scn = context.scene
layout.label("TEST")
# First String
layout.prop(scn, 'MyString1', text="")
row = layout.row(align=True)
row.operator("my.button", text="1", icon="CANCEL", toggle=True)
# Second String
layout.prop(scn, 'MyString2', text="")
row = layout.row(align=True)
row.operator("my.button", text="2", icon="CANCEL", toggle=True)
# Button
class OBJECT_OT_Button(bpy.types.Operator):
bl_idname = "my.button"
bl_label = "Button"
def execute(self, context):
scn = context.scene
layout = self.layout
icon = LayoutPanel.draw
if scn.MyString1 == "MyString2" | row.operator(toggle=True):
label = "TEST2"
icon.row.operator[icon] == "ERROR"
icon.row.operator[text] == "A"
icon.row.operator[toggle] = True
else:
scn.MyString1 == "MyString1"
label = "TEST1"
icon.row.operator[icon] == "CANCEL"
icon.row.operator[text] == "B"
icon.row.operator[toggle] = False
return{'FINISHED'}
bpy.utils.register_module(__name__)
layout.prop(obj, "someboolprop", toggle=True, icon='MONKEY' if obj.someboolprop else 'NONE', text="Something" if obj.someboolprop else "Something Else")
will give you a switch toggle, rather than a checkbox. $\endgroup$