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

111 lines
3.6 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-27 16:04:03 +05:30
import {TkinterBase, TkinterWidgetBase} from "./base"
2024-09-26 11:59:24 +05:30
import { Layouts } from "../../../canvas/constants/layouts"
2024-09-22 22:24:35 +05:30
2024-09-27 16:04:03 +05:30
class Label extends TkinterWidgetBase{
2024-09-22 22:24:35 +05:30
static widgetType = "label"
constructor(props) {
super(props)
2024-09-25 17:27:12 +05:30
this.droppableTags = null
2024-09-22 22:24:35 +05:30
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
2024-09-22 22:24:35 +05:30
this.state = {
...this.state,
2024-09-27 16:04:03 +05:30
widgetName: "Label",
2024-09-22 22:24:35 +05:30
size: { width: 80, 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)
}
}
},
labelWidget: {
label: "Text",
tool: Tools.INPUT,
2024-09-22 22:24:35 +05:30
toolProps: {placeholder: "text", maxLength: 100},
value: "Label",
onChange: (value) => this.setAttrValue("labelWidget", value)
},
imageUpload: {
label: "Image",
tool: Tools.UPLOADED_LIST,
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
value: "",
onChange: (value) => this.setAttrValue("imageUpload", value)
},
2024-09-22 22:24:35 +05:30
}
}
2024-09-27 16:04:03 +05:30
2024-09-22 22:24:35 +05:30
}
2024-09-26 23:16:43 +05:30
componentDidMount(){
super.componentDidMount()
2024-09-27 16:04:03 +05:30
2024-09-26 23:16:43 +05:30
this.setAttrValue("styling.backgroundColor", "#E4E2E2")
2024-09-27 16:04:03 +05:30
// this.setWidgetName("label") // Don't do this this causes issues while loading data
2024-09-26 23:16:43 +05:30
}
2024-09-26 11:59:24 +05:30
2024-09-26 23:16:43 +05:30
generateCode(variableName, parent){
2024-09-26 11:59:24 +05:30
2024-09-26 23:16:43 +05:30
const labelText = this.getAttrValue("labelWidget")
const bg = this.getAttrValue("styling.backgroundColor")
const fg = this.getAttrValue("styling.foregroundColor")
return [
`${variableName} = tk.Label(master=${parent}, text="${labelText}")`,
`${variableName}.config(bg="${bg}", fg="${fg}")`,
`${variableName}.${this.getLayoutCode()}`
]
2024-09-22 22:24:35 +05:30
}
2024-09-26 23:16:43 +05:30
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
labelWidget: this.state.attrs.labelWidget,
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-content-start tw-h-full tw-rounded-md tw-overflow-hidden">
2024-09-27 16:04:03 +05:30
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-content-center tw-place-items-center "
style={this.state.widgetInnerStyling}>
2024-09-22 22:24:35 +05:30
{/* {this.props.children} */}
2024-09-27 16:04:03 +05:30
<div className="" style={{color: this.getAttrValue("styling.foregroundColor")}}>
2024-09-22 22:24:35 +05:30
{this.getAttrValue("labelWidget")}
</div>
</div>
</div>
)
}
}
export default Label