Skip to content
Snippets Groups Projects
Commit 3990d013 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Add start of MessageLabel impl

parent aedc06ae
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Pango from gi.repository import Pango
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import GLib
from gajim.common import app from gajim.common import app
from gajim.common import i18n from gajim.common import i18n
...@@ -29,6 +28,7 @@ ...@@ -29,6 +28,7 @@
from gajim.common.i18n import _ from gajim.common.i18n import _
from .util import get_cursor from .util import get_cursor
from .util import make_pango_attribute
URI_TAGS = ['uri', 'address', 'xmppadr', 'mailadr'] URI_TAGS = ['uri', 'address', 'xmppadr', 'mailadr']
...@@ -42,11 +42,33 @@ def __init__(self, account): ...@@ -42,11 +42,33 @@ def __init__(self, account):
self._account = account self._account = account
self._textview = MessageTextview(self._account) self._text_widget = MessageTextview(self._account)
self.add(self._textview) # self._text_widget = MessageLabel(self._account)
self.add(self._text_widget)
def add_content(self, block): def add_content(self, block):
self._textview.print_text_with_styling(block) self._text_widget.print_text_with_styling(block)
class MessageLabel(Gtk.Label):
def __init__(self, account):
Gtk.Label.__init__(self)
self.set_hexpand(True)
self.set_selectable(True)
self.set_line_wrap(True)
self.set_xalign(0)
self.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
self._account = account
def print_text_with_styling(self, block):
attr_list = Pango.AttrList()
for span in block.spans:
attr = make_pango_attribute(span.name, span.start, span.end)
attr_list.insert(attr)
self.set_text(block.text.strip())
self.set_attributes(attr_list)
class MessageTextview(Gtk.TextView): class MessageTextview(Gtk.TextView):
......
...@@ -903,3 +903,21 @@ def refresh(self): ...@@ -903,3 +903,21 @@ def refresh(self):
account_class = app.css_config.get_dynamic_class(self._account) account_class = app.css_config.get_dynamic_class(self._account)
self.get_style_context().add_class(account_class) self.get_style_context().add_class(account_class)
self.set_tooltip_text(_('Account: %s') % label) self.set_tooltip_text(_('Account: %s') % label)
def make_pango_attribute(name, start, end):
if name == 'strong':
attr = Pango.attr_weight_new(Pango.Weight.BOLD)
if name == 'strike':
attr = Pango.attr_strikethrough_new(True)
if name == 'emphasis':
attr = Pango.attr_style_new(Pango.Style.ITALIC)
if name == 'pre':
attr = Pango.attr_family_new('monospace')
else:
ValueError('unknown attribute %s', name)
attr.start_index = start
attr.end_index = end
return attr
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment