How to add a simple level indicator?
#1
First off, I 'm very new to kodi and programming. I'm working on a Raspberry Pi carputer project with some addons I have created my self (ADC inputs and a serial interface to car bus which is pre-OBD2).

I'm pulling some OBD type data such as coolant temperature which I can easily display the actual value of (a number) but I would like to also add a visual indication such as in the pic below. A visual can be interpreted with a quick glance as opposed to numbers which take a little time to comprehend.

Image

I had thought about using a progress bar to do this but I don't know how to pass a numerical value (percent) to it. Or perhaps there is a more suitable control I could use? It will be updated ~ twice per second. Was hoping someone more knowledgeable than I could get me started in the right direction....

Thanks!

Please let me know if this would be better posted in the Addons section?
Reply
#2
Hello,

did you ever come to implement this? I'm looking for the same implementation.
tnx
Reply
#3
Yes I did.

In your window XML code you need something like this

Code:
<window id="1300">
    <defaultcontrol always="true">1303</defaultcontrol>
    <controls>
        <include>Window_OpenClose_Animation_Zoom</include>
        <include>CommonBackground</include>

        <control type="progress" id="1325">
        <description>level</description>
        <include>Window_OpenClose_Animation_Zoom</include>
        <posx>190</posx>
        <posy>350</posy>
        <width>500</width>
        <height>18</height>
        <texturebg>grey3.png</texturebg>
        <midtexture>green3.png</midtexture>
        <info></info>
        </control>

grey3.png and green3.png are my files defining the look and were created using MS Paint (neither require transparency). grey3.png is my back ground which I made black with a light grey 1 x pix border. Green3.png is the bar which kodi stretches and shrinks to size. These go in your Addon 'Media' folder.

In your python code you need something like this
Code:
xel=xbmcgui.Window(13000)      
xel.getControl(1325).setPercent(float (psi0))

psi0 is my computed value (0-100). Note that the control can only be captured and updated when it is displayed (otherwise kodi will error) so you have to verify this before updating it. I do this by setting a flag when the widow displaying this progress bar is opened and clearing it when the window closes. I check for this flag before updating the progress bar...So I update the progress bar only when it is displayed. Hope this makes sense to you..
Reply
#4
Thank you very much for this info. I'll try to implement this on my setup. I'll be using the fuel level or battery voltage as an example, see if I get get this displayed correctly. The thing is, I'll need to convert the data I believe. e.g. the python code delivering the fuel-level will return a decimal value, say: 30.5 (in liters). If I need to use your code above to parse this value to the gui, do I need to convert the value in "percentage" before ?

A screenshot of what your GUI looks like would be usefull as inspiration for me.

tnx again for the support.
Reply
#5
Here is how I am using the progress bar

Image

Yes you must convert to percent. You need a floating point number between zero and 100. To begin with you can just type in a number such as
xel.getControl(1325).setPercent(50.0) which will set the bar at mid scale.
Reply
#6
Thank you! That looks awsome. I'mm try to implement that on my skin. I might come back her for help.
Greetings,
Reply
#7
Hi km5tz,
I'm trying to do something like this in a skin (update a progress bar with a script) and I'm not getting anywhere - I've been told it's not possible (here). Any chance you could share more of your code with me so I could see what's different about what you're doing?
HDHomerun Quatro, RaspPi/TVHeadend, NUC/Win10/Kodi, Mousetuary skin, Mouse on couch!
Reply
#8
(2017-05-27, 00:13)aegidius Wrote: Hi km5tz,
I'm trying to do something like this in a skin (update a progress bar with a script) and I'm not getting anywhere - I've been told it's not possible (here). Any chance you could share more of your code with me so I could see what's different about what you're doing?

Everything is described in the post above. What are you having difficulty with?
Reply
#9
I tried exactly what you did - basically I could not get any control in an XML file to respond to commands from the python script. Log kept giving script failures with "nonexistent control nnnn" where nnn was the ID in the XML.

I ended up solving the problem a different way - by loading the existing XML from the script directly (as an XML window dialog) and creating extra controls from the python script for its use. A lot of things that should have worked didn't, but I faked up a progress bar out of buttons. Unlike XML, you can control their sizes and positions at runtime by the script.
HDHomerun Quatro, RaspPi/TVHeadend, NUC/Win10/Kodi, Mousetuary skin, Mouse on couch!
Reply

Logout Mark Read Team Forum Stats Members Help
How to add a simple level indicator?0