width = self.drawingarea.allocation.width
sum_height = 0
for layout in self.pangolayout:
- layout.set_width(width * pango.SCALE)
+ layout.set_width((width - layout.marginleft) * pango.SCALE)
layout.posY = sum_height
x, y = layout.get_pixel_size()
sum_height += y
area_bottom = view_y + self.drawingarea.allocation.height
if layout_top <= area_bottom and layout_bottom >= area_top:
self.drawingarea.window.draw_layout(
- gc, 0, layout.posY - int(view_y), layout)
+ gc, layout.marginleft, layout.posY - int(view_y), layout)
def on_drawingarea_expose_event(self, widget, event, data=None):
self.draw_viewport()
def process_queue(self, queue, num):
text = ""
+ current_margin = False
+ attrlist = pango.AttrList()
for data, bold, href, margin in queue:
+ data = data.encode("utf8")
+ if current_margin != margin:
+ layout = self.drawingarea.create_pango_layout(text)
+ layout.set_wrap(pango.WRAP_CHAR)
+ layout.posY = 0
+ layout.resnum = num
+ layout.set_attributes(attrlist)
+ if current_margin:
+ layout.marginleft = 20
+ else:
+ layout.marginleft = 0
+
+ self.pangolayout.append(layout)
+
+ current_margin = margin
+ text = ""
+ attrlist = pango.AttrList()
+
+ if bold:
+ attrlist.insert(pango.AttrWeight(
+ pango.WEIGHT_BOLD, len(text), len(text) + len(data)))
+ if href:
+ attrlist.insert(pango.AttrUnderline(
+ pango.UNDERLINE_SINGLE, len(text), len(text) + len(data)))
+
text += data
- layout = self.drawingarea.create_pango_layout(text)
- layout.set_wrap(pango.WRAP_CHAR)
- layout.posY = 0
- layout.resnum = num
+
+ if text != "":
+ layout = self.drawingarea.create_pango_layout(text)
+ layout.set_wrap(pango.WRAP_CHAR)
+ layout.posY = 0
+ layout.resnum = num
+ layout.set_attributes(attrlist)
+ if current_margin:
+ layout.marginleft = 20
+ else:
+ layout.marginleft = 0
self.pangolayout.append(layout)
self.relayout()
self.drawingarea.queue_draw()