import Widget from "../../../canvas/widgets/base" import Tools from "../../../canvas/constants/tools" import { removeKeyFromObject } from "../../../utils/common" import { CheckSquareFilled } from "@ant-design/icons" import TkinterBase from "./base" export class CheckBox extends TkinterBase{ static widgetType = "check_button" // TODO: remove layouts constructor(props) { super(props) this.droppableTags = null // disables drops // const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute let newAttrs = removeKeyFromObject("layout", this.state.attrs) newAttrs = removeKeyFromObject("styling.backgroundColor", newAttrs) this.minSize = {width: 50, height: 30} this.state = { ...this.state, size: { width: 120, height: 30 }, attrs: { ...newAttrs, styling: { label: "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) => { this.setWidgetInnerStyle("color", value) this.setAttrValue("styling.foregroundColor", value) } } }, checkLabel: { label: "Check Label", tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string toolProps: {placeholder: "Button label", maxLength: 100}, value: "Checkbox", onChange: (value) => this.setAttrValue("checkLabel", value) }, defaultChecked: { label: "Checked", tool: Tools.CHECK_BUTTON, // the tool to display, can be either HTML ELement or a constant string value: true, onChange: (value) => this.setAttrValue("defaultChecked", value) } } } } componentDidMount(){ super.componentDidMount() // this.setAttrValue("styling.backgroundColor", "#fff") this.setWidgetName("Checkbox") this.setWidgetInnerStyle("backgroundColor", "#fff0") } generateCode(variableName, parent){ const labelText = this.getAttrValue("checkLabel") const bg = this.getAttrValue("styling.backgroundColor") const fg = this.getAttrValue("styling.foregroundColor") const code = [ `${variableName} = tk.Checkbutton(master=${parent}, text="${labelText}")`, `${variableName}.config(bg="${bg}", fg="${fg}")`, ] if (this.getAttrValue("defaultChecked")){ code.push(`${variableName}.select()`) } code.push(`${variableName}.${this.getLayoutCode()}`) return code } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() const attrs = this.state.attrs return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, checkLabel: attrs.checkLabel, size: toolBarAttrs.size, ...attrs, }) } renderContent(){ return (
{ this.getAttrValue("defaultChecked") === true && }
{this.getAttrValue("checkLabel")}
) } } export class RadioButton extends Widget{ static widgetType = "radio_button" constructor(props) { super(props) this.droppableTags = null // disables drops // const {layout, ...newAttrs} = this.state.attrs // Removes the layout attribute let newAttrs = removeKeyFromObject("layout", this.state.attrs) newAttrs = removeKeyFromObject("styling.backgroundColor", newAttrs) this.minSize = {width: 50, height: 30} this.state = { ...this.state, size: { width: 120, height: 'fit' }, attrs: { ...newAttrs, styling: { label: "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) => { this.setWidgetInnerStyle("color", value) this.setAttrValue("styling.foregroundColor", value) } } }, radios: { label: "Radio Group", tool: Tools.INPUT_RADIO_LIST, value: {inputs: ["default"], selectedRadio: -1}, onChange: ({inputs, selectedRadio}) => { this.setAttrValue("radios", {inputs, selectedRadio}) } } } } } componentDidMount(){ super.componentDidMount() // this.setAttrValue("styling.backgroundColor", "#fff") this.setWidgetName("Radio button") this.setWidgetInnerStyle("backgroundColor", "#fff0") } generateCode(variableName, parent){ const bg = this.getAttrValue("styling.backgroundColor") const fg = this.getAttrValue("styling.foregroundColor") const radios = this.getAttrValue("radios") // TODO: from here const code = [ `${variableName}_var = tk.IntVar()`, `${variableName} = tk.Radiobutton(master=${parent}, text="")`, `${variableName}.config(bg="${bg}", fg="${fg}")`, ] if (this.getAttrValue("defaultChecked")){ code.push(`${variableName}.select()`) } code.push(`${variableName}.${this.getLayoutCode()}`) return code } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() const attrs = this.state.attrs return ({ id: this.__id, widgetName: toolBarAttrs.widgetName, checkLabel: attrs.checkLabel, size: toolBarAttrs.size, ...attrs, }) } renderContent(){ const {inputs, selectedRadio} = this.getAttrValue("radios") return (
{ inputs.map((value, index) => { return (
{ selectedRadio === index &&
}
{value}
) }) }
) } }