MCPcopy Create free account
hub / github.com/PaulleDemon/PyUIBuilder / generateTkinterCode

Function generateTkinterCode

src/frameworks/tkinter/engine/code.js:94–225  ·  view source on GitHub ↗
(projectName, widgetList=[], widgetRefs=[], assetFiles)

Source from the content-addressed store, hash-verified

92
93
94async function generateTkinterCode(projectName, widgetList=[], widgetRefs=[], assetFiles){
95
96 // console.log("widgetList and refs", projectName, widgetList, widgetRefs, assetFiles)
97
98 let mainWindowCount = 0
99
100 // only MainWindow and/or the TopLevel should be on the canvas
101 const filteredWidgetList = widgetList.filter(widget => widget.widgetType === MainWindow || widget.widgetType === TopLevel)
102
103 for (let widget of filteredWidgetList){
104 if (widget.widgetType === MainWindow){
105 mainWindowCount += 1
106 }
107
108 if (mainWindowCount > 1){
109 message.error("Multiple instances of Main window found, delete one and try again.")
110 return
111 }
112
113 }
114
115 if (mainWindowCount === 0){
116 message.error("Aborting. No instances of Main window found. Add one and try again")
117 return
118 }
119
120 // widget - {id, widgetType: widgetComponentType, children: [], parent: "", initialData: {}}
121
122 const generatedObject = generateTkinterCodeList(filteredWidgetList, widgetRefs.current, "", "")
123
124 const {code: codeLines, imports, requirements, mainVariable, customPythonWidgets} = generatedObject
125
126 console.log("custom python widgets: ", customPythonWidgets)
127
128 // TODO: avoid adding \n inside the list instead rewrite using code.join("\n")
129
130 // TODO: import customWidgets
131 const code = [
132 "# This code is generated by PyUIbuilder: https://pyuibuilder.com",
133 "\n\n",
134 ...imports.flatMap((item, index) => index < imports.length - 1 ? [item, "\n"] : [item]), //add \n to every line
135 "\n\n",
136 ...codeLines,
137 "\n",
138 `${mainVariable}.mainloop()`,
139 ]
140
141 console.log("Code: ", code.join(""), "\n\n requirements:", requirements.join("\n"))
142
143 message.info("starting zipping files, download will start in a few seconds")
144
145 const createFileList = [
146 {
147 fileData: code.join(""),
148 fileName: "main.py",
149 folder: ""
150 }
151 ]

Callers 1

App.jsFile · 0.85

Calls 2

createFilesAndDownloadFunction · 0.90
generateTkinterCodeListFunction · 0.85

Tested by

no test coverage detected