Commits

zjes committed a588d03

Add custom pathes to project

  • Participants
  • Parent commits 40da1db

Comments (0)

Files changed (16)

File src/Project/CMakeLists.txt

     Properties/General.h
     Properties/CodeCheck.h
     CreateProjectDlg.h
+    Properties/PathesModel.h
 )
 
 SET(moc
     Properties/General.cpp
     Properties/CodeCheck.cpp
     CreateProjectDlg.cpp
+    Properties/PathesModel.cpp
 )
 
 SET(res

File src/Project/IProject.h

     virtual PythonCode::IPythonCode* pythonCode() = 0;
     virtual QString interpretName() = 0;
     virtual QString interpretExec() = 0;
+    virtual QStringList interpretPathes() = 0;
     virtual QString guiName() = 0;
 signals:
     void interpretChanged();

File src/Project/ProjectFile.cpp

 QString ProjectFile::interpretExec()
 {
     Python::IPythonPlugin* py = Aux::plugin<Python::IPythonPlugin*>("python");
-    Python::IPythonPlugin::Version *ver = py->pyVersion(interpretName());
-    if (ver)
-        return ver->exec;
+    Python::IPythonPlugin::Version ver = py->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());
+    if (ver.exec.isEmpty())
+        return ver.pathes;
+    return QStringList();
+}
+
+
 QString ProjectFile::fileName()
 {
     return _settings->fileName();
 {
     if (!_pythonCode && !interpretName().isEmpty()){
         _pythonCode = Aux::plugin<PythonCode::IPythonCodePlugin*>("pythoncode")->python();
-        _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName());
+        _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName(), interpretPathes() + extraPathes());
     }
     connect(_pythonCode, SIGNAL(systemError(QString)), SIGNAL(systemError(QString)));
     return _pythonCode;
 {
     if (interpretName() != name){
         _settings->setValue("python/interpret", name);
-        if (_pythonCode)
-            _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName());
+        if (_pythonCode){
+            _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName(), interpretPathes() + extraPathes());
+            emit lintChanged();
+        }
         emit interpretChanged();
     }
 }
 
     _settings->sync();
     if (changed){
-        _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName());
+        _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName(), interpretPathes() + extraPathes());
         emit lintChanged();
     }
 }
     Aux::emitPreferencesChanged("panel-color", color);
 }
 
+QStringList ProjectFile::extraPathes()
+{
+    return _settings->value("common/pathes").toStringList();
+}
+
+void ProjectFile::setExtraPathes(const QStringList& pathes)
+{
+    bool changed = pathes != extraPathes();
+    _settings->setValue("common/pathes", pathes);
+    _settings->sync();;
+    if (changed){
+        _pythonCode->init(interpretExec(), path(), mainScript(), _settings->fileName(), interpretPathes() + extraPathes());
+        emit lintChanged();
+    }
+}
+
+
 }

File src/Project/ProjectFile.h

     virtual PythonCode::IPythonCode* pythonCode();
     virtual QString interpretName();
     virtual QString interpretExec();
+    virtual QStringList interpretPathes();
     void setInterpretName(const QString& name);
     virtual QString guiName();
     void setGuiName(const QString& name);
 
     QColor color();
     void setColor(const QColor& color);
+
+    QStringList extraPathes();
+    void setExtraPathes(const QStringList& pathes);
 public slots:
     virtual void openFile(const QString& fileName, int offset = 0);
 private:

File src/Project/Properties/General.cpp

+#include <QFileDialog>
 #include "Include/PynotoApplication.h"
 #include "Include/IPythonPlugin.h"
 #include "General.h"
+#include "PathesModel.h"
 #include "ProjectFile.h"
 #include "ui_General.h"
 
     _ui->edtFileToShow->setText(_project->shownFiles().join(";"));
     _ui->projectColor->setColor(_project->color());
 
+    _pathes = _project->extraPathes();
+    _ui->pathes->setModel(new PathesModel(&_pathes, this));
+
     refreshPyVersions();
     refreshGuiVersions();
 
     connect(_ui->cmbPyVersion, SIGNAL(currentIndexChanged(int)), SLOT(onPythonChanged(int)));
+    connect(_ui->btnAddCustomPath, SIGNAL(clicked()), SLOT(onAddPath()));
+    connect(_ui->btnDeleteCustomPath, SIGNAL(clicked()), SLOT(onDeletePath()));
+    connect(_ui->pathes, SIGNAL(activated(QModelIndex)), SLOT(onPathActivated(QModelIndex)));
 }
 
 void General::refreshGuiVersions()
     _project->setInterpretName(_ui->cmbPyVersion->itemData(_ui->cmbPyVersion->currentIndex()).toString());
     _project->setGuiName(_ui->cmdFrameworks->itemData(_ui->cmdFrameworks->currentIndex()).toString());
     _project->setColor(_ui->projectColor->color());
+    _project->setExtraPathes(_pathes);
     return true;
 }
 
