diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/debugcontroller.py b/plugins/extensions/pykrita/plugin/plugins/scripter/debugcontroller.py index dc3009bb4c..57ec05bce4 100644 --- a/plugins/extensions/pykrita/plugin/plugins/scripter/debugcontroller.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/debugcontroller.py @@ -1,86 +1,84 @@ from scripter.debugger_scripter import debugger from code import InteractiveConsole import asyncio class DebugController (object): def __init__(self, scripter): self._debugger = None self._cmd = None self.scripter = scripter def start(self, document): self.setCmd(compile(document.data, document.filePath, "exec")) self._debugger = debugger.Debugger(self.scripter, self._cmd) self._debugger.debugprocess.start() loop = asyncio.get_event_loop() loop.run_until_complete(self._debugger.start()) self.updateUIDebugger() def step(self): loop = asyncio.get_event_loop() loop.run_until_complete(self._debugger.step()) self.scripter.uicontroller.setStepped(True) self.updateUIDebugger() - print('depois') def stop(self): loop = asyncio.get_event_loop() loop.run_until_complete(self._debugger.stop()) self.updateUIDebugger() self._debugger = None def setCmd(self, cmd): self._cmd = cmd @property def isActive(self): try: if self._debugger: return self._debugger.debugprocess.is_alive() return False except: return False @property def currentLine(self): try: if self._debugger: - return int(self._debugger.application_data['code']['lineNumber']) + return int(self.debuggerData['code']['lineNumber']) except: return 0 def updateUIDebugger(self): widget = self.scripter.uicontroller.findStackWidget('Debugger') exception = self._debuggerException() - print(exception) if exception: self.scripter.uicontroller.showException(exception) if not self.isActive or self._quitDebugger(): widget.disableToolbar(True) self.scripter.uicontroller.repaintDebugArea() widget.updateWidget() @property def debuggerData(self): try: if self._debugger: return self._debugger.application_data except: return - def _quitDebugger(self): try: - return self._debugger.application_data['quit'] + return self.debuggerData['quit'] except: return False def _debuggerException(self): try: - return self._debugger.application_data['exception'] + print(self.debuggerData['exception']) + return self.debuggerData['exception'] except: return False diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debugger.py b/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debugger.py index 710ceca757..4ce0a7b242 100644 --- a/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debugger.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debugger.py @@ -1,112 +1,98 @@ import bdb import asyncio import inspect import multiprocessing import re - - +import asyncio from . import debuggerformatter class Debugger(bdb.Bdb): def __init__(self, scripter, cmd): bdb.Bdb.__init__(self) self.quit = False self.debugq = multiprocessing.Queue() self.scripter = scripter self.applicationq = multiprocessing.Queue() self.filePath = self.scripter.documentcontroller.activeDocument.filePath - # Create the debug process - self.debugprocess = multiprocessing.Process(target=self.run, args=(cmd,)) self.application_data = {} + self.exception_data = {} + self.debugprocess = multiprocessing.Process(target=self.run, args=(cmd,)) self.currentLine = 0 - # initialize parent + bdb.Bdb.reset(self) def run(self, cmd): try: super(Debugger, self).run(cmd) except: - print('terminado') + print('deu merda cara') def user_call(self, frame, args): name = frame.f_code.co_name or "" def user_line(self, frame): """Handler that executes with every line of code""" co = frame.f_code if self.filePath!=co.co_filename: return self.currentLine = frame.f_lineno self.applicationq.put({ "code": { "file": co.co_filename, "name": co.co_name, "lineNumber": str(frame.f_lineno) }, "frame": { "firstLineNumber": co.co_firstlineno, "locals": debuggerformatter.format_data(frame.f_locals), "globals": debuggerformatter.format_data(frame.f_globals) }, "trace": "line" }) if self.quit: return self.set_quit() - if self.currentLine==0: return else: - # Wait for a debug command cmd = self.debugq.get() if cmd == "step": - # If stepping through code, return this handler return - if cmd == "stop": - # If stopping execution, raise an exception return self.set_quit() def user_return(self, frame, value): name = frame.f_code.co_name or "" + if name == '': self.applicationq.put({ "quit": True}) def user_exception(self, frame, exception): - name = frame.f_code.co_name or "" - print(str(exception)) - self.applicationq.put({ "exception": str(exception)}) - + self.applicationq.put({ "exception": str(exception[1])}) async def display(self): """Coroutine for updating the UI""" - # Wait for the application queue to have an update to the GUI while True: if self.applicationq.empty(): await asyncio.sleep(0.3) else: - # The application queue has at least one item, let's act on every item that's in it while not self.applicationq.empty(): - # Get info to the GUI - self.application_data = self.applicationq.get() - self.scripter.uicontroller.repaintDebugArea() - return + self.application_data.update(self.applicationq.get()) + self.scripter.uicontroller.repaintDebugArea() + return async def start(self): await self.display() async def step(self): - # Tell the debugger we want to step in self.debugq.put("step") - await self.display() async def stop(self): - # Tell the debugger we're stopping execution self.debugq.put("stop") self.applicationq.put({ "quit": True}) await self.display() diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debuggerformatter.py b/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debuggerformatter.py index e589054173..ff3f6a3c93 100644 --- a/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debuggerformatter.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/debugger_scripter/debuggerformatter.py @@ -1,26 +1,26 @@ import re import inspect def format_data(data): globals()['types'] = __import__('types') exclude_keys = ['copyright', 'credits', 'False', 'True', 'None', 'Ellipsis', 'quit', 'QtCriticalMsg', 'krita_path', 'QtWarningMsg', 'QWIDGETSIZE_MAX', 'QtFatalMsg', 'PYQT_CONFIGURATION', 'on_load', 'PYQT_VERSION', 'on_pykrita_unloading', 'on_unload', 'QT_VERSION', 'QtInfoMsg', 'PYQT_VERSION_STR', 'qApp', 'QtSystemMsg', 'QtDebugMsg', 'on_pykrita_loaded', 'QT_VERSION_STR'] exclude_valuetypes = [types.BuiltinFunctionType, types.BuiltinMethodType, types.ModuleType, types.FunctionType] - return [{k: v} for k, v in data.items() if not (k in exclude_keys or + return [{k: {'value': str(v), 'type': str(type(v))}} for k, v in data.items() if not (k in exclude_keys or type(v) in exclude_valuetypes or re.search(r'^(__).*\1$', k) or inspect.isclass(v) or inspect.isfunction(v))] diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py index e3cea4a6dd..868674ee08 100644 --- a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/actions/runaction/runaction.py @@ -1,47 +1,44 @@ from PyQt5.QtWidgets import QAction, QMessageBox from PyQt5.QtGui import QIcon import sys from . import docwrapper import os class RunAction(QAction): def __init__(self, scripter, parent=None): super(RunAction, self).__init__(parent) self.scripter = scripter self.editor = self.scripter.uicontroller.editor self.output = self.scripter.uicontroller.findStackWidget('OutPut') self.triggered.connect(self.run) self.setText('Run') # path to the icon #self.setIcon(QIcon('/home/eliakincosta/Pictures/play.svg')) @property def parent(self): return 'toolBar' def run(self): document = self.scripter.uicontroller.invokeAction('save') if document: stdout = sys.stdout stderr = sys.stderr output = docwrapper.DocWrapper(self.output.document()) output.write("======================================\n") sys.stdout = output sys.stderr = output script = self.editor.document().toPlainText() try: bc = compile(document.data, document.filePath, "exec") + exec(bc) except Exception as e: - QMessageBox.critical(self.editor, "Error compiling script", str(e)) - return - - exec(bc) - + self.scripter.uicontroller.showException(str(e)) sys.stdout = stdout sys.stderr = stderr diff --git a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/stackwidgets/debuggerwidget/debuggertable.py b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/stackwidgets/debuggerwidget/debuggertable.py index a573924ddc..f1c1445bfe 100644 --- a/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/stackwidgets/debuggerwidget/debuggertable.py +++ b/plugins/extensions/pykrita/plugin/plugins/scripter/ui_scripter/stackwidgets/debuggerwidget/debuggertable.py @@ -1,33 +1,33 @@ from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem class DebuggerTable(QTableWidget): def __init__(self, parent=None): super(DebuggerTable, self).__init__(parent) self.setColumnCount(4) tableHeader = ['Scope', 'Name', 'Value', 'Type'] self.setHorizontalHeaderLabels(tableHeader) self.setEditTriggers(self.NoEditTriggers) def updateTable(self, data): self.clearContents() self.setRowCount(0) - if data and not data.get('quit'): + if data and not data.get('quit') and not data.get('exception'): locals_list = data['frame']['locals'] globals_list = data['frame']['globals'] all_variables = {'locals': locals_list, 'globals': globals_list} for scope_key in all_variables: for item in all_variables[scope_key]: for key, value in item.items(): row = self.rowCount() self.insertRow(row) self.setItem(row, 0, QTableWidgetItem(str(scope_key))) self.setItem(row, 1, QTableWidgetItem(key)) - self.setItem(row, 2, QTableWidgetItem(str(value))) - self.setItem(row, 3, QTableWidgetItem(str(type(value)))) + self.setItem(row, 2, QTableWidgetItem(value['value'])) + self.setItem(row, 3, QTableWidgetItem(value['type']))