Пример #1
0
class CycleStrip(gtk.HBox):
    """
    CycleStrip class.
    
    This widget use for cycle drawing background, but use CachePixbuf to accelerate render.
    
    @undocumented: expose_cycle_strip
    """

    def __init__(self, background_dpixbuf):
        """
        Initialize CycleStrip class.
        
        @param background_dpixbuf: DynamicPixbuf background.
        """
        gtk.HBox.__init__(self)
        self.background_dpixbuf = background_dpixbuf
        self.cache_pixbuf = CachePixbuf()

        self.set_size_request(-1, self.background_dpixbuf.get_pixbuf().get_height())

        self.connect("expose-event", self.expose_cycle_strip)

    def expose_cycle_strip(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        background_pixbuf = self.background_dpixbuf.get_pixbuf()

        self.cache_pixbuf.scale(background_pixbuf, rect.width, rect.height)

        draw_pixbuf(cr, self.cache_pixbuf.get_cache(), rect.x, rect.y)

        return False
Пример #2
0
class CycleStrip(gtk.HBox):
    '''
    CycleStrip class.

    This widget use for cycle drawing background, but use CachePixbuf to accelerate render.

    @undocumented: expose_cycle_strip
    '''
    def __init__(self, background_dpixbuf):
        '''
        Initialize CycleStrip class.

        @param background_dpixbuf: DynamicPixbuf background.
        '''
        gtk.HBox.__init__(self)
        self.background_dpixbuf = background_dpixbuf
        self.cache_pixbuf = CachePixbuf()

        self.set_size_request(
            -1,
            self.background_dpixbuf.get_pixbuf().get_height())

        self.connect("expose-event", self.expose_cycle_strip)

    def expose_cycle_strip(self, widget, event):
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation

        background_pixbuf = self.background_dpixbuf.get_pixbuf()

        self.cache_pixbuf.scale(background_pixbuf, rect.width, rect.height)

        draw_pixbuf(cr, self.cache_pixbuf.get_cache(), rect.x, rect.y)

        return False
Пример #3
0
class VolumeButton(gtk.Button):
    '''
    Volume button.
    '''
    
    __gsignals__ = {
        "volume-state-changed":(gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_INT,))
        }
    
    def __init__(self,
                 volume_max_value = 100,
                 volume_width = 52,
                 volume_x = 0,
                 volume_y = 15,
                 line_height = 3,
                 volume_padding_x = 5,
                 volume_level_values = [(1, 33),(34, 66),(67, 100)],
                 scroll_bool = False,
                 press_emit_bool = False,
                 inc_value=5,
                 bg_pixbuf = ui_theme.get_pixbuf("volumebutton/bg.png"),
                 fg_pixbuf = ui_theme.get_pixbuf("volumebutton/fg.png"),
                 zero_volume_normal_pixbuf = ui_theme.get_pixbuf("volumebutton/zero_normal.png"),
                 zero_volume_hover_pixbuf = ui_theme.get_pixbuf("volumebutton/zero_hover.png"),
                 zero_volume_press_pixbuf = ui_theme.get_pixbuf("volumebutton/zero_press.png"),
                 min_volume_normal_pixbuf = ui_theme.get_pixbuf("volumebutton/lower_normal.png"),
                 min_volume_hover_pixbuf = ui_theme.get_pixbuf("volumebutton/lower_hover.png"),
                 min_volume_press_pixbuf = ui_theme.get_pixbuf("volumebutton/lower_press.png"),
                 mid_volume_normal_pixbuf = ui_theme.get_pixbuf("volumebutton/middle_normal.png"),
                 mid_volume_hover_pixbuf = ui_theme.get_pixbuf("volumebutton/middle_hover.png"),
                 mid_volume_press_pixbuf = ui_theme.get_pixbuf("volumebutton/middle_press.png"),
                 max_volume_normal_pixbuf = ui_theme.get_pixbuf("volumebutton/high_normal.png"),
                 max_volume_hover_pixbuf = ui_theme.get_pixbuf("volumebutton/high_hover.png"),
                 max_volume_press_pixbuf = ui_theme.get_pixbuf("volumebutton/high_press.png"),
                 mute_volume_normal_pixbuf = ui_theme.get_pixbuf("volumebutton/mute_normal.png"),
                 mute_volume_hover_pixbuf = ui_theme.get_pixbuf("volumebutton/mute_hover.png"),
                 mute_volume_press_pixbuf = ui_theme.get_pixbuf("volumebutton/mute_press.png"),
                 point_volume_pixbuf = ui_theme.get_pixbuf("volumebutton/point_normal.png"),
                 ):        
        '''
        Initialize VolumeButton class.
        
        @param volume_max_value: Maximum value of volume, default is 100.
        @param volume_width: Width of volume button widget, default is 52 pixel.
        @param volume_x: X padding of volume button widget.
        @param volume_y: Y padding of volume button widget.
        @param line_height: Height of volume progressbar, default is 3 pixel.
        @param volume_padding_x: X padding value around volume progressbar.
        @param volume_level_values: The values of volume level.
        @param scroll_bool: True allowed scroll to change value, default is False.
        @param press_emit_bool: True to emit `volume-state-changed` signal when press, default is False.
        @param inc_value: The increase value of volume change, default is 5.
        '''
        gtk.Button.__init__(self)
        ###########################
        if volume_x < max_volume_normal_pixbuf.get_pixbuf().get_width():
            volume_x = max_volume_normal_pixbuf.get_pixbuf().get_width()
        '''Init pixbuf.'''
        self.__bg_pixbuf = bg_pixbuf
        self.__fg_pixbuf = fg_pixbuf
        self.__bg_cache_pixbuf = CachePixbuf()
        self.__fg_cache_pixbuf = CachePixbuf()
        # zero volume pixbuf.
        self.__zero_volume_normal_pixbuf  = zero_volume_normal_pixbuf
        self.__zero_volume_hover_pixbuf   = zero_volume_hover_pixbuf
        self.__zero_volume_press_pixbuf   = zero_volume_press_pixbuf
        # min volume pixbuf.
        self.__min_volume_normal_pixbuf  = min_volume_normal_pixbuf
        self.__min_volume_hover_pixbuf   = min_volume_hover_pixbuf
        self.__min_volume_press_pixbuf   = min_volume_press_pixbuf
        # mid volume pixbuf:        
        self.__mid_volume_normal_pixbuf     = mid_volume_normal_pixbuf
        self.__mid_volume_hover_pixbuf      = mid_volume_hover_pixbuf
        self.__mid_volume_press_pixbuf        = mid_volume_press_pixbuf
        # max volume pixbuf[normal, hover, press].        
        self.__max_volume_normal_pixbuf  = max_volume_normal_pixbuf
        self.__max_volume_hover_pixbuf   = max_volume_hover_pixbuf
        self.__max_volume_press_pixbuf   = max_volume_press_pixbuf
        # mute volume pixbuf[normal, hover, press].
        self.__mute_volume_normal_pixbuf    = mute_volume_normal_pixbuf
        self.__mute_volume_hover_pixbuf     = mute_volume_hover_pixbuf 
        self.__mute_volume_press_pixbuf     = mute_volume_press_pixbuf
        # point volume pixbuf.
        self.__point_volume_pixbuf    = point_volume_pixbuf        
        '''Init Set VolumeButton attr.'''
        '''Init value.'''
        self.__press_emit_bool  = press_emit_bool
        self.__line_height       = line_height
        self.__current_value    = 0
        self.__mute_bool        = False
        self.temp_mute_bool     = False
        self.__drag             = False 
        self.__volume_max_value = volume_max_value
        self.__volume_width     = volume_width
        
        self.__volume_left_x    = volume_x - self.__max_volume_normal_pixbuf.get_pixbuf().get_width() - volume_padding_x
        self.__volume_left_y    = volume_y - self.__max_volume_normal_pixbuf.get_pixbuf().get_height()/2 + self.__point_volume_pixbuf.get_pixbuf().get_height()/2
        self.__volume_right_x   = volume_x
        self.__volume_right_y   = volume_y
        '''Left'''
        self.volume_level_values = volume_level_values
        self.__volume_state = MIN_STATE
        self.__mouse_state  = MOUSE_VOLUME_STATE_NORMAL
        '''Right'''
        # bg value.
        self.__bg_x         = 0
        self.__bg_y         = self.__volume_right_y
        self.__bg_padding_x = self.__volume_right_x
        # fg value.
        self.__fg_x         = 0
        self.__fg_y         = self.__volume_right_y
        self.__fg_padding_x = self.__volume_right_x
        # point value.
        self.__point_y         = self.__volume_right_y
        self.__point_padding_x = self.__volume_right_x
        self.inc_value = inc_value
        
        '''Init VolumeButton event.'''
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.connect("expose-event",         self.__expose_draw_volume)
        self.connect("motion-notify-event",  self.__motion_mouse_set_point)
        self.connect("button-press-event",   self.__press_mouse_set_point)
        self.connect("button-release-event", self.__release_mouse_set_point)
        '''Event value'''
        self.press_bool = False
        # scroll event.
        if scroll_bool:
            self.connect("scroll-event",     self.__scroll_mouse_set_point)
            
        self.set_size_request(volume_width + self.__volume_left_x + self.__volume_right_x + self.__mute_volume_normal_pixbuf.get_pixbuf().get_width(), 30)
        
        set_clickable_cursor(self)
            
    def set_press_emit_bool(self, emit_bool):
        self.__press_emit_bool = emit_bool
        
    def __set_point_padding_x(self, event):
        self.__mute_bool = False
        self.__point_padding_x = int(event.x)   
        self.queue_draw()        
        
    def __press_mouse_set_point(self, widget, event):    
        temp_x = int(event.x)
        
        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf().get_width()/2
        temp_max_x = self.__bg_x + self.__bg_padding_x + self.__volume_width + self.__point_volume_pixbuf.get_pixbuf().get_width()/2
        self.queue_draw()
        if temp_min_x < temp_x < temp_max_x:            
            self.__set_point_padding_x(event)
            self.__drag = True
        else:    
            if self.__volume_left_x <= temp_x <= temp_min_x:                
                # Set mouse state press.
                self.__mouse_state = MOUSE_VOLUME_STATE_PRESS
                self.temp_mute_bool = True
                self.press_bool = True
        
    def __release_mouse_set_point(self, widget, event):        
        # Set mouse state normal.
        self.__mouse_state = MOUSE_VOLUME_STATE_NORMAL        
        self.__drag = False
        self.press_bool = False
        
        temp_x = int(event.x)
        temp_y = int(event.y)
        
        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf().get_width()/2
        if self.__volume_left_x <= temp_x <= temp_min_x  and ( self.__volume_left_y <=temp_y < (self.__volume_left_y + self.__mute_volume_hover_pixbuf.get_pixbuf().get_height())):
            if self.temp_mute_bool and not self.__mute_bool:
                # Set mute state.
                self.__mute_bool = not self.__mute_bool
                self.__volume_state = MUTE_STATE 
                self.temp_mute_bool = False
            else: # modify state.
                self.__mute_bool = False
                self.temp_mute_bool = False
                self.__set_volume_value_to_state(self.__current_value)                
                self.queue_draw()
            
        if self.__press_emit_bool:
            self.emit("volume-state-changed", self.__current_value, self.__volume_state)        
        
        self.queue_draw()    
        
    def __motion_mouse_set_point(self, widget, event):
        temp_x = int(event.x)
        temp_y = int(event.y)
        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf().get_width()/2
        
        if (self.__volume_left_x <= temp_x <= temp_min_x) and ( self.__volume_left_y <=temp_y < (self.__volume_left_y + self.__mute_volume_hover_pixbuf.get_pixbuf().get_height())):
            self.__mouse_state = MOUSE_VOLUME_STATE_HOVER
        else:
            self.__mouse_state = MOUSE_VOLUME_STATE_NORMAL
        if not self.press_bool:
            self.queue_draw()
            
        if self.__drag:
            self.__set_point_padding_x(event)        
        
    def __scroll_mouse_set_point(self, widget, event):    
        if event.direction == gtk.gdk.SCROLL_UP:
            self.volume_other_set_value(VOLUME_RIGHT)
        elif event.direction == gtk.gdk.SCROLL_DOWN:
            self.volume_other_set_value(VOLUME_LEFT)
            
    def volume_other_set_value(self, volume_type):    
        point_width_average      = self.__point_volume_pixbuf.get_pixbuf().get_width() / 2 
        temp_min = (self.__point_padding_x - point_width_average)
        temp_max = (self.__point_padding_x + self.__volume_width - point_width_average)
        
        self.__mute_bool = False
        
        if volume_type == VOLUME_RIGHT:
            if self.__point_padding_x >= temp_max:
                self.__point_padding_x = temp_max
            else:    
                self.__point_padding_x += self.inc_value
        elif volume_type == VOLUME_LEFT:
            if self.__point_padding_x <= temp_min:
                self.__point_padding_x = temp_min
            else:    
                self.__point_padding_x -= self.inc_value
            
        self.queue_draw()
        
    def __expose_draw_volume(self, widget, event):                        
        self.__draw_volume_right(widget, event)              # 1: get current value.
        self.__set_volume_value_to_state(self.__current_value) # 2: value to state.
        self.__draw_volume_left(widget, event)               # 3: draw state pixbuf.        
        
        if not self.__press_emit_bool:
            self.emit("volume-state-changed", self.__current_value, self.__volume_state)
        # propagate_expose(widget, event)
        return True

        
    '''Left function'''        
    @property
    def volume_state(self):
        return self.__volume_state 
    
    @volume_state.setter
    def volume_state(self, state):
        if state == MIN_STATE:
            self.__volume_state = MIN_STATE
        elif state == ZERO_STATE:    
            self.__volume_state = ZERO_STATE
        elif state == MID_STATE:    
            self.__volume_state = MID_STATE
        elif state == MAX_STATE:    
            self.__volume_state = MAX_STATE
        elif state == MUTE_STATE:    
            self.__volume_state = MUTE_STATE
            
            
    @volume_state.getter        
    def volume_state(self):
        return self.__volume_state
        
    @volume_state.deleter
    def volume_state(self):
        del self.__volume_state
        
    def set_volume_level_values(self, show_value):
        try:
            show_value[0][0] - show_value[0][1]
            show_value[1][0] - show_value[1][1]
            show_value[2][0] - show_value[2][1]
            
            self.volume_level_values = show_value
        except:    
            print "Error show value!!"
        
    def __set_volume_value_to_state(self, value):
        if not self.__mute_bool:
            temp_show_value = self.volume_level_values
            if temp_show_value[0][0] <= value <= temp_show_value[0][1]:
                self.__volume_state = MIN_STATE
            elif temp_show_value[1][0] <= value <= temp_show_value[1][1]:
                self.__volume_state = MID_STATE
            elif temp_show_value[2][0] <= value <= temp_show_value[2][1]:
                self.__volume_state = MAX_STATE
            elif 0 == value:    
                self.__volume_state = ZERO_STATE
        else:        
            self.__volume_state = MUTE_STATE
                    
    def set_volume_mute(self, mute_flag=True):
        if mute_flag:
            self.temp_mute_bool = False
            self.__mute_bool = True
            self.__volume_state = MUTE_STATE
        else:
            self.temp_mute_bool = False
            self.__mute_bool = False
            self.__set_volume_value_to_state(self.value)

        self.queue_draw()
        
    def __draw_volume_left(self, widget, event):
        cr = widget.window.cairo_create()
        x, y, w, h = widget.allocation
        
        if self.__volume_state == MUTE_STATE: # mute state.           
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:                
                pixbuf = self.__mute_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:        
                pixbuf = self.__mute_volume_hover_pixbuf            
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mute_volume_press_pixbuf                
        elif self.__volume_state == ZERO_STATE: # zero state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:                
                pixbuf = self.__zero_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:        
                pixbuf = self.__zero_volume_hover_pixbuf            
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__zero_volume_press_pixbuf                        
        elif self.__volume_state == MIN_STATE: # min state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:                
                pixbuf = self.__min_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:        
                pixbuf = self.__min_volume_hover_pixbuf            
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__min_volume_press_pixbuf                        
        elif self.__volume_state == MID_STATE: # mid state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:                
                pixbuf = self.__mid_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:        
                pixbuf = self.__mid_volume_hover_pixbuf            
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mid_volume_press_pixbuf                        
        elif self.__volume_state == MAX_STATE: # max state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:                
                pixbuf = self.__max_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:        
                pixbuf = self.__max_volume_hover_pixbuf            
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__max_volume_press_pixbuf            
            
            
        draw_pixbuf(cr,
                    pixbuf.get_pixbuf(),
                    x + self.__volume_left_x,
                    y + self.__volume_left_y,
                    )
    
    '''Right function'''            
    @property
    def line_height(self):
        return self.__line_height
    
    @line_height.setter
    def line_height(self, width):
        self.__line_height = width
        self.queue_draw()
        
    @line_height.getter    
    def line_height(self):    
        return self.__line_height
    
    @line_height.deleter
    def line_height(self):
        del self.__line_height
        
    @property    
    def value(self):
        return self.__current_value
    
    @value.setter
    def value(self, value):        
        if 0 <= value <= self.__volume_max_value:
            Tooltip.text(self, str(value))
            temp_padding = (float(self.__volume_max_value) / self.__volume_width)
            temp_padding_x = float(value) / temp_padding            
            self.__point_padding_x = temp_padding_x + ((self.__fg_padding_x))
            self.queue_draw()
            
    @value.getter        
    def value(self):        
        return self.__current_value
        
    
    def set_volume_position(self, x, y):        
        self.__volume_right_x = x
        self.__volume_right_y = y
        # Set x.
        self.__bg_padding_x    = self.__volume_right_x
        self.__fg_padding_x    = self.__volume_right_x
        self.__point_padding_x = self.__volume_right_x
        # Set y.
        self.__bg_y    = self.__volume_right_y
        self.__fg_y    = self.__volume_right_y
        self.__point_y = self.__volume_right_y
        
    @property    
    def max_value(self):    
        self.__volume_max_value
        
    @max_value.setter    
    def max_value(self, max_value):            
        self.__volume_max_value = max_value
        
    @max_value.getter    
    def max_value(self):            
        return self.__volume_max_value
        
    @max_value.deleter
    def max_value(self):
        del self.__volume_max_value
        
    def __draw_volume_right(self, widget, event):
        cr = widget.window.cairo_create()
        cr.set_line_width(self.__line_height)
        x, y, w, h = widget.allocation
    
        fg_height_average = (self.__point_volume_pixbuf.get_pixbuf().get_height() - self.__fg_pixbuf.get_pixbuf().get_height()) / 2
        bg_height_average = (self.__point_volume_pixbuf.get_pixbuf().get_height() - self.__bg_pixbuf.get_pixbuf().get_height()) / 2
        point_width_average      = self.__point_volume_pixbuf.get_pixbuf().get_width() / 2 
        ##################################################
        # Draw bg.
        if self.__volume_width > 0:
            self.__bg_cache_pixbuf.scale(self.__bg_pixbuf.get_pixbuf(), 
                                         self.__volume_width,
                                         self.__bg_pixbuf.get_pixbuf().get_height(),
                                         )
            draw_pixbuf(
                cr,
                self.__bg_cache_pixbuf.get_cache(),
                x + self.__bg_x + self.__bg_padding_x,
                y + self.__bg_y + bg_height_average)
        
        temp_fg_padding_x = self.__point_padding_x - (self.__fg_x + self.__fg_padding_x) 
        
        if temp_fg_padding_x < 0:
            temp_fg_padding_x = 0
        if temp_fg_padding_x > self.__volume_width:    
            temp_fg_padding_x = self.__volume_width
        # Get current value.    
        self.__current_value = temp_fg_padding_x * (float(self.__volume_max_value) / self.__volume_width)
        
        # Draw fg. 
        if temp_fg_padding_x > 0:
            self.__fg_cache_pixbuf.scale(self.__fg_pixbuf.get_pixbuf(), 
                                         int(temp_fg_padding_x),
                                         self.__fg_pixbuf.get_pixbuf().get_height(),
                                         )
            draw_pixbuf(
                cr,
                self.__fg_cache_pixbuf.get_cache(),
                x + self.__fg_x + self.__fg_padding_x,
                y + self.__fg_y + fg_height_average)
        #################################################
        # Draw point.                        
        temp_point_padding_x     = (self.__point_padding_x - point_width_average)

        temp_min = (self.__volume_right_x - point_width_average)
        temp_max = (self.__volume_right_x + self.__volume_width - point_width_average)
        if temp_point_padding_x < temp_min:
            temp_point_padding_x = temp_min
        if temp_point_padding_x > temp_max:    
            temp_point_padding_x = temp_max
            
        draw_pixbuf(cr, 
                    self.__point_volume_pixbuf.get_pixbuf(), 
                    x + temp_point_padding_x,
                    y + self.__point_y)    
