xbmcgui.ListItem
#1
Hi,

I try something in my Addon.
I do not know anything about python so do not tell me "learn or leave"

This is my Code
Code:
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import time

import xbmcaddon
import xbmcgui
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306


addon        = xbmcaddon.Addon()
addonname     = addon.getAddonInfo('name')
path = addon.getAddonInfo('path').decode('utf-8')

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import subprocess
# Raspberry Pi pin configuration:
RST = 24
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0

# 128x32 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width
height = disp.height
image = Image.new('1', (width, height))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
draw.rectangle((0,0,width,height), outline=0, fill=0)

# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
padding = -2
top = padding
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 0


# Load default font.
font = ImageFont.truetype('/home/osmc/lcd.ttf', 52)

# Alternatively load a TTF font.  Make sure the .ttf font file is in the same directory as the python script!
# Some other nice fonts to try: http://www.dafont.com/bitmap.php
# font = ImageFont.truetype('Minecraftia.ttf', 8)

while True:

    # Draw a black filled box to clear the image.
    draw.rectangle((0,0,width,height), outline=0, fill=0)

    # Shell scripts for system monitoring from here : https://unix.stackexchange.com/questions/119126/command-to-display-memory-usage-disk-usage-and-cpu-load
  
    CPU = xbmcgui.ListItem(title)
  

    # Write two lines of text.

    
    draw.text((x, top+5),     str(CPU), font=font, fill=255)
  

    # Display image.
    disp.image(image)
    disp.display()
    time.sleep(.1)

My question, How can I get InfoLabels from Kodi to show on my small Display.

Thanks for help.
Reply
#2
xbmcgui.listitem is how you build and recall custom items, If all you want is playing meta, use infolabels...

http://kodi.wiki/view/InfoLabels#Player_labels

Code:
xbmc.getInfoLabel('Player.Title')
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#3
Wow thank you.
O.K. I get it so far. But it shows the wrong ListItem.Label.
Next Question,
How can I Scroll the text?
And how can I change the InfoLabel on different view. Like Clock on Menu. Name on Movie view....
Thanks again for Help
Reply
#4
@tjost

Quote:I do not know anything about python so do not tell me "learn or leave"

There's absolutely nothing wrong with being a beginner and asking elementary questions. But you should realize that nobody is going to write your code for you so it's better to have some general knowledge to apply given advice to your code.

Quote:How can I Scroll the text?

From the code in the OP I see that you are using PIL library to render text as an image bitmap for a RPi mini-display. You need to render your scrolling animation frame by frame and output it to the mini-display. This is not a trivial task for an absolute beginner so you should learn some basics, after all.

Quote:And how can I change the InfoLabel on different view. Like Clock on Menu. Name on Movie view....

The post above yours contain a lint to the listing of available infolabels. Use appropriate infolabel to retrieve the necessary information.
Reply
#5
Quote:There's absolutely nothing wrong with being a beginner and asking elementary questions. But you should realize that nobody is going to write your code for you so it's better to have some general knowledge to apply given advice to your code.

I am trying by myself and figured out a lot of things.

And i don´t want anyone to write my code. I do just need some help for understanding.

Yes I am using the PIP Library and Scrolling is not easy.

I can Show ChannelNumber or Name.

Question:
How can I check if the 'CPU' has a value and if its empty than show something else?

Like:
if CPU=1
draw.text ...
else
draw.text ...

?

Thank You

The Problem is I searched now 3 Month in the Internet for a driver to use my Display with LCDProc but nothing. And Compiling a driver I way over my skills.
Reply
#6
@tjost

Quote:How can I check if the 'CPU' has a value and if its empty than show something else?

Again, I strongly recommend to learn some basics, because you won't achieve much by blind copy-pasting without understanding what you are doing. And comparison operators are Python 101: https://www.tutorialspoint.com/python/co...xample.htm

Note that Python is a strongly (but dynamically) typed language so comparing values of different types (e.g. str and int: '2' == 2) always produces False. The only exception are str and unicode types which you can actually compare (in Python 2 only). And to test a string for emptiness you don't need to compare it with an empty string, an empty string is always tested as False, and a non-empty string is tested as True:
PHP Code:
if foo:
    ...
else:
    ... 
Reply
#7
@ Roman_V_M

ok i do understand your point but I am not a person who is capable of reading theoretical stuff and understand it.
I try and then I do have an idea and try to do it. If it dosen´ twerk. I ask. Thats why there are Forums.
If anyone would learn first and then ask no one needs a Forum.

But is not only in this Forum it is in nearly every Forum like this. Learn it and then ask questions. Thats the wrong way. New Ideas came only from people that try before they know what they where doing.

I hope my point is clear. More help for Noobs Smile
Reply
#8
(2017-06-22, 18:58)tjost Wrote: @ Roman_V_M

ok i do understand your point but I am not a person who is capable of reading theoretical stuff and understand it.
I try and then I do have an idea and try to do it. If it dosen´ twerk. I ask. Thats why there are Forums.
If anyone would learn first and then ask no one needs a Forum.

But is not only in this Forum it is in nearly every Forum like this. Learn it and then ask questions. Thats the wrong way. New Ideas came only from people that try before they know what they where doing.

