reduce chars and lines in helpers
This commit is contained in:
parent
73a4bf97e8
commit
028bfbb6f0
|
@ -622,17 +622,12 @@ class StatusTable:
|
||||||
if status != '':
|
if status != '':
|
||||||
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
|
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
|
||||||
# FIXME: check and do the same if we have more than one \n
|
# FIXME: check and do the same if we have more than one \n
|
||||||
status = self.strip_text(status, 50)
|
status = gtkgui_helpers.reduce_chars_newlines(status, 50, 1)
|
||||||
|
else:
|
||||||
|
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 1)
|
||||||
str_status += ' - ' + status
|
str_status += ' - ' + status
|
||||||
return gtkgui_helpers.escape_for_pango_markup(str_status)
|
return gtkgui_helpers.escape_for_pango_markup(str_status)
|
||||||
|
|
||||||
# fix "too long status make the tooltip large than the screen" problem
|
|
||||||
def strip_text(self, text, max_length):
|
|
||||||
text = text.strip()
|
|
||||||
if len(text) > max_length:
|
|
||||||
text = text[:max_length - 3] + '...'
|
|
||||||
return text
|
|
||||||
|
|
||||||
def add_status_row(self, file_path, show, str_status):
|
def add_status_row(self, file_path, show, str_status):
|
||||||
''' appends a new row with status icon to the table '''
|
''' appends a new row with status icon to the table '''
|
||||||
self.current_row += 1
|
self.current_row += 1
|
||||||
|
@ -706,14 +701,17 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
|
||||||
iconset = 'sun'
|
iconset = 'sun'
|
||||||
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
file_path = os.path.join(gajim.DATA_DIR, 'iconsets', iconset, '16x16')
|
||||||
for acct in accounts:
|
for acct in accounts:
|
||||||
mesage = gtkgui_helpers.escape_for_pango_markup(acct['message'])
|
message = gtkgui_helpers.reduce_chars_newlines(acct['message'], 50, 1)
|
||||||
mesage = self.strip_text(mesage, 50)
|
message = gtkgui_helpers.escape_for_pango_markup(message)
|
||||||
self.add_status_row(file_path, acct['show'], '<span weight="bold">' +
|
self.add_status_row(file_path, acct['show'], '<span weight="bold">' +
|
||||||
gtkgui_helpers.escape_for_pango_markup(acct['name']) + '</span>'
|
gtkgui_helpers.escape_for_pango_markup(acct['name']) + '</span>'
|
||||||
+ ' - ' + mesage)
|
+ ' - ' + message)
|
||||||
|
|
||||||
elif len(accounts) == 1:
|
elif len(accounts) == 1:
|
||||||
text = _('Gajim - %s') % accounts[0]['status_line']
|
message = gtkgui_helpers.reduce_chars_newlines(accounts[0]['status_line'],
|
||||||
|
50, 1)
|
||||||
|
message = gtkgui_helpers.escape_for_pango_markup(message)
|
||||||
|
text = _('Gajim - %s') % message
|
||||||
else:
|
else:
|
||||||
text = _('Gajim - %s') % helpers.get_uf_show('offline')
|
text = _('Gajim - %s') % helpers.get_uf_show('offline')
|
||||||
self.text_lable.set_markup(text)
|
self.text_lable.set_markup(text)
|
||||||
|
|
|
@ -388,15 +388,9 @@ class GroupchatWindow(chat.Chat):
|
||||||
full_subject = None
|
full_subject = None
|
||||||
|
|
||||||
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
|
if gtk.gtk_version < (2, 6, 0) or gtk.pygtk_version < (2, 6, 0):
|
||||||
# long subject makes window bigger than the screen
|
subject = gtkgui_helpers.reduce_chars_newlines(subject, 80, 2)
|
||||||
def _cut_if_long(str):
|
else:
|
||||||
if len(str) > 80:
|
subject = gtkgui_helpers.reduce_chars_newlines(subject, 0, 2)
|
||||||
str = str[:77] + '...'
|
|
||||||
return str
|
|
||||||
if len(subject) > 80:
|
|
||||||
subjects = map(lambda e: _cut_if_long(e), subject.split('\n'))
|
|
||||||
subject = reduce(lambda e, e1: e + '\n' + e1, subjects)
|
|
||||||
|
|
||||||
subject = gtkgui_helpers.escape_for_pango_markup(subject)
|
subject = gtkgui_helpers.escape_for_pango_markup(subject)
|
||||||
name_label.set_markup(
|
name_label.set_markup(
|
||||||
'<span weight="heavy" size="x-large">%s</span>\n%s' % (room_jid, subject))
|
'<span weight="heavy" size="x-large">%s</span>\n%s' % (room_jid, subject))
|
||||||
|
|
|
@ -28,6 +28,33 @@ i18n.init()
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
|
||||||
|
def reduce_chars_newlines(text, max_chars = 0, max_lines = 0,
|
||||||
|
widget = None):
|
||||||
|
''' Cut the chars after 'max_chars' on each line
|
||||||
|
and show only the first 'max_lines'. If there is more text
|
||||||
|
to be shown, display the whole text in tooltip on 'widget'
|
||||||
|
If any of the params is not present(None or 0) the action
|
||||||
|
on it is not performed
|
||||||
|
'''
|
||||||
|
def _cut_if_long(str):
|
||||||
|
if len(str) > max_chars:
|
||||||
|
str = str[:max_chars - 3] + '...'
|
||||||
|
return str
|
||||||
|
|
||||||
|
if max_lines == 0:
|
||||||
|
lines = text.split('\n')
|
||||||
|
else:
|
||||||
|
lines = text.split('\n', max_lines)[:max_lines]
|
||||||
|
if max_chars > 0:
|
||||||
|
if lines:
|
||||||
|
lines = map(lambda e: _cut_if_long(e), lines)
|
||||||
|
if lines:
|
||||||
|
reduced_text = reduce(lambda e, e1: e + '\n' + e1, lines)
|
||||||
|
else:
|
||||||
|
reduced_text = ''
|
||||||
|
if reduced_text != text and widget is not None:
|
||||||
|
pass # FIXME show tooltip
|
||||||
|
return reduced_text
|
||||||
|
|
||||||
def convert_bytes(string):
|
def convert_bytes(string):
|
||||||
suffix = ''
|
suffix = ''
|
||||||
|
|
|
@ -133,15 +133,10 @@ class TabbedChatWindow(chat.Chat):
|
||||||
#FIXME: when gtk2.4 is OOOOLD do it via glade2.10+
|
#FIXME: when gtk2.4 is OOOOLD do it via glade2.10+
|
||||||
if gtk.pygtk_version >= (2, 6, 0) and gtk.gtk_version >= (2, 6, 0):
|
if gtk.pygtk_version >= (2, 6, 0) and gtk.gtk_version >= (2, 6, 0):
|
||||||
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
||||||
|
status = gtkgui_helpers.reduce_chars_newlines(status, 0, 2)
|
||||||
#FIXME: remove me when gtk24 is OLD
|
#FIXME: remove me when gtk24 is OLD
|
||||||
elif status is not None and len(status) > 50:
|
elif status is not None:
|
||||||
def _cut_if_long(str):
|
status = gtkgui_helpers.reduce_chars_newlines(status, 50, 2)
|
||||||
if len(str) > 50:
|
|
||||||
str = str[:47] + '...'
|
|
||||||
return str
|
|
||||||
if len(status) > 50:
|
|
||||||
status = map(lambda e: _cut_if_long(e), status.split('\n'))
|
|
||||||
status = reduce(lambda e, e1: e + '\n' + e1, status)
|
|
||||||
|
|
||||||
status = gtkgui_helpers.escape_for_pango_markup(status)
|
status = gtkgui_helpers.escape_for_pango_markup(status)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue