Skip to content

Commit 1601016

Browse files
committed
Refactor main.py, add CI/CD pipeline, and improve project structure
Code Organization Refactored main.py from 1200+ lines to ~800 lines with clear section organization Renamed self.import_proyect → self.import_project (fixed typo) Standardized naming conventions and added type hints throughout Improved docstrings and comments for maintainability UI/UX Fixes Fixed #right_sidebar.py layout: Changed from CTkScrollableFrame to CTkFrame with separate scrollable containers for widgets and treeview sections Improved grid layout with fixed row/column weights for better responsiveness Added proper minsize constraints to prevent widget collapse on resize Fixed TreeView widget stretch behavior (set stretch=False, added minwidth=140) Project Infrastructure Created pyproject.toml with project metadata, dependencies, and tool configurations Created requirements.txt with core dependencies (customtkinter, pillow, CTkMessagebox, pyyaml) Added __init__.py to centralize module exports and avoid wildcard imports Implemented proper public/private API definition with __all__ CI/CD Pipeline Added GitHub Actions workflow build.yml: Automated builds for Linux (ubuntu-latest) and Windows (windows-latest) PyInstaller configuration for creating standalone executables Tagged releases trigger automatic compilation and artifact upload Single executable per OS (Linux .tar.gz, Windows .zip) Automatic GitHub Release creation with generated notes Code Quality Removed dangling global app references, now using proper self passing Consolidated repeated code patterns into helper methods Fixed undefined variable references and import paths Improved message queue system with clearer state management Files Added build.yml - CI/CD automation pyproject.toml - Project metadata and build configuration requirements.txt - Dependency management __init__.py - Module API definition Files Modified main.py - Complete refactoring and cleanup right_sidebar.py - Layout fixes and responsiveness improvements How to use Deploy with tags: GitHub Actions will automatically compile and create a Release with executables.
1 parent 9f03b57 commit 1601016

8 files changed

Lines changed: 804 additions & 770 deletions

File tree

.github/workflows/build.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# filepath: /home/thiago/Documentos/GitHub/CTkDesigner/.github/workflows/build.yml
2+
name: Build & Release
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v*' # Trigger solo en tags v1.0.0, v2.0.1, etc.
8+
9+
jobs:
10+
build-linux:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.11'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
pip install pyinstaller
27+
28+
- name: Build with PyInstaller
29+
run: |
30+
pyinstaller --onefile pyinstaller.spec
31+
cd dist
32+
tar -czf CTkDesigner-linux-x64.tar.gz CTkDesigner/
33+
ls -lah
34+
35+
- name: Upload artifact
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: CTkDesigner-linux-x64
39+
path: dist/CTkDesigner-linux-x64.tar.gz
40+
41+
build-windows:
42+
runs-on: windows-latest
43+
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v4
47+
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: '3.11'
52+
53+
- name: Install dependencies
54+
run: |
55+
python -m pip install --upgrade pip
56+
pip install -r requirements.txt
57+
pip install pyinstaller
58+
59+
- name: Build with PyInstaller
60+
run: |
61+
pyinstaller --onefile pyinstaller.spec
62+
cd dist
63+
powershell Compress-Archive -Path CTkDesigner -DestinationPath CTkDesigner-windows-x64.zip
64+
dir
65+
66+
- name: Upload artifact
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: CTkDesigner-windows-x64
70+
path: dist/CTkDesigner-windows-x64.zip
71+
72+
release:
73+
needs: [build-linux, build-windows]
74+
runs-on: ubuntu-latest
75+
76+
steps:
77+
- name: Checkout code
78+
uses: actions/checkout@v4
79+
80+
- name: Download all artifacts
81+
uses: actions/download-artifact@v4
82+
with:
83+
path: artifacts
84+
85+
- name: List artifacts
86+
run: |
87+
find artifacts -type f
88+
89+
- name: Create Release
90+
uses: softprops/action-gh-release@v1
91+
with:
92+
files: |
93+
artifacts/CTkDesigner-linux-x64/CTkDesigner-linux-x64.tar.gz
94+
artifacts/CTkDesigner-windows-x64/CTkDesigner-windows-x64.zip
95+
draft: false
96+
prerelease: false
97+
generate_release_notes: true
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

autosaves/autosave_1749516955.json.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

autosaves/autosave_1749521873.json.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

components/right_sidebar.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
from functions.generic import *
1111
from functions.import_widget import *
1212
import logging
13-
class RightSidebar(ctk.CTkScrollableFrame):
13+
class RightSidebar(ctk.CTkFrame):
1414
TREEVIEW_WIDTH = 180
1515
PADDING = 5
1616

1717
def __init__(self, parent, virtual_window, app):
18-
super().__init__(parent, width=200)
18+
super().__init__(parent, width=220)
1919
self.app = app
2020
self.configure_treeview_style()
2121
self.grid_columnconfigure(0, weight=1)
22+
self.grid_rowconfigure(1, weight=1)
23+
self.grid_rowconfigure(3, weight=1)
2224
self.virtual_window = virtual_window
2325
self.widget_tree = {}
2426
self.buttons = {}
@@ -35,14 +37,19 @@ def configure_treeview_style(self):
3537

