From e3a59f8cf7c1fb0200f7478b8bf9c60bfc43d446 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 20 Apr 2012 03:05:59 +0900 Subject: [PATCH] add simple debug console --- aqt/main.py | 27 +++++++++++++++++++++++++++ designer/debug.ui | 45 +++++++++++++++++++++++++++++++++++++++++++++ designer/main.ui | 1 - 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 designer/debug.ui diff --git a/aqt/main.py b/aqt/main.py index 9914c29ca..8fa33c527 100755 --- a/aqt/main.py +++ b/aqt/main.py @@ -528,6 +528,10 @@ upload, overwriting any changes either here or on AnkiWeb. Proceed?""")): def setupKeys(self): self.keyHandler = None + # debug shortcut + self.debugShortcut = QShortcut(QKeySequence("Ctrl+:"), self) + self.connect( + self.debugShortcut, SIGNAL("activated()"), self.onDebug) def keyPressEvent(self, evt): # do we have a delegate? @@ -889,6 +893,29 @@ will be lost. Continue?""")) diag.connect(box, SIGNAL("accepted()"), onDelete) diag.exec_() + # Debugging + ###################################################################### + + def onDebug(self): + d = QDialog() + frm = aqt.forms.debug.Ui_Dialog() + frm.setupUi(d) + d.connect(frm.line, SIGNAL("returnPressed()"), lambda: self.onDebugRet(frm)) + d.exec_() + + def onDebugRet(self, frm): + import pprint + line = frm.line.text() + if not line: + return + def card(): + return self.reviewer.card.__dict__ + locals = dict(mw=self, card=card) + ret = eval(line, globals(), locals) + if not isinstance(ret, basestring): + ret = pprint.pformat(ret) + frm.log.appendPlainText(">>> %s\n%s\n" % (line, ret)) + # System specific code ########################################################################## diff --git a/designer/debug.ui b/designer/debug.ui new file mode 100644 index 000000000..6f49cd645 --- /dev/null +++ b/designer/debug.ui @@ -0,0 +1,45 @@ + + + Dialog + + + + 0 + 0 + 643 + 580 + + + + Debug Console + + + + + + + + Expression: + + + + + + + + + + + + Qt::NoFocus + + + true + + + + + + + + diff --git a/designer/main.ui b/designer/main.ui index bf2a998af..2eb7a2356 100644 --- a/designer/main.ui +++ b/designer/main.ui @@ -99,7 +99,6 @@ -