1
1
# -*- coding: utf-8 -*-
2
2
from gi.repository import Gtk, GLib, Gdk
3
3
4
-
from .theme_model import THEME_MODEL, get_theme_options_by_key
4
+
from .theme_model import THEME_MODEL_NEW, get_theme_options_by_key
5
5
from .palette_cache import PaletteCache
6
6
from .color import (
7
7
convert_theme_color_to_gdk, convert_gdk_to_theme_color,
11
11
from .i18n import _
12
12
13
13
14
+
SECTION_MARGIN = 20
15
+
LIST_ITEM_MARGIN = 10
16
+
17
+
14
18
def check_value_filter(value_filter_data, colorscheme):
15
19
filter_results = []
16
20
for key, values in value_filter_data.items():
@@ -45,7 +49,7 @@ def __init__(self, display_name, key, callback, value_widget):
45
49
self.callback = callback
46
50
self.key = key
47
51
48
-
self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
52
+
self.hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50, margin=LIST_ITEM_MARGIN)
49
53
self.add(self.hbox)
50
54
label = Gtk.Label(label=display_name, xalign=0)
51
55
self.hbox.pack_start(label, True, True, 0)
@@ -456,23 +460,56 @@ def __init__(self, display_name, key, callback):
456
460
)
457
461
458
462
459
-
class SeparatorListBoxRow(Gtk.ListBoxRow):
463
+
# class SeparatorListBoxRow(Gtk.ListBoxRow):
464
+
class SeparatorListBoxRow(Gtk.Box):
460
465
461
466
def set_markup(self, markup):
462
467
self.label.set_markup("<b>{}</b>".format(markup))
463
468
464
469
def __init__(self, display_name=None):
465
-
super().__init__(activatable=False, selectable=False)
470
+
# super().__init__(activatable=False, selectable=False)
471
+
super().__init__()
466
472
467
473
self.label = Gtk.Label(xalign=0)
468
474
if display_name:
469
475
self.set_markup(display_name)
470
476
471
-
hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
472
-
hbox.pack_start(Gtk.Label(), True, True, 2)
473
-
hbox.pack_start(self.label, True, True, 4)
477
+
# hbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
478
+
# hbox.pack_start(Gtk.Label(), True, True, 2)
479
+
# hbox.pack_start(self.label, True, True, 4)
480
+
481
+
# self.add(hbox)
482
+
483
+
self.add(self.label)
484
+
485
+
486
+
class SectionListBox(Gtk.Box):
487
+
488
+
def __init__(self, *args, **kwargs):
489
+
super().__init__(
490
+
*args,
491
+
orientation=Gtk.Orientation.VERTICAL,
492
+
margin=SECTION_MARGIN,
493
+
**kwargs
494
+
)
495
+
# self.set_margin_bottom(SECTION_MARGIN//2)
496
+
self.set_margin_top(SECTION_MARGIN//2)
497
+
self.listbox = Gtk.ListBox()
498
+
self.listbox.set_selection_mode(Gtk.SelectionMode.NONE)
499
+
# self.titlebox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
500
+
self.titlebox = Gtk.Stack()
501
+
self.titlebox.set_margin_bottom(LIST_ITEM_MARGIN)
502
+
super().add(self.titlebox)
503
+
# super().add(self.listbox)
504
+
frame = Gtk.Frame()
505
+
frame.add(self.listbox)
506
+
super().add(frame)
507
+
508
+
def add(self, *args, **kwargs):
509
+
self.listbox.add(*args, **kwargs)
474
510
475
-
self.add(hbox)
511
+
def add_title(self, *args, **kwargs):
512
+
self.titlebox.add(*args, **kwargs)
476
513
477
514
478
515
class ThemeColorsList(Gtk.ScrolledWindow):
@@ -490,135 +527,147 @@ def color_edited(self, key, value):
490
527
self.theme[key] = value
491
528
self.color_edited_callback(self.theme)
492
529
493
-
def build_theme_model_rows(self):
530
+
def build_theme_model_rows(self): # pylint: disable=too-many-branches
494
531
self._error_messages_row = SeparatorListBoxRow()
495
-
self.listbox.add(self._error_messages_row)
532
+
self.mainbox.add(self._error_messages_row)
496
533
self._all_rows = {}
497
-
for option_idx, theme_value in enumerate(THEME_MODEL):
498
-
key = theme_value.get('key')
499
-
display_name = theme_value.get('display_name', key)
500
-
row = None
501
-
502
-
callbacks = [self.color_edited, ]
503
-
if theme_value.get('reload_theme'):
504
-
def _callback(key, value):
505
-
for theme_option in get_theme_options_by_key(key):
506
-
theme_option['fallback_value'] = value
507
-
self.theme = self.theme_reload_callback()
508
-
callbacks = [_callback, ]
509
-
elif theme_value.get('reload_options') or key in [
510
-
'ICONS_STYLE', 'THEME_STYLE',
511
-
'TERMINAL_BASE_TEMPLATE', 'TERMINAL_THEME_MODE',
512
-
'TERMINAL_THEME_AUTO_BGFG', 'TERMINAL_FG', 'TERMINAL_BG',
513
-
]:
514
-
def _callback(key, value): # pylint:disable=unused-argument
515
-
self.open_theme(self.theme)
516
-
callbacks += [_callback, ]
517
-
518
-
if key in [
519
-
'TERMINAL_THEME_MODE', 'TERMINAL_THEME_ACCURACY',
520
-
'TERMINAL_THEME_EXTEND_PALETTE', 'TERMINAL_BASE_TEMPLATE',
521
-
'_PIL_PALETTE_QUALITY', '_PIL_PALETTE_STYLE',
522
-
]:
523
-
# @TODO: instead of wrapping them by key name create a signal
524
-
# and emit it from each slow plugin
525
-
def _wrap_slow_callbacks(slow_callbacks):
526
-
def _new_cb(key, value):
527
-
GLib.timeout_add(0, self.disable, priority=GLib.PRIORITY_HIGH)
528
-
for slow_cb in slow_callbacks:
529
-
Gdk.threads_add_idle(GLib.PRIORITY_LOW, slow_cb, key, value, )
530
-
GLib.idle_add(self.enable, priority=GLib.PRIORITY_LOW)
531
-
return _new_cb
532
-
533
-
callbacks = [_wrap_slow_callbacks(callbacks), ]
534
-
535
-
def create_callback(_callbacks):
536
-
def _callback(key, value):
537
-
for each in _callbacks:
538
-
each(key, value)
539
-
540
-
return _callback
541
-
542
-
callback = create_callback(callbacks)
543
-
544
-
if theme_value['type'] == 'color':
545
-
row = ColorListBoxRow(
546
-
display_name, key,
547
-
callback=callback,
548
-
transient_for=self.transient_for
549
-
)
550
-
elif theme_value['type'] == 'bool':
551
-
row = BoolListBoxRow(
552
-
display_name, key, callback=callback
553
-
)
554
-
elif theme_value['type'] == 'int':
555
-
row = IntListBoxRow(
556
-
display_name, key, callback=callback,
557
-
min_value=theme_value.get('min_value'),
558
-
max_value=theme_value.get('max_value')
559
-
)
560
-
elif theme_value['type'] == 'float':
561
-
row = FloatListBoxRow(
562
-
display_name, key, callback=callback,
563
-
min_value=theme_value.get('min_value'),
564
-
max_value=theme_value.get('max_value')
565
-
)
566
-
elif theme_value['type'] == 'separator':
567
-
row = SeparatorListBoxRow(display_name)
568
-
elif theme_value['type'] == 'image_path':
569
-
row = ImagePathListBoxRow(display_name, key, callback)
570
-
elif theme_value['type'] == 'options':
571
-
row = OptionsListBoxRow(
572
-
key=key,
573
-
display_name=display_name,
574
-
options=theme_value['options'],
575
-
callback=callback
576
-
)
577
-
if row:
578
-
self._all_rows[option_idx] = row
579
-
self.listbox.add(row)
534
+
for section_id, section in THEME_MODEL_NEW.items():
535
+
section_box = SectionListBox()
536
+
for option_idx, theme_value in enumerate(section):
537
+
key = theme_value.get('key')
538
+
display_name = theme_value.get('display_name', key)
539
+
row = None
540
+
541
+
callbacks = [self.color_edited, ]
542
+
if theme_value.get('reload_theme'):
543
+
def _callback(key, value):
544
+
for theme_option in get_theme_options_by_key(key):
545
+
theme_option['fallback_value'] = value
546
+
self.theme = self.theme_reload_callback()
547
+
callbacks = [_callback, ]
548
+
elif theme_value.get('reload_options') or key in [
549
+
'ICONS_STYLE', 'THEME_STYLE',
550
+
'TERMINAL_BASE_TEMPLATE', 'TERMINAL_THEME_MODE',
551
+
'TERMINAL_THEME_AUTO_BGFG', 'TERMINAL_FG', 'TERMINAL_BG',
552
+
]:
553
+
def _callback(key, value): # pylint:disable=unused-argument
554
+
self.open_theme(self.theme)
555
+
callbacks += [_callback, ]
556
+
557
+
if key in [
558
+
'TERMINAL_THEME_MODE', 'TERMINAL_THEME_ACCURACY',
559
+
'TERMINAL_THEME_EXTEND_PALETTE', 'TERMINAL_BASE_TEMPLATE',
560
+
'_PIL_PALETTE_QUALITY', '_PIL_PALETTE_STYLE',
561
+
]:
562
+
# @TODO: instead of wrapping them by key name create a signal
563
+
# and emit it from each slow plugin
564
+
def _wrap_slow_callbacks(slow_callbacks):
565
+
def _new_cb(key, value):
566
+
GLib.timeout_add(0, self.disable, priority=GLib.PRIORITY_HIGH)
567
+
for slow_cb in slow_callbacks:
568
+
Gdk.threads_add_idle(GLib.PRIORITY_LOW, slow_cb, key, value, )
569
+
GLib.idle_add(self.enable, priority=GLib.PRIORITY_LOW)
570
+
return _new_cb
571
+
572
+
callbacks = [_wrap_slow_callbacks(callbacks), ]
573
+
574
+
def create_callback(_callbacks):
575
+
def _callback(key, value):
576
+
for each in _callbacks:
577
+
each(key, value)
578
+
579
+
return _callback
580
+
581
+
callback = create_callback(callbacks)
582
+
583
+
if theme_value['type'] == 'color':
584
+
row = ColorListBoxRow(
585
+
display_name, key,
586
+
callback=callback,
587
+
transient_for=self.transient_for
588
+
)
589
+
elif theme_value['type'] == 'bool':
590
+
row = BoolListBoxRow(
591
+
display_name, key, callback=callback
592
+
)
593
+
elif theme_value['type'] == 'int':
594
+
row = IntListBoxRow(
595
+
display_name, key, callback=callback,
596
+
min_value=theme_value.get('min_value'),
597
+
max_value=theme_value.get('max_value')
598
+
)
599
+
elif theme_value['type'] == 'float':
600
+
row = FloatListBoxRow(
601
+
display_name, key, callback=callback,
602
+
min_value=theme_value.get('min_value'),
603
+
max_value=theme_value.get('max_value')
604
+
)
605
+
elif theme_value['type'] == 'separator':
606
+
row = SeparatorListBoxRow(display_name)
607
+
elif theme_value['type'] == 'image_path':
608
+
row = ImagePathListBoxRow(display_name, key, callback)
609
+
elif theme_value['type'] == 'options':
610
+
row = OptionsListBoxRow(
611
+
key=key,
612
+
display_name=display_name,
613
+
options=theme_value['options'],
614
+
callback=callback
615
+
)
616
+
if row:
617
+
self._all_rows.setdefault(section_id, {})[option_idx] = row
618
+
if theme_value['type'] in ('separator', ):
619
+
section_box.add_title(row)
620
+
else:
621
+
section_box.add(row)
622
+
623
+
self.mainbox.add(section_box)
580
624
581
625
def open_theme(self, theme): # pylint: disable=too-many-branches
582
626
self.theme = theme
583
627
error_messages = []
584
628
if "NOGUI" in theme:
585
629
error_messages.append(_("Can't Be Edited in GUI"))
586
-
for option_idx, theme_value in enumerate(THEME_MODEL):
587
-
key = theme_value.get('key')
588
-
if isinstance(theme.get(key), Exception):
589
-
error_messages.append(str(theme[key]))
590
-
continue
591
-
row = self._all_rows.get(option_idx)
592
630
593
-
if not row:
594
-
continue
595
-
if "NOGUI" in theme:
596
-
row.hide()
597
-
continue
598
-
if theme_value.get('filter'):
599
-
if not theme_value['filter'](theme):
600
-
row.hide()
631
+
for section_id, section in THEME_MODEL_NEW.items():
632
+
for option_idx, theme_value in enumerate(section):
633
+
key = theme_value.get('key')
634
+
if isinstance(theme.get(key), Exception):
635
+
error_messages.append(str(theme[key]))
636
+
continue
637
+
row = self._all_rows.get(section_id, {}).get(option_idx)
638
+
639
+
if not row:
601
640
continue
602
-
if theme_value.get('value_filter'):
603
-
if not check_value_filter(theme_value['value_filter'], theme):
641
+
if "NOGUI" in theme:
604
642
row.hide()
605
643
continue
606
-
if theme_value['type'] in ['color', 'options', 'bool', 'int', 'float', 'image_path']:
607
-
row.set_value(theme[key])
608
-
row.show()
609
-
if error_messages:
610
-
self._error_messages_row.set_markup('\n'.join(error_messages))
611
-
self._error_messages_row.show()
612
-
else:
613
-
self._error_messages_row.hide()
644
+
if theme_value.get('filter'):
645
+
if not theme_value['filter'](theme):
646
+
row.hide()
647
+
continue
648
+
if theme_value.get('value_filter'):
649
+
if not check_value_filter(theme_value['value_filter'], theme):
650
+
row.hide()
651
+
continue
652
+
if theme_value['type'] in [
653
+
'color', 'options', 'bool', 'int', 'float', 'image_path'
654
+
]:
655
+
row.set_value(theme[key])
656
+
row.show()
657
+
if error_messages:
658
+
self._error_messages_row.set_markup('\n'.join(error_messages))
659
+
self._error_messages_row.show()
660
+
else:
661
+
self._error_messages_row.hide()
614
662
615
663
def hide_all_rows(self):
616
664
self._error_messages_row.hide()
617
-
for option_idx, _theme_value in enumerate(THEME_MODEL):
618
-
row = self._all_rows.get(option_idx)
619
-
if not row:
620
-
continue
621
-
row.hide()
665
+
for section_id, section in THEME_MODEL_NEW.items():
666
+
for option_idx in range(len(section)):
667
+
row = self._all_rows.get(section_id, {}).get(option_idx)
668
+
if not row:
669
+
continue
670
+
row.hide()
622
671
623
672
def disable(self):
624
673
# self.transient_for.disable()
@@ -635,7 +684,6 @@ def __init__(self, color_edited_callback, theme_reload_callback, transient_for):
635
684
self.color_edited_callback = color_edited_callback
636
685
self.theme_reload_callback = theme_reload_callback
637
686
638
-
self.listbox = Gtk.ListBox()
639
-
self.listbox.set_selection_mode(Gtk.SelectionMode.NONE)
687
+
self.mainbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
640
688
self.build_theme_model_rows()
641
-
self.add(self.listbox)
689
+
self.add(self.mainbox)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4