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

156 lines
4.8 KiB
JavaScript
Raw Normal View History

2024-09-22 22:24:35 +05:30
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
2024-09-25 17:27:12 +05:30
import TkinterBase from "./base"
2024-09-22 22:24:35 +05:30
2024-09-25 17:27:12 +05:30
export class Input extends TkinterBase{
2024-09-22 22:24:35 +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.droppableTags = null // disables drops
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
2024-09-22 22:24:35 +05:30
this.state = {
...this.state,
size: { width: 120, height: 40 },
attrs: {
...newAttrs,
2024-09-22 22:24:35 +05:30
styling: {
...newAttrs.styling,
2024-09-22 22:24:35 +05:30
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) => {
2024-09-25 17:27:12 +05:30
this.setWidgetInnerStyle("color", value)
2024-09-22 22:24:35 +05:30
this.setAttrValue("styling.foregroundColor", value)
}
}
},
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("Entry")
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">
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-25 17:27:12 +05:30
export class Text extends TkinterBase{
static widgetType = "Text"
constructor(props) {
super(props)
this.droppableTags = null
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
this.state = {
...this.state,
size: { width: 120, height: 80 },
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) => {
2024-09-25 17:27:12 +05:30
this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
},
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")
}
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}>
<div className="tw-text-sm tw-text-gray-300">
{this.getAttrValue("placeHolder")}
</div>
</div>
</div>
)
}
}