Fixes in Python debugger
This commit is contained in:
parent
7862fb29c7
commit
77d98a4d32
|
@ -47,6 +47,7 @@
|
|||
#include "FileDialog.h"
|
||||
#include "Macro.h"
|
||||
#include "PythonDebugger.h"
|
||||
#include "PythonEditor.h"
|
||||
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
@ -124,10 +125,6 @@ EditorView::~EditorView()
|
|||
getWindowParameter()->Detach( this );
|
||||
}
|
||||
|
||||
void EditorView::drawMarker(int line, int x, int y, QPainter*)
|
||||
{
|
||||
}
|
||||
|
||||
QPlainTextEdit* EditorView::getEditor() const
|
||||
{
|
||||
return d->textEdit;
|
||||
|
@ -293,7 +290,7 @@ bool EditorView::open(const QString& fileName)
|
|||
QFileInfo fi(fileName);
|
||||
d->timeStamp = fi.lastModified().toTime_t();
|
||||
d->activityTimer->setSingleShot(true);
|
||||
d->activityTimer->start(3000);
|
||||
d->activityTimer->start(3000);
|
||||
|
||||
setCurrentFileName(fileName);
|
||||
return true;
|
||||
|
@ -399,6 +396,7 @@ void EditorView::printPdf()
|
|||
void EditorView::setCurrentFileName(const QString &fileName)
|
||||
{
|
||||
d->fileName = fileName;
|
||||
/*emit*/ changeFileName(d->fileName);
|
||||
d->textEdit->document()->setModified(false);
|
||||
|
||||
QString shownName;
|
||||
|
@ -488,12 +486,11 @@ void EditorView::focusInEvent (QFocusEvent * e)
|
|||
|
||||
// ---------------------------------------------------------
|
||||
|
||||
PythonEditorView::PythonEditorView(QPlainTextEdit* editor, QWidget* parent)
|
||||
: EditorView(editor, parent), m_debugLine(-1),
|
||||
breakpoint(QLatin1String(":/icons/breakpoint.png")),
|
||||
debugMarker(QLatin1String(":/icons/debug-marker.png"))
|
||||
PythonEditorView::PythonEditorView(PythonEditor* editor, QWidget* parent)
|
||||
: EditorView(editor, parent), _pye(editor)
|
||||
{
|
||||
_dbg = Application::Instance->macroManager()->debugger();
|
||||
connect(this, SIGNAL(changeFileName(const QString&)),
|
||||
editor, SLOT(setFileName(const QString&)));
|
||||
}
|
||||
|
||||
PythonEditorView::~PythonEditorView()
|
||||
|
@ -532,18 +529,6 @@ bool PythonEditorView::onHasMsg(const char* pMsg) const
|
|||
return EditorView::onHasMsg(pMsg);
|
||||
}
|
||||
|
||||
void PythonEditorView::drawMarker(int line, int x, int y, QPainter* p)
|
||||
{
|
||||
Breakpoint bp = _dbg->getBreakpoint(fileName());
|
||||
if (bp.checkLine(line)) {
|
||||
p->drawPixmap(x, y, breakpoint);
|
||||
}
|
||||
if (m_debugLine == line) {
|
||||
p->drawPixmap(x, y+2, debugMarker);
|
||||
debugRect = QRect(x, y+2, debugMarker.width(), debugMarker.height());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the opened script in the macro manager.
|
||||
*/
|
||||
|
@ -554,42 +539,22 @@ void PythonEditorView::executeScript()
|
|||
|
||||
void PythonEditorView::startDebug()
|
||||
{
|
||||
if (_dbg->start()) {
|
||||
_dbg->runFile(fileName());
|
||||
_dbg->stop();
|
||||
}
|
||||
_pye->startDebug();
|
||||
}
|
||||
|
||||
void PythonEditorView::toggleBreakpoint()
|
||||
{
|
||||
QTextCursor cursor = getEditor()->textCursor();
|
||||
int line = cursor.blockNumber() + 1;
|
||||
_dbg->toggleBreakpoint(line, fileName());
|
||||
// getMarker()->update();
|
||||
_pye->toggleBreakpoint();
|
||||
}
|
||||
|
||||
void PythonEditorView::showDebugMarker(int line)
|
||||
{
|
||||
m_debugLine = line;
|
||||
// getMarker()->update();
|
||||
QTextCursor cursor = getEditor()->textCursor();
|
||||
cursor.movePosition(QTextCursor::StartOfBlock);
|
||||
int cur = cursor.blockNumber() + 1;
|
||||
if (cur > line) {
|
||||
for (int i=line; i<cur; i++)
|
||||
cursor.movePosition(QTextCursor::Up);
|
||||
}
|
||||
else if (cur < line) {
|
||||
for (int i=cur; i<line; i++)
|
||||
cursor.movePosition(QTextCursor::Down);
|
||||
}
|
||||
getEditor()->setTextCursor(cursor);
|
||||
_pye->showDebugMarker(line);
|
||||
}
|
||||
|
||||
void PythonEditorView::hideDebugMarker()
|
||||
{
|
||||
m_debugLine = -1;
|
||||
// getMarker()->update();
|
||||
_pye->hideDebugMarker();
|
||||
}
|
||||
|
||||
#include "moc_EditorView.cpp"
|
||||
|
|
|
@ -50,8 +50,6 @@ public:
|
|||
~EditorView();
|
||||
|
||||
QPlainTextEdit* getEditor() const;
|
||||
//todo: remove
|
||||
virtual void drawMarker(int line, int x, int y, QPainter*);
|
||||
void OnChange(Base::Subject<const char*> &rCaller,const char* rcReason);
|
||||
|
||||
const char *getName(void) const {return "EditorView";}
|
||||
|
@ -90,6 +88,9 @@ private Q_SLOTS:
|
|||
void undoAvailable(bool);
|
||||
void redoAvailable(bool);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeFileName(const QString&);
|
||||
|
||||
private:
|
||||
void setCurrentFileName(const QString &fileName);
|
||||
bool saveFile();
|
||||
|
@ -98,21 +99,18 @@ private:
|
|||
EditorViewP* d;
|
||||
};
|
||||
|
||||
class PythonDebugger;
|
||||
class PythonEditor;
|
||||
class GuiExport PythonEditorView : public EditorView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PythonEditorView(QPlainTextEdit* editor, QWidget* parent);
|
||||
PythonEditorView(PythonEditor* editor, QWidget* parent);
|
||||
~PythonEditorView();
|
||||
|
||||
//todo: remove
|
||||
void drawMarker(int line, int x, int y, QPainter*);
|
||||
bool onMsg(const char* pMsg,const char** ppReturn);
|
||||
bool onHasMsg(const char* pMsg) const;
|
||||
|
||||
//todo: move to PythonEditor
|
||||
public Q_SLOTS:
|
||||
void executeScript();
|
||||
void startDebug();
|
||||
|
@ -120,13 +118,8 @@ public Q_SLOTS:
|
|||
void showDebugMarker(int line);
|
||||
void hideDebugMarker();
|
||||
|
||||
//todo: move to PythonEditor
|
||||
private:
|
||||
int m_debugLine;
|
||||
QRect debugRect;
|
||||
QPixmap breakpoint;
|
||||
QPixmap debugMarker;
|
||||
PythonDebugger* _dbg;
|
||||
PythonEditor* _pye;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
|
|
@ -30,8 +30,10 @@
|
|||
#endif
|
||||
|
||||
#include "PythonEditor.h"
|
||||
#include "PythonDebugger.h"
|
||||
#include "Application.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "Macro.h"
|
||||
#include "FileDialog.h"
|
||||
#include "DlgEditorImp.h"
|
||||
|
||||
|
@ -45,8 +47,19 @@ namespace Gui {
|
|||
struct PythonEditorP
|
||||
{
|
||||
QMap<QString, QColor> colormap; // Color map
|
||||
int debugLine;
|
||||
QRect debugRect;
|
||||
QPixmap breakpoint;
|
||||
QPixmap debugMarker;
|
||||
QString filename;
|
||||
PythonDebugger* debugger;
|
||||
PythonEditorP()
|
||||
: debugLine(-1),
|
||||
breakpoint(QLatin1String(":/icons/breakpoint.png")),
|
||||
debugMarker(QLatin1String(":/icons/debug-marker.png"))
|
||||
{
|
||||
debugger = Application::Instance->macroManager()->debugger();
|
||||
|
||||
colormap[QLatin1String("Text")] = Qt::black;
|
||||
colormap[QLatin1String("Bookmark")] = Qt::cyan;
|
||||
colormap[QLatin1String("Breakpoint")] = Qt::red;
|
||||
|
@ -98,18 +111,61 @@ PythonEditor::~PythonEditor()
|
|||
delete d;
|
||||
}
|
||||
|
||||
void PythonEditor::setFileName(const QString& fn)
|
||||
{
|
||||
d->filename = fn;
|
||||
}
|
||||
|
||||
void PythonEditor::startDebug()
|
||||
{
|
||||
if (d->debugger->start()) {
|
||||
d->debugger->runFile(d->filename);
|
||||
d->debugger->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void PythonEditor::toggleBreakpoint()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
int line = cursor.blockNumber() + 1;
|
||||
d->debugger->toggleBreakpoint(line, d->filename);
|
||||
getMarker()->update();
|
||||
}
|
||||
|
||||
void PythonEditor::showDebugMarker(int line)
|
||||
{
|
||||
d->debugLine = line;
|
||||
getMarker()->update();
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.movePosition(QTextCursor::StartOfBlock);
|
||||
int cur = cursor.blockNumber() + 1;
|
||||
if (cur > line) {
|
||||
for (int i=line; i<cur; i++)
|
||||
cursor.movePosition(QTextCursor::Up);
|
||||
}
|
||||
else if (cur < line) {
|
||||
for (int i=cur; i<line; i++)
|
||||
cursor.movePosition(QTextCursor::Down);
|
||||
}
|
||||
setTextCursor(cursor);
|
||||
}
|
||||
|
||||
void PythonEditor::hideDebugMarker()
|
||||
{
|
||||
d->debugLine = -1;
|
||||
getMarker()->update();
|
||||
}
|
||||
|
||||
void PythonEditor::drawMarker(int line, int x, int y, QPainter* p)
|
||||
{
|
||||
#if 0
|
||||
Breakpoint bp = _dbg->getBreakpoint(fileName());
|
||||
Breakpoint bp = d->debugger->getBreakpoint(d->filename);
|
||||
if (bp.checkLine(line)) {
|
||||
p->drawPixmap(x, y, breakpoint);
|
||||
p->drawPixmap(x, y, d->breakpoint);
|
||||
}
|
||||
if (m_debugLine == line) {
|
||||
p->drawPixmap(x, y+2, debugMarker);
|
||||
debugRect = QRect(x, y+2, debugMarker.width(), debugMarker.height());
|
||||
if (d->debugLine == line) {
|
||||
p->drawPixmap(x, y+2, d->debugMarker);
|
||||
d->debugRect = QRect(x, y+2, d->debugMarker.width(), d->debugMarker.height());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PythonEditor::contextMenuEvent ( QContextMenuEvent * e )
|
||||
|
|
|
@ -45,6 +45,11 @@ public:
|
|||
PythonEditor(QWidget *parent = 0);
|
||||
~PythonEditor();
|
||||
|
||||
void startDebug();
|
||||
void toggleBreakpoint();
|
||||
void showDebugMarker(int line);
|
||||
void hideDebugMarker();
|
||||
|
||||
public Q_SLOTS:
|
||||
/** Inserts a '#' at the beginning of each selected line or the current line if
|
||||
* nothing is selected
|
||||
|
@ -56,6 +61,7 @@ public Q_SLOTS:
|
|||
* this line is skipped.
|
||||
*/
|
||||
void onUncomment();
|
||||
void setFileName(const QString&);
|
||||
|
||||
protected:
|
||||
/** Pops up the context menu with some extensions */
|
||||
|
|
|
@ -99,6 +99,8 @@ protected:
|
|||
/** Draw a beam in the line where the cursor is. */
|
||||
void paintEvent (QPaintEvent * e);
|
||||
void resizeEvent(QResizeEvent* e);
|
||||
QWidget* getMarker() const
|
||||
{ return lineNumberArea; }
|
||||
virtual void drawMarker(int line, int x, int y, QPainter*);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user