Skip to content

Commit

Permalink
Add Color to Python activityMetrics
Browse files Browse the repository at this point in the history
Using name "color" and renamed "date"/"time" for compatibility with R API
  • Loading branch information
amtriathlon committed Dec 13, 2017
1 parent a3e23fd commit d7579be
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Python/SIP/Bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Athlete.h"
#include "GcUpgrade.h"
#include "PythonChart.h"
#include "Colors.h"

#include "Bindings.h"

#include <QWebEngineView>
Expand Down Expand Up @@ -150,9 +152,9 @@ Bindings::activityMetrics(RideItem* item) const
//
if (PyDateTimeAPI == NULL) PyDateTime_IMPORT;// import datetime if necessary
QDate d = item->dateTime.date();
PyDict_SetItemString(dict, "Date", PyDate_FromDate(d.year(), d.month(), d.day()));
PyDict_SetItemString(dict, "date", PyDate_FromDate(d.year(), d.month(), d.day()));
QTime t = item->dateTime.time();
PyDict_SetItemString(dict, "Time", PyTime_FromTime(t.hour(), t.minute(), t.second(), t.msec()));
PyDict_SetItemString(dict, "time", PyTime_FromTime(t.hour(), t.minute(), t.second(), t.msec()));

//
// METRICS
Expand Down Expand Up @@ -185,6 +187,27 @@ Bindings::activityMetrics(RideItem* item) const
PyDict_SetItemString(dict, field.name.replace(" ","_").toUtf8().constData(), PyUnicode_FromString(item->getText(field.name, "").toUtf8().constData()));
}

//
// add Color
//
QString color;

// apply item color, remembering that 1,1,1 means use default (reverse in this case)
if (item->color == QColor(1,1,1,1)) {

// use the inverted color, not plot marker as that hideous
QColor col =GCColor::invertColor(GColor(CPLOTBACKGROUND));

// white is jarring on a dark background!
if (col==QColor(Qt::white)) col=QColor(127,127,127);

color = col.name();
} else
color = item->color.name();

// add to the dict
PyDict_SetItemString(dict, "color", PyUnicode_FromString(color.toUtf8().constData()));

return dict;
}

Expand Down

0 comments on commit d7579be

Please sign in to comment.