Skip to content

Commit

Permalink
Merge pull request #32 from HojdaAdelin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
HojdaAdelin authored Jul 1, 2024
2 parents bd4c68f + b22c2ed commit 0131972
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Fixded save
- Input & Output won't be displayed when populate treeview
- Redraw textbox after find & replace
- Fix run

# Version: 1.4

Expand Down
1 change: 0 additions & 1 deletion imtervale.out

This file was deleted.

1 change: 0 additions & 1 deletion intervale.out

This file was deleted.

Binary file modified src/GUI/__pycache__/gui.cpython-311.pyc
Binary file not shown.
Binary file modified src/GUI/__pycache__/textbox.cpython-311.pyc
Binary file not shown.
8 changes: 4 additions & 4 deletions src/GUI/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def __init__(self, *args, **kwargs):
utility_drop.add_option(option="Run F5", command=lambda:run.run_cpp_file(treeview_frame, scroll.text))
utility_drop.add_option(option="Paint Mode Ctrl+P", command=lambda:open_paint_mode(self))
utility_drop.add_separator()
utility_drop.add_option(option="Start Server", command= lambda:scroll.start_server())
utility_drop.add_option(option="Join Local Server", command=lambda:scroll.start_client())
utility_drop.add_option(option="Disconnect", command=lambda:scroll.disconnect_client())
utility_drop.add_option(option="Server Panel", command=lambda:open_server_panel(self))
utility_drop.add_option(option="Start Server (Beta)", command= lambda:scroll.start_server())
utility_drop.add_option(option="Join Local Server (Beta)", command=lambda:scroll.start_client())
utility_drop.add_option(option="Disconnect (Beta)", command=lambda:scroll.disconnect_client())
utility_drop.add_option(option="Server Panel (Beta)", command=lambda:open_server_panel(self))

statusbar_instance = statusbar.StatusBar(self, text="")
scroll = textbox.ScrollText(self, statusbar_instance)
Expand Down
23 changes: 21 additions & 2 deletions src/GUI/textbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def gui(self, font_size):
'and', 'and_eq', 'asm', 'bitand', 'bitor', 'compl', 'not', 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq',
'true', 'false'
]

self.local_variables = set()
self.current_file = None

def binding(self):
self.text.bind('<Up>', self.on_up_key)
Expand All @@ -102,6 +105,22 @@ def binding(self):
self.text.bind('<space>', self.hide_suggestions) # Hide suggestions on space
self.text.bind("<Escape>", self.hide_suggestions)
self.text.bind_all('<KeyRelease>', self.on_keyrelease_all)
self.text.bind('<<Modified>>', self.on_text_modified)

def on_text_modified(self, event=None):
# Obține textul curent din widget
text = self.text.get("1.0", tk.END)

# Folosim regex pentru a găsi variabile locale
pattern = re.compile(r'\b\w+\b')
matches = pattern.findall(text)
current_word = self.get_current_word()
# Actualizăm setul de variabile locale
self.local_variables = set(matches) - set(self.keywords) - {current_word}
self.text.edit_modified(False)
# Actualizăm sugestiile
if file_menu.return_file() == ".cpp":
self.update_suggestions()

def on_up_key(self, event):
if self.suggestions.winfo_ismapped():
Expand All @@ -115,7 +134,7 @@ def on_up_key(self, event):
return 'break'
else:
return None

def on_down_key(self, event):
if self.suggestions.winfo_ismapped():

Expand Down Expand Up @@ -161,7 +180,7 @@ def update_suggestions(self):

typed_word = self.get_current_word()
if typed_word:
matching_keywords = [kw for kw in self.keywords if kw.startswith(typed_word)]
matching_keywords = [kw for kw in (list(self.local_variables) + self.keywords) if kw.startswith(typed_word)]
if matching_keywords:
self.show_suggestions(matching_keywords)
else:
Expand Down
Binary file modified src/MainMenu/__pycache__/run.cpython-311.pyc
Binary file not shown.
31 changes: 18 additions & 13 deletions src/MainMenu/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,42 @@ def run_cpp_file(tree, text_widget):
if file_path is None:
messagebox.showerror("Error", "No files are open.")
return

if not file_path.endswith(".cpp"):
messagebox.showerror("Error", "Only .cpp files can be run.")
return

# Extragem conținutul din text_widget
code_content = text_widget.get("1.0", "end-1c")

# Creăm un fișier temporar pentru a scrie codul
with tempfile.NamedTemporaryFile(delete=False, suffix=".cpp", mode='w', encoding='utf-8') as temp_file:
# Obținem directorul fișierului curent
current_file_dir = os.path.dirname(file_path)

# Creăm un fișier temporar în directorul curent al fișierului
with tempfile.NamedTemporaryFile(delete=False, suffix=".cpp", mode='w', encoding='utf-8', dir=current_file_dir) as temp_file:
temp_file.write(code_content)
temp_file_path = temp_file.name

# Compilarea fișierului temporar .cpp
executable_name = temp_file_path.replace(".cpp", ".exe")
error_log = temp_file_path.replace(".cpp", "_error.log")
base_name = os.path.splitext(os.path.basename(file_path))[0]
executable_name = os.path.join(current_file_dir, f"{base_name}.exe")
error_log = os.path.join(current_file_dir, f"{base_name}_error.log")
compile_command = f"g++ {temp_file_path} -o {executable_name} 2> {error_log}"

# Rularea comenzii de compilare
compile_process = subprocess.run(compile_command, shell=True)
compile_process = subprocess.run(compile_command, shell=True, cwd=current_file_dir)

if compile_process.returncode != 0:
# Dacă există erori de compilare, deschidem cmd și afișăm erorile
run_command = f"start cmd /k type {error_log}"
subprocess.run(run_command, shell=True)
subprocess.run(run_command, shell=True, cwd=current_file_dir)
else:
# Dacă compilarea reușește, rulăm fișierul executabil în cmd
run_command = f"start cmd /k {executable_name}"
subprocess.run(run_command, shell=True)
run_command = f"start cmd /k {os.path.basename(executable_name)}"
subprocess.run(run_command, shell=True, cwd=current_file_dir)
time.sleep(1)
output = file_menu.return_output()
if output:
if output and os.path.exists(output):
with open(output, "r") as file:
file_content = file.read()
tree.output.configure(state="normal")
Expand All @@ -59,9 +63,10 @@ def run_cpp_file(tree, text_widget):

# Ștergem fișierul temporar după rulare
os.remove(temp_file_path)
os.remove(executable_name)
if os.path.exists(executable_name):
os.remove(executable_name)
if os.path.exists(error_log):
os.remove(error_log)

# Exemplu de utilizare într-o funcție sau într-un buton:
# run_cpp_file(tree, text_widget)
# run_cpp_file(tree, text_widget)

0 comments on commit 0131972

Please sign in to comment.