Esempio n. 1
0
    def on_render(self, window, widget, background_area, cell_area,
                  expose_area, flags):
        widget_wrapper = wrappermap.wrapper(widget)
        cell_wrapper = wrappermap.wrapper(self)

        selected = (flags & gtk.CELL_RENDERER_SELECTED)
        if selected:
            if widget.flags() & gtk.HAS_FOCUS:
                state = gtk.STATE_SELECTED
            else:
                state = gtk.STATE_ACTIVE
        else:
            state = gtk.STATE_NORMAL
        if cell_wrapper.IGNORE_PADDING:
            area = background_area
        else:
            xpad = self.props.xpad
            ypad = self.props.ypad
            area = gtk.gdk.Rectangle(cell_area.x + xpad, cell_area.y + ypad,
                                     cell_area.width - xpad * 2,
                                     cell_area.height - ypad * 2)
        context = drawing.DrawingContext(window, area, expose_area)
        if (selected and not widget_wrapper.draws_selection
                and widget_wrapper.use_custom_style):
            # Draw the base color as our background.  This erases the gradient
            # that GTK draws for selected items.
            window.draw_rectangle(widget.style.base_gc[state], True,
                                  background_area.x, background_area.y,
                                  background_area.width,
                                  background_area.height)
        context.style = drawing.DrawingStyle(widget_wrapper,
                                             use_base_color=True,
                                             state=state)
        widget_wrapper.layout_manager.update_cairo_context(context.context)
        hotspot_tracker = widget_wrapper.hotspot_tracker
        if (hotspot_tracker and hotspot_tracker.hit
                and hotspot_tracker.column == self.column
                and hotspot_tracker.path == self.path):
            hotspot = hotspot_tracker.name
        else:
            hotspot = None
        if (self.path, self.column) == widget_wrapper.hover_info:
            hover = widget_wrapper.hover_pos
            hover = (hover[0] - xpad, hover[1] - ypad)
        else:
            hover = None
        # NOTE: CustomCellRenderer.cell_data_func() sets up its attributes
        # from the model itself, so we don't have to worry about setting them
        # here.
        widget_wrapper.layout_manager.reset()
        cell_wrapper.render(context, widget_wrapper.layout_manager, selected,
                            hotspot, hover)
Esempio n. 2
0
    def drawRect_(self, rect):
        context = drawing.DrawingContext(self, self.bounds(), rect)
        context.style = drawing.DrawingStyle()
        wrapper = wrappermap.wrapper(self)
        wrapper.state = 'normal'
        disabled = wrapper.get_disabled()
        if not disabled:
            if self.state() == NSOnState:
                wrapper.state = 'pressed'
            elif self.mouse_inside:
                wrapper.state = 'hover'
            else:
                wrapper.state = 'normal'

        wrapper.draw(context, self.layout_manager)
        self.layout_manager.reset()
Esempio n. 3
0
 def drawRect_(self, dest_rect):
     if self.image is not None:
         source_rect = self.calculateSourceRectFromDestRect_(dest_rect)
         context = NSGraphicsContext.currentContext()
         context.setShouldAntialias_(YES)
         context.setImageInterpolation_(NSImageInterpolationHigh)
         context.saveGraphicsState()
         drawing.flip_context(self.bounds().size.height)
         self.image.nsimage.drawInRect_fromRect_operation_fraction_(
             dest_rect, source_rect, NSCompositeSourceOver, 1.0)
         context.restoreGraphicsState()
     if self.border:
         context = drawing.DrawingContext(self, self.bounds(), dest_rect)
         context.style = drawing.DrawingStyle()
         context.set_line_width(1)
         context.set_color((0, 0, 0))  # black
         context.rectangle(0, 0, context.width, context.height)
         context.stroke()
Esempio n. 4
0
 def on_get_size(self, widget, cell_area=None):
     wrapper = wrappermap.wrapper(self)
     widget_wrapper = wrappermap.wrapper(widget)
     style = drawing.DrawingStyle(widget_wrapper, use_base_color=True)
     # NOTE: CustomCellRenderer.cell_data_func() sets up its attributes
     # from the model itself, so we don't have to worry about setting them
     # here.
     width, height = wrapper.get_size(style, widget_wrapper.layout_manager)
     x_offset = self.props.xpad
     y_offset = self.props.ypad
     width += self.props.xpad * 2
     height += self.props.ypad * 2
     if cell_area:
         x_offset += cell_area.x
         y_offset += cell_area.x
         extra_width = max(0, cell_area.width - width)
         extra_height = max(0, cell_area.height - height)
         x_offset += int(round(self.props.xalign * extra_width))
         y_offset += int(round(self.props.yalign * extra_height))
     return x_offset, y_offset, width, height
Esempio n. 5
0
 def drawRect_(self, rect):
     context = drawing.DrawingContext(self, self.bounds(), rect)
     context.style = drawing.DrawingStyle()
     wrappermap.wrapper(self).draw(context, self.layout_manager)
     self.layout_manager.reset()