Gtk UI: Use a TextView for dialogs with multiple text lines

This commit is contained in:
Thomas Perl 2021-08-18 20:34:55 +02:00
parent 7a4afcc198
commit 4310fdbf5e
3 changed files with 39 additions and 11 deletions

View File

@ -462,13 +462,11 @@ class gPodderPreferences(BuilderWidget):
if not container or not model:
return
# This is one ugly hack, but it displays the attributes of
# the metadata object of the container..
info = '\n'.join('<b>%s:</b> %s' %
tuple(map(html.escape, list(map(str, (key, value)))))
for key, value in container.metadata.get_sorted())
info = '\n'.join('<b>{}:</b> {}'.format(html.escape(key), html.escape(value))
for key, value in container.metadata.get_sorted()
if key not in ('title', 'description'))
self.show_message(info, _('Extension module info'), important=True)
self.show_message_details(container.metadata.title, container.metadata.description, info)
def open_weblink(self, w, url):
util.open_website(url)

View File

@ -78,6 +78,37 @@ class BuilderWidget(GtkBuilderWidget):
"""Return a Gtk.Window that should be the parent of dialogs"""
return self.main_window
def show_message_details(self, title, message, details):
dlg = Gtk.MessageDialog(self.main_window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK)
dlg.set_title(title)
dlg.set_property('text', title)
dlg.format_secondary_text(message)
# make message copy/pastable
for lbl in dlg.get_message_area():
if isinstance(lbl, Gtk.Label):
lbl.set_halign(Gtk.Align.START)
lbl.set_selectable(True)
tv = Gtk.TextView()
tv.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
tv.set_border_width(10)
tv.set_editable(False)
tb = Gtk.TextBuffer()
tb.insert_markup(tb.get_start_iter(), details, -1)
tv.set_buffer(tb)
tv.set_property('expand', True)
sw = Gtk.ScrolledWindow()
sw.set_size_request(400, 200)
sw.set_property('shadow-type', Gtk.ShadowType.IN)
sw.add(tv)
sw.show_all()
dlg.get_message_area().add(sw)
dlg.get_widget_for_response(Gtk.ResponseType.OK).grab_focus()
dlg.run()
dlg.destroy()
def show_message(self, message, title=None, important=False, widget=None):
if important:
show_message_dialog(self.main_window, message, title)

View File

@ -2486,11 +2486,10 @@ class gPodder(BuilderWidget, dbus.service.Object):
# Report failed subscriptions to the user
if failed:
title = _('Could not add some podcasts')
message = _('Some podcasts could not be added to your list:') \
+ '\n\n' + '\n'.join(
html.escape('%s: %s' % (
url, error_messages.get(url, _('Unknown')))) for url in failed)
self.show_message(message, title, important=True)
message = _('Some podcasts could not be added to your list:')
details = '\n\n'.join('<b>{}</b>:\n{}'.format(html.escape(url),
html.escape(error_messages.get(url, _('Unknown')))) for url in failed)
self.show_message_details(title, message, details)
# Upload subscription changes to gpodder.net
self.mygpo_client.on_subscribe(worked)