Skip to content

Commit

Permalink
Add runner for python files
Browse files Browse the repository at this point in the history
  • Loading branch information
chebupelka8 committed Feb 23, 2024
1 parent 504baa4 commit ef39986
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
HtmlCodeEditorArea, StyleCodeEditorArea, JsonCodeEditorArea,
ImageViewer, TextEditorArea, WINDOW_SIZE, Restarter,
ThemeChanger, EditorFontManager, SettingsMenu, WorkbenchFontManager,
EditorSettingsUpdater
EditorSettingsUpdater, FileRunner
)
from scr.interface.basic import Splitter

Expand Down Expand Up @@ -75,6 +75,9 @@ def setup_ui(self) -> None:
QShortcut("Ctrl+P", self).activated.connect(
lambda: self.__click_file_tree(self.fileTree.open_file(FileDialog.get_open_file_name()))
)
QShortcut("Ctrl+F5", self).activated.connect(
lambda: FileRunner.run_python_file(self.tabEditor.get_current_path(), self.fileTree.get_current_directory())
)

EditorFontManager.add_font_updater(self.tabEditor.update_all_tabs_font)
EditorSettingsUpdater.add_updater(self.tabEditor.update_all_tabs_settings)
Expand Down
2 changes: 1 addition & 1 deletion scr/data/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"workbench": {
"font": {
"family": "Inter-Medium.otf",
"family": "CascadiaMono.ttf",
"size": 13,
"bold": false,
"italic": false
Expand Down
1 change: 1 addition & 0 deletions scr/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .theme_manager import *
from .settings_updater import *
from .font import *
from .run import *
17 changes: 17 additions & 0 deletions scr/scripts/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
import threading

from .file_checker import FileChecker


class FileRunner:

@staticmethod
def run_python_file(__path: str, __dir: str) -> None:
if not FileChecker.is_python_file(__path): return

thread = threading.Thread(
target=lambda:
os.system(f"cd {os.path.normpath(__dir)} && python.exe {os.path.basename(os.path.normpath(__path))}")
)
thread.start()
4 changes: 4 additions & 0 deletions scr/widgets/file_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ def open_file(self, __path: str):
return self.get_index_by_path(__path)

def open_directory(self, __path: str) -> None:
self.__directory = __path
self.model.setRootPath(__path)
self.setRootIndex(self.model.index(__path))

def get_current_directory(self) -> str:
return self.__directory

def show_hide_file_tree(self) -> None:
if self.isVisible():
self.setVisible(False)
Expand Down
2 changes: 1 addition & 1 deletion scr/widgets/tab_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_current_path(self) -> str:
if hasattr(self.currentWidget(), "get_full_path"):
return self.currentWidget().get_full_path()
else:
return "" # it's need for remove exception
return "" # it's need to remove exception

def removeTab(self, __index: int):
super().removeTab(__index)
Expand Down

0 comments on commit ef39986

Please sign in to comment.