Skip to content

Commit

Permalink
added console output and bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
wishrohitv committed May 3, 2024
1 parent 7bdd5ff commit ffec86e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 27 deletions.
7 changes: 3 additions & 4 deletions components/terminal/py_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def run_commands(self, cm):
except Exception as e:
print(e)
return str(e)

except Exception as e:
print(e)
return str(e)
# '''
else:
try:
s = subprocess.run(code, stdout=subprocess.PIPE, universal_newlines=True,text=True)
s = subprocess.run(code, stdout=subprocess.PIPE, universal_newlines=True, text=True)
Clock.schedule_once(self.focus_terminal, 0.3)
return s.stdout

Expand All @@ -73,12 +73,11 @@ def run_commands(self, cm):
def focus_terminal(self, dt):
self.ids.console.focus = True


def update_textinput_width(self, instance, textinput_width, text_width):
self.initial_textinput_len_x = textinput_width

if self.initial_textinput_len_x < text_width:
instance.width = (Window.width + text_width)
instance.width = (Window.width + text_width)
self.initial_textinput_len_x = text_width
else:
instance.width = self.initial_textinput_len_x
Expand Down
13 changes: 13 additions & 0 deletions components/widgets/terminal_splitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from kivy.graphics import Color, Rectangle
from kivy.uix.splitter import Splitter


class TerminalSplitter(Splitter):
def __init__(self, **kwargs):
super(TerminalSplitter, self).__init__(**kwargs)
self.size_hint = 1, .4
self.strip_size = '3pt'
self.sizable_from = "top"
with self.canvas:
Color(rgba=(60 / 255, 48 / 255, 72 / 255, 1))
#Rectangle(pos=self.pos, size=self.size)
10 changes: 8 additions & 2 deletions main.kv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Screen:
name: "home_ui"
# parent box
on_kv_post:
#:import TopHeader components.topheader.top_header.TopHeader
#:import SideMenu components.sidemenu.side_menu.SideMenu
#:import SideMenuTabWindows components.sidemenu.side_menu.SideMenuTabWindows
#:import WelcomeTab components.codetabs.all_tabs.WelcomeTab
#:import Terminal components.terminal.py_terminal.Terminal

Expand All @@ -18,6 +18,12 @@ Screen:
# child box for spliters
BoxLayout:
orientation: "horizontal"
canvas:
Color:
rgba: (60/255, 48/255, 72/255, .3)
Rectangle:
pos: self.pos
size: self.size
BoxLayout:
size_hint_x: None
width: self.minimum_width
Expand All @@ -26,7 +32,7 @@ Screen:
orientation:'vertical'
id: tab_and_consle_container
BoxLayout:
size_hint: 1,1
size_hint: 1, 1
id: tab_container
# side menu Tab
Splitter:
Expand Down
58 changes: 37 additions & 21 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import io

from kivy.lang import Builder
from kivy.factory import Factory
from kivy.uix.label import Label
from kivy.utils import platform
from kivy.core.window import Window
from kivy.uix.splitter import Splitter
from plyer import filechooser
from app_storage_implement.app_storage import storage_path
import threading, time, asyncio, os, sys
import threading, time, asyncio, os, sys, io
from kivy.app import App

from components.sidemenu.side_menu import SideMenu
from components.sidemenu.side_menu import SideMenuTabWindows


class EditorApp(App):
console_open = True
side_menu_open = True

def build(self):
# front ui
Expand All @@ -32,32 +32,45 @@ def __init__(self, **args):
self.current_tabs_active_code = ""
self.current_tabs_active_file_path = ""

self.engine = None
self.current_active_tabs = []

# sidemenutabwindows initialization
self.spliter_side_workspace_menu = Splitter(size_hint_x=.4, sizable_from="right", strip_size='3pt',
min_size="145dp",
max_size="450dp")
self.spliter_side_workspace_menu.add_widget(SideMenuTabWindows())


# side tabs state mananger if tab is opend or not
def on_left_tab_state(self, instance):
# print(instance.name, instance.state)
side_tab_list = self.root.ids.tab_container.children
# print(side_tab_list)

if len(side_tab_list) == 2:
if self.side_menu_open:
if instance.state == "normal":
self.root.ids.tab_container.remove_widget(self.root.ids.splliter_sidemenutabswindows)
self.root.ids.tab_container.remove_widget(self.root.ids.tab_container.children[1])
self.side_menu_open = False

if len(side_tab_list) < 2:
else:
if instance.state == "down":
self.root.ids.tab_container.add_widget(self.root.ids.splliter_sidemenutabswindows, 1)
self.root.ids.tab_container.add_widget(self.spliter_side_workspace_menu, 1)
self.side_menu_open = True

def open_console_and_close(self, instance):
from components.widgets.terminal_splitter import TerminalSplitter
from components.terminal.py_terminal import Terminal
terminal_splitter = TerminalSplitter()
terminal_splitter.add_widget(Terminal())

tab_and_console = self.root.ids.tab_and_consle_container
terminal_ = self.root.ids.terminal_place
# print(tab_and_console.children)

if self.console_open:
tab_and_console.remove_widget(terminal_)
tab_and_console.remove_widget(tab_and_console.children[0])
self.console_open = False
else:
tab_and_console.add_widget(terminal_)
tab_and_console.add_widget(terminal_splitter, 0)
self.console_open = True

# update cursor line and column
Expand Down Expand Up @@ -216,9 +229,11 @@ def close_tab(self, instance, tab_id):
# run code function
def run_code(self):
import subprocess
from components.widgets.popup_console_output import ConsoleOutPutPopup
from kivy.uix.popup import Popup
compiler = None
output = None

compiler_selection = self.current_tabs_active_file_path.split(".")
# print(compiler_selection)
if compiler_selection[-1] == "js":
Expand All @@ -231,24 +246,26 @@ def run_code(self):
with open(self.current_tabs_active_file_path, mode="r", encoding="utf-8") as j:
code = j.read()
old_stdout = sys.stdout
new_stdout = io.StringIO
new_stdout = io.StringIO()
sys.stdout = new_stdout
exec(code)
exec(code, globals())
output = new_stdout.getvalue()
sys.stdout = old_stdout
else:
co = subprocess.run([compiler, self.current_tabs_active_file_path])
output = subprocess.run([compiler, self.current_tabs_active_file_path], stdout=subprocess.PIPE,
universal_newlines=True, text=True)

f = Label(text=str(output))
f = ConsoleOutPutPopup(str(output.stdout))

self.popup = Popup(title='Console Output', title_color="green", title_size=18, content=f,
auto_dismiss=True, size_hint=(.7, .4), separator_color="purple",
background_color=(0, 0, 1, 1))
popup = Popup(title='Console Output', title_color="green", title_size=18, content=f,
auto_dismiss=True, size_hint=(.7, .4), separator_color="purple",
background_color=(0, 0, 1, 1))
popup.open()
except Exception as e:
print(type(e))
l = Label(text=str(e))
popup = Popup(title='Console Output', title_color="blue", title_size=18, content=l,
auto_dismiss=True, size_hint=(.45, .21), separator_color="purple",
auto_dismiss=True, size_hint=(.6, .21), separator_color="purple",
background_color=(0, 0, 1, 1))

popup.open()
Expand All @@ -265,7 +282,6 @@ def _on_current_active_tabs(self, instance):
# save file from active tabs
def save_active_file_from_header(self):
if self.current_tabs_active_file_path:

with open(self.current_tabs_active_file_path, "w") as f:
f.write(self.current_tabs_active_code)

Expand Down

0 comments on commit ffec86e

Please sign in to comment.