Ejemplo n.º 1
0
    def do_render(self, cr, widget, background_area, cell_area, flags):
        """ Render the actions. Implementation of Gtk.CellRenderer.render()."""

        cr.set_line_width(self.line_width)

        # Draw a white background.
        cr.rectangle(background_area.x, background_area.y,
                     background_area.width, background_area.height)
        cr.set_source_rgb(1, 1, 1)
        cr.fill()

        # Draw the actions.
        actions = self.get_property("actions").actions
        start_x = cell_area.x + self.item_spacing
        start_y = cell_area.y + old_div(
            (cell_area.height - self.item_height), 2)
        action_num = 0
        for action in actions:
            action_type = AlienFXThemeFile.get_action_type(action)
            if action_type == AlienFXThemeFile.KW_ACTION_TYPE_FIXED:
                colours = AlienFXThemeFile.get_action_colours(action)
                if len(colours) == 1:
                    colours_normalized = [
                        old_div(float(x), self.max_colour_val)
                        for x in colours[0]
                    ]
                    if self._get_intensity(colours_normalized) > 0.5:
                        border_colour = self.border_selected_dark
                    else:
                        border_colour = self.border_selected_light
                    (red, green, blue) = colours_normalized
                    cr.rectangle(start_x, start_y, self.item_width,
                                 self.item_height)
                    cr.set_source_rgb(red, green, blue)
                    cr.fill()
            elif action_type == AlienFXThemeFile.KW_ACTION_TYPE_BLINK:
                colours = AlienFXThemeFile.get_action_colours(action)
                if len(colours) == 1:
                    colours_normalized = [
                        old_div(float(x), self.max_colour_val)
                        for x in colours[0]
                    ]
                    border_colour = self.border_selected_light
                    (red, green, blue) = colours_normalized
                    cr.rectangle(start_x, start_y, old_div(self.item_width, 2),
                                 self.item_height)
                    cr.set_source_rgb(red, green, blue)
                    cr.fill()
                    cr.rectangle(start_x + old_div(self.item_width, 2),
                                 start_y, old_div(self.item_width,
                                                  2), self.item_height)
                    cr.set_source_rgb(0, 0, 0)
                    cr.fill()
            elif action_type == AlienFXThemeFile.KW_ACTION_TYPE_MORPH:
                colours = AlienFXThemeFile.get_action_colours(action)
                if len(colours) == 2:
                    colours_normalized1 = [
                        old_div(float(x), self.max_colour_val)
                        for x in colours[0]
                    ]
                    colours_normalized2 = [
                        old_div(float(x), self.max_colour_val)
                        for x in colours[1]
                    ]
                    border_colours = [
                        self.border_selected_light, self.border_selected_dark
                    ]
                    if (self._get_intensity(colours_normalized1) +
                            self._get_intensity(colours_normalized2)) > 1:
                        border_colour = self.border_selected_dark
                    else:
                        border_colour = self.border_selected_light
                    (red1, green1, blue1) = colours_normalized1
                    (red2, green2, blue2) = colours_normalized2
                    cr.rectangle(start_x, start_y, self.item_width,
                                 self.item_height)
                    gradient = cairo.LinearGradient(start_x, 0,
                                                    start_x + self.item_width,
                                                    0)
                    gradient.add_color_stop_rgb(0, red1, green1, blue1)
                    gradient.add_color_stop_rgb(1, red2, green2, blue2)
                    cr.set_source(gradient)
                    cr.fill()

            # Check if this action is selected.
            selected = False
            if ((self.selected_action is not None)
                    and (action_num == self.selected_action)
                    and (flags & Gtk.CellRendererState.SELECTED)):
                selected = True

            # draw the action border.
            (red, green, blue) = self.border_normal
            cr.rectangle(start_x, start_y, self.item_width, self.item_height)
            cr.set_source_rgb(red, green, blue)
            cr.stroke()

            # Draw the selection border.
            if selected:
                cr.set_line_width(2)
                (red, green, blue, alpha) = border_colour
                cr.set_source_rgba(red, green, blue, alpha)
                cr.rectangle(start_x + 3, start_y + 3, self.item_width - 3 - 3,
                             self.item_height - 3 - 3)
                cr.stroke()
            start_x += self.item_spacing + self.item_width + self.line_width
            action_num += 1