Пример #4
0
class TimeZone(gtk.EventBox):
    '''
    TimeZone class.
    '''

    __gsignals__ = {
        "changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (int,)),}

    def __init__(self,
                 timezone=0,
                 width=800,
                 height=409,
                 padding_top=0,
                 padding_left=0,
                 ):
        '''
        Initialize TimeZone class.

        @param timezone: Timezone, default is 0.
        @param width: The width of timezone, default is 800 pixels.
        @param height: The height of timezone, default is 409 pixels.
        @param padding_top: The padding value of top, default is 0.
        @param padding_left: The padding value of left, default is 0.
        '''
        gtk.EventBox.__init__(self)

        self.__timezone = timezone + 9

        self.width = width
        self.height = height
        self.set_size_request(self.width, self.height)

        self.padding_top = padding_top
        self.padding_left = padding_left

        self.__const_width = 800
        self.__const_height = 409

        self.cache_bg_pixbuf = CachePixbuf()
        self.bg_pixbuf = ui_theme.get_pixbuf("timezone/bg.png")
        self.cache_timezone_pixbuf = CachePixbuf()
        self.timezone_pixbuf = []
        i = -9
        while i <= 13:
            self.timezone_pixbuf.append(ui_theme.get_pixbuf("timezone/timezone_%d.png" % i))

            i += 1

        self.connect("button-press-event", self.__button_press)
        self.connect("expose-event", self.__expose)

    def set_timezone(self, timezone):
        '''
        set timezone.

        @param timezone: Timezone to set.
        '''
        self.__timezone = timezone + 9
        if self.__timezone < 0:
            self.__timezone = 0

        if self.__timezone > 23:
            self.__timezone = 23

        self.queue_draw()

    def __button_press(self, widget, event):
        if event.x > self.width or event.y > self.height:
            return

        self.__timezone = int(event.x * 24 / self.width) - 2;
        if self.__timezone < 0:
            self.__timezone = 0

        if self.__timezone > 23:
            self.__timezone = 23

        self.emit("changed", self.__timezone - 9)

        self.window.invalidate_rect(self.allocation, True)

    def __expose(self, widget, event):
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y = rect.x, rect.y
        x -= self.padding_left
        y -= self.padding_top * 2

        with cairo_state(cr):
            cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF"))
            cr.rectangle(x,
                         y,
                         rect.width,
                         rect.height + self.padding_top)
            cr.fill()

            if self.width < self.__const_width or self.height < self.__const_height:
                self.cache_bg_pixbuf.scale(self.bg_pixbuf.get_pixbuf(),
                                           self.width,
                                           self.height)
                self.cache_timezone_pixbuf.scale(self.timezone_pixbuf[self.__timezone].get_pixbuf(),
                                                 self.width,
                                                 self.height)

                draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), x, y)
                draw_pixbuf(cr, self.cache_timezone_pixbuf.get_cache(), x, y)
            else:
                draw_pixbuf(cr, self.bg_pixbuf.get_pixbuf(), x, y)
                draw_pixbuf(cr,
                            self.timezone_pixbuf[self.__timezone].get_pixbuf(),
                            x,
                            y)

        return True