3638
def create_widgets_section(self):
3739
ctk.CTkLabel(self, text=self.app.translator.translate("LABEL_WIDGETS_TEXT")).grid(row=0, column=0, padx=self.PADDING, pady=self.PADDING, sticky="w")
40+
41+
self.widgets_scroll = ctk.CTkScrollableFrame(self)
42+
self.widgets_scroll.grid(row=1, column=0, padx=self.PADDING, pady=(0, self.PADDING), sticky="nsew")
43+
self.widgets_scroll.grid_columnconfigure(0, weight=1)
44+
3845
for i, widget in enumerate(widgets):
3946
self.create_widget_button(widget, i + 1, True)
4047
#self.create_widget_button(self.app.translator.translate("IMPORT_WIDGET_BUTTON"), i + 1)
4148

4249
def import_custom_widget(self):
4350
widget=load_classes_from_file(filedialog.askopenfilename(
44-
title=translator.translate("FILE_DIALOG_SELECT_FILE"),
45-
filetypes=[(translator.get("filedialog.file_type"), "*.py"), ("Todos los archivos", "*.*")]
51+
title=self.app.translator.translate("FILE_DIALOG_SELECT_FILE"),
52+
filetypes=[(self.app.translator.get("filedialog.file_type"), "*.py"), ("Todos los archivos", "*.*")]
4653
))
4754
self.app.cross_update_text_info(self.app.translator.translate_with_vars("USER_WIDGET_DETAILS", {"widget": widget}))
4855
self.app.virtual_window._extracted_from_create_and_place_widget_5(widget[0](self.virtual_window), 100, 100)
@@ -55,7 +62,7 @@ def create_widget_button(self, widget:object, row:int, h:str = None):
5562
"""Crea un botón para cada widget y lo agrega a la sección de widgets."""
5663
dic_help = widgets_info.get(self.app.translator.current_language)
5764
btn = ctk.CTkButton(
58-
self,
65+
self.widgets_scroll,
5966
text=widget,
6067
command=self.check_widget(widget),
6168
**BUTTON_STYLE
@@ -76,10 +83,16 @@ def enable_buttons(self):
7683
btn.configure(state="normal")
7784

7885
def create_treeview_section(self):
79-
ctk.CTkLabel(self, text=self.app.translator.translate("LABEL_SCHEME_TEXT")).grid(row=len(widgets) + 1, column=0, padx=self.PADDING, pady=self.PADDING, sticky="w")
80-
self.tree = ttk.Treeview(self, selectmode="browse", show="tree")
81-
self.tree.grid(row=len(widgets) + 2, column=0, padx=self.PADDING, pady=self.PADDING, sticky="nsew")
82-
self.tree.column("#0", width=self.TREEVIEW_WIDTH, stretch=True)
86+
ctk.CTkLabel(self, text=self.app.translator.translate("LABEL_SCHEME_TEXT")).grid(row=2, column=0, padx=self.PADDING, pady=self.PADDING, sticky="w")
87+
88+
self.tree_container = ctk.CTkFrame(self)
89+
self.tree_container.grid(row=3, column=0, padx=self.PADDING, pady=(0, self.PADDING), sticky="nsew")
90+
self.tree_container.grid_columnconfigure(0, weight=1)
91+
self.tree_container.grid_rowconfigure(0, weight=1)
92+
93+
self.tree = ttk.Treeview(self.tree_container, selectmode="browse", show="tree")
94+
self.tree.grid(row=0, column=0, sticky="nsew")
95+
self.tree.column("#0", width=self.TREEVIEW_WIDTH, minwidth=140, stretch=False)
8396
self.tree.heading("#0", text="Widgets")
8497

8598
def add_widget(self, widget:object):

functions/__init__.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
Functions module - Utilidades reutilizables para CTkDesigner.
3+
4+
Expone las funciones públicas de cada submódulo.
5+
"""
6+
7+
# Generic utilities
8+
from .generic import validate_input, hex_to_rgb, parse_color, fix_color_format
9+
10+
# Widget utilities
11+
from .import_widget import load_classes_from_file, get_class_parameters
12+
from .widget_resize import enable_resizable_highlight, remove_remark
13+
14+
# UI utilities
15+
from .sidebars_utils import (
16+
clear_widgets,
17+
update_treeview,
18+
create_property_entry,
19+
create_property_entries,
20+
)
21+
22+
# Animation utilities
23+
from .create_widget_animation import create_widget_with_animation
24+
25+
# Translator manager
26+
from .translator_manager import translator, initialize_translator
27+
28+
__all__ = [
29+
# Generic
30+
"validate_input",
31+
"hex_to_rgb",
32+
"parse_color",
33+
"fix_color_format",
34+
# Import/Widget
35+
"load_classes_from_file",
36+
"get_class_parameters",
37+
"enable_resizable_highlight",
38+
"remove_remark",
39+
# Sidebars
40+
"clear_widgets",
41+
"update_treeview",
42+
"create_property_entry",
43+
"create_property_entries",
44+
# Animation
45+
"create_widget_with_animation",
46+
# Translator
47+
"translator",
48+
"initialize_translator",
49+
]

0 commit comments

Comments
 (0)