Hi everyone
I have a question about how is the syntax to execute the action to add or remove the props.pends object in a power chart from the script, I'm programming a button to add a path of history from a table already configured, what I need is to add this path to the pen, and likewise remove it, could you please give me an idea, is that so far I'm starting on this topic.
Thank you very much
Adding a pen:
def runAction(self, event):
history_provider = "QADB"
tag_provider = "default"
desired_name = "sine3"
tag_path = "_symulation_/sine/sine3"
desired_pen_color = "#00FF00"
# Now, construct a historical source to refer to.
source = "histprov:{0}:/drv:qa-robot:{1}:/tag:{2}".format(history_provider, tag_provider, tag_path)
pen_shape = {
"visible": True,
"data": {
"aggregateMode": "default",
"source": source
},
"plot": 0,
"selectable": True,
"display": {
"interpolation": "curveLinear",
"breakLine": True,
"styles": {
"normal": {
"fill": {
"color": desired_pen_color,
"opacity": 0.8
},
"stroke": {
"color": desired_pen_color,
"width": 1,
"dashArray": 0,
"opacity": 0.8
}
},
"highlighted": {
"fill": {
"color": desired_pen_color,
"opacity": 1
},
"stroke": {
"color": desired_pen_color,
"width": 1,
"dashArray": 0,
"opacity": 1
}
},
"muted": {
"fill": {
"color": desired_pen_color,
"opacity": 0.4
},
"stroke": {
"color": desired_pen_color,
"width": 1,
"dashArray": 0,
"opacity": 0.4
}
},
"selected": {
"fill": {
"color": desired_pen_color,
"opacity": 1
},
"stroke": {
"color": desired_pen_color,
"width": 1,
"dashArray": 0,
"opacity": 1
}
}
},
"type": "line",
"radius": 3
},
"name": desired_name,
"axis": "",
"enabled": True
}
self.getSibling("PowerChart").props.pens.append(pen_shape)
Removing the pen:
There are multiple ways to go about this, but essentially you'll want to remove whichever pen entry has the source you want to remove.
def runAction(self, event):
history_provider = "QADB"
tag_provider = "default"
tag_path = "_symulation_/sine/sine3"
source = "histprov:{0}:/drv:qa-robot:{1}:/tag:{2}".format(history_provider, tag_provider, tag_path)
for i in range(len(self.getSibling("PowerChart").props.pens)):
if self.getSibling("PowerChart").props.pens[i].data.source == source:
del self.getSibling("PowerChart").props.pens[i]
I would like to define different pen colors. I see some code examples that creates random colors...
from random import randint
colors = []
for i in range(10):
colors.append('#%06X' % randint(0, 0xFFFFFF))
print colors
... but I was hoping for a consistent approach, where pen 1 is always a certain color, pen 10 is always a certain color, etc.
I know I could define a list and refer to that, but was wondering if a method already existed to do this automatically. Thoughts?