Пример #5
0
class Notebook(gtk.EventBox):
    """Notebook."""

    def __init__(
        self,
        items,
        foreground_left_pixbuf=ui_theme.get_pixbuf("notebook/foreground_left.png"),
        foreground_middle_pixbuf=ui_theme.get_pixbuf("notebook/foreground_middle.png"),
        foreground_right_pixbuf=ui_theme.get_pixbuf("notebook/foreground_right.png"),
        background_left_pixbuf=ui_theme.get_pixbuf("notebook/background_left.png"),
        background_middle_pixbuf=ui_theme.get_pixbuf("notebook/background_middle.png"),
        background_right_pixbuf=ui_theme.get_pixbuf("notebook/background_right.png"),
    ):
        """Init notebook."""
        # Init.
        gtk.EventBox.__init__(self)
        self.set_visible_window(False)
        self.set_can_focus(True)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)

        self.items = items
        self.current_item_index = 0
        self.padding_side = 27  # pixel
        self.padding_middle = 10  # pixel
        self.foreground_left_pixbuf = foreground_left_pixbuf
        self.foreground_middle_pixbuf = foreground_middle_pixbuf
        self.foreground_right_pixbuf = foreground_right_pixbuf
        self.background_left_pixbuf = background_left_pixbuf
        self.background_middle_pixbuf = background_middle_pixbuf
        self.background_right_pixbuf = background_right_pixbuf
        self.cache_bg_pixbuf = CachePixbuf()
        self.cache_fg_pixbuf = CachePixbuf()

        # Calcuate tab width.
        (self.tab_width, self.tab_height) = self.calculate_tab_width()
        self.set_size_request(-1, self.tab_height)

        # Expose.
        self.connect("expose-event", self.expose_notebook)
        self.connect("button-press-event", self.button_press_notebook)

    def calculate_tab_width(self):
        """Calculate tab width."""
        self.icon_width = 0
        max_tab_content_width = 0
        for (item_icon, item_content, item_callback) in self.items:
            if self.icon_width == 0 and item_icon != None:
                self.icon_width = item_icon.get_pixbuf().get_width()

            (content_width, content_height) = get_content_size(item_content, DEFAULT_FONT_SIZE)
            if content_width > max_tab_content_width:
                max_tab_content_width = content_width

        tab_image_height = self.foreground_left_pixbuf.get_pixbuf().get_height()

        if self.icon_width == 0:
            tab_width = self.padding_side * 2 + max_tab_content_width
        else:
            tab_width = self.padding_side * 2 + self.padding_middle + self.icon_width + max_tab_content_width

        return (tab_width, tab_image_height)

    def expose_notebook(self, widget, event):
        """Expose notebook."""
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        foreground_left_pixbuf = self.foreground_left_pixbuf.get_pixbuf()
        self.cache_fg_pixbuf.scale(
            self.foreground_middle_pixbuf.get_pixbuf(),
            self.tab_width - foreground_left_pixbuf.get_width() * 2,
            self.tab_height,
        )
        foreground_middle_pixbuf = self.cache_fg_pixbuf.get_cache()
        foreground_right_pixbuf = self.foreground_right_pixbuf.get_pixbuf()
        background_left_pixbuf = self.background_left_pixbuf.get_pixbuf()
        self.cache_bg_pixbuf.scale(
            self.background_middle_pixbuf.get_pixbuf(),
            self.tab_width - background_left_pixbuf.get_width() * 2,
            self.tab_height,
        )
        background_middle_pixbuf = self.cache_bg_pixbuf.get_cache()
        background_right_pixbuf = self.background_right_pixbuf.get_pixbuf()

        # Draw tab.
        for (index, (item_icon, item_content, item_callback)) in enumerate(self.items):
            # Draw background.
            if self.current_item_index == index:
                draw_pixbuf(cr, foreground_left_pixbuf, rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr,
                    foreground_middle_pixbuf,
                    rect.x + index * self.tab_width + foreground_left_pixbuf.get_width(),
                    rect.y,
                )
                draw_pixbuf(
                    cr,
                    foreground_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width - foreground_left_pixbuf.get_width(),
                    rect.y,
                )
            else:
                draw_pixbuf(cr, background_left_pixbuf, rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr,
                    background_middle_pixbuf,
                    rect.x + index * self.tab_width + background_left_pixbuf.get_width(),
                    rect.y,
                )
                draw_pixbuf(
                    cr,
                    background_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width - background_left_pixbuf.get_width(),
                    rect.y,
                )

            # Draw content.
            (content_width, content_height) = get_content_size(item_content, DEFAULT_FONT_SIZE)
            if item_icon != None:
                tab_render_width = self.icon_width + self.padding_middle + content_width
                draw_pixbuf(
                    cr,
                    item_icon.get_pixbuf(),
                    rect.x + index * self.tab_width + (self.tab_width - tab_render_width) / 2,
                    rect.y + (self.tab_height - item_icon.get_pixbuf().get_height()) / 2,
                )

                draw_text(
                    cr,
                    item_content,
                    rect.x
                    + index * self.tab_width
                    + (self.tab_width - tab_render_width) / 2
                    + self.icon_width
                    + self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )
            else:
                tab_render_width = content_width
                draw_text(
                    cr,
                    item_content,
                    rect.x
                    + index * self.tab_width
                    + (self.tab_width - tab_render_width) / 2
                    + self.icon_width
                    + self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )

        propagate_expose(widget, event)

        return True

    def button_press_notebook(self, widget, event):
        """Button press notebook."""
        # Get tab index.
        tab_index = int(event.x / self.tab_width)
        if tab_index < len(self.items):
            self.current_item_index = tab_index

            # Redraw.
            self.queue_draw()

            # Callback.
            if self.items[tab_index][2] != None:
                self.items[tab_index][2]()
