Files
PyUIBuilder/src/frameworks/tkinter/widgets/input.js

154 lines
4.4 KiB
JavaScript
Raw Normal View History

2024-09-22 22:24:35 +05:30
import Tools from "../../../canvas/constants/tools"
import { convertObjectToKeyValueString } from "../../../utils/common"
import { TkinterWidgetBase } from "./base"
2024-09-22 22:24:35 +05:30
export class Input extends TkinterWidgetBase{
2024-09-22 22:24:35 +05:30
static widgetType = "entry"
2025-03-11 07:23:17 +05:30
static displayName = "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: {
...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){
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}")`,
`${variableName}.config(${config})`,
2024-09-26 23:16:43 +05:30
`${variableName}.${this.getLayoutCode()}`
]
}
2024-09-22 22:24:35 +05:30
getToolbarAttrs(){
const toolBarAttrs = super.getToolbarAttrs()
2024-09-22 22:24:35 +05:30
return ({
id: this.__id,
widgetName: toolBarAttrs.widgetName,
2024-09-22 22:24:35 +05:30
placeHolder: this.state.attrs.placeHolder,
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">
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center"
2025-03-22 11:11:19 +05:30
ref={this.styleAreaRef}
style={this.getInnerRenderStyling()}>
2024-09-22 22:24:35 +05:30
<div className="tw-text-sm tw-text-gray-300">
{this.getAttrValue("placeHolder")}
</div>
</div>
</div>
)
}
}
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,
2024-09-30 15:30:46 +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")
}
generateCode(variableName, parent){
const placeHolderText = this.getAttrValue("placeHolder")
const config = convertObjectToKeyValueString(this.getConfigCode())
return [
2024-09-30 15:30:46 +05:30
`${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 (
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start "
2025-03-22 11:11:19 +05:30
ref={this.styleAreaRef}
style={this.getInnerRenderStyling()}>
<div className="tw-text-sm tw-text-gray-300">
{this.getAttrValue("placeHolder")}
</div>
</div>
</div>
)
}
}