add simple debug console

This commit is contained in:
Damien Elmes 2012-04-20 03:05:59 +09:00
parent ff6abe2b9d
commit e3a59f8cf7
3 changed files with 72 additions and 1 deletions

View file

@ -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
##########################################################################

45
designer/debug.ui Normal file
View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>643</width>
<height>580</height>
</rect>
</property>
<property name="windowTitle">
<string>Debug Console</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Expression:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="line"/>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="log">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -99,7 +99,6 @@
<addaction name="actionOpenPluginFolder"/>
<addaction name="separator"/>
<addaction name="menuStartup"/>
<addaction name="separator"/>
</widget>
<widget class="QMenu" name="menuMaintenance">
<property name="title">