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

Function generateCustomTkCode

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

Source from the content-addressed store, hash-verified

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

Callers 1

App.jsFile · 0.85

Calls 2

createFilesAndDownloadFunction · 0.90
generateCustomTkCodeListFunction · 0.85

Tested by

no test coverage detected