diff --git a/plugins/python/scripter/debugger_scripter/debugger.py b/plugins/python/scripter/debugger_scripter/debugger.py index 2ccdde60dc..cb4602f321 100644 --- a/plugins/python/scripter/debugger_scripter/debugger.py +++ b/plugins/python/scripter/debugger_scripter/debugger.py @@ -1,126 +1,126 @@ """ Copyright (c) 2017 Eliakin Costa This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import bdb import multiprocessing import sys if sys.version_info[0] > 2: import asyncio else: import trollius as 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 self.application_data = {} self.exception_data = {} self.debugprocess = multiprocessing.Process(target=self._run, args=(self.filePath,)) self.currentLine = 0 bdb.Bdb.reset(self) def _run(self, filename): try: self.mainpyfile = self.canonic(filename) with open(filename, "rb") as fp: statement = "exec(compile(%r, %r, 'exec'))" % \ (fp.read(), self.mainpyfile) self.run(statement) except Exception as e: raise e 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: cmd = self.debugq.get() if cmd == "step": return if cmd == "stop": 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): self.applicationq.put({"exception": str(exception[1])}) @asyncio.coroutine def display(self): """Coroutine for updating the UI""" while True: if self.applicationq.empty(): # 'yield from' is not available in Python 2. for i in asyncio.sleep(0.3): yield i else: while not self.applicationq.empty(): self.application_data.update(self.applicationq.get()) self.scripter.uicontroller.repaintDebugArea() return @asyncio.coroutine def start(self): - yield self.display() + yield from self.display() @asyncio.coroutine def step(self): self.debugq.put("step") - yield self.display() + yield from self.display() @asyncio.coroutine def stop(self): self.debugq.put("stop") self.applicationq.put({"quit": True}) - yield self.display() + yield from self.display() diff --git a/plugins/python/scripter/ui_scripter/actions/debugaction/debugaction.py b/plugins/python/scripter/ui_scripter/actions/debugaction/debugaction.py index a40a328a74..d74460c5b7 100644 --- a/plugins/python/scripter/ui_scripter/actions/debugaction/debugaction.py +++ b/plugins/python/scripter/ui_scripter/actions/debugaction/debugaction.py @@ -1,47 +1,47 @@ """ Copyright (c) 2017 Eliakin Costa This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ from PyQt5.QtWidgets import QAction from PyQt5.QtGui import QIcon, QPixmap, QKeySequence from scripter import resources_rc from PyQt5.QtCore import Qt import krita class DebugAction(QAction): def __init__(self, scripter, parent=None): super(DebugAction, self).__init__(parent) self.scripter = scripter self.triggered.connect(self.debug) self.setText(i18n("Debug")) self.setToolTip(i18n("Debug Ctrl+D")) self.setIcon(QIcon(':/icons/debug.svg')) self.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_D)) @property def parent(self): return 'toolBar', def debug(self): if self.scripter.uicontroller.invokeAction('save'): self.scripter.uicontroller.setActiveWidget(i18n('Debugger')) self.scripter.debugcontroller.start(self.scripter.documentcontroller.activeDocument) - widget = self.scripter.uicontroller.findTabWidget(i81n('Debugger')) + widget = self.scripter.uicontroller.findTabWidget(i18n('Debugger')) widget.startDebugger()