import Widget from "../../../canvas/widgets/base" import Tools from "../../../canvas/constants/tools" class TopLevel extends Widget{ static widgetType = "toplevel" static displayName = "Top Level" constructor(props) { super(props) this.droppableTags = { exclude: ["image", "video", "media", "main_window", "toplevel"] } this.maxSize = { width: 2000, height: 2000 } // disables resizing above this number this.state = { ...this.state, size: { width: 450, height: 200 }, widgetName: "top level", attrs: { ...this.state.attrs, title: { label: "Window Title", tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string toolProps: {placeholder: "Window title", maxLength: 40}, value: "Top level", onChange: (value) => this.setAttrValue("title", value) } } } } componentDidMount(){ this.setAttrValue("styling.backgroundColor", "#E4E2E2") super.componentDidMount() } generateCode(variableName, parent){ const backgroundColor = this.getAttrValue("styling.backgroundColor") return [ `${variableName} = tk.Toplevel(master=${parent})`, `${variableName}.config(bg="${backgroundColor}")`, `${variableName}.title("${this.getAttrValue("title")}")` ] } getToolbarAttrs(){ const toolBarAttrs = super.getToolbarAttrs() return ({ widgetName: toolBarAttrs.widgetName, title: this.state.attrs.title, size: toolBarAttrs.size, ...this.state.attrs, }) } renderContent(){ return (
{this.getAttrValue("title")}
{this.props.children}
) } } export default TopLevel