Пример #6
0
class HScalebar(gtk.HScale):
    '''
    HScalebar.
    
    @undocumented: expose_h_scalebar
    @undocumented: press_volume_progressbar
    '''
	
    def __init__(self,
                 left_fg_dpixbuf,
                 left_bg_dpixbuf,
                 middle_fg_dpixbuf,
                 middle_bg_dpixbuf,
                 right_fg_dpixbuf,
                 right_bg_dpixbuf,
                 point_dpixbuf
                 ):
        '''
        Init HScalebar class.
        
        @param left_fg_dpixbuf: Left foreground pixbuf.
        @param left_bg_dpixbuf: Left background pixbuf.
        @param middle_fg_dpixbuf: Middle foreground pixbuf.
        @param middle_bg_dpixbuf: Middle background pixbuf.
        @param right_fg_dpixbuf: Right foreground pixbuf.
        @param right_bg_dpixbuf: Right background pixbuf.
        @param point_dpixbuf: Pointer pixbuf.
        '''
        # Init.
        gtk.HScale.__init__(self)
        self.set_draw_value(False)
        self.set_range(0, 100)
        self.left_fg_dpixbuf = left_fg_dpixbuf
        self.left_bg_dpixbuf = left_bg_dpixbuf
        self.middle_fg_dpixbuf = middle_fg_dpixbuf
        self.middle_bg_dpixbuf = middle_bg_dpixbuf
        self.right_fg_dpixbuf = right_fg_dpixbuf
        self.right_bg_dpixbuf = right_bg_dpixbuf
        self.point_dpixbuf = point_dpixbuf
        self.cache_bg_pixbuf = CachePixbuf()
        self.cache_fg_pixbuf = CachePixbuf()
        
        # Set size request.
        self.set_size_request(-1, self.point_dpixbuf.get_pixbuf().get_height())
        
        # Redraw.
        self.connect("expose-event", self.expose_h_scalebar)
        self.connect("button-press-event", self.press_volume_progressbar)
        
    def expose_h_scalebar(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Init pixbuf.
        left_fg_pixbuf = self.left_fg_dpixbuf.get_pixbuf()
        left_bg_pixbuf = self.left_bg_dpixbuf.get_pixbuf()
        middle_fg_pixbuf = self.middle_fg_dpixbuf.get_pixbuf()
        middle_bg_pixbuf = self.middle_bg_dpixbuf.get_pixbuf()
        right_fg_pixbuf = self.right_fg_dpixbuf.get_pixbuf()
        right_bg_pixbuf = self.right_bg_dpixbuf.get_pixbuf()
        point_pixbuf = self.point_dpixbuf.get_pixbuf()
        
        # Init value.
        upper = self.get_adjustment().get_upper() 
        lower = self.get_adjustment().get_lower() 
        total_length = max(upper - lower, 1)
        side_width = left_bg_pixbuf.get_width()
        point_width = point_pixbuf.get_width()
        point_height = point_pixbuf.get_height()
        x, y, w, h = rect.x + point_width / 2, rect.y, rect.width - point_width, rect.height
        line_height = left_bg_pixbuf.get_height()
        line_y = y + (point_height - line_height) / 2
        value = int((self.get_value() - lower) / total_length * w)

        # Draw background.
        self.cache_bg_pixbuf.scale(middle_bg_pixbuf, w - side_width * 2, line_height)
        draw_pixbuf(cr, left_bg_pixbuf, x, line_y)
        draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), x + side_width, line_y)
        draw_pixbuf(cr, right_bg_pixbuf, x + w - side_width, line_y)
        
        # Draw foreground.
        if value > 0:
            self.cache_fg_pixbuf.scale(middle_fg_pixbuf, value, line_height)
            draw_pixbuf(cr, left_fg_pixbuf, x, line_y)
            draw_pixbuf(cr, self.cache_fg_pixbuf.get_cache(), x + side_width, line_y)
            draw_pixbuf(cr, right_fg_pixbuf, x + value, line_y)
            
        # Draw drag point.
        draw_pixbuf(cr, point_pixbuf, x + value - point_pixbuf.get_width() / 2, y)    
                
        return True        

    def press_volume_progressbar(self, widget, event):
        '''
        Internal callback for `button-press-event` signal.
        '''
        # Init.
        if is_left_button(event):
            rect = widget.allocation
            lower = self.get_adjustment().get_lower()
            upper = self.get_adjustment().get_upper()
            point_width = self.point_dpixbuf.get_pixbuf().get_width()
            
            # Set value.
            self.set_value(lower + ((event.x - point_width / 2)  / (rect.width - point_width)) * (upper - lower))
            self.queue_draw()
        
        return False
