Frontend-And-Backend 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- frontend_and_backend-0.1.1/.idea/.gitignore +3 -0
- frontend_and_backend-0.1.1/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- frontend_and_backend-0.1.1/.idea/misc.xml +7 -0
- frontend_and_backend-0.1.1/.idea/modules.xml +8 -0
- frontend_and_backend-0.1.1/.idea/pythonProject2.iml +8 -0
- frontend_and_backend-0.1.1/.idea/workspace.xml +61 -0
- frontend_and_backend-0.1.1/.pypirc +3 -0
- frontend_and_backend-0.1.1/LICENSE +21 -0
- frontend_and_backend-0.1.1/PKG-INFO +12 -0
- frontend_and_backend-0.1.1/README.md +1 -0
- frontend_and_backend-0.1.1/pyproject.toml +19 -0
- frontend_and_backend-0.1.1/src/frontend_and_backend/__init__.py +3 -0
- frontend_and_backend-0.1.1/src/frontend_and_backend/dataManager.py +51 -0
- frontend_and_backend-0.1.1/src/frontend_and_backend/screenGui/__init__.py +3 -0
- frontend_and_backend-0.1.1/src/frontend_and_backend/screenGui/core.py +360 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="Black">
|
|
4
|
+
<option name="sdkName" value="Python 3.12 (pythonProject2)" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (pythonProject2)" project-jdk-type="Python SDK" />
|
|
7
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/pythonProject2.iml" filepath="$PROJECT_DIR$/.idea/pythonProject2.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="PYTHON_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AutoImportSettings">
|
|
4
|
+
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ChangeListManager">
|
|
7
|
+
<list default="true" id="b46feabd-e3ba-4118-bfa6-f9339bd60a29" name="Changes" comment="" />
|
|
8
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
9
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
10
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
11
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
12
|
+
</component>
|
|
13
|
+
<component name="FileTemplateManagerImpl">
|
|
14
|
+
<option name="RECENT_TEMPLATES">
|
|
15
|
+
<list>
|
|
16
|
+
<option value="Python Script" />
|
|
17
|
+
</list>
|
|
18
|
+
</option>
|
|
19
|
+
</component>
|
|
20
|
+
<component name="ProjectColorInfo">{
|
|
21
|
+
"associatedIndex": 4
|
|
22
|
+
}</component>
|
|
23
|
+
<component name="ProjectId" id="3MMemKZb5syeUFXMTetpFliEbES" />
|
|
24
|
+
<component name="ProjectViewState">
|
|
25
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
26
|
+
<option name="showLibraryContents" value="true" />
|
|
27
|
+
</component>
|
|
28
|
+
<component name="PropertiesComponent">{
|
|
29
|
+
"keyToString": {
|
|
30
|
+
"Python.Main.executor": "Run",
|
|
31
|
+
"Python.app.executor": "Run",
|
|
32
|
+
"Python.core.executor": "Run",
|
|
33
|
+
"RunOnceActivity.ShowReadmeOnStart": "true"
|
|
34
|
+
}
|
|
35
|
+
}</component>
|
|
36
|
+
<component name="RecentsManager">
|
|
37
|
+
<key name="MoveFile.RECENT_KEYS">
|
|
38
|
+
<recent name="E:\pythonProject2\src" />
|
|
39
|
+
<recent name="E:\pythonProject2" />
|
|
40
|
+
<recent name="E:\pythonProject2\DataManager" />
|
|
41
|
+
</key>
|
|
42
|
+
</component>
|
|
43
|
+
<component name="SharedIndexes">
|
|
44
|
+
<attachedChunks>
|
|
45
|
+
<set>
|
|
46
|
+
<option value="bundled-python-sdk-babbdf50b680-746f403e7f0c-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-241.15989.155" />
|
|
47
|
+
</set>
|
|
48
|
+
</attachedChunks>
|
|
49
|
+
</component>
|
|
50
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
51
|
+
<component name="TaskManager">
|
|
52
|
+
<task active="true" id="Default" summary="Default task">
|
|
53
|
+
<changelist id="b46feabd-e3ba-4118-bfa6-f9339bd60a29" name="Changes" comment="" />
|
|
54
|
+
<created>1795165021937</created>
|
|
55
|
+
<option name="number" value="Default" />
|
|
56
|
+
<option name="presentableId" value="Default" />
|
|
57
|
+
<updated>1795165021937</updated>
|
|
58
|
+
</task>
|
|
59
|
+
<servers />
|
|
60
|
+
</component>
|
|
61
|
+
</project>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Muhammed Nehan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: Frontend_And_Backend
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A collection of useful Python utilities.
|
|
5
|
+
Author-email: Nehan <muhammednehanpt@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Requires-Dist: pillow>=10.0.0
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
This project is made for who just want simple python With frontend and backend code
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This project is made for who just want simple python With frontend and backend code
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "Frontend_And_Backend"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
license = "MIT"
|
|
9
|
+
license-files = ["LICENSE"]
|
|
10
|
+
description = "A collection of useful Python utilities."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
authors = [{ name = "Nehan", email = "muhammednehanpt@gmail.com" }]
|
|
14
|
+
dependencies = [
|
|
15
|
+
# List any external libraries your kit needs, e.g., "requests>=2.28.0"
|
|
16
|
+
"pillow>=10.0.0",
|
|
17
|
+
]
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/frontend_and_backend"]
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sqlite3
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DatabaseManager:
|
|
6
|
+
def __init__(self, db_path: str, db_name: str):
|
|
7
|
+
os.makedirs(db_path, exist_ok=True)
|
|
8
|
+
|
|
9
|
+
if not db_name.endswith(".db"):
|
|
10
|
+
db_name += ".db"
|
|
11
|
+
|
|
12
|
+
self.full_path = os.path.join(db_path, db_name)
|
|
13
|
+
self._init_table()
|
|
14
|
+
|
|
15
|
+
def _connect(self):
|
|
16
|
+
return sqlite3.connect(self.full_path)
|
|
17
|
+
|
|
18
|
+
def _init_table(self):
|
|
19
|
+
"""Creates the storage table with an INTEGER primary key."""
|
|
20
|
+
with self._connect() as conn:
|
|
21
|
+
conn.execute("""
|
|
22
|
+
CREATE TABLE IF NOT EXISTS records (
|
|
23
|
+
id INTEGER PRIMARY KEY,
|
|
24
|
+
data TEXT NOT NULL
|
|
25
|
+
)
|
|
26
|
+
""")
|
|
27
|
+
|
|
28
|
+
def _validate_id(self, item_id: int):
|
|
29
|
+
"""Ensures the ID is strictly an integer (and not a boolean)."""
|
|
30
|
+
if isinstance(item_id, bool) or not isinstance(item_id, int):
|
|
31
|
+
raise TypeError(f"ID must be an integer, got {type(item_id).__name__}")
|
|
32
|
+
|
|
33
|
+
def add(self, item_id: int, data: str):
|
|
34
|
+
"""Adds an item with a numeric ID."""
|
|
35
|
+
self._validate_id(item_id)
|
|
36
|
+
with self._connect() as conn:
|
|
37
|
+
conn.execute(
|
|
38
|
+
"INSERT OR REPLACE INTO records (id, data) VALUES (?, ?)",
|
|
39
|
+
(item_id, str(data))
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def read(self, item_id: int) -> str | None:
|
|
43
|
+
"""Reads the data assigned to the numeric ID."""
|
|
44
|
+
self._validate_id(item_id)
|
|
45
|
+
with self._connect() as conn:
|
|
46
|
+
cursor = conn.execute(
|
|
47
|
+
"SELECT data FROM records WHERE id = ?",
|
|
48
|
+
(item_id,)
|
|
49
|
+
)
|
|
50
|
+
row = cursor.fetchone()
|
|
51
|
+
return row[0] if row else None
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import tkinter as tk
|
|
4
|
+
from tkinter import messagebox, ttk
|
|
5
|
+
from typing import Callable, Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GUI:
|
|
9
|
+
def __init__(
|
|
10
|
+
self,
|
|
11
|
+
layout_file: str = "layout.json",
|
|
12
|
+
width: int = 500,
|
|
13
|
+
height: int = 400,
|
|
14
|
+
title: str = "My GUI App",
|
|
15
|
+
icon: Optional[str] = None,
|
|
16
|
+
):
|
|
17
|
+
self.layout_file = layout_file
|
|
18
|
+
self.width = width
|
|
19
|
+
self.height = height
|
|
20
|
+
self.title = title
|
|
21
|
+
self.icon = icon
|
|
22
|
+
self._editor_mode = False
|
|
23
|
+
self._widgets = {}
|
|
24
|
+
self._bindings = {}
|
|
25
|
+
self.root: Optional[tk.Tk] = None
|
|
26
|
+
|
|
27
|
+
def _apply_icon(self, window: tk.Tk):
|
|
28
|
+
"""Applies a crisp multi-resolution window icon using Lanczos resampling."""
|
|
29
|
+
if not self.icon or not os.path.exists(self.icon):
|
|
30
|
+
return
|
|
31
|
+
try:
|
|
32
|
+
if self.icon.lower().endswith(".ico"):
|
|
33
|
+
window.iconbitmap(self.icon)
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
from PIL import Image, ImageTk
|
|
38
|
+
base_img = Image.open(self.icon).convert("RGBA")
|
|
39
|
+
sizes = [16, 32, 48, 64]
|
|
40
|
+
icons = [
|
|
41
|
+
ImageTk.PhotoImage(base_img.resize((s, s), Image.Resampling.LANCZOS))
|
|
42
|
+
for s in sizes
|
|
43
|
+
]
|
|
44
|
+
window.iconphoto(True, *icons)
|
|
45
|
+
window._icon_refs = icons
|
|
46
|
+
except ImportError:
|
|
47
|
+
img = tk.PhotoImage(file=self.icon)
|
|
48
|
+
window.iconphoto(True, img)
|
|
49
|
+
window._icon_ref = img
|
|
50
|
+
except tk.TclError:
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
def editor(self, enabled: bool = True):
|
|
54
|
+
"""Toggle between visual drag-and-drop editor mode and live runtime mode."""
|
|
55
|
+
self._editor_mode = enabled
|
|
56
|
+
|
|
57
|
+
def on_click(self, widget_id: str, callback: Callable):
|
|
58
|
+
"""Hook a Python function to a Button's ID."""
|
|
59
|
+
self._bindings[widget_id] = callback
|
|
60
|
+
|
|
61
|
+
def get_text(self, widget_id: str) -> str:
|
|
62
|
+
"""Read text from an InputBox or TextView by ID."""
|
|
63
|
+
widget = self._widgets.get(widget_id)
|
|
64
|
+
if isinstance(widget, tk.Entry):
|
|
65
|
+
return widget.get()
|
|
66
|
+
elif isinstance(widget, tk.Label):
|
|
67
|
+
return widget.cget("text")
|
|
68
|
+
raise KeyError(f"No readable widget found with ID '{widget_id}'")
|
|
69
|
+
|
|
70
|
+
def set_text(self, widget_id: str, value: str):
|
|
71
|
+
"""Set text on a TextView or InputBox by ID."""
|
|
72
|
+
widget = self._widgets.get(widget_id)
|
|
73
|
+
if isinstance(widget, tk.Label):
|
|
74
|
+
widget.config(text=str(value))
|
|
75
|
+
elif isinstance(widget, tk.Entry):
|
|
76
|
+
widget.delete(0, tk.END)
|
|
77
|
+
widget.insert(0, str(value))
|
|
78
|
+
else:
|
|
79
|
+
raise KeyError(f"No writable widget found with ID '{widget_id}'")
|
|
80
|
+
|
|
81
|
+
def find_by_id(self, widget_id: str):
|
|
82
|
+
"""Direct access to the underlying Tkinter widget (like Android's findViewById)."""
|
|
83
|
+
return self._widgets.get(widget_id)
|
|
84
|
+
|
|
85
|
+
def run(self):
|
|
86
|
+
"""Starts either the visual editor or the live app."""
|
|
87
|
+
if self._editor_mode:
|
|
88
|
+
self._launch_editor()
|
|
89
|
+
else:
|
|
90
|
+
self._launch_runtime()
|
|
91
|
+
|
|
92
|
+
# ==========================================
|
|
93
|
+
# RUNTIME MODE (Responsive Scaling Enabled)
|
|
94
|
+
# ==========================================
|
|
95
|
+
def _launch_runtime(self):
|
|
96
|
+
if not os.path.exists(self.layout_file):
|
|
97
|
+
raise FileNotFoundError(
|
|
98
|
+
f"Layout file '{self.layout_file}' not found. Run with gui.editor(True) first to design and save it."
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
with open(self.layout_file, "r", encoding="utf-8") as f:
|
|
102
|
+
items = json.load(f)
|
|
103
|
+
|
|
104
|
+
self.root = tk.Tk()
|
|
105
|
+
self.root.title(self.title)
|
|
106
|
+
self.root.geometry(f"{self.width}x{self.height}")
|
|
107
|
+
self.root.resizable(True, True) # Allow any window size or maximize
|
|
108
|
+
self._apply_icon(self.root)
|
|
109
|
+
|
|
110
|
+
base_w = float(self.width)
|
|
111
|
+
base_h = float(self.height)
|
|
112
|
+
layout_records = []
|
|
113
|
+
|
|
114
|
+
for item in items:
|
|
115
|
+
w_type = item["type"]
|
|
116
|
+
w_id = item["id"]
|
|
117
|
+
x, y = item["x"], item["y"]
|
|
118
|
+
text = item.get("text", "")
|
|
119
|
+
char_width = item.get("width", 15)
|
|
120
|
+
base_font_size = 10 if w_type == "Button" else 11
|
|
121
|
+
is_bold = (w_type == "Button")
|
|
122
|
+
|
|
123
|
+
if w_type == "InputBox":
|
|
124
|
+
widget = tk.Entry(self.root, width=char_width, font=("Arial", base_font_size))
|
|
125
|
+
widget.insert(0, text)
|
|
126
|
+
elif w_type == "Button":
|
|
127
|
+
cmd = self._bindings.get(w_id)
|
|
128
|
+
widget = tk.Button(self.root, text=text, width=char_width, command=cmd, font=("Arial", base_font_size, "bold"))
|
|
129
|
+
elif w_type == "TextView":
|
|
130
|
+
widget = tk.Label(self.root, text=text, font=("Arial", base_font_size))
|
|
131
|
+
else:
|
|
132
|
+
continue
|
|
133
|
+
|
|
134
|
+
widget.place(x=x, y=y)
|
|
135
|
+
self._widgets[w_id] = widget
|
|
136
|
+
layout_records.append({
|
|
137
|
+
"widget": widget,
|
|
138
|
+
"type": w_type,
|
|
139
|
+
"base_x": x,
|
|
140
|
+
"base_y": y,
|
|
141
|
+
"base_width": char_width,
|
|
142
|
+
"base_font": base_font_size,
|
|
143
|
+
"bold": is_bold,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
def on_resize(event):
|
|
147
|
+
# Only react to top-level root window resize events
|
|
148
|
+
if event.widget is not self.root:
|
|
149
|
+
return
|
|
150
|
+
if event.width <= 1 or event.height <= 1:
|
|
151
|
+
return
|
|
152
|
+
|
|
153
|
+
scale_x = event.width / base_w
|
|
154
|
+
scale_y = event.height / base_h
|
|
155
|
+
font_scale = min(scale_x, scale_y)
|
|
156
|
+
|
|
157
|
+
for rec in layout_records:
|
|
158
|
+
new_x = int(rec["base_x"] * scale_x)
|
|
159
|
+
new_y = int(rec["base_y"] * scale_y)
|
|
160
|
+
new_font_size = max(7, int(rec["base_font"] * font_scale))
|
|
161
|
+
|
|
162
|
+
font_tuple = ("Arial", new_font_size, "bold") if rec["bold"] else ("Arial", new_font_size)
|
|
163
|
+
rec["widget"].config(font=font_tuple)
|
|
164
|
+
|
|
165
|
+
if rec["type"] in ("InputBox", "Button"):
|
|
166
|
+
# Keep character width proportional to horizontal vs font scaling
|
|
167
|
+
adjusted_chars = max(2, int(rec["base_width"] * (scale_x / font_scale)))
|
|
168
|
+
rec["widget"].config(width=adjusted_chars)
|
|
169
|
+
|
|
170
|
+
rec["widget"].place(x=new_x, y=new_y)
|
|
171
|
+
|
|
172
|
+
self.root.bind("<Configure>", on_resize)
|
|
173
|
+
self.root.mainloop()
|
|
174
|
+
|
|
175
|
+
# ==========================================
|
|
176
|
+
# VISUAL EDITOR MODE (gui.editor(True))
|
|
177
|
+
# ==========================================
|
|
178
|
+
def _launch_editor(self):
|
|
179
|
+
editor_win = tk.Tk()
|
|
180
|
+
editor_win.title(f"Visual Layout Editor - {self.layout_file}")
|
|
181
|
+
editor_win.geometry(f"{self.width + 380}x{max(self.height + 60, 480)}")
|
|
182
|
+
self._apply_icon(editor_win)
|
|
183
|
+
|
|
184
|
+
items_data = []
|
|
185
|
+
selected_index = [None]
|
|
186
|
+
canvas_widgets = []
|
|
187
|
+
|
|
188
|
+
# --- Left Panel: Palette ---
|
|
189
|
+
palette = tk.Frame(editor_win, width=150, bg="#2b2b2b", padx=10, pady=10)
|
|
190
|
+
palette.pack(side=tk.LEFT, fill=tk.Y)
|
|
191
|
+
tk.Label(palette, text="PALETTE", fg="white", bg="#2b2b2b", font=("Arial", 10, "bold")).pack(pady=(0, 10))
|
|
192
|
+
|
|
193
|
+
# --- Right Panel: Properties & ID Inspector ---
|
|
194
|
+
inspector = tk.Frame(editor_win, width=210, bg="#f0f0f0", padx=10, pady=10)
|
|
195
|
+
inspector.pack(side=tk.RIGHT, fill=tk.Y)
|
|
196
|
+
tk.Label(inspector, text="ATTRIBUTES", bg="#f0f0f0", font=("Arial", 10, "bold")).pack(pady=(0, 10))
|
|
197
|
+
|
|
198
|
+
tk.Label(inspector, text="Widget ID:", bg="#f0f0f0").pack(anchor="w")
|
|
199
|
+
id_var = tk.StringVar()
|
|
200
|
+
tk.Entry(inspector, textvariable=id_var).pack(fill=tk.X, pady=(0, 8))
|
|
201
|
+
|
|
202
|
+
tk.Label(inspector, text="Text / Placeholder:", bg="#f0f0f0").pack(anchor="w")
|
|
203
|
+
text_var = tk.StringVar()
|
|
204
|
+
tk.Entry(inspector, textvariable=text_var).pack(fill=tk.X, pady=(0, 8))
|
|
205
|
+
|
|
206
|
+
tk.Label(inspector, text="Width (chars):", bg="#f0f0f0").pack(anchor="w")
|
|
207
|
+
width_var = tk.IntVar(value=15)
|
|
208
|
+
tk.Entry(inspector, textvariable=width_var).pack(fill=tk.X, pady=(0, 12))
|
|
209
|
+
|
|
210
|
+
# --- Center Panel: Design Canvas ---
|
|
211
|
+
center_frame = tk.Frame(editor_win, bg="#dcdcdc", padx=10, pady=10)
|
|
212
|
+
center_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
213
|
+
|
|
214
|
+
canvas = tk.Frame(center_frame, width=self.width, height=self.height, bg="white", relief=tk.SUNKEN, bd=2)
|
|
215
|
+
canvas.pack()
|
|
216
|
+
canvas.pack_propagate(False)
|
|
217
|
+
|
|
218
|
+
def select_item(idx):
|
|
219
|
+
selected_index[0] = idx
|
|
220
|
+
data = items_data[idx]
|
|
221
|
+
id_var.set(data["id"])
|
|
222
|
+
text_var.set(data["text"])
|
|
223
|
+
width_var.set(data["width"])
|
|
224
|
+
render_canvas()
|
|
225
|
+
|
|
226
|
+
def apply_properties():
|
|
227
|
+
idx = selected_index[0]
|
|
228
|
+
if idx is None:
|
|
229
|
+
return
|
|
230
|
+
new_id = id_var.get().strip()
|
|
231
|
+
if not new_id:
|
|
232
|
+
messagebox.showerror("Invalid ID", "Widget ID cannot be empty.")
|
|
233
|
+
return
|
|
234
|
+
for i, item in enumerate(items_data):
|
|
235
|
+
if i != idx and item["id"] == new_id:
|
|
236
|
+
messagebox.showerror("Duplicate ID", f"ID '{new_id}' is already used.")
|
|
237
|
+
return
|
|
238
|
+
|
|
239
|
+
items_data[idx]["id"] = new_id
|
|
240
|
+
items_data[idx]["text"] = text_var.get()
|
|
241
|
+
try:
|
|
242
|
+
items_data[idx]["width"] = int(width_var.get())
|
|
243
|
+
except ValueError:
|
|
244
|
+
pass
|
|
245
|
+
render_canvas()
|
|
246
|
+
|
|
247
|
+
def delete_selected():
|
|
248
|
+
idx = selected_index[0]
|
|
249
|
+
if idx is not None:
|
|
250
|
+
items_data.pop(idx)
|
|
251
|
+
selected_index[0] = None
|
|
252
|
+
id_var.set("")
|
|
253
|
+
text_var.set("")
|
|
254
|
+
render_canvas()
|
|
255
|
+
|
|
256
|
+
def render_canvas():
|
|
257
|
+
for w in canvas_widgets:
|
|
258
|
+
w.destroy()
|
|
259
|
+
canvas_widgets.clear()
|
|
260
|
+
|
|
261
|
+
for idx, item in enumerate(items_data):
|
|
262
|
+
is_selected = (idx == selected_index[0])
|
|
263
|
+
border_color = "#0078d7" if is_selected else "#cccccc"
|
|
264
|
+
|
|
265
|
+
wrapper = tk.Frame(canvas, bg=border_color, padx=2, pady=2)
|
|
266
|
+
wrapper.place(x=item["x"], y=item["y"])
|
|
267
|
+
|
|
268
|
+
if item["type"] == "InputBox":
|
|
269
|
+
w = tk.Entry(wrapper, width=item["width"], font=("Arial", 11))
|
|
270
|
+
w.insert(0, item["text"])
|
|
271
|
+
elif item["type"] == "Button":
|
|
272
|
+
w = tk.Button(wrapper, text=item["text"], width=item["width"], font=("Arial", 10, "bold"))
|
|
273
|
+
elif item["type"] == "TextView":
|
|
274
|
+
w = tk.Label(wrapper, text=item["text"], font=("Arial", 11), bg="white")
|
|
275
|
+
|
|
276
|
+
w.pack()
|
|
277
|
+
|
|
278
|
+
if is_selected:
|
|
279
|
+
tag = tk.Label(canvas, text=f"@{item['id']}", bg="#0078d7", fg="white", font=("Arial", 8))
|
|
280
|
+
tag.place(x=item["x"], y=max(0, item["y"] - 18))
|
|
281
|
+
canvas_widgets.append(tag)
|
|
282
|
+
|
|
283
|
+
def make_drag_handlers(index, frame):
|
|
284
|
+
drag_data = {"x": 0, "y": 0}
|
|
285
|
+
|
|
286
|
+
def on_press(event):
|
|
287
|
+
select_item(index)
|
|
288
|
+
drag_data["x"] = event.x
|
|
289
|
+
drag_data["y"] = event.y
|
|
290
|
+
|
|
291
|
+
def on_drag(event):
|
|
292
|
+
new_x = frame.winfo_x() + (event.x - drag_data["x"])
|
|
293
|
+
new_y = frame.winfo_y() + (event.y - drag_data["y"])
|
|
294
|
+
new_x = max(0, min(self.width - 30, new_x))
|
|
295
|
+
new_y = max(0, min(self.height - 20, new_y))
|
|
296
|
+
items_data[index]["x"] = new_x
|
|
297
|
+
items_data[index]["y"] = new_y
|
|
298
|
+
frame.place(x=new_x, y=new_y)
|
|
299
|
+
|
|
300
|
+
def on_release(event):
|
|
301
|
+
render_canvas()
|
|
302
|
+
|
|
303
|
+
return on_press, on_drag, on_release
|
|
304
|
+
|
|
305
|
+
press_fn, drag_fn, release_fn = make_drag_handlers(idx, wrapper)
|
|
306
|
+
for target in (wrapper, w):
|
|
307
|
+
target.bind("<Button-1>", press_fn)
|
|
308
|
+
target.bind("<B1-Motion>", drag_fn)
|
|
309
|
+
target.bind("<ButtonRelease-1>", release_fn)
|
|
310
|
+
|
|
311
|
+
canvas_widgets.append(wrapper)
|
|
312
|
+
|
|
313
|
+
def add_widget(w_type: str):
|
|
314
|
+
count = sum(1 for i in items_data if i["type"] == w_type) + 1
|
|
315
|
+
default_id = f"{w_type.lower()}_{count}"
|
|
316
|
+
default_text = {
|
|
317
|
+
"InputBox": "",
|
|
318
|
+
"Button": "Click Me",
|
|
319
|
+
"TextView": "TextView"
|
|
320
|
+
}[w_type]
|
|
321
|
+
default_width = 18 if w_type == "InputBox" else 12
|
|
322
|
+
|
|
323
|
+
items_data.append({
|
|
324
|
+
"type": w_type,
|
|
325
|
+
"id": default_id,
|
|
326
|
+
"x": 40 + (len(items_data) * 15) % 150,
|
|
327
|
+
"y": 40 + (len(items_data) * 25) % 200,
|
|
328
|
+
"text": default_text,
|
|
329
|
+
"width": default_width
|
|
330
|
+
})
|
|
331
|
+
select_item(len(items_data) - 1)
|
|
332
|
+
|
|
333
|
+
def save_layout():
|
|
334
|
+
with open(self.layout_file, "w", encoding="utf-8") as f:
|
|
335
|
+
json.dump(items_data, f, indent=2)
|
|
336
|
+
messagebox.showinfo("Saved", f"Layout saved to '{self.layout_file}'!")
|
|
337
|
+
|
|
338
|
+
for widget_type in ("InputBox", "Button", "TextView"):
|
|
339
|
+
btn = tk.Button(
|
|
340
|
+
palette,
|
|
341
|
+
text=f"+ {widget_type}",
|
|
342
|
+
bg="#3c3f41",
|
|
343
|
+
fg="white",
|
|
344
|
+
relief=tk.FLAT,
|
|
345
|
+
pady=6,
|
|
346
|
+
command=lambda t=widget_type: add_widget(t)
|
|
347
|
+
)
|
|
348
|
+
btn.pack(fill=tk.X, pady=4)
|
|
349
|
+
|
|
350
|
+
tk.Button(inspector, text="Apply Changes", bg="#0078d7", fg="white", command=apply_properties).pack(fill=tk.X, pady=4)
|
|
351
|
+
tk.Button(inspector, text="Delete Widget", bg="#d9534f", fg="white", command=delete_selected).pack(fill=tk.X, pady=4)
|
|
352
|
+
ttk.Separator(inspector, orient="horizontal").pack(fill=tk.X, pady=15)
|
|
353
|
+
tk.Button(inspector, text="SAVE LAYOUT", bg="#28a745", fg="white", font=("Arial", 10, "bold"), pady=6, command=save_layout).pack(fill=tk.X)
|
|
354
|
+
|
|
355
|
+
if os.path.exists(self.layout_file):
|
|
356
|
+
with open(self.layout_file, "r", encoding="utf-8") as f:
|
|
357
|
+
items_data.extend(json.load(f))
|
|
358
|
+
render_canvas()
|
|
359
|
+
|
|
360
|
+
editor_win.mainloop()
|