import Tools from "../../../canvas/constants/tools" import { convertObjectToKeyValueString } from "../../../utils/common" import { TkinterWidgetBase } from "./base" export class Input extends TkinterWidgetBase{ static widgetType = "entry" static displayName = "Entry" constructor(props) { super(props) this.state = { ...this.state, size: { width: 120, height: 40 }, widgetName: "Entry", attrs: { ...this.state.attrs, placeHolder: { label: "PlaceHolder", tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string toolProps: {placeholder: "text", maxLength: 100}, value: "placeholder text", onChange: (value) => this.setAttrValue("placeHolder", value) } } } } componentDidMount(){ super.componentDidMount() this.setAttrValue("styling.backgroundColor", "#fff") } generateCode(variableName, parent){ const placeHolderText = this.getAttrValue("placeHolder") const config = convertObjectToKeyValueString(this.getConfigCode()) return [ `${variableName} = tk.Entry(master=${parent}, text="${placeHolderText}")`, `${variableName}.config(${config})`, `${variableName}.${this.getLayoutCode()}` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, placeHolder: this.state.attrs.placeHolder, size: toolBarAttrs.size, ...this.state.attrs, }) } renderContent(){ return (
{this.getAttrValue("placeHolder")}
) } } export class Text extends TkinterWidgetBase{ static widgetType = "Text" constructor(props) { super(props) this.state = { ...this.state, size: { width: 120, height: 80 }, attrs: { ...this.state.attrs, // placeHolder: { // label: "PlaceHolder", // tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string // toolProps: {placeholder: "text", maxLength: 100}, // value: "placeholder text", // onChange: (value) => this.setAttrValue("placeHolder", value) // } } } } componentDidMount(){ super.componentDidMount() this.setAttrValue("styling.backgroundColor", "#fff") this.setWidgetName("text") } generateCode(variableName, parent){ const placeHolderText = this.getAttrValue("placeHolder") const config = convertObjectToKeyValueString(this.getConfigCode()) return [ `${variableName} = tk.Text(master=${parent})`, `${variableName}.config(${config})`, `${variableName}.${this.getLayoutCode()}` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, placeHolder: this.state.attrs.placeHolder, size: toolBarAttrs.size, ...this.state.attrs, }) } renderContent(){ return (
{this.getAttrValue("placeHolder")}
) } }