Philipp Hörist pushed to branch master at gajim / gajim
Commits: 42597b8e by lovetox at 2020-08-31T21:04:13+02:00 Settings: Add PopoverSetting
- - - - - 05180de0 by lovetox at 2020-08-31T21:04:13+02:00 Accounts: Use PopoverSetting
- - - - -
4 changed files:
- gajim/data/style/gajim.css - gajim/gtk/accounts.py - gajim/gtk/const.py - gajim/gtk/settings.py
Changes:
===================================== gajim/data/style/gajim.css ===================================== @@ -330,3 +330,11 @@ button.flat.link { padding: 0; border: 0; } #NotificationPopupTitle { font-weight: bold; } + + +popover.combo list { min-width: 200px; margin: 12px;} +popover.combo { padding: 0px; } +popover.combo list { border-style: none; background-color: transparent; } +popover.combo list > row { padding: 0px 12px 0px 12px; min-height: 50px; } +popover.combo list > row:not(:last-child) { border-bottom: 1px solid alpha(#cdc7c2, 0.5); } +popover.combo scrollbar.vertical { padding-top: 2px; padding-bottom: 2px; }
===================================== gajim/gtk/accounts.py ===================================== @@ -736,9 +736,10 @@ class AdvancedPage(GenericSettingPage): SettingType.ACCOUNT_CONFIG, 'autoauth', desc=_('Automatically accept all contact requests')),
- Setting(SettingKind.COMBO, _('Filetransfer Preference'), + Setting(SettingKind.POPOVER, _('Filetransfer Preference'), SettingType.ACCOUNT_CONFIG, 'filetransfer_preference', - props={'combo_items': ['httpupload', 'jingle']}, + props={'entries': {'httpupload': _('Upload Files'), + 'jingle': _('Send Files Directly')}}, desc=_('Preferred file transfer mechanism for ' 'file drag&drop on a chat window')) ]
===================================== gajim/gtk/const.py ===================================== @@ -58,6 +58,7 @@ class SettingKind(IntEnum): CHANGEPASSWORD = 11 COMBO = 12 COLOR = 13 + POPOVER = 14
@unique
===================================== gajim/gtk/settings.py ===================================== @@ -98,6 +98,7 @@ class SettingsBox(Gtk.ListBox): SettingKind.HOSTNAME: CutstomHostnameSetting, SettingKind.CHANGEPASSWORD: ChangePasswordSetting, SettingKind.COMBO: ComboSetting, + SettingKind.POPOVER: PopoverSetting, }
if extend is not None: @@ -545,6 +546,77 @@ class LoginSetting(DialogSetting): self.set_activatable(not anonym)
+class PopoverSetting(GenericSetting): + + __gproperties__ = { + "setting-value": (str, 'Dummy', '', '', + GObject.ParamFlags.READWRITE),} + + def __init__(self, *args, entries): + GenericSetting.__init__(self, *args) + + box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, + spacing=12) + box.set_halign(Gtk.Align.END) + + self._current_label = Gtk.Label() + self._current_label.set_valign(Gtk.Align.CENTER) + image = Gtk.Image.new_from_icon_name('pan-down-symbolic', + Gtk.IconSize.MENU) + image.set_valign(Gtk.Align.CENTER) + + box.add(self._current_label) + box.add(image) + + menu_listbox = Gtk.ListBox() + menu_listbox.set_selection_mode(Gtk.SelectionMode.NONE) + for value, label in entries.items(): + menu_listbox.add(PopoverRow(label, value)) + menu_listbox.connect('row-activated', self._on_menu_row_activated) + + scrolled_window = Gtk.ScrolledWindow() + scrolled_window.set_propagate_natural_height(True) + scrolled_window.set_propagate_natural_width(True) + scrolled_window.set_max_content_height(400) + scrolled_window.set_policy(Gtk.PolicyType.NEVER, + Gtk.PolicyType.AUTOMATIC) + scrolled_window.add(menu_listbox) + scrolled_window.show_all() + + self._popover = Gtk.Popover() + self._popover.get_style_context().add_class('combo') + self._popover.set_relative_to(image) + self._popover.set_position(Gtk.PositionType.BOTTOM) + self._popover.add(scrolled_window) + + self.setting_box.pack_end(box, True, True, 0) + + self._current_label.set_text(entries.get(self.setting_value, '')) + + self.show_all() + + def _on_menu_row_activated(self, listbox, row): + listbox.unselect_all() + self._current_label.set_text(row.label) + self._popover.popdown() + + self.set_value(row.value) + + def on_row_activated(self): + self._popover.popup() + + +class PopoverRow(Gtk.ListBoxRow): + def __init__(self, label, value): + Gtk.ListBoxRow.__init__(self) + self.label = label + self.value = value + + label = Gtk.Label(label=label) + label.set_xalign(0) + self.add(label) + + class ComboSetting(GenericSetting):
__gproperties__ = {
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/bd67cd00b5a1135d29271fa60a1f4ba9...