mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Start Python Embedding
.. just bootstrapping, so Python is loaded and version number made available in the about box. .. see gcconfig.pri.in and src.pro for settings needed .. not considering threading etc at this point
This commit is contained in:
@@ -42,6 +42,9 @@
|
||||
#ifdef GC_HAS_CLOUD_DB
|
||||
#include "CloudDBCommon.h"
|
||||
#endif
|
||||
#ifdef GC_WANT_PYTHON
|
||||
#include "PythonEmbed.h"
|
||||
#endif
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
@@ -295,6 +298,9 @@ main(int argc, char *argv[])
|
||||
#ifdef GC_WANT_R
|
||||
rtool = NULL;
|
||||
#endif
|
||||
#ifdef GC_WANT_PYTHON
|
||||
python = NULL;
|
||||
#endif
|
||||
|
||||
// numerous bugs related to autoscaling and opengl that have persisted since Qt5.6 on and off
|
||||
// now we support hidpi natively we will unset scaling factors and use our own scaling ratios
|
||||
@@ -418,6 +424,11 @@ main(int argc, char *argv[])
|
||||
if (rtool->failed == true) rtool=NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GC_WANT_PYTHON
|
||||
if (python == NULL) python = new PythonEmbed(); // initialise python in this thread ?
|
||||
#endif
|
||||
|
||||
//this is the path within the current directory where GC will look for
|
||||
//files to allow USB stick support
|
||||
QString localLibraryPath="Library/GoldenCheetah";
|
||||
|
||||
@@ -72,6 +72,10 @@
|
||||
#include "Rversion.h"
|
||||
#endif
|
||||
|
||||
#ifdef GC_WANT_PYTHON
|
||||
#include "PythonEmbed.h"
|
||||
#endif
|
||||
|
||||
GcCrashDialog::GcCrashDialog(QDir homeDir) : QDialog(NULL, Qt::Dialog), home(homeDir)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose, true); // caller must delete me, once they've extracted the name
|
||||
@@ -313,6 +317,7 @@ QString GcCrashDialog::versionHTML()
|
||||
"<tr><td colspan=\"2\">SAMPLERATE</td><td>%15</td></tr>"
|
||||
"<tr><td colspan=\"2\">SSL</td><td>%16</td></tr>"
|
||||
"<tr><td colspan=\"2\">R</td><td>%17</td></tr>"
|
||||
"<tr><td colspan=\"2\">Python</td><td>%20</td></tr>"
|
||||
"<tr><td colspan=\"2\">WEBKIT</td><td>%18</td></tr>"
|
||||
"<tr><td colspan=\"2\">LMFIT</td><td>%19</td></tr>"
|
||||
"</table>"
|
||||
@@ -356,7 +361,11 @@ QString GcCrashDialog::versionHTML()
|
||||
#else
|
||||
.arg("none")
|
||||
#endif
|
||||
|
||||
#ifdef GC_HAVE_PYTHON
|
||||
.arg(python->version.split(" ").at(0));
|
||||
#else
|
||||
.arg("none")
|
||||
#endif
|
||||
;
|
||||
|
||||
QString versionText = QString("<center>" + gc_version + lib_version + "</center>");
|
||||
|
||||
68
src/Python/PythonEmbed.cpp
Normal file
68
src/Python/PythonEmbed.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Mark Liversedge (liversedge@gmail.com)
|
||||
*
|
||||
* Additionally, for the original source used as a basis for this (RInside.cpp)
|
||||
* Released under the same GNU public license.
|
||||
*
|
||||
* Copyright (C) 2009 Dirk Eddelbuettel
|
||||
* Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "PythonEmbed.h"
|
||||
#include "Settings.h"
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
// Python header - using a C preprocessor hack
|
||||
// GC_PYTHON_INCDIR is from gcconfig.pri, typically python3.6
|
||||
#ifdef slots // clashes with python headers
|
||||
#undef slots
|
||||
#endif
|
||||
#include GC_PYTHONHEADER
|
||||
|
||||
// global instance of embedded python
|
||||
PythonEmbed *python;
|
||||
|
||||
PythonEmbed::~PythonEmbed()
|
||||
{
|
||||
}
|
||||
|
||||
PythonEmbed::PythonEmbed(const bool verbose, const bool interactive) : verbose(verbose), interactive(interactive)
|
||||
{
|
||||
loaded = false;
|
||||
name = QString("GoldenCheetah");
|
||||
|
||||
// tell python our program name
|
||||
Py_SetProgramName((wchar_t*) name.toStdString().c_str());
|
||||
|
||||
// need to load the interpreter etc
|
||||
Py_InitializeEx(0);
|
||||
|
||||
// set the module path in the same way the interpreter would
|
||||
PyObject *sys = PyImport_ImportModule("sys");
|
||||
PyObject *path = PyObject_GetAttrString(sys, "path");
|
||||
PyList_Append(path, PyUnicode_FromString("."));
|
||||
|
||||
// get version
|
||||
version = QString(Py_GetVersion());
|
||||
version.replace("\n", " ");
|
||||
|
||||
fprintf(stderr, "Python loaded [%s]\n", version.toStdString().c_str());
|
||||
|
||||
loaded = true;
|
||||
}
|
||||
48
src/Python/PythonEmbed.h
Normal file
48
src/Python/PythonEmbed.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Mark Liversedge (liversedge@gmail.com)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef GC_PYTHONEMBED_H
|
||||
#define GC_PYTHONEMBED_H
|
||||
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class PythonEmbed;
|
||||
extern PythonEmbed *python;
|
||||
|
||||
// a plain C++ class, no QObject stuff
|
||||
class PythonEmbed {
|
||||
|
||||
public:
|
||||
|
||||
PythonEmbed(const bool verbose=false, const bool interactive=false);
|
||||
~PythonEmbed();
|
||||
|
||||
// the program being constructed/parsed
|
||||
QStringList program;
|
||||
|
||||
QString name;
|
||||
QString version;
|
||||
|
||||
bool verbose;
|
||||
bool interactive;
|
||||
|
||||
bool loaded;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -17,6 +17,15 @@
|
||||
# can be run to install these packages; see it for more info.
|
||||
#DEFINES += GC_WANT_R
|
||||
|
||||
# Uncomment below if you want Python charting / ML etc
|
||||
# You will need Python Development tools installed
|
||||
# PYTHONHEADER goes directly into the header file so
|
||||
# make sure you escape the braces etc
|
||||
#DEFINES += GC_WANT_PYTHON
|
||||
#PYTHONHEADER = \<python3.6/Python.h\>
|
||||
##PYTHONINCLUDES = -I/usr/include
|
||||
#PYTHONLIBS = -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -lpython3.6m
|
||||
|
||||
# put output into a separate dir
|
||||
# to keep main directory clear
|
||||
#DESTDIR = .
|
||||
|
||||
38
src/src.pro
38
src/src.pro
@@ -82,7 +82,7 @@ lessThan(QT_MAJOR_VERSION, 5) {
|
||||
###=======================================================================
|
||||
### Directory Structure - Split into subdirs to be more manageable
|
||||
###=======================================================================
|
||||
INCLUDEPATH += ./ANT ./Train ./FileIO ./Cloud ./Charts ./Metrics ./Gui ./Core ./R ./Planning
|
||||
INCLUDEPATH += ./ANT ./Train ./FileIO ./Cloud ./Charts ./Metrics ./Gui ./Core ./R ./Python ./Planning
|
||||
QMAKE_CFLAGS_ISYSTEM =
|
||||
|
||||
|
||||
@@ -266,6 +266,42 @@ RESOURCES = $${PWD}/Resources/application.qrc $${PWD}/Resources/RideWindow.qrc
|
||||
DEFINES += GC_HAVE_LMFIT
|
||||
}
|
||||
|
||||
###=========================
|
||||
### OPTIONAL => Embed Python
|
||||
###=========================
|
||||
|
||||
notsupported = "INFO: Embedded Python requires version QT >= 5.9, no support for"
|
||||
notsupported += $${QT_VERSION}
|
||||
|
||||
contains(DEFINES, "GC_WANT_PYTHON") {
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||
|
||||
greaterThan(QT_MINOR_VERSION, 8) {
|
||||
|
||||
DEFINES += GC_PYTHONHEADER=$${PYTHONHEADER}
|
||||
!isEmpty(PYTHONINCLUDES) QMAKE_CXXFLAGS += $${PYTHONINCLUDES}
|
||||
LIBS += $${PYTHONLIBS}
|
||||
|
||||
## Python integration
|
||||
HEADERS += Python/PythonEmbed.h
|
||||
SOURCES += Python/PythonEmbed.cpp
|
||||
|
||||
DEFINES += GC_HAVE_PYTHON
|
||||
|
||||
} else {
|
||||
# QT5 but not 5.5 or higher
|
||||
message($$notsupported)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
# QT5 but not 5.5 or higher
|
||||
message($$notsupported)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
###====================
|
||||
### OPTIONAL => Embed R
|
||||
###====================
|
||||
|
||||
Reference in New Issue
Block a user