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

130 lines
4.6 KiB
JavaScript
Raw Normal View History

2024-09-23 22:49:44 +05:30
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
2024-09-23 23:13:36 +05:30
import { DownOutlined, UpOutlined } from "@ant-design/icons"
2024-09-25 17:27:12 +05:30
import TkinterBase from "./base"
2024-09-23 22:49:44 +05:30
2024-09-25 17:27:12 +05:30
class SpinBox extends TkinterBase{
2024-09-23 22:49:44 +05:30
static widgetType = "spin_box"
2024-09-26 23:16:43 +05:30
2024-09-23 22:49:44 +05:30
constructor(props) {
super(props)
this.droppableTags = null // disables drops
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
this.state = {
...this.state,
2024-09-23 23:13:36 +05:30
size: { width: 70, height: 'fit' },
2024-09-23 22:49:44 +05:30
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)
2024-09-23 22:49:44 +05:30
this.setAttrValue("styling.foregroundColor", value)
}
}
},
2024-09-23 23:13:36 +05:30
spinProps: {
label: "Properties",
display: "horizontal",
min: {
label: "Min",
tool: Tools.NUMBER_INPUT, // the tool to display, can be either HTML ELement or a constant string
toolProps: { placeholder: "min" },
value: 0,
onChange: (value) => this.setAttrValue("spinProps.min", value)
},
max: {
label: "Max",
tool: Tools.NUMBER_INPUT,
toolProps: { placeholder: "max"},
value: 100,
onChange: (value) => this.setAttrValue("spinProps.max", value)
},
step: {
label: "Step",
tool: Tools.NUMBER_INPUT,
toolProps: { placeholder: "max", stringMode: true, step: "0.1"},
value: 1,
onChange: (value) => this.setAttrValue("spinProps.step", value)
},
default: {
label: "Default",
tool: Tools.NUMBER_INPUT,
toolProps: { placeholder: "max", stringMode: true, step: "0.1"},
value: 0,
onChange: (value) => this.setAttrValue("spinProps.default", value)
}
},
2024-09-23 22:49:44 +05:30
}
}
}
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#fff")
2024-09-23 23:13:36 +05:30
this.setWidgetName("SpinBox")
2024-09-23 22:49:44 +05:30
}
2024-09-26 23:16:43 +05:30
generateCode(variableName, parent){
const min = this.getAttrValue("spinProps.min")
const max = this.getAttrValue("spinProps.max")
const step = this.getAttrValue("spinProps.step")
const defaultValue = this.getAttrValue("spinProps.defaultValue")
const bg = this.getAttrValue("styling.backgroundColor")
const fg = this.getAttrValue("styling.foregroundColor")
return [
`${variableName} = tk.Spinbox(master=${parent})`,
`${variableName}.config(bg="${bg}", fg="${fg}", from_=${min}, to=${max},
increment=${step})`,
`${variableName}.${this.getLayoutCode()}`
]
}
2024-09-23 22:49:44 +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-flex tw-place-items-center tw-justify-between" style={this.state.widgetInnerStyling}>
2024-09-23 23:13:36 +05:30
<div className="tw-text-sm ">
{this.getAttrValue("spinProps.default")}
</div>
<div className="tw-flex tw-flex-col tw-text-black tw-gap-1 tw-text-sm">
<UpOutlined />
<DownOutlined />
2024-09-23 22:49:44 +05:30
</div>
</div>
</div>
)
}
}
export default SpinBox