#!/usr/bin/python import cairo import sys from gi.repository import Gtk class Example(Gtk.Window): def __init__(self, width): super(Example, self).__init__() self._width = width self.init_ui() def init_ui(self): darea = Gtk.DrawingArea() darea.connect("draw", self.on_draw) self.add(darea) self.set_title("Linear gradients") self.resize(340, 390) self.set_position(Gtk.WindowPosition.CENTER) self.connect("delete-event", Gtk.main_quit) self.show_all() def on_draw(self, wid, cr): gradient = cairo.LinearGradient(0.500000, 0.000000, 0.500000, 1.000000) gradient.add_color_stop_rgba(0.0, 0.105882, 0.180392, 0.054902, 1.000000) gradient.add_color_stop_rgba(1.000000, 0.286275, 0.423529, 0.129412, 1.000000) cr.scale(self._width, 390) cr.rectangle(0, 0, 1, 1) cr.set_source(gradient) cr.fill() def main(width): Example(width) Gtk.main() if __name__ == "__main__": print("Pass 'work' as first argument to make it working, ie. try to render a gradient with width == 131071 instead of 131072") width = 131072 if len(sys.argv) == 2 and sys.argv[1] == "work": width = 131071 main(width)