import Widget from "../../../canvas/widgets/base" import Tools from "../../../canvas/constants/tools" import { removeKeyFromObject } from "../../../utils/common" import TkinterBase from "./base" class Button extends TkinterBase{ static widgetType = "button" constructor(props) { super(props) this.droppableTags = null const newAttrs = removeKeyFromObject("layout", this.state.attrs) this.state = { ...this.state, size: { width: 80, height: 40 }, attrs: { ...newAttrs, styling: { ...newAttrs.styling, foregroundColor: { label: "Foreground Color", tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string value: "#000", onChange: (value) => { this.setWidgetInnerStyle("color", value) this.setAttrValue("styling.foregroundColor", value) } } }, buttonLabel: { label: "Button Label", tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string toolProps: {placeholder: "Button label", maxLength: 100}, value: "Button", onChange: (value) => this.setAttrValue("buttonLabel", value) } } } } componentDidMount(){ super.componentDidMount() this.setWidgetName("button") this.setAttrValue("styling.backgroundColor", "#E4E2E2") } generateCode(variableName, parent){ const labelText = this.getAttrValue("buttonLabel") const bg = this.getAttrValue("styling.backgroundColor") const fg = this.getAttrValue("styling.foregroundColor") return [ `${variableName} = tk.Button(master=${parent}, text="${labelText}")`, `${variableName}.config(bg="${bg}", fg="${fg}")`, `${variableName}.${this.getLayoutCode()}` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, buttonLabel: this.state.attrs.buttonLabel, size: toolBarAttrs.size, ...this.state.attrs, }) } renderContent(){ return (
{/* {this.props.children} */}
{this.getAttrValue("buttonLabel")}
) } } export default Button