From c1587c3cebf64b76e026f4eba3117d8e67f373cf Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sun, 28 Mar 2010 09:59:19 -0300 Subject: [PATCH] Closing the updatebox works. --- mitterlib/ui/helpers/gtk_updatebox.py | 42 +++++++++++++++++++-------- mitterlib/ui/ui_pygtk.py | 4 +-- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/mitterlib/ui/helpers/gtk_updatebox.py b/mitterlib/ui/helpers/gtk_updatebox.py index 3d8ae20..0017d41 100644 --- a/mitterlib/ui/helpers/gtk_updatebox.py +++ b/mitterlib/ui/helpers/gtk_updatebox.py @@ -19,9 +19,24 @@ import gtk import logging +import gettext +# ---------------------------------------------------------------------- +# Logging +# ---------------------------------------------------------------------- _log = logging.getLogger('ui.pygtk.updatebox') +# ---------------------------------------------------------------------- +# I18n bits +# ---------------------------------------------------------------------- +t = gettext.translation('ui_pygtk', fallback=True) +# Still mark translations inside ui_pygtk +_ = t.gettext +N_ = t.ngettext + +# ---------------------------------------------------------------------- +# UpdateBox class +# ---------------------------------------------------------------------- class UpdateBox(gtk.VBox): """Custom update box widget.""" def __init__(self, avatar, spell_check=True): @@ -37,13 +52,16 @@ class UpdateBox(gtk.VBox): status_bar = gtk.HBox(False, 0) self._update_status = gtk.Label() + self._update_info = gtk.Label() close_button = gtk.Button(stock=gtk.STOCK_CLOSE) close_button.set_relief(gtk.RELIEF_NONE) close_button.connect('clicked', self.hide) status_bar = gtk.HBox(False, 0) - status_bar.pack_start(self._update_status, expand=True, fill=True, + status_bar.pack_start(self._update_status, expand=True, fill=False, + padding=0) + status_bar.pack_start(self._update_info, expand=True, fill=False, padding=0) status_bar.pack_start(close_button, expand=False, fill=False, padding=0) @@ -70,12 +88,19 @@ class UpdateBox(gtk.VBox): _log.debug('Error initializing spell checking: ' \ 'spell checking disabled') + self._text.get_buffer().connect('changed', self._count_chars) + self._count_chars() # To show something + def show(self, reply_to=None): """Show the update box and all related widgets.""" super(UpdateBox, self).show() - self._reply_to = reply_to self.show_all() - _log.debug('show') + + if reply_to: + info = _('(replying to %s)') % (self._reply_to) + self._update_info.set_text(info) + else: + self._update_info.set_text('') return def hide(self, caller=None): @@ -85,19 +110,12 @@ class UpdateBox(gtk.VBox): self.hide_all() return - def _count_chars(self, text_buffer): + def _count_chars(self, text_buffer=None): """Count the number of chars in the edit field and update the label that shows the available space.""" count = len(self.text) - if self._reply_to: - suffix = _('(replying to %s)') % (self._reply_to) - else: - suffix = '' - - # TODO: gettext to properly use "characters"/"character" - text = N_('%d character %s', '%d characters %s', count) % (count, - suffix) + text = N_('%d character', '%d characters', count) % (count) self._update_status.set_text(text) return True diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index f298128..40c4d4b 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -625,11 +625,9 @@ class Interface(object): def _clear_text(self, widget): """Clear the text field.""" - self._update_text.get_buffer().set_text('') - self._delete_info = None self._clear_reply() - self._hide_update_box() + self._update_field.hide() # change the focus to the grid. page = self._main_tabs.get_current_page()