+void General::onAddPath()
+{
+    QFileDialog dlg(this);
+    dlg.setFileMode(QFileDialog::DirectoryOnly);
+    dlg.setWindowTitle(tr("Select extra path"));
+    dlg.setDirectory(_project->path());
+    if (dlg.exec() == QDialog::Accepted)
+        qobject_cast<PathesModel*>(_ui->pathes->model())->addCustomPath(dlg.directory().absolutePath());
+}
+
+void General::onDeletePath()
+{
+    qobject_cast<PathesModel*>(_ui->pathes->model())->deleteCustomPath(_ui->pathes->currentIndex());
+}
+
+void General::onPathActivated(const QModelIndex& index)
+{
+    _ui->btnDeleteCustomPath->setEnabled(index.isValid());
+}
+
+
 }

File src/Project/Properties/General.h

 #ifndef _GENERAL_H_
 #define _GENERAL_H_
 #include <QWidget>
+#include <QModelIndex>
 
 namespace Ui {
     class General;
     void refreshPyVersions();
     void refreshGuiVersions();
     void onPythonChanged(int);
+
+    void onAddPath();
+    void onDeletePath();
+    void onPathActivated(const QModelIndex& index);
 private:
     Ui::General *_ui;
     ProjectFile* _project;
+    QStringList _pathes;
 };
 
 }

File src/Project/Properties/General.ui

    <rect>
     <x>0</x>
     <y>0</y>
-    <width>529</width>
-    <height>422</height>
+    <width>527</width>
+    <height>420</height>
    </rect>
   </property>
   <property name="windowTitle">
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
-    <layout class="QFormLayout" name="formLayout">
-     <item row="0" column="0">
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Project name:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="1">
-      <widget class="QLineEdit" name="edtProjectName"/>
-     </item>
-     <item row="2" column="0">
-      <widget class="QLabel" name="label_2">
-       <property name="text">
-        <string>Python version:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="1">
-      <layout class="QHBoxLayout" name="horizontalLayout">
-       <item>
-        <widget class="QComboBox" name="cmbPyVersion"/>
-       </item>
-       <item>
-        <widget class="QPushButton" name="btnSetupPython">
-         <property name="text">
-          <string>Setup</string>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </item>
-     <item row="3" column="0">
-      <widget class="QLabel" name="label_3">
-       <property name="text">
-        <string>GUI Framework:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="1">
-      <widget class="QComboBox" name="cmdFrameworks"/>
-     </item>
-     <item row="1" column="0">
-      <widget class="QLabel" name="label_4">
-       <property name="text">
-        <string>Project main script:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="0">
-      <widget class="QLabel" name="lbl">
-       <property name="text">
-        <string>Show files in tree:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="4" column="1">
-      <widget class="QLineEdit" name="edtFileToShow"/>
-     </item>
-     <item row="1" column="1">
-      <widget class="FileNameSelect" name="mainScript" native="true">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="0">
-      <widget class="QLabel" name="label_5">
-       <property name="text">
-        <string>Project color:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="5" column="1">
-      <widget class="ColorChooser" name="projectColor">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-         <horstretch>0</horstretch>
-         <verstretch>0</verstretch>
-        </sizepolicy>
-       </property>
-       <property name="minimumSize">
-        <size>
-         <width>120</width>
-         <height>0</height>
-        </size>
-       </property>
-       <property name="text">
-        <string/>
-       </property>
-      </widget>
-     </item>
-    </layout>
+    <widget class="QGroupBox" name="groupBox_2">
+     <property name="title">
+      <string>Main</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label">
+        <property name="text">
+         <string>Project name:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="edtProjectName"/>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_4">
+        <property name="text">
+         <string>Project main script:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="FileNameSelect" name="mainScript" native="true">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_3">
+     <property name="title">
+      <string>Python</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout_2">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Python version:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QComboBox" name="cmbPyVersion"/>
+        </item>
+        <item>
+         <widget class="QPushButton" name="btnSetupPython">
+          <property name="text">
+           <string>Setup</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_3">
+        <property name="text">
+         <string>GUI Framework:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QComboBox" name="cmdFrameworks"/>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox_4">
+     <property name="title">
+      <string>Appereance</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout_3">
+      <item row="0" column="0">
+       <widget class="QLabel" name="lbl">
+        <property name="text">
+         <string>Show files in tree:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1">
+       <widget class="QLineEdit" name="edtFileToShow"/>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_5">
+        <property name="text">
+         <string>Project color:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="ColorChooser" name="projectColor">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="minimumSize">
+         <size>
+          <width>120</width>
+          <height>0</height>
+         </size>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Additional pathes</string>
+     </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_2">
+      <item>
+       <widget class="QListView" name="pathes"/>
+      </item>
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout_4">
+        <item>
+         <widget class="QPushButton" name="btnAddCustomPath">
+          <property name="enabled">
+           <bool>true</bool>
+          </property>
+          <property name="text">
+           <string>Add custom</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="btnDeleteCustomPath">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+          <property name="text">
+           <string>Delete custom</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="verticalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>40</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
    </item>
   </layout>
  </widget>

File src/Project/Properties/PathesModel.cpp

+#include <QDebug>
+#include "PathesModel.h"
+
+namespace Project {
+
+PathesModel::PathesModel(QStringList * cPathes, QObject *parent):
+    QAbstractListModel(parent),
+    _cPathes(cPathes)
+{
+
+}
+
+int PathesModel::rowCount(const QModelIndex & parent) const
+{
+    return _cPathes->length();
+}
+
+QVariant PathesModel::data(const QModelIndex & index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    if (role == Qt::DisplayRole){
+        return _cPathes->at(index.row());
+    }
+    return QVariant();
+}
+
+QModelIndex PathesModel::addCustomPath(const QString& path)
+{
+    beginInsertRows(QModelIndex(), _cPathes->length() - 1, _cPathes->length() - 1);
+    _cPathes->append(path);
+    QModelIndex index = createIndex(_cPathes->length() - 1, 0);
+    endInsertRows();
+    return index;
+}
+
+QModelIndex PathesModel::deleteCustomPath(const QModelIndex& index)
+{
+    beginRemoveRows(QModelIndex(), index.row(), index.row());
+    _cPathes->removeAt(index.row());
+    QModelIndex ret = createIndex(index.row()-1 > 0 ? index.row()-1 : 0, 0);
+    endRemoveRows();
+    return ret;
+}
+
+}

File src/Project/Properties/PathesModel.h

+#ifndef _PATHESMODEL_H_
+#define _PATHESMODEL_H_
+#include <QStringList>
+#include <QAbstractListModel>
+
+namespace Project {
+
+class PathesModel: public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    PathesModel(QStringList* cPathes, QObject *parent = NULL);
+    virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
+    virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+public slots:
+    QModelIndex addCustomPath(const QString& path);
+    QModelIndex deleteCustomPath(const QModelIndex& index);
+private:
+    QStringList * _cPathes;
+};
+
+}
+#endif

File src/Python/IPythonPlugin.h

     virtual void setupVersions(QWidget *parent) = 0;
     virtual QList<Version> listVersions() = 0;
     virtual QStringList guiFrameworks(const QString& pythonName) = 0;
-    virtual Version* pyVersion(const QString& name) = 0;
+    virtual Version pyVersion(const QString& name) = 0;
 };
 
 }

File src/Python/Preferences/SetupPyVersions.ui

    <rect>
     <x>0</x>
     <y>0</y>
-    <width>518</width>
-    <height>470</height>
+    <width>516</width>
+    <height>468</height>
    </rect>
   </property>
   <property name="windowTitle">

File src/Python/PythonPlugin.cpp

     return QList<IPreferencesPage*>() << new SetupPyVersions;
 }
 
-IPythonPlugin::Version* PythonPlugin::pyVersion(const QString& name)
+IPythonPlugin::Version PythonPlugin::pyVersion(const QString& name)
 {
     Settings set;
     foreach(Version ver, set.versions()){
         if (ver.name == name)
-            return &ver;
+            return ver;
     }
-    return NULL;
+    Version ver("", "", "");
+    return ver;
 }
 
 }

File src/Python/PythonPlugin.h

     virtual QList<Version> listVersions();
     virtual QList<IPreferencesPage*> preferences();
     virtual QStringList guiFrameworks(const QString& pythonName);
-    virtual Version* pyVersion(const QString& name);
+    virtual Version pyVersion(const QString& name);
 };
 
 }

File src/PythonCode/IPythonCode.h

 
     virtual ~IPythonCode(){}
 public:
-    virtual void init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile) = 0;
+    virtual void init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile, const QStringList& extraPathes) = 0;
     virtual void codeComplit(const QString& fileName, const QString& cnt, int pos) = 0;
     virtual void errorList(const QString& fileName, const QString & content) = 0;
     virtual void close() = 0;

File src/PythonCode/PythonCode.cpp

 }
 
 
-void PythonCode::init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile)
+void PythonCode::init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile, const QStringList& extraPathes)
 {
     QString path = QApplication::applicationDirPath() + "/python3/rope.py";
     if (!QFile::exists(path))
     qDebug() << path << interpret;
 
     _proc = new QProcess(this);
+    QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+    env.insert("PYTHONPATH", extraPathes.join(":"));
+    _proc->setProcessEnvironment(env);
     connect(_proc, SIGNAL(readyReadStandardError()), SLOT(onError()));
     connect(_proc, SIGNAL(error(QProcess::ProcessError)), SLOT(onRunError(QProcess::ProcessError)));
 

File src/PythonCode/PythonCode.h

     PythonCode();
     virtual ~PythonCode();
 
-    virtual void init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile);
+    virtual void init(const QString& interpret, const QString& projectPath, const QString& mainScript, const QString& projectFile, const QStringList& extraPathes);
     virtual void codeComplit(const QString& fileName, const QString& cnt, int pos);
     virtual void errorList(const QString& fileName, const QString & content);
     virtual void close();