diff --git a/src/frameworks/tkinter/widgets/ checkButton.js b/src/frameworks/tkinter/widgets/ checkButton.js
index 2823b77..66c9e19 100644
--- a/src/frameworks/tkinter/widgets/ checkButton.js
+++ b/src/frameworks/tkinter/widgets/ checkButton.js
@@ -1,12 +1,12 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
-import { Checkbox } from "antd"
import { removeKeyFromObject } from "../../../utils/common"
-import { CheckOutlined, CheckSquareFilled } from "@ant-design/icons"
+import { CheckSquareFilled } from "@ant-design/icons"
+import TkinterBase from "./base"
-export class CheckBox extends Widget{
+export class CheckBox extends TkinterBase{
static widgetType = "check_button"
// TODO: remove layouts
@@ -34,7 +34,7 @@ export class CheckBox extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -61,7 +61,7 @@ export class CheckBox extends Widget{
super.componentDidMount()
// this.setAttrValue("styling.backgroundColor", "#fff")
this.setWidgetName("Checkbox")
- this.setWidgetStyling("backgroundColor", "#fff0")
+ this.setWidgetInnerStyle("backgroundColor", "#fff0")
}
getToolbarAttrs(){
@@ -81,7 +81,7 @@ export class CheckBox extends Widget{
renderContent(){
return (
@@ -135,7 +135,7 @@ export class RadioButton extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -158,8 +158,8 @@ export class RadioButton extends Widget{
componentDidMount(){
super.componentDidMount()
// this.setAttrValue("styling.backgroundColor", "#fff")
- this.setWidgetName("Checkbox")
- this.setWidgetStyling("backgroundColor", "#fff0")
+ this.setWidgetName("Radio button")
+ this.setWidgetInnerStyle("backgroundColor", "#fff0")
}
getToolbarAttrs(){
@@ -182,7 +182,7 @@ export class RadioButton extends Widget{
return (
{
@@ -201,7 +201,7 @@ export class RadioButton extends Widget{
}
-
+
{value}
diff --git a/src/frameworks/tkinter/widgets/base.js b/src/frameworks/tkinter/widgets/base.js
new file mode 100644
index 0000000..86a3b64
--- /dev/null
+++ b/src/frameworks/tkinter/widgets/base.js
@@ -0,0 +1,197 @@
+import { Layouts, PosType } from "../../../canvas/constants/layouts"
+import Tools from "../../../canvas/constants/tools";
+import Widget from "../../../canvas/widgets/base";
+
+
+
+class TkinterBase extends Widget {
+
+ componentDidMount(){
+ super.componentDidMount()
+ console.log("parent layout: ", this.state.parentLayout)
+ // this.setParentLayout(this.props.initialData)
+ }
+
+
+
+ setParentLayout(layout){
+ // show attributes related to the layout manager
+ let updates = {
+ parentLayout: layout,
+ }
+ console.log("Parent layout updated1: ", layout)
+
+ this.removeAttr("gridManager")
+ if (layout === Layouts.FLEX || layout === Layouts.GRID) {
+
+ updates = {
+ ...updates,
+ positionType: PosType.NONE
+ }
+ console.log("Manager1 :", layout)
+ if (layout === Layouts.GRID) {
+ // Set attributes related to grid layout manager
+ updates = {
+ ...updates,
+ attrs: {
+ ...this.state.attrs,
+ gridManager: {
+ label: "Grid manager",
+ display: "horizontal",
+ row: {
+ label: "Row",
+ tool: Tools.NUMBER_INPUT,
+ toolProps: { placeholder: "width", max: 1000, min: 1 },
+ value: 1,
+ onChange: (value) => {
+ this.setAttrValue("gridManager.row", value)
+
+ const previousRow = this.getWidgetOuterStyle("gridRow") || "1/1"
+
+ const [_row=1, rowSpan=1] = previousRow.replace(/\s+/g, '').split("/").map(Number)
+
+
+ this.setWidgetOuterStyle("gridRow", `${value+' / '+rowSpan}`)
+ }
+ },
+ rowSpan: {
+ label: "Row span",
+ tool: Tools.NUMBER_INPUT,
+ toolProps: { placeholder: "height", max: 1000, min: 1 },
+ value: 1,
+ onChange: (value) => {
+ this.setAttrValue("gridManager.rowSpan", value)
+
+ const previousRow = this.getWidgetOuterStyle("gridRow") || "1/1"
+
+ const [row=1, _rowSpan=1] = previousRow.replace(/\s+/g, '').split("/").map(Number)
+
+ this.setWidgetOuterStyle("gridRow", `${row + ' / ' +value}`)
+ }
+ },
+ column: {
+ label: "Column",
+ tool: Tools.NUMBER_INPUT,
+ toolProps: { placeholder: "height", max: 1000, min: 1 },
+ value: 1,
+ onChange: (value) => {
+ this.setAttrValue("gridManager.column", value)
+
+ const previousRow = this.getWidgetOuterStyle("gridColumn") || "1/1"
+
+ const [_col=1, colSpan=1] = previousRow.replace(/\s+/g, '').split("/").map(Number)
+ console.log("column: ", value, colSpan)
+ this.setWidgetOuterStyle("gridColumn", `${value +' / ' + colSpan}`)
+ }
+ },
+ columnSpan: {
+ label: "Column span",
+ tool: Tools.NUMBER_INPUT,
+ toolProps: { placeholder: "height", max: 1000, min: 1 },
+ value: 1,
+ onChange: (value) => {
+ this.setAttrValue("gridManager.columnSpan", value)
+
+ const previousCol = this.getWidgetOuterStyle("gridColumn") || "1/1"
+
+ console.log("Value: ", previousCol)
+
+ const [col=1, _colSpan=1] = previousCol.replace(/\s+/g, '').split("/").map(Number)
+
+ this.setWidgetOuterStyle("gridColumn", `${col + ' / ' + value}`)
+ }
+ },
+ }
+ }
+ }
+
+ }
+
+ } else if (layout === Layouts.PLACE) {
+ updates = {
+ ...updates,
+ positionType: PosType.ABSOLUTE
+ }
+ }
+
+ console.log("Parent layout updated2: ", updates)
+
+ this.updateState(updates)
+
+ return updates
+ }
+
+ /**
+ * loads the data
+ * @param {object} data
+ */
+ load = (data) => {
+
+ if (Object.keys(data).length === 0) return // no data to load
+
+ data = {...data} // create a shallow copy
+
+ const {attrs, parentLayout, ...restData} = data
+
+
+ let layoutUpdates = {
+ parentLayout: parentLayout
+ }
+
+ if (parentLayout === Layouts.FLEX || parentLayout === Layouts.GRID){
+
+ layoutUpdates = {
+ ...layoutUpdates,
+ positionType: PosType.NONE
+ }
+
+ }else if (parentLayout === Layouts.PLACE){
+ layoutUpdates = {
+ ...layoutUpdates,
+ positionType: PosType.ABSOLUTE
+ }
+ }
+
+ const newData = {
+ ...restData,
+ ...layoutUpdates
+ }
+
+ this.setState(newData, () => {
+ let layoutAttrs = this.setParentLayout(parentLayout).attrs || {}
+ console.log("loaded layout2: ", layoutUpdates)
+
+
+ // UPdates attrs
+ let newAttrs = { ...this.state.attrs, ...layoutAttrs }
+
+ // Iterate over each path in the updates object
+ Object.entries(attrs).forEach(([path, value]) => {
+ const keys = path.split('.')
+ const lastKey = keys.pop()
+
+ // Traverse the nested object within attrs
+ let nestedObject = newAttrs
+
+ keys.forEach(key => {
+ nestedObject[key] = { ...nestedObject[key] } // Ensure immutability for each nested level
+ nestedObject = nestedObject[key]
+ })
+
+ // Set the value at the last key
+ if (nestedObject[lastKey])
+ nestedObject[lastKey].value = value
+ })
+
+ this.updateState({ attrs: newAttrs })
+
+ })
+
+
+ }
+
+
+}
+
+
+export default TkinterBase
\ No newline at end of file
diff --git a/src/frameworks/tkinter/widgets/button.js b/src/frameworks/tkinter/widgets/button.js
index f1b49b8..362ae5c 100644
--- a/src/frameworks/tkinter/widgets/button.js
+++ b/src/frameworks/tkinter/widgets/button.js
@@ -1,9 +1,10 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
+import TkinterBase from "./base"
-class Button extends Widget{
+class Button extends TkinterBase{
static widgetType = "button"
@@ -25,7 +26,7 @@ class Button extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -68,7 +69,7 @@ class Button extends Widget{
return (
-
+
{/* {this.props.children} */}
{this.getAttrValue("buttonLabel")}
diff --git a/src/frameworks/tkinter/widgets/frame.js b/src/frameworks/tkinter/widgets/frame.js
index 04b9ce7..1bf177b 100644
--- a/src/frameworks/tkinter/widgets/frame.js
+++ b/src/frameworks/tkinter/widgets/frame.js
@@ -1,7 +1,8 @@
import Widget from "../../../canvas/widgets/base"
+import TkinterBase from "./base"
-class Frame extends Widget{
+class Frame extends TkinterBase{
static widgetType = "frame"
@@ -25,9 +26,10 @@ class Frame extends Widget{
}
renderContent(){
+ // console.log("widget styling: ", this.state.widgetInnerStyling)
return (
-
diff --git a/src/frameworks/tkinter/widgets/input.js b/src/frameworks/tkinter/widgets/input.js
index fca46fb..0530225 100644
--- a/src/frameworks/tkinter/widgets/input.js
+++ b/src/frameworks/tkinter/widgets/input.js
@@ -1,9 +1,10 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
+import TkinterBase from "./base"
-export class Input extends Widget{
+export class Input extends TkinterBase{
static widgetType = "entry"
@@ -26,7 +27,7 @@ export class Input extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -67,7 +68,7 @@ export class Input extends Widget{
renderContent(){
return (
-
+
{this.getAttrValue("placeHolder")}
@@ -79,7 +80,7 @@ export class Input extends Widget{
}
-export class Text extends Widget{
+export class Text extends TkinterBase{
static widgetType = "Text"
@@ -102,7 +103,7 @@ export class Text extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -142,7 +143,7 @@ export class Text extends Widget{
renderContent(){
return (
-
+
{this.getAttrValue("placeHolder")}
diff --git a/src/frameworks/tkinter/widgets/label.js b/src/frameworks/tkinter/widgets/label.js
index 3239fc4..430de65 100644
--- a/src/frameworks/tkinter/widgets/label.js
+++ b/src/frameworks/tkinter/widgets/label.js
@@ -1,19 +1,17 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
+import TkinterBase from "./base"
-class Label extends Widget{
+class Label extends TkinterBase{
static widgetType = "label"
constructor(props) {
super(props)
- this.droppableTags = {
- // TODO: exclude all
- exclude: ["image", "video", "media", "main_window", "toplevel"]
- }
+ this.droppableTags = null
const newAttrs = removeKeyFromObject("layout", this.state.attrs)
@@ -30,7 +28,7 @@ class Label extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -50,7 +48,7 @@ class Label extends Widget{
componentDidMount(){
super.componentDidMount()
this.setAttrValue("styling.backgroundColor", "#fff")
- this.setWidgetStyling("backgroundColor", "#fff0")
+ this.setWidgetInnerStyle("backgroundColor", "#fff0")
}
getToolbarAttrs(){
@@ -70,7 +68,7 @@ class Label extends Widget{
renderContent(){
return (
-
+
{/* {this.props.children} */}
{this.getAttrValue("labelWidget")}
diff --git a/src/frameworks/tkinter/widgets/mainWindow.js b/src/frameworks/tkinter/widgets/mainWindow.js
index f2e973f..0dd9762 100644
--- a/src/frameworks/tkinter/widgets/mainWindow.js
+++ b/src/frameworks/tkinter/widgets/mainWindow.js
@@ -65,7 +65,7 @@ class MainWindow extends Widget{
-
diff --git a/src/frameworks/tkinter/widgets/optionMenu.js b/src/frameworks/tkinter/widgets/optionMenu.js
index fd8893e..73b3489 100644
--- a/src/frameworks/tkinter/widgets/optionMenu.js
+++ b/src/frameworks/tkinter/widgets/optionMenu.js
@@ -3,9 +3,10 @@ import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
import { ArrowDownOutlined, DownOutlined } from "@ant-design/icons"
+import TkinterBase from "./base"
-class OptionMenu extends Widget{
+class OptionMenu extends TkinterBase{
static widgetType = "option_menu"
// FIXME: the radio buttons are not visible because of the default heigh provided
@@ -34,7 +35,7 @@ class OptionMenu extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -65,7 +66,7 @@ class OptionMenu extends Widget{
super.componentDidMount()
// this.setAttrValue("styling.backgroundColor", "#fff")
this.setWidgetName("Option menu")
- this.setWidgetStyling("backgroundColor", "#fff")
+ this.setWidgetInnerStyle("backgroundColor", "#fff")
}
getToolbarAttrs(){
@@ -94,7 +95,7 @@ class OptionMenu extends Widget{
return (
@@ -115,7 +116,7 @@ class OptionMenu extends Widget{
-
+
{value}
diff --git a/src/frameworks/tkinter/widgets/slider.js b/src/frameworks/tkinter/widgets/slider.js
index 972ee06..d75e0ce 100644
--- a/src/frameworks/tkinter/widgets/slider.js
+++ b/src/frameworks/tkinter/widgets/slider.js
@@ -1,9 +1,10 @@
import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
+import TkinterBase from "./base"
-class Slider extends Widget{
+class Slider extends TkinterBase{
static widgetType = "scale"
@@ -26,7 +27,7 @@ class Slider extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
diff --git a/src/frameworks/tkinter/widgets/spinBox.js b/src/frameworks/tkinter/widgets/spinBox.js
index 341fec4..107589e 100644
--- a/src/frameworks/tkinter/widgets/spinBox.js
+++ b/src/frameworks/tkinter/widgets/spinBox.js
@@ -2,9 +2,10 @@ import Widget from "../../../canvas/widgets/base"
import Tools from "../../../canvas/constants/tools"
import { removeKeyFromObject } from "../../../utils/common"
import { DownOutlined, UpOutlined } from "@ant-design/icons"
+import TkinterBase from "./base"
-class SpinBox extends Widget{
+class SpinBox extends TkinterBase{
static widgetType = "spin_box"
constructor(props) {
@@ -26,7 +27,7 @@ class SpinBox extends Widget{
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
value: "#000",
onChange: (value) => {
- this.setWidgetStyling("color", value)
+ this.setWidgetInnerStyle("color", value)
this.setAttrValue("styling.foregroundColor", value)
}
}
@@ -92,7 +93,7 @@ class SpinBox extends Widget{
renderContent(){
return (
-
+
{this.getAttrValue("spinProps.default")}
diff --git a/src/frameworks/tkinter/widgets/toplevel.js b/src/frameworks/tkinter/widgets/toplevel.js
index 731096d..6e759c0 100644
--- a/src/frameworks/tkinter/widgets/toplevel.js
+++ b/src/frameworks/tkinter/widgets/toplevel.js
@@ -65,7 +65,7 @@ class TopLevel extends Widget{
-