def add_book(self, name, chapters): flowbox = Gtk.FlowBox() flowbox.set_valign(Gtk.Align.START) flowbox.set_max_children_per_line(30) flowbox.set_selection_mode(Gtk.SelectionMode.NONE) flowbox.show() for chapter in chapters: button = Gtk.Button(name, label=chapter) button.show() button.connect('clicked', self.show_page, self.scrolled_window, name, chapter) flowbox.add(button) expand = Handy.ExpanderRow() expand.set_property("title", name) expand.add(flowbox) expand.show() self.book_list.add(expand)
def open(self): def on_get_password(attributes, password, name, login_entry, password_entry): if not attributes or not password: return login_entry.set_text(attributes['login']) password_entry.set_text(password) self.set_title(_('Servers Settings')) self.set_transient_for(self.parent) settings = Settings.get_default().servers_settings languages = Settings.get_default().servers_languages servers_data = {} for server_data in get_servers_list(order_by=('name', 'lang')): main_id = get_server_main_id_by_id(server_data['id']) if main_id not in servers_data: servers_data[main_id] = dict( main_id=main_id, name=server_data['name'], module=server_data['module'], langs=[], ) if not languages or server_data['lang'] in languages: servers_data[main_id]['langs'].append(server_data['lang']) for server_main_id, server_data in servers_data.items(): if not server_data['langs']: continue server_class = getattr(server_data['module'], server_data['main_id'].capitalize()) has_login = getattr(server_class, 'has_login') server_settings = settings.get(server_main_id) server_enabled = server_settings is None or server_settings['enabled'] is True if len(server_data['langs']) > 1 or has_login: vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) vbox.set_border_width(12) expander_row = Handy.ExpanderRow() expander_row.set_title(server_data['name']) expander_row.set_enable_expansion(server_enabled) expander_row.connect('notify::enable-expansion', self.on_server_activated, server_main_id) expander_row.add(vbox) self.group.add(expander_row) if len(server_data['langs']) > 1: for lang in server_data['langs']: lang_enabled = server_settings is None or server_settings['langs'].get(lang, True) hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) label = Gtk.Label(LANGUAGES[lang], xalign=0) label.get_style_context().add_class('dim-label') hbox.pack_start(label, True, True, 0) switch = Gtk.Switch.new() switch.set_active(lang_enabled) switch.connect('notify::active', self.on_server_language_activated, server_main_id, lang) hbox.pack_start(switch, False, False, 0) vbox.add(hbox) if has_login: frame = Gtk.Frame() vbox.add(frame) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) box.set_margin_top(6) box.set_margin_right(6) box.set_margin_bottom(6) box.set_margin_left(6) frame.add(box) label = Gtk.Label(_('User Account')) label.set_valign(Gtk.Align.CENTER) box.pack_start(label, True, True, 0) login_entry = Gtk.Entry() login_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, 'avatar-default-symbolic') box.pack_start(login_entry, True, True, 0) password_entry = Gtk.Entry() password_entry.set_input_purpose(Gtk.InputPurpose.PASSWORD) password_entry.set_visibility(False) password_entry.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, 'dialog-password-symbolic') box.pack_start(password_entry, True, True, 0) btn = Gtk.Button(_('Test')) btn.connect('clicked', self.test_account_login, server_main_id, server_class, login_entry, password_entry) btn.set_always_show_image(True) box.pack_start(btn, False, False, 0) helper = SecretAccountHelper() helper.get(server_main_id, on_get_password, login_entry, password_entry) else: action_row = Handy.ActionRow() action_row.set_title(server_data['name']) switch = Gtk.Switch.new() switch.set_active(server_enabled) switch.set_valign(Gtk.Align.CENTER) switch.connect('notify::active', self.on_server_activated, server_main_id) action_row.add(switch) self.group.add(action_row) self.group.show_all() self.present()
store.append(Flatpak("music", "flathub")) # Build Combo Row # row2 = Handy.ComboRow() row2.set_icon_name('face-wink') row2.set_title("Combo Row") row2.set_subtitle("this is a subtitle") row2.bind_name_model(store, bind_model_func) label = Gtk.Label.new( "This is shown when expanded. This is hidden when not expanded") # Build Expandable Row # https://lazka.github.io/pgi-docs/#Handy-0.0/classes/ExpanderRow.html row3 = Handy.ExpanderRow() row3.set_icon_name('battery-good') row3.set_title("Expander Row") row3.set_subtitle("this is a subtitle") row3.set_expanded(False) row3.set_show_enable_switch(False) row3.add(label) row3.show_all() # Create List Box # https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ListBox.html box = Gtk.ListBox() box.set_selection_mode(Gtk.SelectionMode.NONE) # Add Rows to List Box # https://lazka.github.io/pgi-docs/Gtk-3.0/classes/ListBox.html#Gtk.ListBox.insert