Skip to content

Commit e6c8cd4

Browse files
improvement - added icons in editor panel
1 parent 9c6fb8b commit e6c8cd4

File tree

9 files changed

+574
-103
lines changed

9 files changed

+574
-103
lines changed

.github/workflows/build-and-release.yml

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,45 @@ name: Build EXE and Release
33
on:
44
push:
55
branches:
6-
- main
6+
- main
7+
8+
permissions:
9+
contents: write
710

811
jobs:
912
build:
1013
runs-on: windows-latest
1114

1215
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@v3
15-
16-
- name: Set up Python
17-
uses: actions/setup-python@v4
18-
with:
19-
python-version: '3.13.2'
20-
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install -r requirements.txt
25-
pip install pyinstaller
26-
27-
- name: Build executable with PyInstaller
28-
run: |
29-
pyinstaller app.py --onefile --noconsole --name c_editor
30-
31-
- name: Get short commit hash
32-
id: vars
33-
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
34-
35-
- name: Create GitHub Release
36-
uses: softprops/action-gh-release@v1
37-
with:
38-
tag_name: "build-${{ env.SHORT_SHA }}"
39-
name: "Build ${{ env.SHORT_SHA }}"
40-
draft: false
41-
prerelease: false
42-
files: dist/c_editor.exe
43-
env:
44-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: '3.13.2'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
pip install pyinstaller
29+
30+
- name: Build executable with PyInstaller
31+
run: |
32+
pyinstaller app.py --onefile --noconsole --name c_editor
33+
34+
- name: Get short commit hash
35+
id: vars
36+
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
37+
38+
- name: Create GitHub Release
39+
uses: softprops/action-gh-release@v1
40+
with:
41+
tag_name: "build-${{ env.SHORT_SHA }}"
42+
name: "Build ${{ env.SHORT_SHA }}"
43+
draft: false
44+
prerelease: false
45+
files: dist/c_editor.exe
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

app.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import customtkinter as ctk
22
from ui.theme import setup_theme
3-
from ui.widgets import create_editor, create_output, create_menu
3+
from ui.widgets import create_editor, create_output, create_menu, create_status_bar
44
from utils.highlighter import highlight
55

66
app = ctk.CTk()
7-
app.geometry("1000x750")
8-
app.title("C Code Editor & Runner")
7+
app.geometry("1200x750")
8+
app.title("ChiX - C Code Editor & Runner")
99

1010
setup_theme()
1111

@@ -14,6 +14,9 @@
1414
"current_file": None,
1515
"editor": None,
1616
"output": None,
17+
"app": app,
18+
"line_numbers": None,
19+
"status_bar": None,
1720
}
1821

1922
# === Toolbar Menu (Top) ===
@@ -23,12 +26,15 @@
2326
main_frame = ctk.CTkFrame(app)
2427
main_frame.pack(fill="both", expand=True)
2528

26-
# === Code Editor (Middle) ===
27-
state["editor"] = create_editor(main_frame)
29+
# === Code Editor (Middle) with line numbers ===
30+
state["editor"] = create_editor(main_frame, state)
2831

2932
# === Output Console (Bottom) ===
3033
state["output"] = create_output(main_frame)
3134

35+
# === Status Bar (Bottom) ===
36+
state["status_bar"] = create_status_bar(app, state)
37+
3238
# === Default Template ===
3339
starter = """#include <stdio.h>
3440

@@ -43,4 +49,8 @@
4349
state["editor"].insert("1.0", starter)
4450
highlight(state["editor"])
4551

46-
app.mainloop()
52+
# === Application info ===
53+
credits = "ChiX Editor by Prakhar Doneria | Open Source: github.com/PrakharDoneria/ChiX"
54+
state["status_bar"].set_credits(credits)
55+
56+
app.mainloop()

compiler/compiler.py

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,52 @@
11
import subprocess
2+
import os
3+
import shutil
24

35
def check_gcc_installed():
4-
"""Check if gcc (MinGW) is available in PATH."""
6+
"""Check if GCC is installed and available in PATH"""
57
try:
6-
result = subprocess.run(["gcc", "--version"], capture_output=True, text=True)
7-
return result.returncode == 0
8+
# Try to run gcc --version to check if GCC is installed
9+
subprocess.run(['gcc', '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10+
return True
811
except FileNotFoundError:
912
return False
1013

11-
def compile_c_code(source_path: str, exe_path: str):
12-
"""Compile the C file using gcc and return status and message."""
13-
compile_cmd = ["gcc", source_path, "-o", exe_path]
14-
14+
def compile_c_code(source_path, output_path):
15+
"""Compiles C source code with GCC
16+
17+
Args:
18+
source_path: Path to .c source file
19+
output_path: Path to output executable
20+
21+
Returns:
22+
(success, message): Tuple containing success status and output message
23+
"""
24+
if not os.path.exists(source_path):
25+
return False, "[ERROR] Source file not found"
26+
27+
# Delete output file if it already exists
28+
if os.path.exists(output_path):
29+
try:
30+
os.remove(output_path)
31+
except:
32+
return False, "[ERROR] Could not remove previous executable"
33+
34+
# Compile the code
1535
try:
16-
result = subprocess.run(compile_cmd, capture_output=True, text=True)
17-
if result.returncode != 0:
18-
return False, f"[Compilation Error]\n{result.stderr}"
19-
return True, "[Compilation Successful]\n"
36+
result = subprocess.run(
37+
['gcc', source_path, '-o', output_path],
38+
stdout=subprocess.PIPE,
39+
stderr=subprocess.PIPE,
40+
text=True
41+
)
42+
43+
# Check if compilation was successful
44+
if result.returncode == 0:
45+
return True, "[SUCCESS] Compilation completed. Running program..."
46+
else:
47+
# Return compilation errors
48+
error_msg = result.stderr if result.stderr else "Unknown compilation error"
49+
return False, f"[ERROR] Compilation failed:\n{error_msg}"
50+
2051
except Exception as e:
21-
return False, f"[Error] Failed to compile: {e}"
52+
return False, f"[ERROR] Compilation process failed: {str(e)}"

core/file_ops.py

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,95 @@
1+
import customtkinter as ctk
12
from tkinter import filedialog
3+
import os
24

35
def new_file(state):
4-
state["current_file"] = None
5-
state["editor"].delete("1.0", "end")
6-
state["output"].delete("1.0", "end")
6+
"""Create a new file and clear the editor"""
7+
if state["editor"]:
8+
state["editor"].delete("1.0", "end")
9+
state["current_file"] = None
10+
11+
# Update status bar if available
12+
if "status_bar" in state and state["status_bar"]:
13+
state["status_bar"].update_file_info()
14+
15+
# Set window title
16+
if "app" in state and state["app"]:
17+
state["app"].title("ChiX - C Code Editor & Runner")
718

8-
def open_file(state, highlight):
9-
path = filedialog.askopenfilename(filetypes=[("C Files", "*.c")])
10-
if path:
11-
with open(path, "r") as file:
12-
code = file.read()
13-
state["editor"].delete("1.0", "end")
14-
state["editor"].insert("1.0", code)
15-
state["current_file"] = path
16-
highlight(state["editor"])
19+
def open_file(state, highlight_func=None):
20+
"""Open a file and load it into the editor"""
21+
file_path = filedialog.askopenfilename(
22+
filetypes=[
23+
("C Files", "*.c"),
24+
("Header Files", "*.h"),
25+
("All Files", "*.*")
26+
]
27+
)
28+
29+
if file_path:
30+
try:
31+
with open(file_path, "r") as file:
32+
content = file.read()
33+
if state["editor"]:
34+
state["editor"].delete("1.0", "end")
35+
state["editor"].insert("1.0", content)
36+
state["current_file"] = file_path
37+
38+
# Apply syntax highlighting if function provided
39+
if highlight_func:
40+
highlight_func(state["editor"])
41+
42+
# Update status bar if available
43+
if "status_bar" in state and state["status_bar"]:
44+
state["status_bar"].update_file_info(file_path)
45+
46+
# Set window title
47+
if "app" in state and state["app"]:
48+
filename = os.path.basename(file_path)
49+
state["app"].title(f"ChiX - {filename}")
50+
51+
except Exception as e:
52+
if state["output"]:
53+
state["output"].insert("end", f"Error opening file: {e}\n")
1754

1855
def save_file(state):
56+
"""Save the current file"""
1957
if state["current_file"]:
20-
with open(state["current_file"], "w") as file:
21-
file.write(state["editor"].get("1.0", "end-1c"))
58+
try:
59+
content = state["editor"].get("1.0", "end-1c")
60+
with open(state["current_file"], "w") as file:
61+
file.write(content)
62+
63+
if state["output"]:
64+
state["output"].delete("1.0", "end")
65+
state["output"].insert("end", f"File saved: {state['current_file']}\n")
66+
67+
except Exception as e:
68+
if state["output"]:
69+
state["output"].insert("end", f"Error saving file: {e}\n")
2270
else:
2371
save_file_as(state)
2472

2573
def save_file_as(state):
26-
path = filedialog.asksaveasfilename(defaultextension=".c", filetypes=[("C Files", "*.c")])
27-
if path:
28-
state["current_file"] = path
29-
with open(path, "w") as file:
30-
file.write(state["editor"].get("1.0", "end-1c"))
74+
"""Save the current file as a new file"""
75+
file_path = filedialog.asksaveasfilename(
76+
defaultextension=".c",
77+
filetypes=[
78+
("C Files", "*.c"),
79+
("Header Files", "*.h"),
80+
("All Files", "*.*")
81+
]
82+
)
83+
84+
if file_path:
85+
state["current_file"] = file_path
86+
save_file(state)
87+
88+
# Update status bar if available
89+
if "status_bar" in state and state["status_bar"]:
90+
state["status_bar"].update_file_info(file_path)
91+
92+
# Set window title
93+
if "app" in state and state["app"]:
94+
filename = os.path.basename(file_path)
95+
state["app"].title(f"ChiX - {filename}")

core/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ def run_code(state):
2525
if platform.system() == "Windows":
2626
subprocess.Popen(f'start cmd /k "{exe}"', shell=True)
2727
else:
28-
subprocess.Popen(['x-terminal-emulator', '-e', exe])
28+
subprocess.Popen(['x-terminal-emulator', '-e', exe])

requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
customtkinter
22
pygments
3-
pyinstaller
3+
pyinstaller
4+
keyboard
5+
ttkbootstrap
6+
pillow

ui/theme.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import customtkinter as ctk
22

33
def setup_theme():
4+
# Set appearance mode and theme
45
ctk.set_appearance_mode("dark")
56
ctk.set_default_color_theme("blue")
7+
8+
# Theme configuration for widgets - using the correct structure
9+
try:
10+
# Adjust button corner radius
11+
ctk.ThemeManager.theme["CTkButton"]["corner_radius"] = 4
12+
ctk.ThemeManager.theme["CTkButton"]["border_width"] = 0
13+
14+
# Try to modify button colors if possible
15+
if "fg_color" in ctk.ThemeManager.theme["CTkButton"]:
16+
ctk.ThemeManager.theme["CTkButton"]["fg_color"] = ["#3e79cc", "#3e79cc"]
17+
if "hover_color" in ctk.ThemeManager.theme["CTkButton"]:
18+
ctk.ThemeManager.theme["CTkButton"]["hover_color"] = ["#5294e2", "#5294e2"]
19+
except (KeyError, AttributeError):
20+
# If we can't access theme directly, just skip custom styling
21+
pass

0 commit comments

Comments
 (0)