2024-09-22 22:24:35 +05:30
|
|
|
import Tools from "../../../canvas/constants/tools"
|
2024-09-27 19:22:33 +05:30
|
|
|
import { convertObjectToKeyValueString } from "../../../utils/common"
|
|
|
|
|
import { TkinterWidgetBase } from "./base"
|
2024-09-22 22:24:35 +05:30
|
|
|
|
|
|
|
|
|
2024-09-27 19:22:33 +05:30
|
|
|
export class Input extends TkinterWidgetBase{
|
2024-09-22 22:24:35 +05:30
|
|
|
|
2024-09-23 12:31:01 +05:30
|
|
|
static widgetType = "entry"
|
2024-09-23 23:13:36 +05:30
|
|
|
|
2024-09-22 22:24:35 +05:30
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 120, height: 40 },
|
2024-09-27 16:04:03 +05:30
|
|
|
widgetName: "Entry",
|
2024-09-22 22:24:35 +05:30
|
|
|
attrs: {
|
2024-09-27 19:22:33 +05:30
|
|
|
...this.state.attrs,
|
2024-09-22 22:24:35 +05:30
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 23:16:43 +05:30
|
|
|
generateCode(variableName, parent){
|
|
|
|
|
|
2024-09-27 19:22:33 +05:30
|
|
|
const placeHolderText = this.getAttrValue("placeHolder")
|
|
|
|
|
|
|
|
|
|
const config = convertObjectToKeyValueString(this.getConfigCode())
|
|
|
|
|
|
2024-09-26 23:16:43 +05:30
|
|
|
return [
|
|
|
|
|
`${variableName} = tk.Entry(master=${parent}, text="${placeHolderText}")`,
|
2024-09-27 19:22:33 +05:30
|
|
|
`${variableName}.config(${config})`,
|
2024-09-26 23:16:43 +05:30
|
|
|
`${variableName}.${this.getLayoutCode()}`
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-22 22:24:35 +05:30
|
|
|
getToolbarAttrs(){
|
2024-09-23 12:31:01 +05:30
|
|
|
|
|
|
|
|
const toolBarAttrs = super.getToolbarAttrs()
|
|
|
|
|
|
2024-09-22 22:24:35 +05:30
|
|
|
return ({
|
|
|
|
|
id: this.__id,
|
2024-09-23 12:31:01 +05:30
|
|
|
widgetName: toolBarAttrs.widgetName,
|
2024-09-22 22:24:35 +05:30
|
|
|
placeHolder: this.state.attrs.placeHolder,
|
2024-09-23 18:25:40 +05:30
|
|
|
size: toolBarAttrs.size,
|
2024-09-22 22:24:35 +05:30
|
|
|
|
|
|
|
|
...this.state.attrs,
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderContent(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
2024-09-25 17:27:12 +05:30
|
|
|
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center" style={this.state.widgetInnerStyling}>
|
2024-09-22 22:24:35 +05:30
|
|
|
<div className="tw-text-sm tw-text-gray-300">
|
|
|
|
|
{this.getAttrValue("placeHolder")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-27 19:22:33 +05:30
|
|
|
export class Text extends TkinterWidgetBase{
|
2024-09-23 12:31:01 +05:30
|
|
|
|
|
|
|
|
static widgetType = "Text"
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 120, height: 80 },
|
|
|
|
|
attrs: {
|
2024-09-27 19:22:33 +05:30
|
|
|
...this.state.attrs,
|
2024-09-23 12:31:01 +05:30
|
|
|
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")
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-27 19:22:33 +05:30
|
|
|
generateCode(variableName, parent){
|
|
|
|
|
|
|
|
|
|
const placeHolderText = this.getAttrValue("placeHolder")
|
|
|
|
|
|
|
|
|
|
const config = convertObjectToKeyValueString(this.getConfigCode())
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
`${variableName} = tk.Text(master=${parent}, text="${placeHolderText}")`,
|
|
|
|
|
`${variableName}.config(${config})`,
|
|
|
|
|
`${variableName}.${this.getLayoutCode()}`
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-23 12:31:01 +05:30
|
|
|
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 (
|
|
|
|
|
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
2024-09-25 17:27:12 +05:30
|
|
|
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start " style={this.state.widgetInnerStyling}>
|
2024-09-23 12:31:01 +05:30
|
|
|
<div className="tw-text-sm tw-text-gray-300">
|
|
|
|
|
{this.getAttrValue("placeHolder")}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|