Ejemplo n.º 2
0
 def do_render(self, cr, widget, background_area, cell_area, flags):
     """ Render the actions. Implementation of Gtk.CellRenderer.render()."""
     
     cr.set_line_width(self.line_width)
      
     # Draw a white background.
     cr.rectangle(
         background_area.x, background_area.y, 
         background_area.width, background_area.height)
     cr.set_source_rgb(1, 1, 1)
     cr.fill()
     
     # Draw the actions.
     actions = self.get_property("actions").actions
     start_x = cell_area.x + self.item_spacing
     start_y = cell_area.y + old_div((cell_area.height - self.item_height),2)
     action_num = 0
     for action in actions:
         action_type = AlienFXThemeFile.get_action_type(action)
         if action_type == AlienFXThemeFile.KW_ACTION_TYPE_FIXED:
             colours = AlienFXThemeFile.get_action_colours(action)
             if len(colours) == 1:
                 colours_normalized = [
                     old_div(float(x),self.max_colour_val) for x in colours[0]]
                 if self._get_intensity(colours_normalized) > 0.5:
                     border_colour = self.border_selected_dark
                 else:
                     border_colour = self.border_selected_light
                 (red, green, blue) = colours_normalized
                 cr.rectangle(
                     start_x, start_y, self.item_width, self.item_height)
                 cr.set_source_rgb(red, green, blue)
                 cr.fill()
         elif action_type == AlienFXThemeFile.KW_ACTION_TYPE_BLINK:
             colours = AlienFXThemeFile.get_action_colours(action)
             if len(colours) == 1:
                 colours_normalized = [
                     old_div(float(x),self.max_colour_val) for x in colours[0]]
                 border_colour = self.border_selected_light
                 (red, green, blue) = colours_normalized
                 cr.rectangle(
                     start_x, start_y, old_div(self.item_width,2), self.item_height)
                 cr.set_source_rgb(red, green, blue)
                 cr.fill()
                 cr.rectangle(
                     start_x+ old_div(self.item_width,2), start_y, 
                     old_div(self.item_width,2), self.item_height)
                 cr.set_source_rgb(0, 0, 0)
                 cr.fill()
         elif action_type == AlienFXThemeFile.KW_ACTION_TYPE_MORPH:
             colours = AlienFXThemeFile.get_action_colours(action)
             if len(colours) == 2:
                 colours_normalized1 = [
                     old_div(float(x),self.max_colour_val) for x in colours[0]]
                 colours_normalized2 = [
                     old_div(float(x),self.max_colour_val) for x in colours[1]]
                 border_colours = [
                     self.border_selected_light, self.border_selected_dark]
                 if (self._get_intensity(colours_normalized1) + 
                         self._get_intensity(colours_normalized2)) > 1:
                     border_colour = self.border_selected_dark
                 else:
                     border_colour = self.border_selected_light
                 (red1, green1, blue1) = colours_normalized1
                 (red2, green2, blue2) = colours_normalized2
                 cr.rectangle(
                     start_x, start_y, self.item_width, self.item_height)
                 gradient = cairo.LinearGradient(
                     start_x, 0, start_x + self.item_width, 0)
                 gradient.add_color_stop_rgb(0, red1, green1, blue1)
                 gradient.add_color_stop_rgb(1, red2, green2, blue2)
                 cr.set_source(gradient)
                 cr.fill()
                 
         # Check if this action is selected.
         selected = False
         if ((self.selected_action is not None) and 
             (action_num == self.selected_action) and
             (flags & Gtk.CellRendererState.SELECTED)):
                 selected = True
                 
         # draw the action border.
         (red, green, blue) = self.border_normal
         cr.rectangle(start_x, start_y, self.item_width, self.item_height)
         cr.set_source_rgb(red, green, blue)
         cr.stroke()
         
         # Draw the selection border.
         if selected:
             cr.set_line_width(2)
             (red, green, blue, alpha) = border_colour
             cr.set_source_rgba(red, green, blue, alpha)
             cr.rectangle(start_x+3, start_y+3, self.item_width-3-3, 
                 self.item_height-3-3)
             cr.stroke()
         start_x += self.item_spacing + self.item_width + self.line_width
         action_num += 1