Hallo an alle die sich die Zeit das zu lesen und zu verstehen.
Ich stehe etwas auf dem Schlauch.
Ich versuche mein AddOn für das Adafruit SSD1306 OLED Display zu verfeinern stoße dabei aber eine Grenze.
Hier mal mein 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 sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
sys.path.append('/storage/.kodi/addons/virtual.SSD1306-libraries/lib')
reload(sys)
sys.setdefaultencoding('utf-8')
import time
import xbmcvfs
import subprocess
import xbmcaddon
import xbmcgui
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
import os
import os.path
addon = xbmcaddon.Addon()
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))
# 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()
width = disp.width
height = disp.height
image = Image.new('1', (width, height))
image3 = Image.new('1', (width, height))
image6 = 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)
# big thanks to Melewo from the Python-Forum.de for helping me get on track.
padding = 38
shape_width = 128
top = 0
bottom = height-padding
# Move left to right keeping track of the current x position for drawing shapes.
x = 18
x2 = 8
x3 = 0
while True:
# Move left to right keeping track of the current x position for drawing shapes.
playercontent = xbmc.getInfoLabel("Window.Property(xmlfile)")
chnumber = xbmc.getInfoLabel("VideoPlayer.ChannelNumberLabel")
date = xbmc.getInfoLabel("System.Date(dd mm yy)")
movies = xbmc.getCondVisibility("VideoPlayer.Content(movies)")
episodes = xbmc.getCondVisibility("VideoPlayer.Content(episodes)")
videofiles = xbmc.getCondVisibility("VideoPlayer.Content(files)")
livetv = xbmc.getCondVisibility("VideoPlayer.Content(livetv)")
systemwindow = xbmc.getInfoLabel("Window.Property(xmlfile)")
videotime = xbmc.getInfoLabel("VideoPlayer.TimeRemaining")
season = xbmc.getInfoLabel("VideoPlayer.Season")
episode = xbmc.getInfoLabel("VideoPlayer.Episode")
systemtime = xbmc.getInfoLabel("System.Time")
cpulast = xbmc.getInfoLabel("System.CoreUsage(total)")
memlast = xbmc.getInfoLabel("System.Memory(used)")
thumb = xbmc.getInfoLabel("VideoPlayer.ChannelName").decode('utf-8')
audiotype = xbmc.getInfoLabel("MusicPlayer.Codec")
audioduration = xbmc.getInfoLabel("MusicPlayer.TimeRemaining")
suffix = '.png'
suffix2 = '.ttf'
#studioaddon = resource.images.studios.white.getAddonInfo('path').decode('utf-8')
path = addon.getAddonInfo('path').decode('utf-8')
fullpath = os.path.join(path, 'icon/')
display = os.path.join(fullpath, thumb + suffix).decode('utf-8')
error = os.path.join(fullpath, "error" + suffix).decode('utf-8')
alternate = os.path.join(fullpath, 'error' + suffix)
menu = os.path.join(fullpath, 'menu' + suffix)
fontpath = os.path.join(fullpath, 'tiny' + suffix2)
font10= ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 10)
font18 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 18)
font28 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 28)
font30 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 30)
font32 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 32)
font36 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 36)
font60 = ImageFont.truetype('/usr/share/fonts/liberation/LiberationSans-Regular.ttf', 60)
time.sleep(2)
#image = Image.open(display).resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')
if playercontent=="movies":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), systemtime, font=font36, fill=255)
draw.text((x2, padding), videotime, font=font28, fill=255)
disp.image(image)
elif playercontent=="tvshows":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x3, top), "S:" + season + "/E:" + episode, font=font28, fill=255)
draw.text((x2, padding), videotime, font=font28, fill=255)
disp.image(image)
elif playercontent=="files":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), systemtime, font=font36, fill=255)
draw.text((x2, padding), videotime, font=font28, fill=255)
disp.image(image)
elif playercontent=="LiveTV":
def file():
try:
image2 = Image.open(display).resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')
disp.image(image2)
pass
except thumb=="":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), systemtime, font=font36, fill=255)
draw.text((x2, padding), date, font=font28, fill=255)
disp.image(image)
pass
except UnicodeEncodeError:
image6 = Image.open(error).resize((disp.width, disp.height), Image.ANTIALIAS).convert('1')
disp.image(image6)
pass
except IOError:
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x3, top), chnumber, font=font60, fill=255)
disp.image(image)
pass
except playercontent=="":#files/dvd/
draw.rectangle((0,0,width,height), outline=0, fill=0)
#draw.text((x, top), cpulast +"%" , font=font36, fill=255)
draw.text((x2, padding), videotime, font=font28, fill=255)
disp.image(image)
pass
file()
elif videofiles==True:
def file():
try:
if systemwindow=="Home.xml":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), systemtime, font=font36, fill=255)
draw.text((x2, padding), date, font=font28, fill=255)
disp.image(image)
elif systemwindow=="Settings.xml":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), cpulast +"%", font=font32, fill=255)
draw.text((x2, padding), memlast, font=font28, fill=255)
disp.image(image)
elif systemwindow=="MusicVisualisation.xml":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), audiotype, font=font32, fill=255)
draw.text((x2, padding), audioduration, font=font28, fill=255)
disp.image(image)
elif systemwindow=="script-XBMC_Lyrics-main.xml":
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), audiotype, font=font32, fill=255)
draw.text((x2, padding), audioduration, font=font28, fill=255)
disp.image(image)
else:
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), systemtime , font=font36, fill=255)
draw.text((x2, padding), date, font=font28, fill=255)
disp.image(image)
pass
except ValueError:
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x, top), cpulast +"%" , font=font36, fill=255)
draw.text((x2, padding), videotime, font=font28, fill=255)
disp.image(image)
pass
file()
else:
draw.rectangle((0,0,width,height), outline=0, fill=0)
draw.text((x3, top), playercontent, font=font10, fill=255)
draw.text((x2, padding), "to read here", font=font28, fill=255)
disp.image(image)
# Display image.
disp.display()
Alles anzeigen
Grundsätzlich funktioniert das aber...
Ich möchte von Kodi auslesen ob gerade ein Video läuft, wenn ja mach das wenn nein dann prüfe ob Musik läuft wenn ja dann das... wenn nein dann prüfe welches welches Fenster auf ist und mache entsprechen dem Fenster was ich will.
Ich habe null Ahnung von Python darum kann ich auch keinen schollernden Text oder so aber so wie das hier ist geht es ja nur das Kodi scheinbar immer ausgibt das der VideoPlayer aktiv ist und bei LiveTV,DVD,oder Stream wird keine eindeutige WindowID ausgegeben.
xbmcgui.getCurrentWindowDialogId() gibt gar keinen Wert aus.
Ich hoffe man kann mir helfen.
Danke