I hope my point is clear. More help for Noobs Smile

I think you're missing valid points made by @Roman_V_M .. I undestand we were all noobs at some level in our life.
The Issue stems from your OP; your question was answered. Despite that you now want the next step in code, in essence you want someone to write the code for you.

A good rule of thumb I wish all noobs would follow should be to post all code then ask for help.... If I see a genuine attempt at coding, I'll chip in. However, I'd rather educate than assist.
SHOW ALL WORK, as you would in a classroom and I'm sure you will find a number of people willing to help you.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#9
@ Lunatixz

I get your point. I am sorry if it looks like this but this is not what I want.
I do not want anyone to write my code.
I searched for answers in the web and tried the code but get stuck so I asked again.
Look at the times of my posts.

But I do understand the misunderstanding.
Reply
#10
Code:
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import time

import xbmcaddon
import xbmcgui
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import os

addon        = xbmcaddon.Addon()
addonname     = addon.getAddonInfo('name')
path = addon.getAddonInfo('path').decode('utf-8')

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont


    
import subprocess
# Raspberry Pi pin configuration:
RST = 24
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0

# 128x32 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))
thumb = xbmc.getInfoImage('ListItem.Thumb')
thumb.save('/home/osmc/thumbnail.png', 'PNG')

# Raspberry Pi pin configuration:
RST = 24
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0

# 128x32 display with hardware I2C:
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)

# 128x64 display with hardware I2C:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)

# 128x32 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# 128x64 display with hardware SPI:
# disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, dc=DC, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE, max_speed_hz=8000000))

# Initialize library.
disp.begin()

# Clear display.
disp.clear()
disp.display()

# Load image based on OLED display height.  Note that image is converted to 1 bit color.
# if disp.height == 64:
#    image = Image.open('happycat_oled_64.ppm').convert('1')
# else:
#    image = Image.open('happycat_oled_32.ppm').convert('1')

# Alternatively load a different format image, resize it, and convert to 1 bit color.
image = Image.open('/home/osmc/thumbnail.png').resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')

# Display image.
disp.image(image)
disp.display()
Quote:ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.AttributeError'>
Error Contents: 'str' object has no attribute 'save'
Traceback (most recent call last):
File "/home/osmc/.kodi/addons/script.silentservice.xbmc/LCD.py", line 66, in <module>
thumb.save('/home/osmc/thumbnail.png', 'PNG')
AttributeError: 'str' object has no attribute 'save'
-->End of Python script error report<--

I try to get the thumbnail of my TV Channel and save it.
and then I want to open the File resize it and make a 1bit image of it.

But I do not understand the error message and nothing is saved.
I think I have to import something so the script can save the image!?

Please give me a hint. THX
Reply
#11
@tjost

Quote:I do not want anyone to write my code.

Nevertheless that is exactly what are you doing: throwing some random combination of symbols and expecting someone to clean your mess. If someone wants to write your code for you - it is their choice but you have no right to criticize the community for not willing to work for you for free.

Quote:If anyone would learn first and then ask no one needs a Forum.

It is not true. Nobody can know everything. Even a skilled Python coder who mastered Django, Pandas or other big name libraries may not know the details of working with Kodi API, so there's always topics to discuss.

Quote:But is not only in this Forum it is in nearly every Forum like this. Learn it and then ask questions. Thats the wrong way.

This is the right way because there is a big difference between helping a beginner and willing to work for free for some guy who does not want to learn basic stuff. And your last question does not have anything to do with Kodi, actually. You threw a random string that does not work (big surprise here), and expect that someone will re-write it into working code which, again, is not exactly Kodi-specific. If this is not tricking people into writing your code for you then I don't want to say.
Reply
#12
@ Roman_V_M

I think only you and the other are not willing to unterstand.
I want help with Python to show stuff on my Display.
No one asked you for help personally and if you do not want to help then leave the post.
Do not annoy me with your opinion because of your misunderstanding.

People like you destroy the open community.

I am disappointed and angry.

You ONLY had to look at the code and tell me what my mistake was like "str expect a value and there is none. Try this or try that to show if there is a value."
Thats all. Nothing more and nothing less.
If you are not willing to help do not answer. Very simple.

So close this Threat I will never asked again. Do it all for myself.
Reply
#13
(2017-06-23, 15:31)tjost Wrote: @ Roman_V_M

I think only you and the other are not willing to unterstand.
I want help with Python to show stuff on my Display.
No one asked you for help personally and if you do not want to help then leave the post.
Do not annoy me with your opinion because of your misunderstanding.

People like you destroy the open community.

I am disappointed and angry.

You ONLY had to look at the code and tell me what my mistake was like "str expect a value and there is none. Try this or try that to show if there is a value."
Thats all. Nothing more and nothing less.
If you are not willing to help do not answer. Very simple.

So close this Threat I will never asked again. Do it all for myself.

@tjost nobody is destroying the community...

I believe you're starting in the wrong place, Perhaps you should find a python for beginners discussion forum?
Once you have a fundamental understanding, come back here with your Kodi specific questions.
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply

Logout Mark Read Team Forum Stats Members Help
xbmcgui.ListItem0