working on label image resize fix
This commit is contained in:
@@ -4,6 +4,8 @@ import MainWindow from "../widgets/mainWindow"
|
||||
import { message } from "antd"
|
||||
import TopLevel from "../widgets/toplevel"
|
||||
|
||||
const pythonFiles = require.context("../pythonWidgets", false, /\.py$/)
|
||||
|
||||
|
||||
// FIXME: if the toplevel comes first, before the MainWindow in widgetlist the root may become null
|
||||
// Recursive function to generate the code list, imports, requirements, and track mainVariable
|
||||
@@ -13,6 +15,8 @@ function generateTkinterCodeList(widgetList = [], widgetRefs = [], parentVariabl
|
||||
let requirements = new Set([])
|
||||
let code = []
|
||||
|
||||
let customPythonWidgets = new Set([])
|
||||
|
||||
for (let widget of widgetList) {
|
||||
const widgetRef = widgetRefs[widget.id].current
|
||||
let varName = widgetRef.getVariableName()
|
||||
@@ -20,6 +24,7 @@ function generateTkinterCodeList(widgetList = [], widgetRefs = [], parentVariabl
|
||||
// Add imports and requirements to sets
|
||||
widgetRef.getImports().forEach(importItem => imports.add(importItem))
|
||||
widgetRef.getRequirements().forEach(requirementItem => requirements.add(requirementItem))
|
||||
widgetRef.getRequiredCustomPyFiles().forEach(customFile => customPythonWidgets.add(customFile))
|
||||
|
||||
// Set main variable if the widget is MainWindow
|
||||
if (widget.widgetType === MainWindow) {
|
||||
@@ -68,6 +73,8 @@ function generateTkinterCodeList(widgetList = [], widgetRefs = [], parentVariabl
|
||||
// Merge child imports, requirements, and code
|
||||
imports = new Set([...imports, ...childResult.imports])
|
||||
requirements = new Set([...requirements, ...childResult.requirements])
|
||||
customPythonWidgets = new Set([...customPythonWidgets, ...childResult.customPythonWidgets])
|
||||
|
||||
code.push(...childResult.code)
|
||||
|
||||
mainVariable = childResult.mainVariable || mainVariable // the main variable is the main window variable
|
||||
@@ -78,6 +85,7 @@ function generateTkinterCodeList(widgetList = [], widgetRefs = [], parentVariabl
|
||||
imports: Array.from(imports),
|
||||
code: code,
|
||||
requirements: Array.from(requirements),
|
||||
customPythonWidgets: Array.from(customPythonWidgets),
|
||||
mainVariable
|
||||
}
|
||||
}
|
||||
@@ -113,9 +121,13 @@ async function generateTkinterCode(projectName, widgetList=[], widgetRefs=[], as
|
||||
|
||||
const generatedObject = generateTkinterCodeList(filteredWidgetList, widgetRefs.current, "", "")
|
||||
|
||||
const {code: codeLines, imports, requirements, mainVariable} = generatedObject
|
||||
const {code: codeLines, imports, requirements, mainVariable, customPythonWidgets} = generatedObject
|
||||
|
||||
console.log("custom python widgets: ", customPythonWidgets)
|
||||
|
||||
// TODO: avoid adding \n inside the list instead rewrite using code.join("\n")
|
||||
|
||||
// TODO: import customWidgets
|
||||
const code = [
|
||||
"# This code is generated by PyUIbuilder: https://pyuibuilder.com",
|
||||
"\n\n",
|
||||
@@ -147,6 +159,26 @@ async function generateTkinterCode(projectName, widgetList=[], widgetRefs=[], as
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: add empty __init__ file
|
||||
for (let customWidget of customPythonWidgets){
|
||||
|
||||
let [fileName, extension] = customWidget.split(".")
|
||||
|
||||
if (!extension){
|
||||
fileName = `${fileName}.py`
|
||||
}
|
||||
|
||||
|
||||
const fileContent = pythonFiles(`./${fileName}`);
|
||||
|
||||
console.log("file name: ", fileContent.default, pythonFiles(`./${fileName}`))
|
||||
createFileList.push({
|
||||
fileData: new Blob([fileContent], { type: "text/plain" }),
|
||||
fileName: fileName,
|
||||
folder: "customWidgets"
|
||||
})
|
||||
}
|
||||
|
||||
for (let asset of assetFiles){
|
||||
|
||||
if (asset.fileType === "image"){
|
||||
|
||||
Reference in New Issue
Block a user