Commits

zjes committed aeae303

Improve application console and initialy add python ui rendering

Comments (0)

Files changed (8)

src/Designer/DesignerWidget.cpp

 #include "internals/formwindowbase_p.h"
 #include "DesignerHeader.h"
 
+#include "Include/PynotoApplication.h"
+#include "Include/IProjectPlugin.h"
+#include "Include/IProject.h"
+
 #include "DesignerWidget.h"
 #include "ui_DesignerWidget.h"
 
     _form(NULL)
 {
     _ui->setupUi(this);
+    _project = Aux::plugin<Project::IProjectPlugin*>("project")->project();
 }
 
 DesignerWidget::~DesignerWidget()
 
 void DesignerWidget::renderPyFile()
 {
-    /*QFileInfo info = QFileInfo(_fileName);
-    QString pyFile = info.absoluteDir().path() % QDir::separator() % "Ui_" % info.baseName() % ".py";
-    //qDebug() << pyFile;
-    QStringList args;
-    if (_project->pythonVersion() > 2)
-        args << "--from-imports";
-    args << "-o";
-    args << pyFile;
-    args << _fileName;
-    QProcess proc;
-    proc.start(Settings::instance()->pyuic4(), args);
-    proc.waitForFinished();*/
+    QString uic = _project->pythonUic();
+    if (!uic.isEmpty()){
+        QFileInfo info = QFileInfo(_fileName);
+        QString pyFile = info.absoluteDir().path() % QDir::separator() % "Ui_" % info.baseName() % ".py";
+
+        QStringList args;
+        //if (_project->pythonVersion() > 2)
+        //    args << "--from-imports";
+        args << uic;
+        args << "-o";
+        args << pyFile;
+        args << _fileName;
+        QProcess proc;
+        proc.start(_project->interpretExec(), args);
+        proc.waitForFinished();
+    }
 }
 
 void DesignerWidget::activate()

src/Designer/DesignerWidget.h

 class QDesignerPropertyEditorInterface;
 class QDesignerActionEditorInterface;
 
+namespace Project { class IProject; }
 
 namespace Designer
 {
     QDesignerObjectInspectorInterface *_oi;
     QDesignerPropertyEditorInterface * _pe;
     QDesignerActionEditorInterface *_ae;
+
+    Project::IProject * _project;
 };
 
 }

src/Main/Consoles/ApplicationConsole.cpp

 void ApplicationConsole::projectRunned()
 {
     _header->projectRunned(true);
+    _output->clear();
 }
 
 void ApplicationConsole::projectStoped()

src/Main/Consoles/ApplicationOutput.cpp

 namespace Main {
 
 ApplicationOutput::ApplicationOutput(QWidget *parent) :
-    QPlainTextEdit(parent)
+    QPlainTextEdit(parent),
+    _linksActive(false),
+    _mousePressed(false)
 {
+    setReadOnly(true);
     _errFmt.setForeground(Qt::red);
     _normFmt.setForeground(Qt::black);
-
+    _fileFind.setPattern(".*File \"(.+)?\", line (\\d+).*");
 }
 
 void ApplicationOutput::addOutput(const QString& line)
 {
-    qDebug() << "out" << line;
-    _mut.lock();
-    //_queue.append(Line(line, 0));
-    QTextCursor cursor = textCursor();
-    moveCursor(QTextCursor::End);
-    cursor.beginEditBlock();
-    cursor.insertText(line.endsWith("\n") ? line : line+"\n", _normFmt);
-    cursor.endEditBlock();
-    //setTextCursor(cursor);
-    scrollToBottom();
-    _mut.unlock();
+    addLine(line, _normFmt);
 }
 
 void ApplicationOutput::addError(const QString& line)
 {
-    qDebug() << "err" << line;
+    addLine(line, _errFmt);
+}
+
+void ApplicationOutput::addLine(const QString& line, const QTextCharFormat& format)
+{
     _mut.lock();
-    //_queue.append(Line(line, 1));
     QTextCursor cursor = textCursor();
+
+    QString insertLine = line.endsWith("\n") ? line : line+"\n";
+
     moveCursor(QTextCursor::End);
     cursor.beginEditBlock();
-    cursor.insertText(line.endsWith("\n") ? line : line+"\n", _errFmt);
+    cursor.insertText(insertLine, format);
+    int pos = 0;
+    if ((pos = _fileFind.indexIn(line, pos)) != -1 ){
+        QString file = _fileFind.cap(1);
+        QString line = _fileFind.cap(2);
+        qDebug() << pos;
+
+        QList<QTextEdit::ExtraSelection> extra = extraSelections();
+        QTextEdit::ExtraSelection sel;
+        sel.format.setAnchorHref(file);
+        sel.format.setAnchor(true);
+        sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline);
+        cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor, insertLine.length()-_fileFind.pos(1));
+        cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, file.length());
+        sel.cursor = cursor;
+        extra.append(sel);
+
+        setExtraSelections(extra);
+    }
+
+
     cursor.endEditBlock();
