Description: Fixes the dialog size of the progress, error and message dialogs Try to show the terminal widget in its full size and expand the details to a readable size. Origin: backport, lp:~aptdaemon Author: Sebastian Heinlein Bug-Ubuntu: https://launchpad.net/bugs/892607 Bug-Ubuntu: https://launchpad.net/bugs/840942 === modified file 'aptdaemon/gtk3widgets.py' --- old/aptdaemon/gtk3widgets.py 2011-11-26 06:48:03 +0000 +++ new/aptdaemon/gtk3widgets.py 2011-12-01 09:35:47 +0000 @@ -597,13 +597,49 @@ # Make the dialog resizable if the expander is expanded # try to restore a previous size if not expander.get_expanded(): - self._expanded_size = self.get_size() + self._expanded_size = (self.expander.terminal.get_visible(), + self.get_size()) self.set_resizable(False) elif self._expanded_size: self.set_resizable(True) - self.resize(*self._expanded_size) + term_visible, (stored_width, stored_height) = self._expanded_size + # Check if the stored size was for the download details or + # the terminal widget + if term_visible != self.expander.terminal.get_visible(): + # The stored size was for the download details, so we need + # get a new size for the terminal widget + self._resize_to_show_details() + else: + self.resize(*self._expanded_size) else: self.set_resizable(True) + self._resize_to_show_details() + + def _resize_to_show_details(self): + """Resize the window to show the expanded details. + + Unfortunately the expander only expands to the preferred size of the + child widget (e.g showing all 80x24 chars of the Vte terminal) if + the window is rendered the first time and the terminal is also visible. + If the expander is expanded afterwards the window won't change its + size anymore. So we have to do this manually. See LP#840942 + """ + win_width, win_height = self.get_size() + exp_width = self.expander.get_allocation().width + exp_height = self.expander.get_allocation().height + if self.expander.terminal.get_visible(): + terminal_width = self.expander.terminal.get_char_width() * 80 + terminal_height = self.expander.terminal.get_char_height() * 24 + self.resize(terminal_width - exp_width + win_width, + terminal_height - exp_height + win_height) + else: + self.resize(win_width + 100, win_height + 200) + + def _on_status_changed(self, trans, status): + # Also resize the window if we switch from download details to + # the terminal window + if status == STATUS_COMMITTING and self.expander.terminal.get_visible(): + self._resize_to_show_details() @deferable def run(self, attach=False, close_on_finished=True, show_error=True, @@ -655,6 +691,8 @@ for sig in self._signals: GObject.source_remove(sig) self._signals = [] + self._signals.append(transaction.connect_after("status-changed", + self._on_status_changed)) self._signals.append(transaction.connect("role-changed", self._on_role_changed)) self._signals.append(transaction.connect("medium-required", @@ -718,7 +756,7 @@ buttons = (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) Gtk.Dialog.__init__(self, parent=parent) self.add_buttons(*buttons) - self.set_resizable(True) + self.set_resizable(False) self.set_border_width(6) self.get_content_area().set_spacing(12) if not stock_type: @@ -743,8 +781,8 @@ self.expander.set_spacing(6) self.expander.set_use_underline(True) self.expander.connect("notify::expanded", self._on_expanded) + self._expanded_size = None vbox_left.pack_start(self.expander, True, True, 0) - self._expanded_size = self.get_size() # Set some initial data text = "" if title: @@ -760,7 +798,8 @@ def _on_expanded(self, expander, param): if expander.get_expanded(): self.set_resizable(True) - self.resize(*self._expanded_size) + if self._expanded_size: + self.resize(*self._expanded_size) else: self._expanded_size = self.get_size() self.set_resizable(False) @@ -1072,33 +1111,29 @@ insert_tagged_text(iter, line, "add") -class _DetailsExpanderMessageDialog(Gtk.MessageDialog): +class _DetailsExpanderMessageDialog(_ExpandableDialog): """ Common base class for Apt*Dialog """ def __init__(self, text, desc, type, details=None, parent=None): - Gtk.MessageDialog.__init__(self, parent=parent, - message_type=type, - buttons=Gtk.ButtonsType.CLOSE) - self.set_markup("%s\n\n%s" % (text, desc)) - self.set_details(details) - - def set_details(self, details): - if not details: - return - #TRANSLATORS: expander label in the error dialog - expander = Gtk.Expander.new_with_mnemonic(_("_Details")) - expander.set_spacing(6) scrolled = Gtk.ScrolledWindow() scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scrolled.set_shadow_type(Gtk.ShadowType.ETCHED_IN) textview = Gtk.TextView() + textview.set_wrap_mode(Gtk.WrapMode.WORD) buffer = textview.get_buffer() - buffer.insert_at_cursor(details) scrolled.add(textview) - expander.add(scrolled) - self.get_message_area().add(expander) - expander.show_all() + #TRANSLATORS: expander label in the error dialog + _ExpandableDialog.__init__(self, parent=parent, + expander_label=_("_Details"), + expanded_child=scrolled, + title=text, message=desc, + stock_type=type) + self.show_all() + if details: + buffer.insert_at_cursor(details) + else: + self.expander.set_visible(False) class AptMessageDialog(_DetailsExpanderMessageDialog): @@ -1109,7 +1144,7 @@ text = get_msg_string_from_enum(enum) desc = get_msg_description_from_enum(enum) _DetailsExpanderMessageDialog.__init__(self, text, desc, - Gtk.MessageType.INFO, details, parent) + Gtk.STOCK_DIALOG_INFO, details, parent) class AptErrorDialog(_DetailsExpanderMessageDialog): """ @@ -1119,4 +1154,4 @@ text = get_error_string_from_enum(error.code) desc = get_error_description_from_enum(error.code) _DetailsExpanderMessageDialog.__init__(self, text, desc, - Gtk.MessageType.ERROR, error.details, parent) + Gtk.STOCK_DIALOG_ERROR, error.details, parent)