Пример #7
0
class VScalebar(gtk.VScale):
    '''
    VScalebar.
    
    @undocumented: expose_v_scalebar
    @undocumented: press_progressbar
    '''
    
    def __init__(self,
                 upper_fg_dpixbuf,
                 upper_bg_dpixbuf,
                 middle_fg_dpixbuf,
                 middle_bg_dpixbuf,
                 bottom_fg_dpixbuf,
                 bottom_bg_dpixbuf,
                 point_dpixbuf,
                 ):
        '''
        Initialize VScalebar class.
        
        @param upper_fg_dpixbuf: Upper foreground pixbuf.
        @param upper_bg_dpixbuf: Upper background pixbuf.
        @param middle_fg_dpixbuf: Middle foreground pixbuf.
        @param middle_bg_dpixbuf: Middle background pixbuf.
        @param bottom_fg_dpixbuf: Bottom foreground pixbuf.
        @param bottom_bg_dpixbuf: Bottom background pixbuf.
        @param point_dpixbuf: Pointer pixbuf.
        '''
        gtk.VScale.__init__(self)

        self.set_draw_value(False)
        self.set_range(0, 100)
        self.__has_point = True
        self.set_inverted(True)
        self.upper_fg_dpixbuf = upper_fg_dpixbuf
        self.upper_bg_dpixbuf = upper_bg_dpixbuf
        self.middle_fg_dpixbuf = middle_fg_dpixbuf
        self.middle_bg_dpixbuf = middle_bg_dpixbuf
        self.bottom_fg_dpixbuf = bottom_fg_dpixbuf
        self.bottom_bg_dpixbuf = bottom_bg_dpixbuf
        self.point_dpixbuf = point_dpixbuf
        self.cache_bg_pixbuf = CachePixbuf()
        self.cache_fg_pixbuf = CachePixbuf()
        
        self.set_size_request(self.point_dpixbuf.get_pixbuf().get_height(), -1)
        
        self.connect("expose-event", self.expose_v_scalebar)
        self.connect("button-press-event", self.press_progressbar)
        
    def expose_v_scalebar(self, widget, event):    
        '''
        Internal callback for `expose-event` signal.
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Init pixbuf.
        upper_fg_pixbuf = self.upper_fg_dpixbuf.get_pixbuf()
        upper_bg_pixbuf = self.upper_bg_dpixbuf.get_pixbuf()
        middle_fg_pixbuf = self.middle_fg_dpixbuf.get_pixbuf()
        middle_bg_pixbuf = self.middle_bg_dpixbuf.get_pixbuf()
        bottom_fg_pixbuf = self.bottom_fg_dpixbuf.get_pixbuf()
        bottom_bg_pixbuf = self.bottom_bg_dpixbuf.get_pixbuf()
        point_pixbuf = self.point_dpixbuf.get_pixbuf()
        
        upper_value = self.get_adjustment().get_upper()
        lower_value = self.get_adjustment().get_lower()
        total_length = max(upper_value - lower_value, 1)
        point_width = point_pixbuf.get_width()
        point_height = point_pixbuf.get_height()
        
        line_width = upper_bg_pixbuf.get_width()
        side_height = upper_bg_pixbuf.get_height()

        x, y, w, h  = rect.x, rect.y + point_height, rect.width, rect.height - point_height - point_height / 2
        line_x = x + (point_width - line_width / 1.5) / 2
        point_y = h - int((self.get_value() - lower_value ) / total_length * h)
        value = int((self.get_value() - lower_value ) / total_length * h)

        self.cache_bg_pixbuf.scale(middle_bg_pixbuf, line_width, h - side_height * 2 + point_height / 2)
        draw_pixbuf(cr, upper_bg_pixbuf, line_x, y - point_height / 2)
        draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), line_x, y + side_height - point_height / 2)
        draw_pixbuf(cr, bottom_bg_pixbuf, line_x, y + h - side_height)
                
        if value > 0:
            self.cache_fg_pixbuf.scale(middle_fg_pixbuf, line_width, value)
            draw_pixbuf(cr, self.cache_fg_pixbuf.get_cache(), line_x, y + point_y - side_height)
        draw_pixbuf(cr, bottom_fg_pixbuf, line_x, y + h - side_height)
        
        if self.get_value() == upper_value:
            draw_pixbuf(cr, upper_fg_pixbuf, line_x, y - point_height / 2)
            
        if self.__has_point:    
            draw_pixbuf(cr, point_pixbuf, x, y + point_y - side_height / 2 - point_height / 2)
            
        return True
        
    def press_progressbar(self, widget, event):
        '''
        Internal callback for `button-press-event` signal.
        '''
        if is_left_button(event):
            rect = widget.allocation
            lower_value = self.get_adjustment().get_lower()
            upper_value = self.get_adjustment().get_upper()
            point_height = self.point_dpixbuf.get_pixbuf().get_height()
            self.set_value(upper_value - ((event.y - point_height / 2) / (rect.height - point_height)) * (upper_value - lower_value) )
            self.queue_draw()
            
        return False    
    
    def set_has_point(self, value):
        '''
        Set has point.
        '''
        self.__has_point = value
        
    def get_has_point(self):    
        '''
        Get has point.
        '''
        return self.__has_point
Пример #8
0
class Notebook(gtk.EventBox):
    '''
    Notebook.

    @undocumented: calculate_tab_width
    @undocumented: expose_notebook
    @undocumented: button_press_notebook
    '''
    def __init__(
        self,
        items,
        foreground_left_pixbuf=ui_theme.get_pixbuf(
            "notebook/foreground_left.png"),
        foreground_middle_pixbuf=ui_theme.get_pixbuf(
            "notebook/foreground_middle.png"),
        foreground_right_pixbuf=ui_theme.get_pixbuf(
            "notebook/foreground_right.png"),
        background_left_pixbuf=ui_theme.get_pixbuf(
            "notebook/background_left.png"),
        background_middle_pixbuf=ui_theme.get_pixbuf(
            "notebook/background_middle.png"),
        background_right_pixbuf=ui_theme.get_pixbuf(
            "notebook/background_right.png"),
    ):
        '''
        Initialize Notebook class.

        @param items: Notebook item, foramt (item_icon, item_content, item_callback).
        @param foreground_left_pixbuf: Left foreground pixbuf.
        @param foreground_middle_pixbuf: Middle foreground pixbuf.
        @param foreground_right_pixbuf: Right foreground pixbuf.
        @param background_left_pixbuf: Left background pixbuf.
        @param background_middle_pixbuf: Middle background pixbuf.
        @param background_right_pixbuf: Right background pixbuf.
        '''
        # Init.
        gtk.EventBox.__init__(self)
        self.set_visible_window(False)
        self.set_can_focus(True)
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)

        self.items = items
        self.current_item_index = 0
        self.padding_side = 27  # pixel
        self.padding_middle = 10  # pixel
        self.foreground_left_pixbuf = foreground_left_pixbuf
        self.foreground_middle_pixbuf = foreground_middle_pixbuf
        self.foreground_right_pixbuf = foreground_right_pixbuf
        self.background_left_pixbuf = background_left_pixbuf
        self.background_middle_pixbuf = background_middle_pixbuf
        self.background_right_pixbuf = background_right_pixbuf
        self.cache_bg_pixbuf = CachePixbuf()
        self.cache_fg_pixbuf = CachePixbuf()

        # Calcuate tab width.
        (self.tab_width, self.tab_height) = self.calculate_tab_width()
        self.set_size_request(-1, self.tab_height)

        # Expose.
        self.connect("expose-event", self.expose_notebook)
        self.connect("button-press-event", self.button_press_notebook)

    def calculate_tab_width(self):
        '''
        Internal function to calculate tab width.
        '''
        self.icon_width = 0
        max_tab_content_width = 0
        for (item_icon, item_content, item_callback) in self.items:
            if self.icon_width == 0 and item_icon != None:
                self.icon_width = item_icon.get_pixbuf().get_width()

            (content_width,
             content_height) = get_content_size(item_content,
                                                DEFAULT_FONT_SIZE)
            if content_width > max_tab_content_width:
                max_tab_content_width = content_width

        tab_image_height = self.foreground_left_pixbuf.get_pixbuf().get_height(
        )

        if self.icon_width == 0:
            tab_width = self.padding_side * 2 + max_tab_content_width
        else:
            tab_width = self.padding_side * 2 + self.padding_middle + self.icon_width + max_tab_content_width

        return (tab_width, tab_image_height)

    def expose_notebook(self, widget, event):
        '''
        Internal callback for `expose-event` signal.

        @param widget: Notebook wiget.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        foreground_left_pixbuf = self.foreground_left_pixbuf.get_pixbuf()
        self.cache_fg_pixbuf.scale(
            self.foreground_middle_pixbuf.get_pixbuf(),
            self.tab_width - foreground_left_pixbuf.get_width() * 2,
            self.tab_height)
        foreground_middle_pixbuf = self.cache_fg_pixbuf.get_cache()
        foreground_right_pixbuf = self.foreground_right_pixbuf.get_pixbuf()
        background_left_pixbuf = self.background_left_pixbuf.get_pixbuf()
        self.cache_bg_pixbuf.scale(
            self.background_middle_pixbuf.get_pixbuf(),
            self.tab_width - background_left_pixbuf.get_width() * 2,
            self.tab_height)
        background_middle_pixbuf = self.cache_bg_pixbuf.get_cache()
        background_right_pixbuf = self.background_right_pixbuf.get_pixbuf()

        # Draw tab.
        for (index, (item_icon, item_content,
                     item_callback)) in enumerate(self.items):
            # Draw background.
            if self.current_item_index == index:
                draw_pixbuf(cr, foreground_left_pixbuf,
                            rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr, foreground_middle_pixbuf,
                    rect.x + index * self.tab_width +
                    foreground_left_pixbuf.get_width(), rect.y)
                draw_pixbuf(
                    cr, foreground_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width -
                    foreground_left_pixbuf.get_width(), rect.y)
            else:
                draw_pixbuf(cr, background_left_pixbuf,
                            rect.x + index * self.tab_width, rect.y)
                draw_pixbuf(
                    cr, background_middle_pixbuf,
                    rect.x + index * self.tab_width +
                    background_left_pixbuf.get_width(), rect.y)
                draw_pixbuf(
                    cr, background_right_pixbuf,
                    rect.x + (index + 1) * self.tab_width -
                    background_left_pixbuf.get_width(), rect.y)

            # Draw content.
            (content_width,
             content_height) = get_content_size(item_content,
                                                DEFAULT_FONT_SIZE)
            if item_icon != None:
                tab_render_width = self.icon_width + self.padding_middle + content_width
                draw_pixbuf(
                    cr, item_icon.get_pixbuf(),
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2, rect.y +
                    (self.tab_height - item_icon.get_pixbuf().get_height()) /
                    2)

                draw_text(
                    cr,
                    item_content,
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2 + self.icon_width +
                    self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )
            else:
                tab_render_width = content_width
                draw_text(
                    cr,
                    item_content,
                    rect.x + index * self.tab_width +
                    (self.tab_width - tab_render_width) / 2 + self.icon_width +
                    self.padding_middle,
                    rect.y + (self.tab_height - content_height) / 2,
                    content_width,
                    content_height,
                    DEFAULT_FONT_SIZE,
                    ui_theme.get_color("notebook_font").get_color(),
                )

        propagate_expose(widget, event)

        return True

    def button_press_notebook(self, widget, event):
        '''
        Internal callback for `button-press-event` signal.

        @param widget: Notebook widget.
        @param event: Button press event.
        '''
        # Get tab index.
        tab_index = int(event.x / self.tab_width)
        if tab_index < len(self.items):
            self.current_item_index = tab_index

            # Redraw.
            self.queue_draw()

            # Callback.
            if self.items[tab_index][2] != None:
                self.items[tab_index][2]()
Пример #9
0
class VolumeButton(gtk.Button):
    '''
    Volume button.
    '''

    __gsignals__ = {
        "volume-state-changed": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (
            gobject.TYPE_INT,
            gobject.TYPE_INT,
        ))
    }

    def __init__(
        self,
        volume_max_value=100,
        volume_width=52,
        volume_x=0,
        volume_y=15,
        line_height=3,
        volume_padding_x=5,
        volume_level_values=[(1, 33), (34, 66), (67, 100)],
        scroll_bool=False,
        press_emit_bool=False,
        inc_value=5,
        bg_pixbuf=ui_theme.get_pixbuf("volumebutton/bg.png"),
        fg_pixbuf=ui_theme.get_pixbuf("volumebutton/fg.png"),
        zero_volume_normal_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/zero_normal.png"),
        zero_volume_hover_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/zero_hover.png"),
        zero_volume_press_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/zero_press.png"),
        min_volume_normal_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/lower_normal.png"),
        min_volume_hover_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/lower_hover.png"),
        min_volume_press_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/lower_press.png"),
        mid_volume_normal_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/middle_normal.png"),
        mid_volume_hover_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/middle_hover.png"),
        mid_volume_press_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/middle_press.png"),
        max_volume_normal_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/high_normal.png"),
        max_volume_hover_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/high_hover.png"),
        max_volume_press_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/high_press.png"),
        mute_volume_normal_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/mute_normal.png"),
        mute_volume_hover_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/mute_hover.png"),
        mute_volume_press_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/mute_press.png"),
        point_volume_pixbuf=ui_theme.get_pixbuf(
            "volumebutton/point_normal.png"),
    ):
        '''
        Initialize VolumeButton class.

        @param volume_max_value: Maximum value of volume, default is 100.
        @param volume_width: Width of volume button widget, default is 52 pixel.
        @param volume_x: X padding of volume button widget.
        @param volume_y: Y padding of volume button widget.
        @param line_height: Height of volume progressbar, default is 3 pixel.
        @param volume_padding_x: X padding value around volume progressbar.
        @param volume_level_values: The values of volume level.
        @param scroll_bool: True allowed scroll to change value, default is False.
        @param press_emit_bool: True to emit `volume-state-changed` signal when press, default is False.
        @param inc_value: The increase value of volume change, default is 5.
        '''
        gtk.Button.__init__(self)
        ###########################
        if volume_x < max_volume_normal_pixbuf.get_pixbuf().get_width():
            volume_x = max_volume_normal_pixbuf.get_pixbuf().get_width()
        '''Init pixbuf.'''
        self.__bg_pixbuf = bg_pixbuf
        self.__fg_pixbuf = fg_pixbuf
        self.__bg_cache_pixbuf = CachePixbuf()
        self.__fg_cache_pixbuf = CachePixbuf()
        # zero volume pixbuf.
        self.__zero_volume_normal_pixbuf = zero_volume_normal_pixbuf
        self.__zero_volume_hover_pixbuf = zero_volume_hover_pixbuf
        self.__zero_volume_press_pixbuf = zero_volume_press_pixbuf
        # min volume pixbuf.
        self.__min_volume_normal_pixbuf = min_volume_normal_pixbuf
        self.__min_volume_hover_pixbuf = min_volume_hover_pixbuf
        self.__min_volume_press_pixbuf = min_volume_press_pixbuf
        # mid volume pixbuf:
        self.__mid_volume_normal_pixbuf = mid_volume_normal_pixbuf
        self.__mid_volume_hover_pixbuf = mid_volume_hover_pixbuf
        self.__mid_volume_press_pixbuf = mid_volume_press_pixbuf
        # max volume pixbuf[normal, hover, press].
        self.__max_volume_normal_pixbuf = max_volume_normal_pixbuf
        self.__max_volume_hover_pixbuf = max_volume_hover_pixbuf
        self.__max_volume_press_pixbuf = max_volume_press_pixbuf
        # mute volume pixbuf[normal, hover, press].
        self.__mute_volume_normal_pixbuf = mute_volume_normal_pixbuf
        self.__mute_volume_hover_pixbuf = mute_volume_hover_pixbuf
        self.__mute_volume_press_pixbuf = mute_volume_press_pixbuf
        # point volume pixbuf.
        self.__point_volume_pixbuf = point_volume_pixbuf
        '''Init Set VolumeButton attr.'''
        '''Init value.'''
        self.__press_emit_bool = press_emit_bool
        self.__line_height = line_height
        self.__current_value = 0
        self.__mute_bool = False
        self.temp_mute_bool = False
        self.__drag = False
        self.__volume_max_value = volume_max_value
        self.__volume_width = volume_width

        self.__volume_left_x = volume_x - self.__max_volume_normal_pixbuf.get_pixbuf(
        ).get_width() - volume_padding_x
        self.__volume_left_y = volume_y - self.__max_volume_normal_pixbuf.get_pixbuf(
        ).get_height() / 2 + self.__point_volume_pixbuf.get_pixbuf(
        ).get_height() / 2
        self.__volume_right_x = volume_x
        self.__volume_right_y = volume_y
        '''Left'''
        self.volume_level_values = volume_level_values
        self.__volume_state = MIN_STATE
        self.__mouse_state = MOUSE_VOLUME_STATE_NORMAL
        '''Right'''
        # bg value.
        self.__bg_x = 0
        self.__bg_y = self.__volume_right_y
        self.__bg_padding_x = self.__volume_right_x
        # fg value.
        self.__fg_x = 0
        self.__fg_y = self.__volume_right_y
        self.__fg_padding_x = self.__volume_right_x
        # point value.
        self.__point_y = self.__volume_right_y
        self.__point_padding_x = self.__volume_right_x
        self.inc_value = inc_value
        '''Init VolumeButton event.'''
        self.add_events(gtk.gdk.ALL_EVENTS_MASK)
        self.connect("expose-event", self.__expose_draw_volume)
        self.connect("motion-notify-event", self.__motion_mouse_set_point)
        self.connect("button-press-event", self.__press_mouse_set_point)
        self.connect("button-release-event", self.__release_mouse_set_point)
        '''Event value'''
        self.press_bool = False
        # scroll event.
        if scroll_bool:
            self.connect("scroll-event", self.__scroll_mouse_set_point)

        self.set_size_request(
            volume_width + self.__volume_left_x + self.__volume_right_x +
            self.__mute_volume_normal_pixbuf.get_pixbuf().get_width(), 30)

        set_clickable_cursor(self)

    def set_press_emit_bool(self, emit_bool):
        self.__press_emit_bool = emit_bool

    def __set_point_padding_x(self, event):
        self.__mute_bool = False
        self.__point_padding_x = int(event.x)
        self.queue_draw()

    def __press_mouse_set_point(self, widget, event):
        temp_x = int(event.x)

        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        temp_max_x = self.__bg_x + self.__bg_padding_x + self.__volume_width + self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        self.queue_draw()
        if temp_min_x < temp_x < temp_max_x:
            self.__set_point_padding_x(event)
            self.__drag = True
        else:
            if self.__volume_left_x <= temp_x <= temp_min_x:
                # Set mouse state press.
                self.__mouse_state = MOUSE_VOLUME_STATE_PRESS
                self.temp_mute_bool = True
                self.press_bool = True

    def __release_mouse_set_point(self, widget, event):
        # Set mouse state normal.
        self.__mouse_state = MOUSE_VOLUME_STATE_NORMAL
        self.__drag = False
        self.press_bool = False

        temp_x = int(event.x)
        temp_y = int(event.y)

        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        if self.__volume_left_x <= temp_x <= temp_min_x and (
                self.__volume_left_y <= temp_y <
            (self.__volume_left_y +
             self.__mute_volume_hover_pixbuf.get_pixbuf().get_height())):
            if self.temp_mute_bool and not self.__mute_bool:
                # Set mute state.
                self.__mute_bool = not self.__mute_bool
                self.__volume_state = MUTE_STATE
                self.temp_mute_bool = False
            else:  # modify state.
                self.__mute_bool = False
                self.temp_mute_bool = False
                self.__set_volume_value_to_state(self.__current_value)
                self.queue_draw()

        if self.__press_emit_bool:
            self.emit("volume-state-changed", self.__current_value,
                      self.__volume_state)

        self.queue_draw()

    def __motion_mouse_set_point(self, widget, event):
        temp_x = int(event.x)
        temp_y = int(event.y)
        temp_min_x = self.__bg_x + self.__bg_padding_x - self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2

        if (self.__volume_left_x <= temp_x <= temp_min_x) and (
                self.__volume_left_y <= temp_y <
            (self.__volume_left_y +
             self.__mute_volume_hover_pixbuf.get_pixbuf().get_height())):
            self.__mouse_state = MOUSE_VOLUME_STATE_HOVER
        else:
            self.__mouse_state = MOUSE_VOLUME_STATE_NORMAL
        if not self.press_bool:
            self.queue_draw()

        if self.__drag:
            self.__set_point_padding_x(event)

    def __scroll_mouse_set_point(self, widget, event):
        if event.direction == gtk.gdk.SCROLL_UP:
            self.volume_other_set_value(VOLUME_RIGHT)
        elif event.direction == gtk.gdk.SCROLL_DOWN:
            self.volume_other_set_value(VOLUME_LEFT)

    def volume_other_set_value(self, volume_type):
        point_width_average = self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        temp_min = (self.__point_padding_x - point_width_average)
        temp_max = (self.__point_padding_x + self.__volume_width -
                    point_width_average)

        self.__mute_bool = False

        if volume_type == VOLUME_RIGHT:
            if self.__point_padding_x >= temp_max:
                self.__point_padding_x = temp_max
            else:
                self.__point_padding_x += self.inc_value
        elif volume_type == VOLUME_LEFT:
            if self.__point_padding_x <= temp_min:
                self.__point_padding_x = temp_min
            else:
                self.__point_padding_x -= self.inc_value

        self.queue_draw()

    def __expose_draw_volume(self, widget, event):
        self.__draw_volume_right(widget, event)  # 1: get current value.
        self.__set_volume_value_to_state(
            self.__current_value)  # 2: value to state.
        self.__draw_volume_left(widget, event)  # 3: draw state pixbuf.

        if not self.__press_emit_bool:
            self.emit("volume-state-changed", self.__current_value,
                      self.__volume_state)
        # propagate_expose(widget, event)
        return True

    '''Left function'''

    @property
    def volume_state(self):
        return self.__volume_state

    @volume_state.setter
    def volume_state(self, state):
        if state == MIN_STATE:
            self.__volume_state = MIN_STATE
        elif state == ZERO_STATE:
            self.__volume_state = ZERO_STATE
        elif state == MID_STATE:
            self.__volume_state = MID_STATE
        elif state == MAX_STATE:
            self.__volume_state = MAX_STATE
        elif state == MUTE_STATE:
            self.__volume_state = MUTE_STATE

    @volume_state.getter
    def volume_state(self):
        return self.__volume_state

    @volume_state.deleter
    def volume_state(self):
        del self.__volume_state

    def set_volume_level_values(self, show_value):
        try:
            show_value[0][0] - show_value[0][1]
            show_value[1][0] - show_value[1][1]
            show_value[2][0] - show_value[2][1]

            self.volume_level_values = show_value
        except:
            print "Error show value!!"

    def __set_volume_value_to_state(self, value):
        if not self.__mute_bool:
            temp_show_value = self.volume_level_values
            if temp_show_value[0][0] <= value <= temp_show_value[0][1]:
                self.__volume_state = MIN_STATE
            elif temp_show_value[1][0] <= value <= temp_show_value[1][1]:
                self.__volume_state = MID_STATE
            elif temp_show_value[2][0] <= value <= temp_show_value[2][1]:
                self.__volume_state = MAX_STATE
            elif 0 == value:
                self.__volume_state = ZERO_STATE
        else:
            self.__volume_state = MUTE_STATE

    def set_volume_mute(self, mute_flag=True):
        if mute_flag:
            self.temp_mute_bool = False
            self.__mute_bool = True
            self.__volume_state = MUTE_STATE
        else:
            self.temp_mute_bool = False
            self.__mute_bool = False
            self.__set_volume_value_to_state(self.value)

        self.queue_draw()

    def __draw_volume_left(self, widget, event):
        cr = widget.window.cairo_create()
        x, y, w, h = widget.allocation

        if self.__volume_state == MUTE_STATE:  # mute state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__mute_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__mute_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mute_volume_press_pixbuf
        elif self.__volume_state == ZERO_STATE:  # zero state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__zero_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__zero_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__zero_volume_press_pixbuf
        elif self.__volume_state == MIN_STATE:  # min state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__min_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__min_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__min_volume_press_pixbuf
        elif self.__volume_state == MID_STATE:  # mid state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__mid_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__mid_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__mid_volume_press_pixbuf
        elif self.__volume_state == MAX_STATE:  # max state.
            if self.__mouse_state == MOUSE_VOLUME_STATE_NORMAL:
                pixbuf = self.__max_volume_normal_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_HOVER:
                pixbuf = self.__max_volume_hover_pixbuf
            elif self.__mouse_state == MOUSE_VOLUME_STATE_PRESS:
                pixbuf = self.__max_volume_press_pixbuf

        draw_pixbuf(
            cr,
            pixbuf.get_pixbuf(),
            x + self.__volume_left_x,
            y + self.__volume_left_y,
        )

    '''Right function'''

    @property
    def line_height(self):
        return self.__line_height

    @line_height.setter
    def line_height(self, width):
        self.__line_height = width
        self.queue_draw()

    @line_height.getter
    def line_height(self):
        return self.__line_height

    @line_height.deleter
    def line_height(self):
        del self.__line_height

    @property
    def value(self):
        return self.__current_value

    @value.setter
    def value(self, value):
        if 0 <= value <= self.__volume_max_value:
            Tooltip.text(self, str(value))
            temp_padding = (float(self.__volume_max_value) /
                            self.__volume_width)
            temp_padding_x = float(value) / temp_padding
            self.__point_padding_x = temp_padding_x + ((self.__fg_padding_x))
            self.queue_draw()

    @value.getter
    def value(self):
        return self.__current_value

    def set_volume_position(self, x, y):
        self.__volume_right_x = x
        self.__volume_right_y = y
        # Set x.
        self.__bg_padding_x = self.__volume_right_x
        self.__fg_padding_x = self.__volume_right_x
        self.__point_padding_x = self.__volume_right_x
        # Set y.
        self.__bg_y = self.__volume_right_y
        self.__fg_y = self.__volume_right_y
        self.__point_y = self.__volume_right_y

    @property
    def max_value(self):
        self.__volume_max_value

    @max_value.setter
    def max_value(self, max_value):
        self.__volume_max_value = max_value

    @max_value.getter
    def max_value(self):
        return self.__volume_max_value

    @max_value.deleter
    def max_value(self):
        del self.__volume_max_value

    def __draw_volume_right(self, widget, event):
        cr = widget.window.cairo_create()
        cr.set_line_width(self.__line_height)
        x, y, w, h = widget.allocation

        fg_height_average = (
            self.__point_volume_pixbuf.get_pixbuf().get_height() -
            self.__fg_pixbuf.get_pixbuf().get_height()) / 2
        bg_height_average = (
            self.__point_volume_pixbuf.get_pixbuf().get_height() -
            self.__bg_pixbuf.get_pixbuf().get_height()) / 2
        point_width_average = self.__point_volume_pixbuf.get_pixbuf(
        ).get_width() / 2
        ##################################################
        # Draw bg.
        if self.__volume_width > 0:
            self.__bg_cache_pixbuf.scale(
                self.__bg_pixbuf.get_pixbuf(),
                self.__volume_width,
                self.__bg_pixbuf.get_pixbuf().get_height(),
            )
            draw_pixbuf(cr, self.__bg_cache_pixbuf.get_cache(),
                        x + self.__bg_x + self.__bg_padding_x,
                        y + self.__bg_y + bg_height_average)

        temp_fg_padding_x = self.__point_padding_x - (self.__fg_x +
                                                      self.__fg_padding_x)

        if temp_fg_padding_x < 0:
            temp_fg_padding_x = 0
        if temp_fg_padding_x > self.__volume_width:
            temp_fg_padding_x = self.__volume_width
        # Get current value.
        self.__current_value = temp_fg_padding_x * (
            float(self.__volume_max_value) / self.__volume_width)

        # Draw fg.
        if temp_fg_padding_x > 0:
            self.__fg_cache_pixbuf.scale(
                self.__fg_pixbuf.get_pixbuf(),
                int(temp_fg_padding_x),
                self.__fg_pixbuf.get_pixbuf().get_height(),
            )
            draw_pixbuf(cr, self.__fg_cache_pixbuf.get_cache(),
                        x + self.__fg_x + self.__fg_padding_x,
                        y + self.__fg_y + fg_height_average)
        #################################################
        # Draw point.
        temp_point_padding_x = (self.__point_padding_x - point_width_average)

        temp_min = (self.__volume_right_x - point_width_average)
        temp_max = (self.__volume_right_x + self.__volume_width -
                    point_width_average)
        if temp_point_padding_x < temp_min:
            temp_point_padding_x = temp_min
        if temp_point_padding_x > temp_max:
            temp_point_padding_x = temp_max

        draw_pixbuf(cr, self.__point_volume_pixbuf.get_pixbuf(),
                    x + temp_point_padding_x, y + self.__point_y)
