|
|
@ -19,9 +19,24 @@ |
|
|
|
|
|
|
|
|
|
|
|
import gtk |
|
|
|
import gtk |
|
|
|
import logging |
|
|
|
import logging |
|
|
|
|
|
|
|
import gettext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
|
|
|
|
|
|
# Logging |
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
|
|
|
_log = logging.getLogger('ui.pygtk.updatebox') |
|
|
|
_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): |
|
|
|
class UpdateBox(gtk.VBox): |
|
|
|
"""Custom update box widget.""" |
|
|
|
"""Custom update box widget.""" |
|
|
|
def __init__(self, avatar, spell_check=True): |
|
|
|
def __init__(self, avatar, spell_check=True): |
|
|
@ -37,13 +52,16 @@ class UpdateBox(gtk.VBox): |
|
|
|
|
|
|
|
|
|
|
|
status_bar = gtk.HBox(False, 0) |
|
|
|
status_bar = gtk.HBox(False, 0) |
|
|
|
self._update_status = gtk.Label() |
|
|
|
self._update_status = gtk.Label() |
|
|
|
|
|
|
|
self._update_info = gtk.Label() |
|
|
|
|
|
|
|
|
|
|
|
close_button = gtk.Button(stock=gtk.STOCK_CLOSE) |
|
|
|
close_button = gtk.Button(stock=gtk.STOCK_CLOSE) |
|
|
|
close_button.set_relief(gtk.RELIEF_NONE) |
|
|
|
close_button.set_relief(gtk.RELIEF_NONE) |
|
|
|
close_button.connect('clicked', self.hide) |
|
|
|
close_button.connect('clicked', self.hide) |
|
|
|
|
|
|
|
|
|
|
|
status_bar = gtk.HBox(False, 0) |
|
|
|
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) |
|
|
|
padding=0) |
|
|
|
status_bar.pack_start(close_button, expand=False, fill=False, |
|
|
|
status_bar.pack_start(close_button, expand=False, fill=False, |
|
|
|
padding=0) |
|
|
|
padding=0) |
|
|
@ -70,12 +88,19 @@ class UpdateBox(gtk.VBox): |
|
|
|
_log.debug('Error initializing spell checking: ' \ |
|
|
|
_log.debug('Error initializing spell checking: ' \ |
|
|
|
'spell checking disabled') |
|
|
|
'spell checking disabled') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._text.get_buffer().connect('changed', self._count_chars) |
|
|
|
|
|
|
|
self._count_chars() # To show something |
|
|
|
|
|
|
|
|
|
|
|
def show(self, reply_to=None): |
|
|
|
def show(self, reply_to=None): |
|
|
|
"""Show the update box and all related widgets.""" |
|
|
|
"""Show the update box and all related widgets.""" |
|
|
|
super(UpdateBox, self).show() |
|
|
|
super(UpdateBox, self).show() |
|
|
|
self._reply_to = reply_to |
|
|
|
|
|
|
|
self.show_all() |
|
|
|
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 |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
def hide(self, caller=None): |
|
|
|
def hide(self, caller=None): |
|
|
@ -85,19 +110,12 @@ class UpdateBox(gtk.VBox): |
|
|
|
self.hide_all() |
|
|
|
self.hide_all() |
|
|
|
return |
|
|
|
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 |
|
|
|
"""Count the number of chars in the edit field and update the |
|
|
|
label that shows the available space.""" |
|
|
|
label that shows the available space.""" |
|
|
|
count = len(self.text) |
|
|
|
count = len(self.text) |
|
|
|
|
|
|
|
|
|
|
|
if self._reply_to: |
|
|
|
text = N_('%d character', '%d characters', count) % (count) |
|
|
|
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) |
|
|
|
|
|
|
|
self._update_status.set_text(text) |
|
|
|
self._update_status.set_text(text) |
|
|
|
return True |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|