move gtkgui_helpers.reduce_chars_newlines to common/helpers.py. It's not GTK related.
This commit is contained in:
parent
1ee6cbc8cf
commit
9b83c74487
|
@ -1045,7 +1045,7 @@ class ChatControl(ChatControlBase):
|
||||||
status = contact.status
|
status = contact.status
|
||||||
if status is not None:
|
if status is not None:
|
||||||
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, max_lines = 2)
|
status = helpers.reduce_chars_newlines(status, max_lines = 2)
|
||||||
status_escaped = gtkgui_helpers.escape_for_pango_markup(status)
|
status_escaped = gtkgui_helpers.escape_for_pango_markup(status)
|
||||||
|
|
||||||
font_attrs, font_attrs_small = self.get_font_attrs()
|
font_attrs, font_attrs_small = self.get_font_attrs()
|
||||||
|
|
|
@ -817,6 +817,33 @@ def get_chat_control(account, contact):
|
||||||
return None
|
return None
|
||||||
return gajim.interface.msg_win_mgr.get_control(contact.jid, account)
|
return gajim.interface.msg_win_mgr.get_control(contact.jid, account)
|
||||||
|
|
||||||
|
def reduce_chars_newlines(text, max_chars = 0, max_lines = 0):
|
||||||
|
'''Cut the chars after 'max_chars' on each line
|
||||||
|
and show only the first 'max_lines'.
|
||||||
|
If any of the params is not present (None or 0) the action
|
||||||
|
on it is not performed'''
|
||||||
|
|
||||||
|
def _cut_if_long(string):
|
||||||
|
if len(string) > max_chars:
|
||||||
|
string = string[:max_chars - 3] + '...'
|
||||||
|
return string
|
||||||
|
|
||||||
|
if isinstance(text, str):
|
||||||
|
text = text.decode('utf-8')
|
||||||
|
|
||||||
|
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 = ''
|
||||||
|
return reduced_text
|
||||||
|
|
||||||
def get_notification_icon_tooltip_text():
|
def get_notification_icon_tooltip_text():
|
||||||
text = None
|
text = None
|
||||||
unread_chat = gajim.events.get_nb_events(types = ['printed_chat',
|
unread_chat = gajim.events.get_nb_events(types = ['printed_chat',
|
||||||
|
@ -868,7 +895,7 @@ def get_notification_icon_tooltip_text():
|
||||||
text = _('Gajim')
|
text = _('Gajim')
|
||||||
elif len(accounts) == 1:
|
elif len(accounts) == 1:
|
||||||
message = accounts[0]['status_line']
|
message = accounts[0]['status_line']
|
||||||
message = gtkgui_helpers.reduce_chars_newlines(message, 100, 1)
|
message = reduce_chars_newlines(message, 100, 1)
|
||||||
message = gtkgui_helpers.escape_for_pango_markup(message)
|
message = gtkgui_helpers.escape_for_pango_markup(message)
|
||||||
text = _('Gajim - %s') % message
|
text = _('Gajim - %s') % message
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -666,7 +666,7 @@ class GroupchatControl(ChatControlBase):
|
||||||
self.subject = subject
|
self.subject = subject
|
||||||
|
|
||||||
self.name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
self.name_label.set_ellipsize(pango.ELLIPSIZE_END)
|
||||||
subject = gtkgui_helpers.reduce_chars_newlines(subject, max_lines = 2)
|
subject = helpers.reduce_chars_newlines(subject, max_lines = 2)
|
||||||
subject = gtkgui_helpers.escape_for_pango_markup(subject)
|
subject = gtkgui_helpers.escape_for_pango_markup(subject)
|
||||||
font_attrs, font_attrs_small = self.get_font_attrs()
|
font_attrs, font_attrs_small = self.get_font_attrs()
|
||||||
text = '<span %s>%s</span>' % (font_attrs, self.room_jid)
|
text = '<span %s>%s</span>' % (font_attrs, self.room_jid)
|
||||||
|
@ -735,7 +735,7 @@ class GroupchatControl(ChatControlBase):
|
||||||
if status and gajim.config.get('show_status_msgs_in_roster'):
|
if status and gajim.config.get('show_status_msgs_in_roster'):
|
||||||
status = status.strip()
|
status = status.strip()
|
||||||
if status != '':
|
if status != '':
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, max_lines = 1)
|
status = helpers.reduce_chars_newlines(status, max_lines = 1)
|
||||||
# escape markup entities and make them small italic and fg color
|
# escape markup entities and make them small italic and fg color
|
||||||
color = gtkgui_helpers._get_fade_color(self.list_treeview,
|
color = gtkgui_helpers._get_fade_color(self.list_treeview,
|
||||||
selected, focus)
|
selected, focus)
|
||||||
|
|
|
@ -169,33 +169,6 @@ def get_default_font():
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def reduce_chars_newlines(text, max_chars = 0, max_lines = 0):
|
|
||||||
'''Cut the chars after 'max_chars' on each line
|
|
||||||
and show only the first 'max_lines'.
|
|
||||||
If any of the params is not present (None or 0) the action
|
|
||||||
on it is not performed'''
|
|
||||||
|
|
||||||
def _cut_if_long(string):
|
|
||||||
if len(string) > max_chars:
|
|
||||||
string = string[:max_chars - 3] + '...'
|
|
||||||
return string
|
|
||||||
|
|
||||||
if isinstance(text, str):
|
|
||||||
text = text.decode('utf-8')
|
|
||||||
|
|
||||||
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 = ''
|
|
||||||
return reduced_text
|
|
||||||
|
|
||||||
def escape_for_pango_markup(string):
|
def escape_for_pango_markup(string):
|
||||||
# escapes < > & ' "
|
# escapes < > & ' "
|
||||||
# for pango markup not to break
|
# for pango markup not to break
|
||||||
|
|
|
@ -514,7 +514,7 @@ class RosterWindow:
|
||||||
if contact.status and gajim.config.get('show_status_msgs_in_roster'):
|
if contact.status and gajim.config.get('show_status_msgs_in_roster'):
|
||||||
status = contact.status.strip()
|
status = contact.status.strip()
|
||||||
if status != '':
|
if status != '':
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, max_lines = 1)
|
status = helpers.reduce_chars_newlines(status, max_lines = 1)
|
||||||
# escape markup entities and make them small italic and fg color
|
# escape markup entities and make them small italic and fg color
|
||||||
color = gtkgui_helpers._get_fade_color(self.tree, selected, focus)
|
color = gtkgui_helpers._get_fade_color(self.tree, selected, focus)
|
||||||
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
|
colorstring = "#%04x%04x%04x" % (color.red, color.green, color.blue)
|
||||||
|
|
|
@ -178,7 +178,7 @@ class StatusTable:
|
||||||
if isinstance(status, str):
|
if isinstance(status, str):
|
||||||
status = unicode(status, encoding='utf-8')
|
status = unicode(status, encoding='utf-8')
|
||||||
# reduce to 100 chars, 1 line
|
# reduce to 100 chars, 1 line
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, 100, 1)
|
status = helpers.reduce_chars_newlines(status, 100, 1)
|
||||||
str_status = gtkgui_helpers.escape_for_pango_markup(str_status)
|
str_status = gtkgui_helpers.escape_for_pango_markup(str_status)
|
||||||
status = gtkgui_helpers.escape_for_pango_markup(status)
|
status = gtkgui_helpers.escape_for_pango_markup(status)
|
||||||
str_status += ' - <i>' + status + '</i>'
|
str_status += ' - <i>' + status + '</i>'
|
||||||
|
@ -233,7 +233,7 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
|
||||||
# there are possible pango TBs on 'set_markup'
|
# there are possible pango TBs on 'set_markup'
|
||||||
if isinstance(message, str):
|
if isinstance(message, str):
|
||||||
message = unicode(message, encoding = 'utf-8')
|
message = unicode(message, encoding = 'utf-8')
|
||||||
message = gtkgui_helpers.reduce_chars_newlines(message, 100, 1)
|
message = helpers.reduce_chars_newlines(message, 100, 1)
|
||||||
message = gtkgui_helpers.escape_for_pango_markup(message)
|
message = gtkgui_helpers.escape_for_pango_markup(message)
|
||||||
if gajim.con_types.has_key(acct['name']) and \
|
if gajim.con_types.has_key(acct['name']) and \
|
||||||
gajim.con_types[acct['name']] in ('tls', 'ssl'):
|
gajim.con_types[acct['name']] in ('tls', 'ssl'):
|
||||||
|
@ -296,7 +296,7 @@ class GCTooltip(BaseTooltip):
|
||||||
status = contact.status.strip()
|
status = contact.status.strip()
|
||||||
if status != '':
|
if status != '':
|
||||||
# escape markup entities
|
# escape markup entities
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, 100, 5)
|
status = helpers.reduce_chars_newlines(status, 100, 5)
|
||||||
status = '<i>' +\
|
status = '<i>' +\
|
||||||
gtkgui_helpers.escape_for_pango_markup(status) + '</i>'
|
gtkgui_helpers.escape_for_pango_markup(status) + '</i>'
|
||||||
properties.append((status, None))
|
properties.append((status, None))
|
||||||
|
@ -479,7 +479,7 @@ class RosterTooltip(NotificationAreaTooltip):
|
||||||
if status:
|
if status:
|
||||||
# reduce long status
|
# reduce long status
|
||||||
# (no more than 100 chars on line and no more than 5 lines)
|
# (no more than 100 chars on line and no more than 5 lines)
|
||||||
status = gtkgui_helpers.reduce_chars_newlines(status, 100, 5)
|
status = helpers.reduce_chars_newlines(status, 100, 5)
|
||||||
# escape markup entities.
|
# escape markup entities.
|
||||||
status = gtkgui_helpers.escape_for_pango_markup(status)
|
status = gtkgui_helpers.escape_for_pango_markup(status)
|
||||||
properties.append(('<i>%s</i>' % status, None))
|
properties.append(('<i>%s</i>' % status, None))
|
||||||
|
|
Loading…
Reference in New Issue