171
class KeyCommon(LayoutItem):
171
class KeyCommon(DrawingItem):
173
173
library-independent key class. Specific rendering options
174
174
are stored elsewhere.
177
# extended id for key specific theme tweaks
178
# e.g. theme_id=DELE.numpad (with id=DELE)
181
# extended id for layout specific tweaks
182
# e.g. "hide.wordlist", for hide button in wordlist mode
185
177
# optional id of a sublayout used as long-press popup
342
334
def is_active(self):
343
335
return not self.type is None
348
def get_svg_id(self):
351
def set_id(self, id, theme_id = None, svg_id = None):
352
self.theme_id, self.id = self.parse_id(id)
354
self.theme_id = theme_id
355
self.svg_id = self.id if not svg_id else svg_id
360
The theme id has the form <id>.<arbitrary identifier>, where
361
the identifier should be a description of the location of
362
the key relative to its surroundings, e.g. 'DELE.next-to-backspace'.
363
Don't use layout names or layer ids for the theme id, they lose
364
their meaning when layouts are copied or renamed by users.
367
id = value.split(".")[0]
371
def split_theme_id(theme_id):
373
Simple split in prefix (id) before the dot and suffix after the dot.
375
components = theme_id.split(".")
376
if len(components) == 1:
377
return components[0], ""
378
return components[0], components[1]
381
def build_theme_id(prefix, postfix):
383
return prefix + "." + postfix
386
def get_similar_theme_id(self, prefix = None):
390
comps = self.theme_id.split(".")[1:]
392
theme_id += "." + comps[0]
395
337
def is_layer_button(self):
396
338
return bool(self.target_layer_id) or self.id.startswith("layer")
422
365
def is_button(self):
423
366
return self.type == BUTTON_TYPE
425
368
def is_pressed_only(self):
426
return self.pressed and not (self.active or \
369
return self.pressed and not (self.active or
373
def is_active_only(self):
374
return self.active and not (self.pressed or
430
378
def is_text_changing(self):
431
379
if not self.is_modifier() and \
432
380
self.type in [KEYCODE_TYPE,
478
426
def get_target_layer_id(self):
479
427
return self.target_layer_id
429
def get_target_layer_parent_id(self):
431
Split off the parent path of the (dot-separated)
434
layer_id = self.target_layer_id
435
pos = layer_id.rfind(".")
437
return layer_id[:pos]
481
441
def get_popup_layout(self):
482
442
if self.popup_id:
483
443
return self.find_sublayout(self.popup_id)
584
540
def get_light_direction(self):
585
541
return config.theme_settings.key_gradient_direction * pi / 180.0
587
def get_fill_color(self):
588
return self._get_color("fill")
590
def get_stroke_color(self):
591
return self._get_color("stroke")
593
def get_label_color(self):
594
return self._get_color("label")
596
def get_secondary_label_color(self):
597
return self._get_color("secondary-label")
599
def get_dwell_progress_color(self):
600
return self._get_color("dwell-progress")
602
543
def get_dwell_progress_canvas_rect(self):
603
544
rect = self.get_label_rect().inflate(0.5)
604
545
return self.context.log_to_canvas_rect(rect)
606
def _get_color(self, element):
607
color_key = (element, self.prelight, self.pressed,
608
self.active, self.locked,
609
self.sensitive, self.scanned)
610
rgba = self.colors.get(color_key)
612
if self.color_scheme:
613
rgba = self.color_scheme.get_key_rgba(self, element)
614
elif element == "label":
615
rgba = [0.0, 0.0, 0.0, 1.0]
617
rgba = [1.0, 1.0, 1.0, 1.0]
618
self.colors[color_key] = rgba
547
def get_color(self, element, state = None):
548
color_key = (element,
549
self.prelight, self.pressed,
550
self.active, self.locked,
551
self.sensitive, self.scanned)
553
return self.colors[color_key]
555
return self.cache_color(element, color_key, state)
621
557
def get_fullsize_rect(self):
622
558
""" Get bounding box of the key at 100% size in logical coordinates """
623
return LayoutItem.get_rect(self)
559
return DrawingItem.get_rect(self)
625
561
def get_canvas_fullsize_rect(self):
626
562
""" Get bounding box of the key at 100% size in canvas coordinates """