-    //setTextCursor(cursor);
     scrollToBottom();
     _mut.unlock();
 }
     verticalScrollBar()->setValue(verticalScrollBar()->maximum());
 }
 
+void ApplicationOutput::mouseMoveEvent(QMouseEvent *e)
+{
+    if (_mousePressed && textCursor().hasSelection())
+        _linksActive = false;
+
+    if (!_linksActive || anchorAt(e->pos()).isEmpty())
+        viewport()->setCursor(Qt::IBeamCursor);
+    else
+        viewport()->setCursor(Qt::PointingHandCursor);
+    QPlainTextEdit::mouseMoveEvent(e);
+}
+
+void ApplicationOutput::mousePressEvent(QMouseEvent * e)
+{
+    _mousePressed = true;
+    QPlainTextEdit::mousePressEvent(e);
+}
+
+void ApplicationOutput::mouseReleaseEvent(QMouseEvent *e)
+{
+    _mousePressed = false;
+
+    if (_linksActive) {
+        const QString href = anchorAt(e->pos());
+        //if (m_formatter)
+        //    m_formatter->handleLink(href);
+    }
+
+    _linksActive = true;
+
+    QPlainTextEdit::mouseReleaseEvent(e);
+}
+
 }

src/Main/Consoles/ApplicationOutput.h

     ApplicationOutput(QWidget *parent = 0);
     void addOutput(const QString& line);
     void addError(const QString& line);
+protected:
+    void mouseMoveEvent(QMouseEvent *e);
+    void mousePressEvent(QMouseEvent * e);
+    void mouseReleaseEvent(QMouseEvent *e);
 private:
     void scrollToBottom();
+    void addLine(const QString& line, const QTextCharFormat& format);
     QTextCharFormat _errFmt;
     QTextCharFormat _normFmt;
     QMutex _mut;
+    bool _linksActive;
+    bool _mousePressed;
+    QRegExp _fileFind;
 };
 
 }

src/Project/IProject.h

     virtual QString interpretExec() = 0;
     virtual QStringList interpretPathes() = 0;
     virtual QString guiName() = 0;
+    virtual QString pythonUic() = 0;
 signals:
     void interpretChanged();
     void shownFilesChanged();

src/Project/ProjectFile.cpp

     _settings(NULL),
     _pythonCode(NULL)
 {
-
+    _python = Aux::plugin<Python::IPythonPlugin*>("python");
 }
 
 ProjectFile::~ProjectFile()
 
 QString ProjectFile::interpretExec()
 {
-    Python::IPythonPlugin* py = Aux::plugin<Python::IPythonPlugin*>("python");
-    Python::IPythonPlugin::Version ver = py->pyVersion(interpretName());
+    Python::IPythonPlugin::Version ver = _python->pyVersion(interpretName());
     if (!ver.exec.isEmpty())
         return ver.exec;
     return "";
 
 QStringList ProjectFile::interpretPathes()
 {
-    Python::IPythonPlugin* py = Aux::plugin<Python::IPythonPlugin*>("python");
-    Python::IPythonPlugin::Version ver = py->pyVersion(interpretName());
+    Python::IPythonPlugin::Version ver = _python->pyVersion(interpretName());
     if (ver.exec.isEmpty())
         return ver.pathes;
     return QStringList();
 }
 
+QString ProjectFile::pythonUic()
+{
+    Python::IPythonPlugin::Version ver = _python->pyVersion(interpretName());
+
+    if (guiName() == "PySide")
+        return ver.pySide.uic;
+
+    return ver.pyQt4.uic;
+}
 
 QString ProjectFile::fileName()
 {

src/Project/ProjectFile.h

 #include "IProject.h"
 
 class QSettings;
+namespace Python { class IPythonPlugin; }
 namespace Project {
 
 class ProjectFile: public IProject
     virtual QString guiName();
     void setGuiName(const QString& name);
 
+    virtual QString pythonUic();
+
     QMap<QString, QVariant> codeCheck();
     void setCodeCheck(const QMap<QString, QVariant>& check);
 
     bool _loaded;
     QSettings * _settings;
     PythonCode::IPythonCode* _pythonCode;
+    Python::IPythonPlugin * _python;
 };
 
 }