Philipp Hörist pushed to branch master at gajim / gajim

Commits:

1 changed file:

Changes:

  • gajim/gtk/settings.py
    ... ... @@ -556,6 +556,9 @@ class PopoverSetting(GenericSetting):
    556 556
         def __init__(self, *args, entries):
    
    557 557
             GenericSetting.__init__(self, *args)
    
    558 558
     
    
    559
    +        if isinstance(entries, list):
    
    560
    +            entries = {key: key for key in entries}
    
    561
    +
    
    559 562
             box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL,
    
    560 563
                           spacing=12)
    
    561 564
             box.set_halign(Gtk.Align.END)
    
    ... ... @@ -569,11 +572,11 @@ class PopoverSetting(GenericSetting):
    569 572
             box.add(self._current_label)
    
    570 573
             box.add(image)
    
    571 574
     
    
    572
    -        menu_listbox = Gtk.ListBox()
    
    573
    -        menu_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    
    574
    -        for value, label in entries.items():
    
    575
    -            menu_listbox.add(PopoverRow(label, value))
    
    576
    -        menu_listbox.connect('row-activated', self._on_menu_row_activated)
    
    575
    +        self._menu_listbox = Gtk.ListBox()
    
    576
    +        self._menu_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
    
    577
    +        self._add_menu_entries(entries)
    
    578
    +        self._menu_listbox.connect('row-activated',
    
    579
    +                                   self._on_menu_row_activated)
    
    577 580
     
    
    578 581
             scrolled_window = Gtk.ScrolledWindow()
    
    579 582
             scrolled_window.set_propagate_natural_height(True)
    
    ... ... @@ -581,7 +584,7 @@ class PopoverSetting(GenericSetting):
    581 584
             scrolled_window.set_max_content_height(400)
    
    582 585
             scrolled_window.set_policy(Gtk.PolicyType.NEVER,
    
    583 586
                                        Gtk.PolicyType.AUTOMATIC)
    
    584
    -        scrolled_window.add(menu_listbox)
    
    587
    +        scrolled_window.add(self._menu_listbox)
    
    585 588
             scrolled_window.show_all()
    
    586 589
     
    
    587 590
             self._popover = Gtk.Popover()
    
    ... ... @@ -596,6 +599,15 @@ class PopoverSetting(GenericSetting):
    596 599
     
    
    597 600
             self.show_all()
    
    598 601
     
    
    602
    +    def _add_menu_entries(self, entries):
    
    603
    +        if isinstance(entries, list):
    
    604
    +            entries = {key: key for key in entries}
    
    605
    +
    
    606
    +        for value, label in entries.items():
    
    607
    +            self._menu_listbox.add(PopoverRow(label, value))
    
    608
    +
    
    609
    +        self._menu_listbox.show_all()
    
    610
    +
    
    599 611
         def _on_menu_row_activated(self, listbox, row):
    
    600 612
             listbox.unselect_all()
    
    601 613
             self._current_label.set_text(row.label)
    
    ... ... @@ -606,6 +618,10 @@ class PopoverSetting(GenericSetting):
    606 618
         def on_row_activated(self):
    
    607 619
             self._popover.popup()
    
    608 620
     
    
    621
    +    def update_entries(self, entries):
    
    622
    +        self._menu_listbox.foreach(self._menu_listbox.remove)
    
    623
    +        self._add_menu_entries(entries)
    
    624
    +
    
    609 625
     
    
    610 626
     class PopoverRow(Gtk.ListBoxRow):
    
    611 627
         def __init__(self, label, value):