2024-09-30 15:54:09 +05:30
|
|
|
import Widget from "../../../canvas/widgets/base"
|
|
|
|
|
import Tools from "../../../canvas/constants/tools"
|
|
|
|
|
import { CustomTkBase } from "./base"
|
2025-03-28 15:56:17 +05:30
|
|
|
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
2024-09-30 15:54:09 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow extends CustomTkBase{
|
|
|
|
|
|
|
|
|
|
static widgetType = "main_window"
|
2025-03-11 07:23:17 +05:30
|
|
|
static displayName = "Main Window"
|
2024-09-30 15:54:09 +05:30
|
|
|
|
2025-03-28 15:56:17 +05:30
|
|
|
|
|
|
|
|
static initialSize = {
|
|
|
|
|
width: 700,
|
|
|
|
|
height: 400
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-09-30 15:54:09 +05:30
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.droppableTags = {
|
|
|
|
|
exclude: ["image", "video", "media", "main_window", "toplevel"]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
...this.state,
|
|
|
|
|
size: { width: 700, height: 400 },
|
|
|
|
|
widgetName: "main",
|
|
|
|
|
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: "Main Window",
|
|
|
|
|
onChange: (value) => this.setAttrValue("title", value)
|
2025-03-28 15:56:17 +05:30
|
|
|
},
|
|
|
|
|
logo: {
|
|
|
|
|
label: "Window Logo",
|
|
|
|
|
tool: Tools.UPLOADED_LIST,
|
|
|
|
|
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
|
|
|
|
|
value: "",
|
|
|
|
|
onChange: (value) => this.setAttrValue("logo", value)
|
2024-09-30 15:54:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2024-09-30 22:18:08 +05:30
|
|
|
this.setAttrValue("styling.backgroundColor", "#23272D")
|
2024-10-01 11:22:45 +05:30
|
|
|
super.componentDidMount()
|
2024-09-30 15:54:09 +05:30
|
|
|
// this.setWidgetName("main") // Don't do this as this will cause conflicts while loading names
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateCode(variableName, parent){
|
|
|
|
|
|
|
|
|
|
const backgroundColor = this.getAttrValue("styling.backgroundColor")
|
2025-03-28 15:56:17 +05:30
|
|
|
const logo = this.getAttrValue("logo")
|
|
|
|
|
|
|
|
|
|
const {width, height} = this.getSize()
|
|
|
|
|
|
|
|
|
|
const code = [
|
|
|
|
|
`${variableName} = ctk.CTk()`,
|
|
|
|
|
`${variableName}.configure(fg_color="${backgroundColor}")`,
|
|
|
|
|
`${variableName}.title("${this.getAttrValue("title")}")`,
|
|
|
|
|
`${variableName}.geometry("${width}x${height}")`,
|
|
|
|
|
...this.getGridLayoutConfigurationCode(variableName)
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if (logo?.name){
|
|
|
|
|
|
|
|
|
|
// code.push(`\n`)
|
|
|
|
|
code.push(`${variableName}_img = Image.open(${getPythonAssetPath(logo.name, "image")})`)
|
|
|
|
|
code.push(`${variableName}_img = ImageTk.PhotoImage(${variableName}_img)`)
|
|
|
|
|
code.push(`${variableName}.iconphoto(False, ${variableName}_img)`)
|
|
|
|
|
// code.push("\n")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return code
|
|
|
|
|
}
|
2024-09-30 15:54:09 +05:30
|
|
|
|
2025-03-28 15:56:17 +05:30
|
|
|
getImports(){
|
|
|
|
|
const imports = super.getImports()
|
|
|
|
|
|
|
|
|
|
if (this.getAttrValue("logo"))
|
|
|
|
|
imports.push("import os", "from PIL import Image, ImageTk", )
|
|
|
|
|
|
|
|
|
|
return imports
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getRequirements(){
|
|
|
|
|
const requirements = super.getRequirements()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.getAttrValue("logo"))
|
|
|
|
|
requirements.push("pillow")
|
|
|
|
|
|
|
|
|
|
return requirements
|
2024-09-30 15:54:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getToolbarAttrs(){
|
|
|
|
|
const toolBarAttrs = super.getToolbarAttrs()
|
|
|
|
|
|
|
|
|
|
return ({
|
|
|
|
|
id: this.__id,
|
|
|
|
|
widgetName: toolBarAttrs.widgetName,
|
|
|
|
|
title: this.state.attrs.title,
|
2025-03-28 15:56:17 +05:30
|
|
|
logo: this.state.attrs.logo,
|
2024-09-30 15:54:09 +05:30
|
|
|
size: toolBarAttrs.size,
|
|
|
|
|
...this.state.attrs,
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderContent(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
|
|
|
|
<div className="tw-flex tw-w-full tw-h-[25px] tw-bg-[#c7c7c7] tw-p-1
|
|
|
|
|
tw-overflow-hidden tw-shadow-xl tw-place-items-center">
|
|
|
|
|
<div className="tw-text-sm">{this.getAttrValue("title")}</div>
|
|
|
|
|
<div className="tw-ml-auto tw-flex tw-gap-1 tw-place-items-center">
|
|
|
|
|
<div className="tw-bg-yellow-400 tw-rounded-full tw-w-[15px] tw-h-[15px]">
|
|
|
|
|
</div>
|
|
|
|
|
<div className="tw-bg-blue-400 tw-rounded-full tw-w-[15px] tw-h-[15px]">
|
|
|
|
|
</div>
|
|
|
|
|
<div className="tw-bg-red-400 tw-rounded-full tw-w-[15px] tw-h-[15px]">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="tw-p-2 tw-w-full tw-relative tw-h-full tw-overflow-hidden tw-content-start"
|
2025-03-22 11:11:19 +05:30
|
|
|
ref={this.styleAreaRef}
|
2024-09-30 15:54:09 +05:30
|
|
|
style={this.state.widgetInnerStyling}>
|
2025-03-28 15:56:17 +05:30
|
|
|
{this.renderTkinterLayout()}
|
2024-09-30 15:54:09 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default MainWindow
|