import Tools from "../../../canvas/constants/tools" import { DownOutlined } from "@ant-design/icons" import { TkinterWidgetBase} from "./base" import { convertObjectToKeyValueString } from "../../../utils/common" class OptionMenu extends TkinterWidgetBase{ static widgetType = "option_menu" constructor(props) { super(props) // const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute this.minSize = {width: 50, height: 30} this.state = { ...this.state, isDropDownOpen: false, widgetName: "Option menu", size: { width: 120, height: 'fit' }, attrs: { ...this.state.attrs, defaultValue: { label: "Default Value", tool: Tools.INPUT, value: "Select option", onChange: ({inputs, selectedRadio}) => { this.setAttrValue("options", {inputs, selectedRadio}) } }, widgetOptions: { label: "Options", tool: Tools.INPUT_RADIO_LIST, value: {inputs: ["option 1"], selectedRadio: -1}, onChange: ({inputs, selectedRadio}) => { this.setAttrValue("widgetOptions", {inputs, selectedRadio}) } } } } console.log("attrs1: ", this.state.attrs) } componentDidMount(){ super.componentDidMount() this.setWidgetInnerStyle("backgroundColor", "#fff") } generateCode(variableName, parent){ const config = convertObjectToKeyValueString(this.getConfigCode()) const defaultValue = this.getAttrValue("defaultValue") const options = JSON.stringify(this.getAttrValue("widgetOptions").inputs) return [ `${variableName}_options = ${options}`, `${variableName} = tk.OptionMenu(master=${parent}, ${defaultValue}, *${variableName}_options)`, `${variableName}.config(${config})`, `${variableName}.${this.getLayoutCode()}` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() const attrs = this.state.attrs console.log("attrs: ", attrs) return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, checkLabel: attrs.checkLabel, size: toolBarAttrs.size, ...attrs, }) } toggleDropDownOpen = () => { this.setState((prev) => ({ isDropDownOpen: !prev.isDropDownOpen })) } renderContent(){ const {inputs, selectedRadio} = this.getAttrValue("widgetOptions") return (
{this.getAttrValue("defaultValue")}
{this.state.isDropDownOpen &&
{ inputs.map((value, index) => { return (
{value}
) }) }
}
) } } export default OptionMenu