Пример #10
0
class VScalebar(gtk.VScale):
    '''
    VScalebar.

    @undocumented: expose_v_scalebar
    @undocumented: press_progressbar
    '''

    def __init__(self,
                 upper_fg_dpixbuf,
                 upper_bg_dpixbuf,
                 middle_fg_dpixbuf,
                 middle_bg_dpixbuf,
                 bottom_fg_dpixbuf,
                 bottom_bg_dpixbuf,
                 point_dpixbuf,
                 ):
        '''
        Initialize VScalebar class.

        @param upper_fg_dpixbuf: Upper foreground pixbuf.
        @param upper_bg_dpixbuf: Upper background pixbuf.
        @param middle_fg_dpixbuf: Middle foreground pixbuf.
        @param middle_bg_dpixbuf: Middle background pixbuf.
        @param bottom_fg_dpixbuf: Bottom foreground pixbuf.
        @param bottom_bg_dpixbuf: Bottom background pixbuf.
        @param point_dpixbuf: Pointer pixbuf.
        '''
        gtk.VScale.__init__(self)

        self.set_draw_value(False)
        self.set_range(0, 100)
        self.__has_point = True
        self.set_inverted(True)
        self.upper_fg_dpixbuf = upper_fg_dpixbuf
        self.upper_bg_dpixbuf = upper_bg_dpixbuf
        self.middle_fg_dpixbuf = middle_fg_dpixbuf
        self.middle_bg_dpixbuf = middle_bg_dpixbuf
        self.bottom_fg_dpixbuf = bottom_fg_dpixbuf
        self.bottom_bg_dpixbuf = bottom_bg_dpixbuf
        self.point_dpixbuf = point_dpixbuf
        self.cache_bg_pixbuf = CachePixbuf()
        self.cache_fg_pixbuf = CachePixbuf()

        self.set_size_request(self.point_dpixbuf.get_pixbuf().get_height(), -1)

        self.connect("expose-event", self.expose_v_scalebar)
        self.connect("button-press-event", self.press_progressbar)

    def expose_v_scalebar(self, widget, event):
        '''
        Internal callback for `expose-event` signal.
        '''
        cr = widget.window.cairo_create()
        rect = widget.allocation

        # Init pixbuf.
        upper_fg_pixbuf = self.upper_fg_dpixbuf.get_pixbuf()
        upper_bg_pixbuf = self.upper_bg_dpixbuf.get_pixbuf()
        middle_fg_pixbuf = self.middle_fg_dpixbuf.get_pixbuf()
        middle_bg_pixbuf = self.middle_bg_dpixbuf.get_pixbuf()
        bottom_fg_pixbuf = self.bottom_fg_dpixbuf.get_pixbuf()
        bottom_bg_pixbuf = self.bottom_bg_dpixbuf.get_pixbuf()
        point_pixbuf = self.point_dpixbuf.get_pixbuf()

        upper_value = self.get_adjustment().get_upper()
        lower_value = self.get_adjustment().get_lower()
        total_length = max(upper_value - lower_value, 1)
        point_width = point_pixbuf.get_width()
        point_height = point_pixbuf.get_height()

        line_width = upper_bg_pixbuf.get_width()
        side_height = upper_bg_pixbuf.get_height()

        x, y, w, h  = rect.x, rect.y + point_height, rect.width, rect.height - point_height - point_height / 2
        line_x = x + (point_width - line_width / 1.5) / 2
        point_y = h - int((self.get_value() - lower_value ) / total_length * h)
        value = int((self.get_value() - lower_value ) / total_length * h)

        self.cache_bg_pixbuf.scale(middle_bg_pixbuf, line_width, h - side_height * 2 + point_height / 2)
        draw_pixbuf(cr, upper_bg_pixbuf, line_x, y - point_height / 2)
        draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), line_x, y + side_height - point_height / 2)
        draw_pixbuf(cr, bottom_bg_pixbuf, line_x, y + h - side_height)

        if value > 0:
            self.cache_fg_pixbuf.scale(middle_fg_pixbuf, line_width, value)
            draw_pixbuf(cr, self.cache_fg_pixbuf.get_cache(), line_x, y + point_y - side_height)
        draw_pixbuf(cr, bottom_fg_pixbuf, line_x, y + h - side_height)

        if self.get_value() == upper_value:
            draw_pixbuf(cr, upper_fg_pixbuf, line_x, y - point_height / 2)

        if self.__has_point:
            draw_pixbuf(cr, point_pixbuf, x, y + point_y - side_height / 2 - point_height / 2)

        return True

    def press_progressbar(self, widget, event):
        '''
        Internal callback for `button-press-event` signal.
        '''
        if is_left_button(event):
            rect = widget.allocation
            lower_value = self.get_adjustment().get_lower()
            upper_value = self.get_adjustment().get_upper()
            point_height = self.point_dpixbuf.get_pixbuf().get_height()
            self.set_value(upper_value - ((event.y - point_height / 2) / (rect.height - point_height)) * (upper_value - lower_value) )
            self.queue_draw()

        return False

    def set_has_point(self, value):
        '''
        Set has point.

        @param value: Set True to make scalebar have point.
        '''
        self.__has_point = value

    def get_has_point(self):
        '''
        Get has point.

        @return: Return True if scalebar have point.
        '''
        return self.__has_point