[pygtk] Cairo Line Width

Jeffrey Drake jeffd at techsociety.ca
Fri Sep 26 12:16:54 WST 2008


In my code below, I set a line width of 1 and then when I go to draw a
grid, what appears is an antialiased line of still width of 2. I need a
single pixel, not the ugly 2 width beast as shown before.

The problem is when drawing the horizontal grid below.

Any ideas on how to fix this?

My original code (without the set_line_width(1) is available at
https://launchpad.net/starz/demo1


- Jeff.

    def draw(self, context):
        rect = self.get_allocation()
#        x = rect.x + rect.width / 2
#        y = rect.y + rect.height / 2
        cx = rect.width
        cy = rect.height
        
        context.set_line_width(1)
        
        # white background
        context.set_source_rgb(1,1,1)
        context.rectangle(0, 0, cx, cy)
        context.fill()
        
        context.stroke()
        
        # no grid if no model
        if self.model == None:
            return
            
        cx = self.width
        cy = self.height
            
        # black grid
        context.set_source_rgb(0,0,0)
      
        # horizontal lines
        for i in xrange(self.model.cy+1):
            context.move_to(0, i * 33)
            context.line_to(cx, i * 33)
            print i*33
            
        for i in xrange(self.model.cx+1):
            context.move_to(i * 33, 0)
            context.line_to(i * 33, cy)
                    
        context.stroke()
        
        # draw planets
        context.set_source_rgb(0.5, 0.5, 0.5)
        
        for x,y in self.model.map:
            context.arc(x * 33 + 10, y * 33 + 10, 8, 0, 2 * math.pi)
            context.fill()
            context.stroke()        



More information about the pygtk mailing list