mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
add simple debug console
This commit is contained in:
parent
ff6abe2b9d
commit
e3a59f8cf7
3 changed files with 72 additions and 1 deletions
27
aqt/main.py
27
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
|
||||
##########################################################################
|
||||
|
||||
|
|
45
designer/debug.ui
Normal file
45
designer/debug.ui
Normal 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>
|
|
@ -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">
|
||||
|
|
Loading…
Reference in a new issue