diff --git a/lcd4linux/src/Photoframe.py b/lcd4linux/src/Photoframe.py index 234bc7e..920c45b 100644 --- a/lcd4linux/src/Photoframe.py +++ b/lcd4linux/src/Photoframe.py @@ -5,11 +5,12 @@ from usb.util import get_string from PIL import Image from struct import pack +from six import ensure_binary from six.moves import cStringIO as StringIO def write_jpg2frame(dev, pic): - """Attach header to picture, pad with zeros if necessary, and send to frame""" + # Attach header to picture, pad with zeros if necessary, and send to frame # create header and stack before picture # middle 4 bytes have size of picture rawdata = b"\xa5\x5a\x18\x04" + pack('<I', len(pic) + 14) + b"\x48\x00\x00\x00" + pic @@ -22,85 +23,86 @@ def write_jpg2frame(dev, pic): def get_known_devices(): - """Return a dict of photo frames""" - dList = [] + # Return a dict of photo frames + dlist = [] # listed as: Name, idVendor, idProduct, [width , height - in pixel if applicable] - # + #0,1 Samsung SPF-75H/76H (23) - dList.append({'name': "SPF75H/76H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200f, 'width': 800, 'height': 480}) - dList.append({'name': "SPF75H/76H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200e}) + dlist.append({'name': "SPF75H/76H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200f, 'width': 800, 'height': 480}) + dlist.append({'name': "SPF75H/76H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200e}) #2,3 Samsung SPF-87H (24) - dList.append({'name': "SPF87H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2034, 'width': 800, 'height': 480}) - dList.append({'name': "SPF87H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2033}) + dlist.append({'name': "SPF87H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2034, 'width': 800, 'height': 480}) + dlist.append({'name': "SPF87H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2033}) #4,5 Samsung SPF-87Hold (25) - dList.append({'name': "SPF87Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2026, 'width': 800, 'height': 480}) - dList.append({'name': "SPF87Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2025}) + dlist.append({'name': "SPF87Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2026, 'width': 800, 'height': 480}) + dlist.append({'name': "SPF87Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2025}) #6,7 Samsung SPF-83H (26) - dList.append({'name': "SPF83H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200d, 'width': 800, 'height': 600}) - dList.append({'name': "SPF83H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200c}) + dlist.append({'name': "SPF83H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200d, 'width': 800, 'height': 600}) + dlist.append({'name': "SPF83H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200c}) #8,9 Samsung SPF-107H (27) - dList.append({'name': "SPF107H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2036, 'width': 1024, 'height': 600}) - dList.append({'name': "SPF107H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2035}) + dlist.append({'name': "SPF107H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2036, 'width': 1024, 'height': 600}) + dlist.append({'name': "SPF107H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2035}) #10,11 Samsung SPF-105P (28) - dList.append({'name': "SPF105P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x201b, 'width': 1024, 'height': 600}) - dList.append({'name': "SPF105P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x201c}) + dlist.append({'name': "SPF105P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x201b, 'width': 1024, 'height': 600}) + dlist.append({'name': "SPF105P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x201c}) #12,13 Samsung SPF-85H/86H (29) - dList.append({'name': "SPF85H/86H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2013, 'width': 800, 'height': 600}) - dList.append({'name': "SPF85H/86H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2012}) + dlist.append({'name': "SPF85H/86H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2013, 'width': 800, 'height': 600}) + dlist.append({'name': "SPF85H/86H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2012}) #14,15 Samsung SPF-72H (210) - dList.append({'name': "SPF72H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200b, 'width': 800, 'height': 480}) - dList.append({'name': "SPF72H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200a}) + dlist.append({'name': "SPF72H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200b, 'width': 800, 'height': 480}) + dlist.append({'name': "SPF72H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200a}) #16,17 Samsung SPF-700T (211) - dList.append({'name': "SPF700T Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2050, 'width': 800, 'height': 600}) - dList.append({'name': "SPF700T Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x204f}) + dlist.append({'name': "SPF700T Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2050, 'width': 800, 'height': 600}) + dlist.append({'name': "SPF700T Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x204f}) #18,19 Samsung SPF-85P/86P (212) - dList.append({'name': "SPF85P/86P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2017, 'width': 800, 'height': 600}) - dList.append({'name': "SPF85P/86P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2016}) + dlist.append({'name': "SPF85P/86P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2017, 'width': 800, 'height': 600}) + dlist.append({'name': "SPF85P/86P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2016}) #20,21 Samsung SPF-107Hold (213) - dList.append({'name': "SPF107Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2028, 'width': 1024, 'height': 600}) - dList.append({'name': "SPF107Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2027}) + dlist.append({'name': "SPF107Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2028, 'width': 1024, 'height': 600}) + dlist.append({'name': "SPF107Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2027}) #22,23 Samsung SPF-1000P (214) - dList.append({'name': "SPF1000P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2040, 'width': 1024, 'height': 600}) - dList.append({'name': "SPF1000P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2039}) + dlist.append({'name': "SPF1000P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2040, 'width': 1024, 'height': 600}) + dlist.append({'name': "SPF1000P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2039}) #24,25 Samsung SPF-800P (215) - dList.append({'name': "SPF800P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2038, 'width': 800, 'height': 480}) - dList.append({'name': "SPF800P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2037}) + dlist.append({'name': "SPF800P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2038, 'width': 800, 'height': 480}) + dlist.append({'name': "SPF800P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2037}) + + # Amazon Fire 7 (9th Generation 2019) + dlist.append({'name': "Amazon Fire 7 Mini Monitor", 'idVendor': 0x1949, 'idProduct': 0x03C3, 'width': 1024, 'height': 600}) + dlist.append({'name': "Amazon Fire 7 Mass Storage", 'idVendor': 0x1949, 'idProduct': 0x03C1}) # Pearl DPF for Testing - dList.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240}) - dList.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240}) + dlist.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240}) + dlist.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240}) - return dList + return dlist -def find_device(Anzahl, device, device2): - """Try to find device on USB bus.""" +def find_device(anzahl, device, device2): + # Try to find device on USB bus. try: - print("[LCD4linux] looking for frame", Anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct']) - if Anzahl == 2: + print("[LCD4linux] looking for frame", anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct']) + if anzahl == 2: d = list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)) if isinstance(d, list): - if len(d) >= 2: - d = d[1] - else: - d = None + d = d[1] if len(d) >= 2 else None else: d = None else: d = list(list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)))[0] - except: + except Exception: from traceback import format_exc print("[LCD4linux] find exception") print("Error: %s" % format_exc()) @@ -108,9 +110,9 @@ def find_device(Anzahl, device, device2): return d -def init_device(Anzahl, device0, device1): - """First try Mini Monitor mode, then Mass storage mode""" - dev = find_device(Anzahl, device0, device1) +def init_device(anzahl, device0, device1): + # First try Mini Monitor mode, then Mass storage mode + dev = find_device(anzahl, device0, device1) if dev is not None: ## found it, trying to init it @@ -124,7 +126,7 @@ def init_device(Anzahl, device0, device1): ts = time() while True: # may need to burn some time - dev = find_device(Anzahl, device0, device1) + dev = find_device(anzahl, device0, device1) if dev is not None and dev.idProduct == device0["idProduct"]: #switching successful break @@ -140,20 +142,36 @@ def init_device(Anzahl, device0, device1): def frame_init(dev): - """Init device so it stays in Mini Monitor mode""" + # Init device so it stays in Mini Monitor mode # this is the minimum required to keep the frame in Mini Monitor mode!!! -# dev.ctrl_transfer(0xc0, 4 ) -# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) + # dev.ctrl_transfer(0xc0, 4 ) + # dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 ) dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x02) def frame_switch(dev): - """Switch device from Mass Storage to Mini Monitor""" + # Switch device from Mass Storage to Mini Monitor + CTRL_TYPE_VENDOR = (2 << 5) + CTRL_IN = 0x80 + CTRL_RECIPIENT_DEVICE = 0 try: sleep(0.5) + s = "\x00" * 251 dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe) - except: + # dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, s, 0xfe ) + # dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1) + # expect(result, [ 0x03 ]) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2) + # expect(result, [ 0x09, 0x04 ]) + # result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1) + # expect(result, [ 0x46 ]) + # settling of the bus and frame takes about 0.42 sec + # give it some extra time, but then still make sure it has settled + except Exception: print("[LCD4linux] switching ERROR") + # from traceback import format_exc + # print format_exc() finally: sleep(2) @@ -161,25 +179,21 @@ def frame_switch(dev): def name(dev): try: return get_string(dev, 1) - except: + except Exception: try: return get_string(dev, 256, 2) - except: + except Exception: return None def main(): global dev, known_devices_list - known_devices_list = get_known_devices() - # define which frame to use, here use Samsung SPF-87H device0 = known_devices_list[0] # Mini Monitor mode device1 = known_devices_list[1] # Mass Storage mode - dev = init_device(1, device0, device1) print("Frame is in Mini Monitor mode and initialized. Sending pictures now") - image = Image.open("mypicture.jpg") #manipulations to consider: # convert diff --git a/lcd4linux/src/dpf.py b/lcd4linux/src/dpf.py index e21c569..ef692d2 100644 --- a/lcd4linux/src/dpf.py +++ b/lcd4linux/src/dpf.py @@ -2,7 +2,7 @@ from six import PY2 try: from . import dpflib -except: +except Exception: print("[LCD4linux] dpflib-Error") PROPERTY_BRIGHTNESS = 0x01 @@ -15,7 +15,7 @@ def setBacklight(dev, value): try: dev.setProperty(PROPERTY_BRIGHTNESS, value) return True - except: + except Exception: print("[LCD4linux] Error set Backlight") return False @@ -29,7 +29,7 @@ def showImage(dev, image): else: dev.showRGBAImage(0, 0, x, y, ir.tobytes()) return True - except: + except Exception: print("[LCD4linux] Error writing DPF Device") return False @@ -37,9 +37,9 @@ def showImage(dev, image): def open(usb): try: d = dpflib.open(usb) - d.setProperty(PROPERTY_ORIENTATION, 1) +# d.setProperty(PROPERTY_ORIENTATION, 1) print("[LCD4linux] open %s" % usb) - except: + except Exception: d = None print("[LCD4linux] open Error: %s" % usb) return d @@ -49,5 +49,5 @@ def close(dev): try: if dev is not None: dev.close() - except: + except Exception: pass diff --git a/lcd4linux/src/module.py b/lcd4linux/src/module.py index 4d5a0b6..a68668c 100644 --- a/lcd4linux/src/module.py +++ b/lcd4linux/src/module.py @@ -79,14 +79,14 @@ def getHold(self): return L4Lelement.Hold def setHold(self, H): - print("[LCD4linuxE] Hold: %s" % H) + print("[LCD4linuxE] hold: %s" % H) L4Lelement.Hold = H def getHoldKey(self): return L4Lelement.HoldKey def setHoldKey(self, H=False): - print("[LCD4linuxE] HoldKey: %s" % H) + print("[LCD4linuxE] holdkey: %s" % H) L4Lelement.HoldKey = H def getFont(self, F="0"): @@ -102,29 +102,27 @@ def getScreen(self): return L4Lelement.Screen def setScreen(self, S, Lcd="", Hold=False): - if Lcd != "": - if len(str(Lcd)) > 1 or int(Lcd) > 3: - Lcd = "1" + if Lcd != "" and (len(str(Lcd)) > 1 or int(Lcd) > 3): + Lcd = "1" L4Lelement.Screen = str(S) L4Lelement.LCD = str(Lcd) L4Lelement.Hold = Hold L4Lelement.Refresh = True - def resetBrightness(self, AKT=""): + def resetBrightness(self, AKT=[]): if len(AKT) == 3: L4Lelement.BrightAkt = AKT else: L4Lelement.Bright = [-1, -1, -1] def setBrightness(self, LCD, BRI=-1): - if int(LCD) < 1 or int(LCD) > 3: - return - L4Lelement.Bright[int(LCD) - 1] = int(BRI) - L4Lelement.Refresh = True + if int(LCD) > 0 and int(LCD) < 4: + L4Lelement.Bright[int(LCD) - 1] = int(BRI) + L4Lelement.Refresh = True def getBrightness(self, LCD=0, ORG=True): if int(LCD) > 0 and int(LCD) < 4: - return L4Lelement.Bright[int(LCD) - 1] if ORG == False else L4Lelement.BrightAkt[int(LCD) - 1] + return [L4Lelement.Bright[int(LCD) - 1]] if ORG == False else [L4Lelement.BrightAkt[int(LCD) - 1]] else: return L4Lelement.Bright if ORG == False else L4Lelement.BrightAkt @@ -145,14 +143,13 @@ def getstatusoutput(cmd): sts = pipe.close() if sts is None: sts = 0 - if text[-1:] == '\n': + if text.endswith == '\n': text = text[:-1] except Exception: sts = 1 text = "- -" print("[LCD4linux] Error on os-call") - finally: - return sts, text + return sts, text def L4LVtest(VV): @@ -172,6 +169,7 @@ def L4LVtest(VV): if O != "": try: f = open(L4Linfo % (O, P)) + B = f.readline() OO = f.readline().strip().split()[1].startswith(VV[1:]) f.close() except Exception: diff --git a/lcd4linux/src/plugin.py b/lcd4linux/src/plugin.py index 1648467..6ded4bd 100644 --- a/lcd4linux/src/plugin.py +++ b/lcd4linux/src/plugin.py @@ -35,7 +35,7 @@ from icalendar import vDatetime, Calendar as iCalendar from imaplib import IMAP4_SSL, IMAP4 from math import pi, floor, cos -from mutagen.id3 import ID3 +from mutagen.id3 import ID3 # type: ignore from mutagen.mp3 import MP3 from mutagen.flac import FLAC from mutagen.easyid3 import EasyID3 @@ -176,7 +176,7 @@ get_backend(find_library=lambda x: "/lib64/libusb-1.0.so.0") print("[LCD4linux] libusb found :-)", getEnigmaVersionString()) USBok = True -Version = "V5.0-r24" +Version = "V5.0-r25" L4LElist = L4Lelement() L4LdoThread = True LCD4enigma2config = resolveFilename(SCOPE_CONFIG) # /etc/enigma2/ @@ -314,7 +314,7 @@ TimeSelect = [("1", _("5s")), ("2", _("10s")), ("3", _("15s")), ("4", _("20s")), ("6", _("30s")), ("8", _("40s")), ("10", _("50s")), ("12", _("1min")), ("24", _("2min")), ("36", _("3min")), ("48", _("4min")), ("60", _("5min")), ("120", _("10min")), ("240", _("20min")), ("360", _("30min")), ("720", _("60min")), ("1440", _("2h")), ("2160", _("3h")), ("3600", _("5h"))] LCDSelect = [("1", _("LCD 1")), ("2", _("LCD 2")), ("12", _("LCD 1+2")), ("3", _("LCD 3")), ("13", _("LCD 1+3")), ("23", _("LCD 2+3")), ("123", _("LCD 1+2+3"))] LCDSwitchSelect = [("0", _("LCD 1-3")), ("1", _("LCD 1")), ("2", _("LCD 2")), ("3", _("LCD 3"))] -LCDType = [("11", _("Pearl (or compatible LCD) 320x240")), ("12", _("Pearl (or compatible LCD) 240x320")), ("121", _("Corby@Pearl 128x128")), ("122", _("Pearl (or compatible LCD) 480x320")), ("123", _("Pearl (or compatible LCD) 800x480")), +LCDType = [("11", _("Pearl (or compatible LCD) 320x240")), ("12", _("Pearl (or compatible LCD) 240x320")), ("121", _("Corby@Pearl 128x128")), ("122", _("AX206 (or compatible LCD) 480x320")), ("123", _("AX206 (or compatible LCD) 800x480")), ("210", _("Samsung SPF-72H 800x480")), ("23", _("Samsung SPF-75H/76H 800x480")), ("24", _("Samsung SPF-87H 800x480")), ("25", _("Samsung SPF-87H old 800x480")), ("26", _("Samsung SPF-83H 800x600")), ("29", _("Samsung SPF-85H/86H 800x600")), ("212", _("Samsung SPF-85P/86P 800x600")), ("28", _("Samsung SPF-105P 1024x600")), ("27", _("Samsung SPF-107H 1024x600")), ("213", _("Samsung SPF-107H old 1024x600")), ("211", _("Samsung SPF-700T 800x600")), ("215", _("Samsung SPF-800P 800x480")), ("214", _("Samsung SPF-1000P 1024x600")), ("430", _("Internal TFT-LCD 400x240")), ("50", _("Internal Box-Skin-LCD")), @@ -2555,7 +2555,7 @@ def setPopText(w): PopText[1] = Code_utf8(w) -def resetWetter(wetter): +def resetWetter(): global wwwWetter global PICwetter wwwWetter = ["", ""] @@ -2698,13 +2698,13 @@ def getFB2(check): def BRI(w1, w2): - gb = L4LElist.getBrightness(w2, False) - return w1 if gb == -1 else gb + gb = int(L4LElist.getBrightness(w2, False)[0]) + return int(w1) if gb == -1 else gb def virtBRI(LCD): global AktNight - vb = BRI(L4LElist.getBrightness(LCD), LCD) + vb = BRI(L4LElist.getBrightness(LCD)[0], LCD) if vb < 1: return 0 elif vb == 10: @@ -2844,7 +2844,7 @@ def ICSdownloads(): nextmonth = today + timedelta(mdays[today.month]) # 2012-01-23 nextmonth2 = today + timedelta(mdays[today.month] - 3) # save Month+1 if days to long DTstart = str(Icomp.decoded("dtstart")) - if strftime("%Y-%m") == DTstart[:7] or nextmonth.strftime("%Y-%m") == DTstart[:7] or nextmonth2.strftime("%Y-%m") == DTstart[:7]: + if DTstart.startswith(strftime("%Y-%m")) or DTstart.startswith(nextmonth.strftime("%Y-%m")) or DTstart.startswith(nextmonth2.strftime("%Y-%m")): D = DTstart[:10] inew = [Code_utf8(Icomp.get('summary')), Icomp.decoded("dtstart"), name[1]] Doppel = False @@ -2886,6 +2886,7 @@ def getResolution(t, r): if int(LCD4linux.xmlOffset.value) != 0: MAX_W -= (int(LCD4linux.xmlOffset.value) * 2) MAX_H -= (int(LCD4linux.xmlOffset.value) * 2) + # ATTENTION: must not be changed to 'endswith()' under any circumstances elif t[1:] == "1": MAX_W, MAX_H = 320, 240 elif t[1:] == "2": @@ -3151,7 +3152,7 @@ def writeHelligkeit(hell, night, STOP): return R AktHelligkeit = [h1, h2, h3] + L4LElist.getBrightness(0, False) L4LElist.resetBrightness([h1, h2, h3]) - L4log("write Bright", AktHelligkeit) + L4log("write Bright: %s" % AktHelligkeit) if SamsungDevice is not None and LCD4linux.LCDType1.value[0] == "1": if dpf.setBacklight(SamsungDevice, h1 if h1 < 8 else 7) == False: dpf.close(SamsungDevice) @@ -4303,12 +4304,12 @@ def __init__(self, cmd): system(cmd + " >/dev/null 2>&1") ShellRunning = False - def cmdFinished(self, data): + def cmdFinished(self): global ShellRunning ShellRunning = False L4log("Shell Stop") - def dataAvail(self, data): + def dataAvail(self): global ShellRunning ShellRunning = False L4log("Shell Data") @@ -4472,10 +4473,10 @@ def getDpfDevice(): if USBok == False: return if LCD4linux.LCDType1.value[0] == "1" and SamsungDevice is None: - L4log("get DPF Device...") + L4log("get DPF1 Device...") if find_dev(1, 0x1908, 0x0102) == True: try: - L4log("open DPF Device0...") + L4log("open DPF1 Device0...") SamsungDevice = dpf.open("usb0") except Exception: L4log("open Error DPF1 Device0") @@ -4517,7 +4518,7 @@ def getDpfDevice(): L4log("open Error DPF3 Device1") SamsungDevice3 = None else: - L4log("DPF2 Device1 not found") + L4log("DPF3 Device1 not found") else: if find_dev(1, 0x1908, 0x0102) == True: try: @@ -4720,16 +4721,15 @@ def __init__(self, cmd): global GrabRunning GrabRunning = True L4logE("Grab Run") - system(cmd + " >/dev/null 2>&1") - self.cmdFinished("") + self.cmdFinished() - def cmdFinished(self, data): + def cmdFinished(self): global GrabRunning L4logE("Grab Stop") GrabRunning = False - def dataAvail(self, data): + def dataAvail(self): pass # Grab @@ -5104,11 +5104,11 @@ def MailDecode(Sdecode): Date = "" for R in mailserver.retr(M)[1]: if str(R).upper().startswith("FROM:"): - From = R[R.find(" "):].strip() + From = R[str(R).find(" "):].strip() elif str(R).upper().startswith("SUBJECT:"): - Subj = R[R.find(" "):].strip() + Subj = R[str(R).find(" "):].strip() elif str(R).upper().startswith("DATE:") and LCD4linux.MailShowDate.value == True: - Date = R[R.find(" "):].strip() + Date = R[str(R).find(" "):].strip() Date = "- %s" % str(Date).split("+")[0].split(",")[-1].strip() if From != "" and Subj != "": break @@ -7929,7 +7929,7 @@ def dirSelected(self, dir, dir1): return if dir + dir1 != "" and dir1.endswith("/"): sel = self["config"].getCurrent()[1] - if dir1[-1:] != "/": + if not dir1.endswith("/"): dir1 += "/" if sel == LCD4linux.PiconPath: LCD4linux.PiconPath.value = dir1 @@ -8110,19 +8110,19 @@ def selectionChanged(self): rmFiles(join(LCD4linux.Picon2Cache.value, "*.png")) if LCD4linux.WetterApi.isChanged(): L4log("Weather API was changed to %s" % LCD4linux.WetterApi.value) - resetWetter(None) + resetWetter() if self.SaveWetter != LCD4linux.WetterCity.value: self.SaveWetter = LCD4linux.WetterCity.value LCD4linux.WetterCoords.value = "0,0" LCD4linux.WetterCoords.save() L4log("Weather city was changed from '%s' to '%s'" % (self.SaveWetter, LCD4linux.WetterCity.value)) - resetWetter(0) + resetWetter() if self.SaveWetter2 != LCD4linux.Wetter2City.value: self.SaveWetter2 = LCD4linux.Wetter2City.value LCD4linux.Wetter2Coords.value = "0,0" LCD4linux.Wetter2Coords.save() L4log("Weather2 city was changed from '%s' to '%s'" % (self.SaveWetter2, LCD4linux.Wetter2City.value)) - resetWetter(1) + resetWetter() if LCD4linux.WetterIconZoom.isChanged() or LCD4linux.WetterRain.isChanged() or LCD4linux.WetterRainZoom.isChanged() or LCD4linux.WetterRainColor.isChanged() or LCD4linux.WetterRainColor2.isChanged() or LCD4linux.WetterRainColor2use.isChanged() or LCD4linux.WetterLine.isChanged() or LCD4linux.WetterTrendArrows.isChanged() or LCD4linux.WetterExtra.isChanged() or LCD4linux.WetterExtraColorFeel.isChanged() or LCD4linux.WetterExtraColorCity.isChanged() or LCD4linux.WetterExtraZoom.isChanged() or LCD4linux.WetterExtraFeel.isChanged() or LCD4linux.WetterWind.isChanged() or LCD4linux.WetterWindLines.isChanged() or LCD4linux.WetterLowColor.isChanged() or LCD4linux.WetterHighColor.isChanged() or LCD4linux.WetterTransparenz.isChanged() or LCD4linux.WetterHumColor.isChanged() or LCD4linux.WetterExtra.isChanged(): PICwetter = [None, None] if LCD4linux.WetterZoom.isChanged() or LCD4linux.StandbyWetterZoom.isChanged() or LCD4linux.MPWetterZoom.isChanged() or LCD4linux.WetterType.isChanged() or LCD4linux.StandbyWetterType.isChanged() or LCD4linux.MPWetterType.isChanged() or LCD4linux.WetterColor.isChanged() or LCD4linux.StandbyWetterColor.isChanged() or LCD4linux.MPWetterColor.isChanged() or LCD4linux.WetterFont.isChanged() or LCD4linux.MPWetterFont.isChanged() or LCD4linux.StandbyWetterFont.isChanged() or LCD4linux.WetterShadow.isChanged() or LCD4linux.StandbyWetterShadow.isChanged() or LCD4linux.MPWetterShadow.isChanged(): @@ -9152,10 +9152,10 @@ def ServiceChange(self): self.LsreftoString = sref.toString() if self.LsreftoString is not None: self.LsrefFile = self.LsreftoString[self.LsreftoString.rfind(":") + 1:] - if self.LsrefFile[:1] != "/": + if self.LsrefFile.startswith("/"): tsref = self.LsreftoString[:-len(self.LsrefFile) - 1] tsref = tsref[tsref.rfind(":") + 1:] - if tsref[:1] == "/": + if tsref.startswith("/"): self.LsrefFile = tsref else: self.LsrefFile = "" @@ -9171,7 +9171,7 @@ def ServiceChange(self): self.Lchannel_name = info and Code_utf8(info.getName(ref)) self.Lchannel_name2 = info and info.getName(ref) self.Lcommand = "" - if self.LsrefFile[:1] == "/" and isfile("%s.meta" % self.LsrefFile): + if self.LsrefFile.startswith("/") and isfile("%s.meta" % self.LsrefFile): try: with open("%s.meta" % self.LsrefFile, "r") as f: service_name = f.readline().strip() @@ -9527,14 +9527,14 @@ def rcKeyPressed(self, key, flag): self.KeyDoppel = 0 if LCD4linux.KeyOff.value[-1:] != "1" and key == self.ko: # PREVIOUS LCDon = True if LCDon == False else False - L4logE("Restart at Off-doublekey", key) + L4logE("Restart at Off-doublekey %s" % key) self.Refresh = "1" self.restartTimer() elif LCD4linux.KeyScreen.value[-1:] != "1" and key == self.k: # FORWARD / INFO ScreenTime = 9999 NextScreen(True) LCD4linux.ScreenActive.value = ScreenActive[0] - L4logE("Restart at Scr-doublekey", key) + L4logE("Restart at Scr-doublekey %s" % key) self.Refresh = "1" self.restartTimer() elif flag == 0: @@ -11006,7 +11006,7 @@ def putWetter(workaround, draw, im): WetterZoom[ConfigWWW] = ConfigZoom POSX, POSY = 1, 0 Wmulti = ConfigZoom / 10.0 - largesize = ConfigType[0] != "3" + largesize = not ConfigType.startswith("3") trendarrows = LCD4linux.WetterTrendArrows.value MAX_Wr = 0 if trendarrows else int(12 * Wmulti) # reduce width of current weather frame when trendarrows are missing if ConfigType.startswith("2"): @@ -11056,7 +11056,7 @@ def putWetter(workaround, draw, im): image_Back = self.im[im].crop((POSXs, ConfigPos, POSXs + MAX_W, ConfigPos + MAX_H)) self.im[Wim].paste(image_Back, (0, 0)) self.draw[Wim] = ImageDraw.Draw(self.im[Wim]) - if ConfigType != "3" and ConfigType[0] != "4": + if ConfigType != "3" and not ConfigType.startswith("4"): i = 0 for curr in self.WWeek[ConfigWWW]: if (i < 4 and ConfigType in ["1", "2", "5"]) or (i < 5 and ConfigType in ["11", "21", "51"]) or (i < 2 and ConfigType in ["12", "22"]): @@ -11152,7 +11152,7 @@ def putWetter(workaround, draw, im): POSY += int(54 * Wmulti) else: POSX += int(54 * Wmulti) - if ConfigType[0] != "5": + if not ConfigType.startswith("5"): if LCD4linux.WetterLine.value == "true": self.draw[Wim].line((POSX, 1, POSX, POSY + int(60 * Wmulti)), fill=ConfigColor) elif LCD4linux.WetterLine.value == "trueLong": @@ -11191,12 +11191,18 @@ def putWetter(workaround, draw, im): Feel = "" else: if trendarrows: - Feelarrow = "●" if OldFeel == -88 else "▲" if OldFeel < float(Feel) else "▼" + if OldFeel == -88: + Feelarrow = "●" + else: + Feelarrow = "▲" if OldFeel < float(Feel) else "▼" OldFeel = float(cleanFeel) Feel = "%s%s" % (Feelarrow, Feel) Feel += "°" if trendarrows: - Temparrow = "●" if OldTemp_c == -88 else "▲" if OldTemp_c < float(Temp_c) else "▼" + if OldTemp_c == -88: + Temparrow = "●" + else: + Temparrow = "▲" if OldTemp_c < float(Temp_c) else "▼" OldTemp_c = float(cleanTemp_c) Temp_c = "%s%s" % (Temparrow, Temp_c) Temp_c += "°" @@ -11239,14 +11245,19 @@ def putWetter(workaround, draw, im): font = ImageFont.truetype(ConfigFont, int(((int(LCD4linux.WetterExtraZoom.value) - 100) / 20.0 + 8) * Wmulti), encoding='unic') ShadowText(Wim, POSX - minus5, POSYs, "%s %s" % (Locname, Wtime), font, LCD4linux.WetterExtraColorCity.value, ConfigShadow) if trendarrows: - Humarrow = "●" if OldHum == -88 else "▲" if OldHum < float(cleanHum) else "▼" + if OldHum == -88: + Humarrow = "●" + else: + Humarrow = "▲" if OldHum < float(cleanHum) else "▼" OldHum = float(cleanHum) Hum = "%s%s" % (Humarrow, Hum) if trendarrows: - Windarrow = "●" if OldWind == -88 else "▲" if OldWind < float(cleanWind[0]) else "▼" + if OldWind == -88: + Windarrow = "●" + else: + Windarrow = "▲" if OldWind < float(cleanWind[0]) else "▼" OldWind = float(cleanWind[0]) Wind = "%s%s" % (Windarrow, Wind) - font = ImageFont.truetype(ConfigFont, int(13 * Wmulti), encoding='unic') if LCD4linux.WetterWindLines.value == "2": Wind = (Wind.split(" ", 2)) @@ -11293,11 +11304,13 @@ def putWetter(workaround, draw, im): font = ImageFont.truetype(ConfigFont, int((18 if largesize else 14) * Wmulti), encoding='unic') w, h = getFsize(Hum, font) if not PY3: # for equal results, 'w' needs an correction under Python 2 - w = int(w * (0.72 if trendarrows else 0.98)) if largesize else int(w * (0.72 if trendarrows else 0.98)) + if largesize: + w = int(w * (0.72 if trendarrows else 0.98)) + else: + w = int(w * (0.72 if trendarrows else 0.98)) PX = MAX_Wc - int(w) PY = POSY + int((40 if largesize else 44) * Wmulti) ShadowText(Wim, PX, PY, Hum, font, LCD4linux.WetterHumColor.value, ConfigShadow) - PICwetter[ConfigWWW] = 1 counter = 20 while PICwetter[ConfigWWW] == "wait" and counter > 0: @@ -11443,14 +11456,20 @@ def putMoon(workaround, draw, im): if ConfigInfo[2] == "1": MoonDist = MoonDistance() if ConfigTrends: - MoonDistarrow = "●" if OldMoonDist == -88 else "▲" if OldMoonDist < MoonDist else "▼" + if OldMoonDist == -88: + MoonDistarrow = "●" + else: + MoonDistarrow = "▲" if OldMoonDist < MoonDist else "▼" OldMoonDist = MoonDist INFOS += "%s%s km" % (MoonDistarrow, round(MoonDist)) if ConfigInfo[1] == "1": illum = 100 - abs((cos(pi * POS) + 0j) ** 1.7 * 100) illum = abs(illum - 1) / .99 if illum - 1 > 0 else 0.0 if ConfigTrends: - illumarrow = "●" if Oldillum in [-88, 0] else "▲" if float(Oldillum) < illum else "▼" + if Oldillum in [-88, 0]: + illumarrow = "●" + else: + illumarrow = "▲" if float(Oldillum) < illum else "▼" Oldillum = illum INFOS += "- %s%s %%" % (illumarrow, round(illum, 1)) if INFOS != "": @@ -11650,7 +11669,7 @@ def putClock(workaround, draw, im): self.ClockName[ConfigNum] = [int(ConfigAnalog), y] self.im[im].paste(self.ClockIm[ConfigNum], (POSX, ConfigPos), self.ClockIm[ConfigNum]) # Weekday in or underneath clockface - if ConfigType[:3] == "521": + if ConfigType.startswith("521"): if "+" in ConfigType: # means weekday in combination with date now = Code_utf8(_(strftime("%A"))) font = ImageFont.truetype(ConfigFont, int(y / 6), encoding='unic') @@ -11692,7 +11711,7 @@ def putClock(workaround, draw, im): self.im[im].paste(pil_image, (POSX + int((x - x1) / 2), ConfigPos + int((y - y1) / 2)), pil_image) # Seconds: Due to the bad refresh rates, the second hand was deliberately not programmed! # Date underneath clockface - if ConfigType[:2] == "52": + if ConfigType.startswith("52"): now = strftime(_("%d.%m.%Y")) font = ImageFont.truetype(ConfigFont, int(y / 6), encoding='unic') w, h = getFsize(now, font) @@ -11908,14 +11927,14 @@ def __init__(self, cmd): GrabTVRunning = True L4logE("GrabTV Run") system(cmd + " >/dev/null 2>&1") - self.cmdFinished("") + self.cmdFinished() - def cmdFinished(self, data): + def cmdFinished(self): global GrabTVRunning L4logE("GrabTV Stop") GrabTVRunning = False - def dataAvail(self, data): + def dataAvail(self): pass def doGrabTVthread(x, y, lcd, vidosd): @@ -12018,7 +12037,7 @@ def putTimer(workaround, draw, im): TL = self.Ltimer_list if ConfigBox == 0 else self.wwwBoxTimer TL = sorted(TL, key=lambda x: x.begin, reverse=False) for timerlist in TL: - if timerlist.disabled == 0 and timerlist.justplay == 0 and str(timerlist.service_ref)[:3] != "-1:": + if timerlist.disabled == 0 and timerlist.justplay == 0 and not str(timerlist.service_ref).startswith("-1:"): if timercount < int(ConfigLines): a = int(config.recording.margin_before.value) * 60 if ConfigType == "0" else 0 b = int(config.recording.margin_after.value) * 60 if ConfigType == "0" else 0 @@ -12284,13 +12303,13 @@ def putProgress(workaround, draw, im): else: ms = 1 font = ImageFont.truetype(ConfigFont, int(ConfigSize * ms) + 8, encoding='unic') # 5 -# if self.Lpath and ":0:" not in self.Lpath and "//" not in self.Lpath: - if self.Llength is not None and self.Llength[0] != -1: # Movie +# if self.Lpath and ":0:" not in self.Lpath and "//" not in self.Lpath: # Movie + if self.Llength is not None and self.Llength[0] != -1: isVideoPlaying = 1 try: length = self.Llength position = self.Lposition - if (length and position) and (length[1] > 0): + if length and (length[1] > 0 and position): if ConfigType[0] in ["2", "4", "6", "8", "9", "A"]: if ConfigType[0] in ["8", "9", "A"] or length[0] == 1: dur = int(position[1] / 90000) @@ -12460,7 +12479,7 @@ def putProgress(workaround, draw, im): isData = True if isData == True and ConfigBorder != "off": event_run = min(max(event_run, 0), ProgressBar) - if ConfigBorder[:4] == "true": + if ConfigBorder.startswith("true"): if ConfigColorBG == "0": # don't fill (=transparency) self.draw[draw].rectangle((POSX + 9, ConfigPos, POSX + ProgressBar + 11, ConfigPos + ConfigSize), outline=ConfigColor) else: @@ -12792,20 +12811,20 @@ def putDescription(workaround, draw, im): event_name = "" if self.LEventsDesc is not None and len(self.LEventsDesc) > 0: if self.LEventsDesc[0][4]: - if self.LEventsDesc[0][5] != "" and (ConfigType[0] == "1" or (ConfigType[0] == "2" and self.LEventsDesc[0][6] == "")): + if self.LEventsDesc[0][5] != "" and (ConfigType.startswith("1") or (ConfigType.startswith("2") and self.LEventsDesc[0][6] == "")): event_name += self.LEventsDesc[0][5] + "\n" if self.LEventsDesc[0][6] != "" and (ConfigType[1] == "1" or (ConfigType[1] == "2" and self.LEventsDesc[0][5] == "")): event_name += self.LEventsDesc[0][6] if event_name == "": if self.LShortDescription is not None and self.LExtendedDescription is not None: - if self.LShortDescription != "" and (ConfigType[0] == "1" or (ConfigType[0] == "2" and self.LExtendedDescription == "")): + if self.LShortDescription != "" and (ConfigType.startswith("1") or (ConfigType.startswith("2") and self.LExtendedDescription == "")): event_name += self.LShortDescription + "\n" if self.LExtendedDescription != "" and (ConfigType[1] == "1" or (ConfigType[1] == "2" and self.LShortDescription == "")): event_name += self.LExtendedDescription if self.LsreftoString is not None and event_name == "": sreffile = self.LsrefFile datei = "%s.txt" % splitext(sreffile)[0] - if sreffile[:1] == "/" and isfile(datei): + if sreffile.startswith("/") and isfile(datei): try: event_name = open(datei, "r").readline().strip() except Exception: @@ -13135,10 +13154,10 @@ def putDev(workaround, draw, im): lx = getSplit(ConfigSplit, ConfigAlign, MAX_W, (w + 20) * co) Bproz = 0 for l in ConfigList: - if l not in DeviceRemove and (isdir(l) == True or l[:3] == "RAM"): + if l not in DeviceRemove and (isdir(l) == True or l.startswith("RAM")): L4logE("Device", l) G = F = B = B1pixel = B2pixel = 0 - if l[:3] == "RAM": + if l.startswith("RAM"): G, F, B = getMem() Bproz = int(F * 100 / G) if F > 0 else 0 B1pixel = ((2 * h) * Bproz / 100) @@ -13178,8 +13197,8 @@ def putDev(workaround, draw, im): Einh = "T" ShadowText(draw, lx + 20, ly, "%.1f" % Fe, font, ConfigColor, ConfigShadow) ShadowText(draw, lx + 20, ly + h, "%sB" % Einh, font, ConfigColor, ConfigShadow) - self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + (2 * h)), outline=LCD4linux.DevBarColor.value, fill=LCD4linux.DevFullColor.value if (Fproz < int(ConfigWarning) and l[:3] != "RAM") else LCD4linux.DevBarColor.value) - if l[:3] == "RAM": + self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + (2 * h)), outline=LCD4linux.DevBarColor.value, fill=LCD4linux.DevFullColor.value if (Fproz < int(ConfigWarning) and not l.startswith("RAM")) else LCD4linux.DevBarColor.value) + if l.startswith("RAM"): self.draw[draw].rectangle((lx + 8, ly, lx + 18, ly + B1pixel), outline=LCD4linux.DevBackColor.value, fill=LCD4linux.DevBackColor.value) self.draw[draw].rectangle((lx + 8, ly + B1pixel, lx + 14, ly + B1pixel + B2pixel), outline=LCD4linux.DevBackColor.value, fill=LCD4linux.DevBackColor.value) else: @@ -13666,7 +13685,7 @@ def putMail(workaround, draw, im): PopCheck = CP if len(PopMail[CP]) > 0: PopCheck = PopMail[CP][0][2] - if ConfigType[:1] == "A" or (ConfigType[:1] == "B" and PopCheck != PopMailUid[CP][0]): + if ConfigType.startswith("A") or (ConfigType.startswith("B") and PopCheck != PopMailUid[CP][0]): NM = 0 for e in PopMail[CP]: if e[2] != PopMailUid[CP][0]: @@ -14186,7 +14205,8 @@ def putCalendar(workaround, draw, im): if ConfigLayout in ["0", "2"]: if datetime.now().day == day[0]: self.draw[4].rectangle((PX1 - w1, POSY, PX1 + w1, POSY + h), fill=ConfigBackColor) - ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value, ConfigShadow) + CalSaSuColor = LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value + ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else CalSaSuColor, ConfigShadow) if ConfigLayout in ["0"] and ICS.get(ICStag, None) is not None: self.draw[4].rectangle((PX1 - w1, POSY, PX1 + w1, POSY + h), outline=CC[int(ICS[ICStag][0][2])]) if int(LCD4linux.CalLine.value) > 1: @@ -14199,7 +14219,8 @@ def putCalendar(workaround, draw, im): if int(LCD4linux.CalLine.value) > 1: self.draw[4].rectangle((PX1 - w1, POSY + h, PX1 + w1, POSY + h), outline=ConfigBackColor) else: - ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value, ConfigShadow) + CalSaSuColor = LCD4linux.CalSaColor.value if day[1] == 5 else LCD4linux.CalSuColor.value + ShadowText(4, PX, POSY, Tag, font, ConfigColor if day[1] < 5 else CalSaSuColor, ConfigShadow) if ConfigLayout in ["1", "2"] and ICS.get(ICStag, None) is not None: self.draw[4].rectangle((PX1 - w1, POSY + h, PX1 + w1, POSY + h), outline=CC[int(ICS[ICStag][0][2])]) if int(LCD4linux.CalLine.value) > 1: