Hello everyone,
I have a problem displaying the image through this method:
self[widget_name].instance.setPixmap(ptr)
I got the error:
{ D } AttributeError: 'NoneType' object has no attribute 'setPixmap'
Everything works outside of my main (very long) plugin code within the Screen class. However, it does not work in my main plug-in code - I always get the error. I know what this error message is about, but I can not imagine what it means in the context of Enigma. I've tried a lot of things.
It looks like the plugin code does not recognize the "widget screen instance" and reports that there is no .setPixmap method for this "instance". What's interesting is that, beyond the basic plugin, the same code for displaying the image works pefectly. I was trying to make a simple short plugin especially just to open the picture and it worked.
Does anyone know what to do with Enigma could be bad ?
Thanks.
In the past, the short plug-in working code + the debug-log error:
04:15:19.6979 { D } self["content_pic"].instance.setPixmap(ptr.__deref__()) # .instance.setPixmap(ptr) # .instance.setPixmap(ptr.__deref__())
04:15:19.6984 { D } AttributeError: 'NoneType' object has no attribute 'setPixmap'
Separate extracted code to display an image that works as a standalone:
###########################################################################
from Screens.Screen import Screen
from Components.Label import Label
from Components.ActionMap import ActionMap
from Plugins.Plugin import PluginDescriptor
from Components.Pixmap import Pixmap
from Components.AVSwitch import AVSwitch
from enigma import ePicLoad, gPixmapPtr
import urllib2 # tento modul vyuzivam na downloadnutie suborov z URL adresy (na disk)
from os import path as os_path, remove as os_remove
cacheUserImages = []
###########################################################################
class HelloWorldScreen(Screen):
skin = '''
<screen position="0,0" title="zobrazenia obrazka" size="1280,720" flags="wfNoBorder">
<widget name="myLabel" position="10,60" size="400,100" font="Regular;20"/>
<widget name="content_pic" position="center,center" size="1280,720" zPosition="1" alphatest="on" />
</screen>
'''
# transparent="1" alphatest="blend" zPosition="-10"
def __init__(self, session, args = None):
Screen.__init__(self, session)
self.session = session
self["content_pic"] = Pixmap()
self["content_pic"].hide()
self["myLabel"] = Label("Hello World ;-)\nStlacaj tlacidla 1, 2, 3, 4.")
self["myActionMap"] = ActionMap( ['OkCancelActions','ColorActions','DirectionActions','SetupActions','MenuActions',
'InfobarEPGActions','InfobarMenuActions','InfobarChannelSelection','GlobalActions'], {
'1' : self.fn1 ,
'2' : self.fn2 ,
'3' : self.fn3 ,
'4' : self.fn4 ,
'cancel' : self.close } , -1)
def fn1(self):
print('MYDEBUGLINE - pokus o otvorenie "images/test1.jpg"')
self.imgRenderWithCache('/usr/lib/enigma2/python/Plugins/Extensions/lesson_07_s3n0/images/test1.jpg')
def fn2(self):
print('MYDEBUGLINE - pokus o otvorenie "images/test2.jpg"')
self.imgRenderWithCache('/usr/lib/enigma2/python/Plugins/Extensions/lesson_07_s3n0/images/test2.jpg')
def fn3(self):
print('MYDEBUGLINE - pokus o otvorenie "images/test3.jpg"')
self.imgRenderWithCache('/usr/lib/enigma2/python/Plugins/Extensions/lesson_07_s3n0/images/test3.jpg')
def fn4(self):
print('MYDEBUGLINE - pokus o otvorenie URL online HTTP image')
self.imgRenderWithCache('https://www.planwallpaper.com/static/images/general-night-golden-gate-bridge-hd-wallpapers-golden-gate-bridge-wallpaper.jpg')
def imgRenderWithCache(self, file_path):
global cacheUserImages
self.file_path = file_path
self.idx = [ i for i, j in enumerate(cacheUserImages) if j[0] == self.file_path ]
if not self.idx: # ak sa nenachadza obrazok v cacheUserImages, tak idem ho nacache-ovat
self.loadImageIntoCache(self.file_path)
self.idx = [ i for i, j in enumerate(cacheUserImages) if j[0] == self.file_path ] # vyhladam index obrazku v cache este raz, uz po znovunahrati obrazka do cache
self.idx = self.idx[0] # skonvertujem <tuple> ci <list> datovy typ na <integer> typ (index na cache musi predstavovat ciselnu hodnotu a ziadny iny datovy typ akym je napr. <tuple>)
ptr = cacheUserImages[self.idx][1]
print('MYDEBUGLINE - img cached data types 0,1:\n%s\n%s\nimg cached data values 0,1:\n%s\n%s\n' % ( type(cacheUserImages[self.idx][0]) , type(ptr) , cacheUserImages[self.idx][0] , ptr ) )
print('MYDEBUGLINE - "content_pic" - type = %s\ndata = %s' % ( type(self["content_pic"]) , self["content_pic"]) )
self["content_pic"].instance.setPixmap(ptr) # .instance.setPixmap(ptr) # .instance.setPixmap(ptr.__deref__())
self["content_pic"].show()
def loadImageIntoCache(self, img_location):
#print('MYDEBUGLINE - obrazok %s sa zatial nenachadza v cache' % img_location)
if img_location[:4] == 'http': # ak jedna o online odkaz na obrazok (HTTP), tak...
self.img = '/tmp/' + os_path.basename(img_location) # self.img = '/tmp/' + self.img.split('/')[-1]
if not self.downloadFile(img_location, self.img): # download image to local disk (/tmp)
print('MYDEBUGLINE - the online image file %s was not found ! so the default local image file will be used !' % self.img)
self.img = '/usr/lib/enigma2/python/Plugins/Extensions/AdRelax/images/wallpaper-transparent65.png'
else: # ak sa vsak jedna o fyzicky subor obrazku na lokalnom disku, tak...
self.img = img_location
if not os_path.exists(self.img):
print('MYDEBUGLINE - the local image file %s was not found ! so the default local image file will be used !' % self.img)
self.img = '/usr/lib/enigma2/python/Plugins/Extensions/AdRelax/images/wallpaper-transparent65.png'
self.img = str(self.img) # musim skonvertovat dodatocne natvrdo znovu nahodny datovy typ, na <str> datovy typ, nakolko nechce potom korektne fungovat metoda .startDecode() napisana v C-jazyku, tiez pridrizene objekty nesmu byt v Unicode znakoch a konverzia na string v Python by to mala vyriesit
#### vyrenderovanie / zdekodovanie obrazka do premennej ptr :
self.picload = ePicLoad()
sc = AVSwitch().getFramebufferScale()
size = self['content_pic'].instance.size()
if self.picload:
self.picload.setPara(( size.width(), size.height(), sc[0], sc[1], False, 1, '#FF000000' ))
# max-X, max-Y, scale-X, scale-Y, aspect_ratio=1.000000, useCache=False, resizetype=1, bg=#FF000000
# max_x(0), max_y(0), .........., aspect_ratio(1.066400), background(0), resizetype(1), usecache(false), thumbnailsize(180)
# setPara(width, height, aspectRatio, as, useCache, resizeType, bg_str)
if self.picload.startDecode(self.img, 0, 0, False) == 0:
ptr = self.picload.getData()
if ptr is not None:
global cacheUserImages
cacheUserImages.append([img_location, ptr])
print('MYDEBUGLINE - img %s successful decoded into cache' % self.img)
print('MYDEBUGLINE - img cached data types 0,1:\n%s\n%s\nimg cached data values 0,1:\n%s\n%s\n' % ( type(img_location) , type(ptr) , img_location , ptr ) )
del self.picload
if img_location[:4] == 'http': # ak sa jednalo o stiahnuty subor z internetu a nahravany do cache, zmazem ho z disku po nahrati do cache
os_remove(self.img)
# pre stiahnutie obrazkovych suborov z internetu musim zmenit UserAgent-a v requestovacej hlavicke, nakolko niektore webstranky nedovoluju stahovat obrazky aj urllib2 klientovi, ktory sa pouziva v Python jazyku
def downloadFile(self, url, targetfile): # targetfile = '/tmp/' + os_path.basename(url)
self.header = { 'User-Agent' : 'Mozilla/5.0' }
try: # open the url and download as file
self.req = urllib2.Request(url, None, self.header)
self.html = urllib2.urlopen(self.req).read()
with open(targetfile,'w') as f:
f.write(self.html)
except HTTPError, e:
print "HTTP Error:", e.code, url
return False
except URLError, e:
print "URL Error:", e.reason, url
return False
except IOError, e:
print "I/O Error:", e.reason, targetfile
return False
return True
###########################################################################
def main(session, **kwargs):
print("MYDEBUGLINE - Hello World starts")
session.open(HelloWorldScreen)
###########################################################################
def Plugins(**kwargs):
return PluginDescriptor(
name = "50 Hello World - vykreslenie obrazka",
description = "podla ihad tutorial lesson 07",
where = PluginDescriptor.WHERE_PLUGINMENU,
icon = "images/hashtag.png",
fnc = main)
Alles anzeigen