python - PyGTK 3 (gi.repository) PangoCairo changing color between drawing text and line -


i'm having problems in changing colors between text , lines in pangocairo drawingarea. both come out same color. here simple python code:

from gi.repository import gtk, pango, pangocairo  class bug(gtk.drawingarea):     def __init__ (self):         gtk.drawingarea.__init__(self)      def do_draw_cb(self, widget, cr):         cr.translate ( 10, 10)          layout = pangocairo.create_layout (cr)         desc = pango.font_description_from_string ("sans 14")         layout.set_font_description( desc)         cr.set_source_rgba(0.0, 1.0, 0.0, 1.0)         layout.set_text("it not easy being green", -1 )          cr.move_to(40, 20)         cr.line_to(70, 20)         cr.set_source_rgba(0.0, 0.0, 0.0, 1.0)  # messes previous set_text         cr.stroke()         pangocairo.show_layout (cr, layout)  def destroy(window):         gtk.main_quit()  window = gtk.window() window.set_title ("green?")  app = bug() app.set_size_request (300, 200)  window.add(app)  app.connect('draw', app.do_draw_cb) window.connect_after('destroy', destroy) window.show_all() gtk.main() 

if remove second set_source_rgba, both text , line green instead of both black. want text in green , line in black. how do this?

for layout, color read when call show_layout, first set_source_rgba effect-less. should show layout after set it's color.

  def do_draw_cb(self, widget, cr):       cr.translate ( 10, 10)        layout = pangocairo.create_layout (cr)       desc = pango.font_description_from_string ("sans 14")       layout.set_font_description( desc)       cr.set_source_rgba(0.0, 1.0, 0.0, 1.0)       layout.set_text("it not easy being green", -1 )       pangocairo.show_layout (cr, layout)        cr.move_to(40, 20)       cr.line_to(70, 20)       cr.set_source_rgba(0.0, 0.0, 0.0, 1.0)  # messes previous set_text       cr.stroke() 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -