forked from OpenPLi/enigma2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skin.py
1250 lines (1138 loc) · 47.4 KB
/
skin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import errno
import xml.etree.cElementTree
from enigma import addFont, eLabel, ePixmap, ePoint, eRect, eSize, eWindow, eWindowStyleManager, eWindowStyleSkinned, getDesktop, gFont, getFontFaces, gRGB
from os.path import basename, dirname, isfile
from Components.config import ConfigSubsection, ConfigText, config
from Components.RcModel import rc_model
from Components.Sources.Source import ObsoleteSource
from Components.SystemInfo import SystemInfo
from Tools.Directories import SCOPE_CONFIG, SCOPE_CURRENT_LCDSKIN, SCOPE_CURRENT_SKIN, SCOPE_FONTS, SCOPE_SKIN, SCOPE_SKIN_IMAGE, resolveFilename
from Tools.Import import my_import
from Tools.LoadPixmap import LoadPixmap
DEFAULT_SKIN = SystemInfo["HasFullHDSkinSupport"] and "PLi-FullNightHD/skin.xml" or "PLi-HD/skin.xml" # SD hardware is no longer supported by the default skin.
EMERGENCY_SKIN = "skin_default/skin.xml"
EMERGENCY_NAME = "Stone II"
DEFAULT_DISPLAY_SKIN = "skin_default/skin_display.xml"
USER_SKIN = "skin_user.xml"
USER_SKIN_TEMPLATE = "skin_user_%s.xml"
SUBTITLE_SKIN = "skin_subtitles.xml"
GUI_SKIN_ID = 0 # Main frame-buffer.
DISPLAY_SKIN_ID = 1 # Front panel / display / LCD.
domScreens = {} # Dictionary of skin based screens.
colors = { # Dictionary of skin color names.
"key_back": gRGB(0x00313131),
"key_blue": gRGB(0x0018188b),
"key_green": gRGB(0x001f771f),
"key_red": gRGB(0x009f1313),
"key_text": gRGB(0x00ffffff),
"key_yellow": gRGB(0x00a08500)
}
fonts = { # Dictionary of predefined and skin defined font aliases.
"Body": ("Regular", 18, 22, 16),
"ChoiceList": ("Regular", 20, 24, 18)
}
menus = {} # Dictionary of images associated with menu entries.
parameters = {} # Dictionary of skin parameters used to modify code behavior.
setups = {} # Dictionary of images associated with setup menus.
switchPixmap = {} # Dictionary of switch images.
windowStyles = {} # Dictionary of window styles for each screen ID.
config.skin = ConfigSubsection()
skin = resolveFilename(SCOPE_SKIN, DEFAULT_SKIN)
if not isfile(skin):
print("[Skin] Error: Default skin '%s' is not readable or is not a file! Using emergency skin." % skin)
DEFAULT_SKIN = EMERGENCY_SKIN
config.skin.primary_skin = ConfigText(default=DEFAULT_SKIN)
config.skin.display_skin = ConfigText(default=DEFAULT_DISPLAY_SKIN)
currentPrimarySkin = None
currentDisplaySkin = None
callbacks = []
runCallbacks = False
# Skins are loaded in order of priority. Skin with highest priority is
# loaded last. This is usually the user-specified skin. In this way
# any duplicated screens will be replaced by a screen of the same name
# with a higher priority.
#
# GUI skins are saved in the settings file as the path relative to
# SCOPE_SKIN. The full path is NOT saved. E.g. "MySkin/skin.xml"
#
# Display skins are saved in the settings file as the path relative to
# SCOPE_CURRENT_LCDSKIN. The full path is NOT saved.
# E.g. "MySkin/skin_display.xml"
#
def InitSkins():
global currentPrimarySkin, currentDisplaySkin
runCallbacks = False
# Add the emergency skin. This skin should provide enough functionality
# to enable basic GUI functions to work.
loadSkin(EMERGENCY_SKIN, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
# Add the subtitle skin.
loadSkin(SUBTITLE_SKIN, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
# Add the front panel / display / lcd skin.
result = []
for skin, name in [(config.skin.display_skin.value, "current"), (DEFAULT_DISPLAY_SKIN, "default")]:
if skin in result: # Don't try to add a skin that has already failed.
continue
config.skin.display_skin.value = skin
if loadSkin(config.skin.display_skin.value, scope=SCOPE_CURRENT_LCDSKIN, desktop=getDesktop(DISPLAY_SKIN_ID), screenID=DISPLAY_SKIN_ID):
currentDisplaySkin = config.skin.display_skin.value
break
print("[Skin] Error: Adding %s display skin '%s' has failed!" % (name, config.skin.display_skin.value))
result.append(skin)
# Add the main GUI skin.
result = []
for skin, name in [(config.skin.primary_skin.value, "current"), (DEFAULT_SKIN, "default")]:
if skin in result: # Don't try to add a skin that has already failed.
continue
config.skin.primary_skin.value = skin
if loadSkin(config.skin.primary_skin.value, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID):
currentPrimarySkin = config.skin.primary_skin.value
break
print("[Skin] Error: Adding %s GUI skin '%s' has failed!" % (name, config.skin.primary_skin.value))
result.append(skin)
# Add an optional skin related user skin "user_skin_<SkinName>.xml". If there is
# not a skin related user skin then try to add am optional generic user skin.
result = None
if isfile(resolveFilename(SCOPE_SKIN, config.skin.primary_skin.value)):
name = USER_SKIN_TEMPLATE % dirname(config.skin.primary_skin.value)
if isfile(resolveFilename(SCOPE_CURRENT_SKIN, name)):
result = loadSkin(name, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
if result is None:
loadSkin(USER_SKIN, scope=SCOPE_CURRENT_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID)
runCallbacks = True
# Temporary entry point for older versions of mytest.py.
#
def loadSkinData(desktop):
InitSkins()
# Method to load a skin XML file into the skin data structures.
#
def loadSkin(filename, scope=SCOPE_SKIN, desktop=getDesktop(GUI_SKIN_ID), screenID=GUI_SKIN_ID):
global windowStyles
filename = resolveFilename(scope, filename)
print("[Skin] Loading skin file '%s'." % filename)
try:
with open(filename, "r") as fd: # This open gets around a possible file handle leak in Python's XML parser.
try:
domSkin = xml.etree.cElementTree.parse(fd).getroot()
# print("[Skin] DEBUG: Extracting non screen blocks from '%s'. (scope='%s')" % (filename, scope))
# For loadSingleSkinData colors, bordersets etc. are applied one after
# the other in order of ascending priority.
loadSingleSkinData(desktop, screenID, domSkin, filename, scope=scope)
for element in domSkin:
if element.tag == "screen": # Process all screen elements.
name = element.attrib.get("name", None)
if name: # Without a name, it's useless!
sid = element.attrib.get("id", None)
if sid is None or sid == screenID: # If there is a screen ID is it for this display.
# print("[Skin] DEBUG: Extracting screen '%s' from '%s'. (scope='%s')" % (name, filename, scope))
domScreens[name] = (element, "%s/" % dirname(filename))
elif element.tag == "windowstyle": # Process the windowstyle element.
id = element.attrib.get("id", None)
if id is not None: # Without an id, it is useless!
id = int(id)
# print("[Skin] DEBUG: Processing a windowstyle ID='%s'." % id)
domStyle = xml.etree.cElementTree.ElementTree(xml.etree.cElementTree.Element("skin"))
domStyle.getroot().append(element)
windowStyles[id] = (desktop, screenID, domStyle, filename, scope)
# Element is not a screen or windowstyle element so no need for it any longer.
reloadWindowStyles() # Reload the window style to ensure all skin changes are taken into account.
print("[Skin] Loading skin file '%s' complete." % filename)
if runCallbacks:
for method in self.callbacks:
if method:
method()
return True
except xml.etree.cElementTree.ParseError as err:
fd.seek(0)
content = fd.readlines()
line, column = err.position
print("[Skin] XML Parse Error: '%s' in '%s'!" % (err, filename))
data = content[line - 1].replace("\t", " ").rstrip()
print("[Skin] XML Parse Error: '%s'" % data)
print("[Skin] XML Parse Error: '%s^%s'" % ("-" * column, " " * (len(data) - column - 1)))
except Exception as err:
print("[Skin] Error: Unable to parse skin data in '%s' - '%s'!" % (filename, err))
except (IOError, OSError) as err:
if err.errno == errno.ENOENT: # No such file or directory
print("[Skin] Warning: Skin file '%s' does not exist!" % filename)
else:
print("[Skin] Error %d: Opening skin file '%s'! (%s)" % (err.errno, filename, err.strerror))
except Exception as err:
print("[Skin] Error: Unexpected error opening skin file '%s'! (%s)" % (filename, err))
return False
def reloadSkins():
domScreens.clear()
colors.clear()
colors = {
"key_back": gRGB(0x00313131),
"key_blue": gRGB(0x0018188b),
"key_green": gRGB(0x001f771f),
"key_red": gRGB(0x009f1313),
"key_text": gRGB(0x00ffffff),
"key_yellow": gRGB(0x00a08500)
}
fonts.clear()
fonts = {
"Body": ("Regular", 18, 22, 16),
"ChoiceList": ("Regular", 20, 24, 18)
}
menus.clear()
parameters.clear()
setups.clear()
switchPixmap.clear()
InitSkins()
def addCallback(callback):
if callback not in callbacks:
callbacks.append(callback)
def removeCallback(callback):
if callback in self.callbacks:
callbacks.remove(callback)
class SkinError(Exception):
def __init__(self, message):
self.msg = message
def __str__(self):
return "[Skin] {%s}: %s! Please contact the skin's author!" % (config.skin.primary_skin.value, self.msg)
# Convert a coordinate string into a number. Used to convert object position and
# size attributes into a number.
# s is the input string.
# e is the the parent object size to do relative calculations on parent
# size is the size of the object size (e.g. width or height)
# font is a font object to calculate relative to font sizes
# Note some constructs for speeding up simple cases that are very common.
#
# Can do things like: 10+center-10w+4%
# To center the widget on the parent widget,
# but move forward 10 pixels and 4% of parent width
# and 10 character widths backward
# Multiplication, division and subexpressions are also allowed: 3*(e-c/2)
#
# Usage: center : Center the object on parent based on parent size and object size.
# e : Take the parent size/width.
# c : Take the center point of parent size/width.
# % : Take given percentage of parent size/width.
# w : Multiply by current font width.
# h : Multiply by current font height.
#
def parseCoordinate(s, e, size=0, font=None):
s = s.strip()
if s == "center": # For speed as this can be common case.
val = 0 if not size else (e - size) / 2
elif s == "*":
return None
else:
try:
val = int(s) # For speed try a simple number first.
except ValueError:
if "t" in s:
s = s.replace("center", str((e - size) / 2.0))
if "e" in s:
s = s.replace("e", str(e))
if "c" in s:
s = s.replace("c", str(e / 2.0))
if "w" in s:
s = s.replace("w", "*%s" % str(fonts[font][3]))
if "h" in s:
s = s.replace("h", "*%s" % str(fonts[font][2]))
if "%" in s:
s = s.replace("%", "*%s" % str(e / 100.0))
try:
val = int(s) # For speed try a simple number first.
except ValueError:
val = int(eval(s))
# print("[Skin] DEBUG: parseCoordinate s='%s', e='%s', size=%s, font='%s', val='%s'." % (s, e, size, font, val))
if val < 0:
val = 0
return val
def getParentSize(object, desktop):
if object:
parent = object.getParent()
# For some widgets (e.g. ScrollLabel) the skin attributes are applied to a
# child widget, instead of to the widget itself. In that case, the parent
# we have here is not the real parent, but it is the main widget. We have
# to go one level higher to get the actual parent. We can detect this
# because the 'parent' will not have a size yet. (The main widget's size
# will be calculated internally, as soon as the child widget has parsed the
# skin attributes.)
if parent and parent.size().isEmpty():
parent = parent.getParent()
if parent:
return parent.size()
elif desktop:
return desktop.size() # Widget has no parent, use desktop size instead for relative coordinates.
return eSize()
def parseValuePair(s, scale, object=None, desktop=None, size=None):
x, y = s.split(",")
parentsize = eSize()
if object and ("c" in x or "c" in y or "e" in x or "e" in y or "%" in x or "%" in y): # Need parent size for ce%
parentsize = getParentSize(object, desktop)
xval = parseCoordinate(x, parentsize.width(), size and size.width() or 0)
yval = parseCoordinate(y, parentsize.height(), size and size.height() or 0)
return (xval * scale[0][0] / scale[0][1], yval * scale[1][0] / scale[1][1])
def parsePosition(s, scale, object=None, desktop=None, size=None):
return ePoint(*parseValuePair(s, scale, object, desktop, size))
def parseSize(s, scale, object=None, desktop=None):
return eSize(*parseValuePair(s, scale, object, desktop))
def parseFont(s, scale=((1, 1), (1, 1))):
if ";" in s:
name, size = s.split(";")
else:
name = s
size = None
try:
f = fonts[name]
name = f[0]
size = f[1] if size is None else size
except KeyError:
if name not in getFontFaces():
f = fonts["Body"]
print("[Skin] Error: Font '%s' (in '%s') is not defined! Using 'Body' font ('%s') instead." % (name, s, f[0]))
name = f[0]
size = f[1] if size is None else size
return gFont(name, int(size) * scale[0][0] / scale[0][1])
def parseColor(s):
if s[0] != "#":
try:
return colors[s]
except KeyError:
raise SkinError("Color '%s' must be #aarrggbb or valid named color" % s)
return gRGB(int(s[1:], 0x10))
def parseParameter(s):
"""This function is responsible for parsing parameters in the skin, it can parse integers, floats, hex colors, hex integers, named colors, fonts and strings."""
if s[0] == "*": # String.
return s[1:]
elif s[0] == "#": # HEX Color.
return int(s[1:], 16)
elif s[:2] == "0x": # HEX Integer.
return int(s, 16)
elif "." in s: # Float number.
return float(s)
elif s in colors: # Named color.
return colors[s].argb()
elif s.find(";") != -1: # Font.
font, size = [x.strip() for x in s.split(";", 1)]
return [font, int(size)]
else: # Integer.
return int(s)
def loadPixmap(path, desktop):
option = path.find("#")
if option != -1:
path = path[:option]
if rc_model.rcIsDefault() is False and basename(path) in ("rc.png", "rc0.png", "rc1.png", "rc2.png", "oldrc.png"):
path = rc_model.getRcImg()
pixmap = LoadPixmap(path, desktop)
if pixmap is None:
raise SkinError("Pixmap file '%s' not found" % path)
return pixmap
def collectAttributes(skinAttributes, node, context, skinPath=None, ignore=(), filenames=frozenset(("pixmap", "pointer", "seek_pointer", "backgroundPixmap", "selectionPixmap", "sliderPixmap", "scrollbarSliderPicture", "scrollbarbackgroundPixmap", "scrollbarBackgroundPicture"))):
size = None
pos = None
font = None
for attrib, value in node.items(): # Walk all attributes.
if attrib not in ignore:
if attrib in filenames:
value = resolveFilename(SCOPE_CURRENT_SKIN, value, path_prefix=skinPath)
# Bit of a hack this, really. When a window has a flag (e.g. wfNoBorder)
# it needs to be set at least before the size is set, in order for the
# window dimensions to be calculated correctly in all situations.
# If wfNoBorder is applied after the size has been set, the window will
# fail to clear the title area. Similar situation for a scrollbar in a
# listbox; when the scrollbar setting is applied after the size, a scrollbar
# will not be shown until the selection moves for the first time.
if attrib == "size":
size = value.encode("utf-8")
elif attrib == "position":
pos = value.encode("utf-8")
elif attrib == "font":
font = value.encode("utf-8")
skinAttributes.append((attrib, font))
else:
skinAttributes.append((attrib, value.encode("utf-8")))
if pos is not None:
pos, size = context.parse(pos, size, font)
skinAttributes.append(("position", pos))
if size is not None:
skinAttributes.append(("size", size))
class AttributeParser:
def __init__(self, guiObject, desktop, scale=((1, 1), (1, 1))):
self.guiObject = guiObject
self.desktop = desktop
self.scaleTuple = scale
def applyOne(self, attrib, value):
try:
getattr(self, attrib)(value)
except AttributeError:
print("[Skin] Attribute '%s' (with value of '%s') in object of type '%s' is not implemented!" % (attrib, value, self.guiObject.__class__.__name__))
except SkinError as err:
print("[Skin] Error: %s" % str(err))
except Exception:
print("[Skin] Attribute '%s' with wrong (or unknown) value '%s' in object of type '%s'!" % (attrib, value, self.guiObject.__class__.__name__))
def applyAll(self, attrs):
for attrib, value in attrs:
self.applyOne(attrib, value)
def conditional(self, value):
pass
def objectTypes(self, value):
pass
def position(self, value):
if isinstance(value, tuple):
self.guiObject.move(ePoint(*value))
else:
self.guiObject.move(parsePosition(value, self.scaleTuple, self.guiObject, self.desktop, self.guiObject.csize()))
def size(self, value):
if isinstance(value, tuple):
self.guiObject.resize(eSize(*value))
else:
self.guiObject.resize(parseSize(value, self.scaleTuple, self.guiObject, self.desktop))
def animationPaused(self, value):
pass
# OpenPLi is missing the C++ code to support this animation method.
#
# def animationMode(self, value):
# try:
# self.guiObject.setAnimationMode({
# "disable": 0x00,
# "off": 0x00,
# "offshow": 0x10,
# "offhide": 0x01,
# "onshow": 0x01,
# "onhide": 0x10,
# "disable_onshow": 0x10,
# "disable_onhide": 0x01
# }[value])
# except KeyError:
# print("[Skin] Error: Invalid animationMode '%s'! Must be one of 'disable', 'off', 'offshow', 'offhide', 'onshow' or 'onhide'." % value)
def title(self, value):
self.guiObject.setTitle(_(value))
def text(self, value):
self.guiObject.setText(_(value))
def font(self, value):
self.guiObject.setFont(parseFont(value, self.scaleTuple))
def secondfont(self, value):
self.guiObject.setSecondFont(parseFont(value, self.scaleTuple))
def zPosition(self, value):
self.guiObject.setZPosition(int(value))
def itemHeight(self, value):
self.guiObject.setItemHeight(int(value))
def pixmap(self, value):
self.guiObject.setPixmap(loadPixmap(value, self.desktop))
def backgroundPixmap(self, value):
self.guiObject.setBackgroundPicture(loadPixmap(value, self.desktop))
def selectionPixmap(self, value):
self.guiObject.setSelectionPicture(loadPixmap(value, self.desktop))
def sliderPixmap(self, value):
self.guiObject.setSliderPicture(loadPixmap(value, self.desktop))
def scrollbarbackgroundPixmap(self, value):
self.guiObject.setScrollbarBackgroundPicture(loadPixmap(value, self.desktop))
def scrollbarSliderPicture(self, value): # For compatibility same as sliderPixmap.
self.guiObject.setSliderPicture(loadPixmap(value, self.desktop))
def scrollbarBackgroundPicture(self, value): # For compatibility same as scrollbarbackgroundPixmap.
self.guiObject.setScrollbarBackgroundPicture(loadPixmap(value, self.desktop))
def alphatest(self, value):
try:
self.guiObject.setAlphatest({
"on": 1,
"off": 0,
"blend": 2
}[value])
except KeyError:
print("[Skin] Error: Invalid alphatest '%s'! Must be one of 'on', 'off' or 'blend'." % value)
def scale(self, value):
value = 1 if value.lower() in ("1", "enabled", "on", "scale", "true", "yes") else 0
self.guiObject.setScale(value)
def orientation(self, value): # Used by eSlider.
try:
self.guiObject.setOrientation(*{
"orVertical": (self.guiObject.orVertical, False),
"orTopToBottom": (self.guiObject.orVertical, False),
"orBottomToTop": (self.guiObject.orVertical, True),
"orHorizontal": (self.guiObject.orHorizontal, False),
"orLeftToRight": (self.guiObject.orHorizontal, False),
"orRightToLeft": (self.guiObject.orHorizontal, True)
}[value])
except KeyError:
print("[Skin] Error: Invalid orientation '%s'! Must be one of 'orVertical', 'orTopToBottom', 'orBottomToTop', 'orHorizontal', 'orLeftToRight' or 'orRightToLeft'." % value)
def valign(self, value):
try:
self.guiObject.setVAlign({
"top": self.guiObject.alignTop,
"center": self.guiObject.alignCenter,
"bottom": self.guiObject.alignBottom
}[value])
except KeyError:
print("[Skin] Error: Invalid valign '%s'! Must be one of 'top', 'center' or 'bottom'." % value)
def halign(self, value):
try:
self.guiObject.setHAlign({
"left": self.guiObject.alignLeft,
"center": self.guiObject.alignCenter,
"right": self.guiObject.alignRight,
"block": self.guiObject.alignBlock
}[value])
except KeyError:
print("[Skin] Error: Invalid halign '%s'! Must be one of 'left', 'center', 'right' or 'block'." % value)
def textOffset(self, value):
x, y = value.split(",")
self.guiObject.setTextOffset(ePoint(int(x) * self.scaleTuple[0][0] / self.scaleTuple[0][1], int(y) * self.scaleTuple[1][0] / self.scaleTuple[1][1]))
def flags(self, value):
flags = value.split(",")
for f in flags:
try:
fv = eWindow.__dict__[f]
self.guiObject.setFlag(fv)
except KeyError:
print("[Skin] Error: Invalid flag '%s'!" % f)
def backgroundColor(self, value):
self.guiObject.setBackgroundColor(parseColor(value))
def backgroundColorSelected(self, value):
self.guiObject.setBackgroundColorSelected(parseColor(value))
def foregroundColor(self, value):
self.guiObject.setForegroundColor(parseColor(value))
def foregroundColorSelected(self, value):
self.guiObject.setForegroundColorSelected(parseColor(value))
def foregroundNotCrypted(self, value):
self.guiObject.setForegroundColor(parseColor(value))
def backgroundNotCrypted(self, value):
self.guiObject.setBackgroundColor(parseColor(value))
def foregroundCrypted(self, value):
self.guiObject.setForegroundColor(parseColor(value))
def backgroundCrypted(self, value):
self.guiObject.setBackgroundColor(parseColor(value))
def foregroundEncrypted(self, value):
self.guiObject.setForegroundColor(parseColor(value))
def backgroundEncrypted(self, value):
self.guiObject.setBackgroundColor(parseColor(value))
def shadowColor(self, value):
self.guiObject.setShadowColor(parseColor(value))
def selectionDisabled(self, value):
self.guiObject.setSelectionEnable(0)
def transparent(self, value):
self.guiObject.setTransparent(int(value))
def borderColor(self, value):
self.guiObject.setBorderColor(parseColor(value))
def borderWidth(self, value):
self.guiObject.setBorderWidth(int(value))
def scrollbarSliderBorderWidth(self, value):
self.guiObject.setScrollbarSliderBorderWidth(int(value))
def scrollbarWidth(self, value):
self.guiObject.setScrollbarWidth(int(value))
def scrollbarSliderBorderColor(self, value):
self.guiObject.setSliderBorderColor(parseColor(value))
def scrollbarSliderForegroundColor(self, value):
self.guiObject.setSliderForegroundColor(parseColor(value))
def scrollbarMode(self, value):
try:
self.guiObject.setScrollbarMode({
"showOnDemand": self.guiObject.showOnDemand,
"showAlways": self.guiObject.showAlways,
"showNever": self.guiObject.showNever,
"showLeft": self.guiObject.showLeft
}[value])
except KeyError:
print("[Skin] Error: Invalid scrollbarMode '%s'! Must be one of 'showOnDemand', 'showAlways', 'showNever' or 'showLeft'." % value)
def enableWrapAround(self, value):
value = True if value.lower() in ("1", "enabled", "enablewraparound", "on", "true", "yes") else False
self.guiObject.setWrapAround(value)
def itemHeight(self, value):
self.guiObject.setItemHeight(int(value))
def pointer(self, value):
(name, pos) = value.split(":")
pos = parsePosition(pos, self.scaleTuple)
ptr = loadPixmap(name, self.desktop)
self.guiObject.setPointer(0, ptr, pos)
def seek_pointer(self, value):
(name, pos) = value.split(":")
pos = parsePosition(pos, self.scaleTuple)
ptr = loadPixmap(name, self.desktop)
self.guiObject.setPointer(1, ptr, pos)
def shadowOffset(self, value):
self.guiObject.setShadowOffset(parsePosition(value, self.scaleTuple))
def noWrap(self, value):
value = 1 if value.lower() in ("1", "enabled", "nowrap", "on", "true", "yes") else 0
self.guiObject.setNoWrap(value)
def applySingleAttribute(guiObject, desktop, attrib, value, scale=((1, 1), (1, 1))):
# Is anyone still using applySingleAttribute?
AttributeParser(guiObject, desktop, scale).applyOne(attrib, value)
def applyAllAttributes(guiObject, desktop, attributes, scale):
AttributeParser(guiObject, desktop, scale).applyAll(attributes)
def reloadWindowStyles():
for id in windowStyles:
desktop, screenID, domSkin, pathSkin, scope = windowStyles[id]
loadSingleSkinData(desktop, screenID, domSkin, pathSkin, scope)
def loadSingleSkinData(desktop, screenID, domSkin, pathSkin, scope=SCOPE_CURRENT_SKIN):
"""Loads skin data like colors, windowstyle etc."""
assert domSkin.tag == "skin", "root element in skin must be 'skin'!"
global colors, fonts, menus, parameters, setups, switchPixmap
for tag in domSkin.findall("output"):
id = tag.attrib.get("id")
if id:
id = int(id)
else:
id = GUI_SKIN_ID
if id == GUI_SKIN_ID:
for res in tag.findall("resolution"):
xres = res.attrib.get("xres")
xres = int(xres) if xres else 720
yres = res.attrib.get("yres")
yres = int(yres) if yres else 576
bpp = res.attrib.get("bpp")
bpp = int(bpp) if bpp else 32
# print("[Skin] DEBUG: Resolution xres=%d, yres=%d, bpp=%d." % (xres, yres, bpp))
from enigma import gMainDC
gMainDC.getInstance().setResolution(xres, yres)
desktop.resize(eSize(xres, yres))
if bpp != 32:
pass # Load palette (Not yet implemented!)
if yres >= 1080:
parameters["AboutHddSplit"] = 1
parameters["AutotimerListChannels"] = (2, 60, 4, 32)
parameters["AutotimerListDays"] = (1, 40, 5, 25)
parameters["AutotimerListHasTimespan"] = (154, 4, 150, 25)
parameters["AutotimerListIcon"] = (3, -1, 36, 36)
parameters["AutotimerListRectypeicon"] = (39, 4, 30, 30)
parameters["AutotimerListTimerName"] = (76, 4, 26, 32)
parameters["AutotimerListTimespan"] = (2, 40, 5, 25)
parameters["ChoicelistDash"] = (0, 3, 1000, 30)
parameters["ChoicelistIcon"] = (7, 0, 52, 38)
parameters["ChoicelistName"] = (68, 3, 1000, 30)
parameters["ChoicelistNameSingle"] = (7, 3, 1000, 30)
parameters["ConfigListSeperator"] = 500
parameters["DreamexplorerIcon"] = (15, 4, 30, 30)
parameters["DreamexplorerName"] = (62, 0, 1200, 38)
parameters["FileListIcon"] = (7, 4, 52, 37)
parameters["FileListMultiIcon"] = (45, 4, 30, 30)
parameters["FileListMultiLock"] = (2, 0, 36, 36)
parameters["FileListMultiName"] = (90, 3, 1000, 32)
parameters["FileListName"] = (68, 4, 1000, 34)
parameters["HelpMenuListExtHlp0"] = (0, 0, 900, 39)
parameters["HelpMenuListExtHlp1"] = (0, 42, 900, 30)
parameters["HelpMenuListHlp"] = (0, 0, 900, 42)
parameters["PartnerBoxBouquetListName"] = (0, 0, 45)
parameters["PartnerBoxChannelListName"] = (0, 0, 45)
parameters["PartnerBoxChannelListTime"] = (0, 78, 225, 30)
parameters["PartnerBoxChannelListTitle"] = (0, 42, 30)
parameters["PartnerBoxE1TimerState"] = (255, 78, 255, 30)
parameters["PartnerBoxE1TimerTime"] = (0, 78, 255, 30)
parameters["PartnerBoxE2TimerIcon"] = (1050, 8, 20, 20)
parameters["PartnerBoxE2TimerIconRepeat"] = (1050, 38, 20, 20)
parameters["PartnerBoxE2TimerState"] = (225, 78, 225, 30)
parameters["PartnerBoxE2TimerTime"] = (0, 78, 225, 30)
parameters["PartnerBoxEntryListIP"] = (180, 2, 225, 38)
parameters["PartnerBoxEntryListName"] = (8, 2, 225, 38)
parameters["PartnerBoxEntryListPort"] = (405, 2, 150, 38)
parameters["PartnerBoxEntryListType"] = (615, 2, 150, 38)
parameters["PartnerBoxTimerName"] = (0, 42, 30)
parameters["PartnerBoxTimerServicename"] = (0, 0, 45)
parameters["PicturePlayerThumb"] = (30, 285, 45, 300, 30, 25)
parameters["PlayListIcon"] = (7, 7, 24, 24)
parameters["PlayListName"] = (38, 2, 1000, 34)
parameters["PluginBrowserDescr"] = (180, 42, 25)
parameters["PluginBrowserDownloadDescr"] = (120, 42, 25)
parameters["PluginBrowserDownloadIcon"] = (15, 0, 90, 76)
parameters["PluginBrowserDownloadName"] = (120, 8, 38)
parameters["PluginBrowserIcon"] = (15, 8, 150, 60)
parameters["PluginBrowserName"] = (180, 8, 38)
parameters["SHOUTcastListItem"] = (30, 27, 35, 96, 35, 33, 60, 32)
parameters["SelectionListDescr"] = (45, 6, 1000, 45)
parameters["SelectionListLock"] = (0, 2, 36, 36)
parameters["ServiceInfoLeft"] = (0, 0, 450, 45)
parameters["ServiceInfoRight"] = (450, 0, 1000, 45)
parameters["VirtualKeyBoard"] = (68, 68)
parameters["VirtualKeyBoardAlignment"] = (0, 0)
parameters["VirtualKeyBoardPadding"] = (7, 7)
parameters["VirtualKeyBoardShiftColors"] = (0x00ffffff, 0x00ffffff, 0x0000ffff, 0x00ff00ff)
for tag in domSkin.findall("include"):
filename = tag.attrib.get("filename")
if filename:
filename = resolveFilename(scope, filename, path_prefix=pathSkin)
if isfile(filename):
loadSkin(filename, scope=scope, desktop=desktop, screenID=screenID)
else:
raise SkinError("Included file '%s' not found" % filename)
for tag in domSkin.findall("switchpixmap"):
for pixmap in tag.findall("pixmap"):
name = pixmap.attrib.get("name")
if not name:
raise SkinError("Pixmap needs name attribute")
filename = pixmap.attrib.get("filename")
if not filename:
raise SkinError("Pixmap needs filename attribute")
resolved = resolveFilename(scope, filename, path_prefix=pathSkin)
if isfile(resolved):
switchPixmap[name] = LoadPixmap(resolved, cached=True)
else:
raise SkinError("The switchpixmap pixmap filename='%s' (%s) not found" % (filename, resolved))
for tag in domSkin.findall("colors"):
for color in tag.findall("color"):
name = color.attrib.get("name")
color = color.attrib.get("value")
if name and color:
colors[name] = parseColor(color)
# print("[Skin] DEBUG: Color name='%s', color='%s'." % (name, color))
else:
raise SkinError("Tag 'color' needs a name and color, got name='%s' and color='%s'" % (name, color))
for tag in domSkin.findall("fonts"):
for font in tag.findall("font"):
filename = font.attrib.get("filename", "<NONAME>")
name = font.attrib.get("name", "Regular")
scale = font.attrib.get("scale")
scale = int(scale) if scale else 100
isReplacement = font.attrib.get("replacement") and True or False
render = font.attrib.get("render")
if render:
render = int(render)
else:
render = 0
filename = resolveFilename(SCOPE_FONTS, filename, path_prefix=pathSkin)
if isfile(filename):
addFont(filename, name, scale, isReplacement, render)
# Log provided by C++ addFont code.
# print("[Skin] Add font: Font path='%s', name='%s', scale=%d, isReplacement=%s, render=%d." % (filename, name, scale, isReplacement, render))
else:
raise SkinError("Font file '%s' not found" % filename)
fallbackFont = resolveFilename(SCOPE_FONTS, "fallback.font", path_prefix=pathSkin)
if isfile(fallbackFont):
addFont(fallbackFont, "Fallback", 100, -1, 0)
# else: # As this is optional don't raise an error.
# raise SkinError("Fallback font '%s' not found" % fallbackFont)
for alias in tag.findall("alias"):
try:
name = alias.attrib.get("name")
font = alias.attrib.get("font")
size = int(alias.attrib.get("size"))
height = int(alias.attrib.get("height", size)) # To be calculated some day.
width = int(alias.attrib.get("width", size))
fonts[name] = (font, size, height, width)
# print("[Skin] Add font alias: name='%s', font='%s', size=%d, height=%s, width=%d." % (name, font, size, height, width))
except Exception as err:
raise SkinError("Bad font alias: '%s'" % str(err))
for tag in domSkin.findall("parameters"):
for parameter in tag.findall("parameter"):
try:
name = parameter.attrib.get("name")
value = parameter.attrib.get("value")
parameters[name] = map(parseParameter, [x.strip() for x in value.split(",")]) if "," in value else parseParameter(value)
except Exception as err:
raise SkinError("Bad parameter: '%s'" % str(err))
for tag in domSkin.findall("menus"):
for setup in tag.findall("menu"):
key = setup.attrib.get("key")
image = setup.attrib.get("image")
if key and image:
menus[key] = image
# print("[Skin] DEBUG: Menu key='%s', image='%s'." % (key, image))
else:
raise SkinError("Tag menu needs key and image, got key='%s' and image='%s'" % (key, image))
for tag in domSkin.findall("setups"):
for setup in tag.findall("setup"):
key = setup.attrib.get("key")
image = setup.attrib.get("image")
if key and image:
setups[key] = image
# print("[Skin] DEBUG: Setup key='%s', image='%s'." % (key, image))
else:
raise SkinError("Tag setup needs key and image, got key='%s' and image='%s'" % (key, image))
for tag in domSkin.findall("subtitles"):
from enigma import eSubtitleWidget
scale = ((1, 1), (1, 1))
for substyle in tag.findall("sub"):
font = parseFont(substyle.attrib.get("font"), scale)
col = substyle.attrib.get("foregroundColor")
if col:
foregroundColor = parseColor(col)
haveColor = 1
else:
foregroundColor = gRGB(0xFFFFFF)
haveColor = 0
col = substyle.attrib.get("borderColor")
if col:
borderColor = parseColor(col)
else:
borderColor = gRGB(0)
borderwidth = substyle.attrib.get("borderWidth")
if borderwidth is None:
borderWidth = 3 # Default: Use a subtitle border.
else:
borderWidth = int(borderwidth)
face = eSubtitleWidget.__dict__[substyle.attrib.get("name")]
eSubtitleWidget.setFontStyle(face, font, haveColor, foregroundColor, borderColor, borderWidth)
for tag in domSkin.findall("windowstyle"):
style = eWindowStyleSkinned()
styleId = tag.attrib.get("id")
if styleId:
styleId = int(styleId)
else:
styleId = GUI_SKIN_ID
font = gFont("Regular", 20) # Default
offset = eSize(20, 5) # Default
for title in tag.findall("title"):
offset = parseSize(title.attrib.get("offset"), ((1, 1), (1, 1)))
font = parseFont(title.attrib.get("font"), ((1, 1), (1, 1)))
style.setTitleFont(font)
style.setTitleOffset(offset)
# print("[Skin] DEBUG: WindowStyle font, offset - '%s' '%s'." % (str(font), str(offset)))
for borderset in tag.findall("borderset"):
bsName = str(borderset.attrib.get("name"))
for pixmap in borderset.findall("pixmap"):
bpName = pixmap.attrib.get("pos")
filename = pixmap.attrib.get("filename")
if filename and bpName:
png = loadPixmap(resolveFilename(scope, filename, path_prefix=pathSkin), desktop)
try:
style.setPixmap(eWindowStyleSkinned.__dict__[bsName], eWindowStyleSkinned.__dict__[bpName], png)
except Exception:
pass
# print("[Skin] DEBUG: WindowStyle borderset name, filename - '%s' '%s'." % (bpName, filename))
for color in tag.findall("color"):
colorType = color.attrib.get("name")
color = parseColor(color.attrib.get("color"))
try:
style.setColor(eWindowStyleSkinned.__dict__["col" + colorType], color)
except Exception:
raise SkinError("Unknown color type '%s'" % colorType)
# print("[Skin] DEBUG: WindowStyle color type, color -" % (colorType, str(color)))
x = eWindowStyleManager.getInstance()
x.setStyle(styleId, style)
for tag in domSkin.findall("margin"):
styleId = tag.attrib.get("id")
if styleId:
styleId = int(styleId)
else:
styleId = GUI_SKIN_ID
r = eRect(0, 0, 0, 0)
v = tag.attrib.get("left")
if v:
r.setLeft(int(v))
v = tag.attrib.get("top")
if v:
r.setTop(int(v))
v = tag.attrib.get("right")
if v:
r.setRight(int(v))
v = tag.attrib.get("bottom")
if v:
r.setBottom(int(v))
# The "desktop" parameter is hard-coded to the GUI screen, so we must ask
# for the one that this actually applies to.
getDesktop(styleId).setMargins(r)
class additionalWidget:
def __init__(self):
pass
# Class that makes a tuple look like something else. Some plugins just assume
# that size is a string and try to parse it. This class makes that work.
class SizeTuple(tuple):
def split(self, *args):
return str(self[0]), str(self[1])
def strip(self, *args):
return "%s,%s" % self
def __str__(self):
return "%s,%s" % self
class SkinContext:
def __init__(self, parent=None, pos=None, size=None, font=None):
if parent is not None:
if pos is not None:
pos, size = parent.parse(pos, size, font)
self.x, self.y = pos
self.w, self.h = size
else:
self.x = None
self.y = None
self.w = None
self.h = None
def __str__(self):
return "Context (%s,%s)+(%s,%s) " % (self.x, self.y, self.w, self.h)
def parse(self, pos, size, font):
if pos == "fill":
pos = (self.x, self.y)
size = (self.w, self.h)
self.w = 0
self.h = 0
else:
w, h = size.split(",")
w = parseCoordinate(w, self.w, 0, font)
h = parseCoordinate(h, self.h, 0, font)
if pos == "bottom":
pos = (self.x, self.y + self.h - h)
size = (self.w, h)
self.h -= h
elif pos == "top":
pos = (self.x, self.y)
size = (self.w, h)
self.h -= h
self.y += h
elif pos == "left":
pos = (self.x, self.y)
size = (w, self.h)
self.x += w
self.w -= w
elif pos == "right":
pos = (self.x + self.w - w, self.y)
size = (w, self.h)
self.w -= w
else:
size = (w, h)
pos = pos.split(",")
pos = (self.x + parseCoordinate(pos[0], self.w, size[0], font), self.y + parseCoordinate(pos[1], self.h, size[1], font))
return (SizeTuple(pos), SizeTuple(size))
# A context that stacks things instead of aligning them.
#
class SkinContextStack(SkinContext):
def parse(self, pos, size, font):
if pos == "fill":
pos = (self.x, self.y)
size = (self.w, self.h)
else:
w, h = size.split(",")
w = parseCoordinate(w, self.w, 0, font)
h = parseCoordinate(h, self.h, 0, font)
if pos == "bottom":
pos = (self.x, self.y + self.h - h)
size = (self.w, h)
elif pos == "top":
pos = (self.x, self.y)
size = (self.w, h)
elif pos == "left":
pos = (self.x, self.y)
size = (w, self.h)
elif pos == "right":
pos = (self.x + self.w - w, self.y)
size = (w, self.h)
else:
size = (w, h)
pos = pos.split(",")
pos = (self.x + parseCoordinate(pos[0], self.w, size[0], font), self.y + parseCoordinate(pos[1], self.h, size[1], font))
return (SizeTuple(pos), SizeTuple(size))