示例#1
0
    def expose_window_frame(self, widget, event):
        '''
        Internal function to expose the window frame.

        @param widget: the window of gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        '''
        if self.expose_frame_function:
            self.expose_frame_function(widget, event)
        elif (self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED !=
              gtk.gdk.WINDOW_STATE_MAXIMIZED
              and self.window.get_state() & gtk.gdk.WINDOW_STATE_FULLSCREEN !=
              gtk.gdk.WINDOW_STATE_FULLSCREEN):
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            x, y, w, h = rect.x, rect.y, rect.width, rect.height

            draw_window_frame(
                cr,
                x,
                y,
                w,
                h,
                ui_theme.get_alpha_color("window_frame_outside_1"),
                ui_theme.get_alpha_color("window_frame_outside_2"),
                ui_theme.get_alpha_color("window_frame_outside_3"),
                ui_theme.get_alpha_color("window_frame_inside_1"),
                ui_theme.get_alpha_color("window_frame_inside_2"),
            )
示例#2
0
 def __init__(self, 
              value=0, 
              lower=0, 
              upper=100, 
              step=10, 
              default_width=55):
     '''
     Initialize SpinBox class.
     
     @param value: Initialize value, default is 0.
     @param lower: Lower value, default is 0.
     @param upper: Upper value, default is 100.
     @param step: Step value, default is 10.
     @param default_width: Default with, default is 55 pixel.
     '''
     gtk.VBox.__init__(self)
     self.current_value = value
     self.lower_value = lower
     self.upper_value = upper
     self.step_value  = step
     self.update_delay = 100 # milliseconds
     self.increase_value_id = None
     self.decrease_value_id = None
     
     # Init.
     self.default_width = default_width
     self.default_height = 22
     self.arrow_button_width = 19
     self.background_color = ui_theme.get_alpha_color("text_entry_background")
     self.acme_color = ui_theme.get_alpha_color("text_entry_acme")
     self.point_color = ui_theme.get_alpha_color("text_entry_point")
     self.frame_point_color = ui_theme.get_alpha_color("text_entry_frame_point")
     self.frame_color = ui_theme.get_alpha_color("text_entry_frame")
     
     # Widget.
     arrow_up_button = self.create_simple_button("up", self.press_increase_button)
     arrow_down_button = self.create_simple_button("down", self.press_decrease_button)
     button_box = gtk.VBox()
     button_box.pack_start(arrow_up_button, False, False)
     button_box.pack_start(arrow_down_button, False, False)
     self.value_entry = Entry(str(value))
     self.value_entry.check_text = is_float
     self.value_entry.connect("changed", lambda entry, value_string: self.update_and_emit(int(value_string)))
     
     self.main_align = gtk.Alignment()
     self.main_align.set(0.5, 0.5, 0, 0)
     hbox = gtk.HBox()
     hbox.pack_start(self.value_entry, False, False)        
     hbox.pack_start(button_box, False, False)
     hbox_align = gtk.Alignment()
     hbox_align.set(0.5, 0.5, 1.0, 1.0)
     hbox_align.set_padding(0, 1, 0, 0)
     hbox_align.add(hbox)
     self.main_align.add(hbox_align)
     self.pack_start(self.main_align, False, False)
     
     # Signals.
     self.connect("size-allocate", self.size_change_cb)
     self.main_align.connect("expose-event", self.expose_spin_bg)
示例#3
0
    def expose_window(self, widget, event):
        '''
        Internal function to expose the window.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.

        @return: Always return True.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw background.
        self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)

        # Draw skin and mask.
        with cairo_state(cr):
            if self.window.get_state(
            ) & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                cr.rectangle(x + 2, y, w - 4, 1)
                cr.rectangle(x + 1, y + 1, w - 2, 1)
                cr.rectangle(x, y + 2, w, h - 4)
                cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                cr.rectangle(x + 1, y + h - 2, w - 2, 1)

                cr.clip()

            self.draw_skin(cr, x, y, w, h)

            # Draw mask.
            self.draw_mask(cr, x, y, w, h)

        # Draw window frame.
        if self.window.get_state(
        ) & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
            draw_window_frame(
                cr,
                x,
                y,
                w,
                h,
                ui_theme.get_alpha_color("window_frame_outside_1"),
                ui_theme.get_alpha_color("window_frame_outside_2"),
                ui_theme.get_alpha_color("window_frame_outside_3"),
                ui_theme.get_alpha_color("window_frame_inside_1"),
                ui_theme.get_alpha_color("window_frame_inside_2"),
            )

        # Propagate expose.
        propagate_expose(widget, event)

        return True
示例#4
0
文件: entry.py 项目: netphi/deepin-ui
    def __init__(self, content="",
                 action_button=None,
                 background_color = ui_theme.get_alpha_color("text_entry_background"),
                 acme_color = ui_theme.get_alpha_color("text_entry_acme"),
                 point_color = ui_theme.get_alpha_color("text_entry_point"),
                 frame_point_color = ui_theme.get_alpha_color("text_entry_frame_point"),
                 frame_color = ui_theme.get_alpha_color("text_entry_frame"),
                 ):
        '''Init input entry.'''
        # Init.
        gtk.VBox.__init__(self)
        self.align = gtk.Alignment()
        self.align.set(0.5, 0.5, 1.0, 1.0)
        self.action_button = action_button
        self.h_box = gtk.HBox()
        self.entry = Entry(content)
        self.background_color = background_color
        self.acme_color = acme_color
        self.point_color = point_color
        self.frame_point_color = frame_point_color
        self.frame_color = frame_color
        
        self.pack_start(self.align, False, False)
        self.align.add(self.h_box)
        self.h_box.pack_start(self.entry)
        if action_button:
            self.action_align = gtk.Alignment()
            self.action_align.set(0.0, 0.5, 0, 0)
            self.action_align.set_padding(0, 0, 0, self.entry.padding_x)
            self.action_align.add(self.action_button)
            
            self.h_box.pack_start(self.action_align)
            
            self.action_button.connect("clicked", lambda w: self.emit_action_active_signal())

        # Handle signal.
        self.align.connect("expose-event", self.expose_text_entry)
        
        # Setup flags.
        self.entry.cursor_visible_flag = False
        self.entry.right_menu_visible_flag = False
        self.entry.select_area_visible_flag = False
        self.entry.editable_flag = False
    
        # Overwrite entry's function.
        self.entry.handle_button_press = self.handle_button_press
        self.entry.handle_focus_out = self.handle_focus_out
        self.entry.handle_key_press = self.handle_key_press
        
        self.shortcut_key = content
        self.shortcut_key_record = None
示例#5
0
 def expose_window_frame(self, widget, event):
     '''Expose window frame.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     draw_window_frame(cr, x, y, w, h,
                       ui_theme.get_alpha_color("window_frame_outside_1"),
                       ui_theme.get_alpha_color("window_frame_outside_2"),
                       ui_theme.get_alpha_color("window_frame_outside_3"),
                       ui_theme.get_alpha_color("window_frame_inside_1"),
                       ui_theme.get_alpha_color("window_frame_inside_2"),
                       )
示例#6
0
    def expose_window(self, widget, event):
        """
        Internal function to expose the window.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.

        @return: Always return True.
        """
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        
        # Clear color to transparent window.
        cr.set_source_rgba(*self.background_color)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()
        
        # Draw background.
        with cairo_state(cr):
            if self.window.get_state() != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                cr.rectangle(x + 2, y, w - 4, 1)
                cr.rectangle(x + 1, y + 1, w - 2, 1)
                cr.rectangle(x, y + 2, w, h - 4)
                cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                cr.rectangle(x + 1, y + h - 2, w - 2, 1)
                
                cr.clip()
            
            skin_config.render_background(cr, self, x, y)
        
            # Draw mask.
            self.draw_mask(cr, x, y, w, h)
            
        # Draw window frame.
        if self.window.get_state() != gtk.gdk.WINDOW_STATE_MAXIMIZED:
            draw_window_frame(cr, x, y, w, h,
                              ui_theme.get_alpha_color("window_frame_outside_1"),
                              ui_theme.get_alpha_color("window_frame_outside_2"),
                              ui_theme.get_alpha_color("window_frame_outside_3"),
                              ui_theme.get_alpha_color("window_frame_inside_1"),
                              ui_theme.get_alpha_color("window_frame_inside_2"),
                              )
        
        # Propagate expose.
        propagate_expose(widget, event)
        
        return True
示例#7
0
    def expose_window(self, widget, event):
        '''
        Internal function to expose the window.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.

        @return: Always return True.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw background.
        self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)

        # Draw skin and mask.
        with cairo_state(cr):
            if self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                cr.rectangle(x + 2, y, w - 4, 1)
                cr.rectangle(x + 1, y + 1, w - 2, 1)
                cr.rectangle(x, y + 2, w, h - 4)
                cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                cr.rectangle(x + 1, y + h - 2, w - 2, 1)

                cr.clip()

            self.draw_skin(cr, x, y, w, h)

            # Draw mask.
            self.draw_mask(cr, x, y, w, h)

        # Draw window frame.
        if self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
            draw_window_frame(cr, x, y, w, h,
                              ui_theme.get_alpha_color("window_frame_outside_1"),
                              ui_theme.get_alpha_color("window_frame_outside_2"),
                              ui_theme.get_alpha_color("window_frame_outside_3"),
                              ui_theme.get_alpha_color("window_frame_inside_1"),
                              ui_theme.get_alpha_color("window_frame_inside_2"),
                              )

        # Propagate expose.
        propagate_expose(widget, event)

        return True
示例#8
0
文件: menu.py 项目: netphi/deepin-ui
 def draw_menu_mask(self, cr, x, y, w, h):
     '''Draw mask.'''
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
     
     # Draw left side.
     draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2,
                  ui_theme.get_shadow_color("menu_side").get_color_info())
示例#9
0
 def expose_window_frame(self, widget, event):
     """
     Internal function to expose the window frame.
     
     @param widget: the window of gtk.Widget.
     @param event: The expose event of type gtk.gdk.Event.
     """
     if self.window.get_state() != gtk.gdk.WINDOW_STATE_MAXIMIZED:
         # Init.
         cr = widget.window.cairo_create()
         rect = widget.allocation
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         
         draw_window_frame(cr, x, y, w, h,
                           ui_theme.get_alpha_color("window_frame_outside_1"),
                           ui_theme.get_alpha_color("window_frame_outside_2"),
                           ui_theme.get_alpha_color("window_frame_outside_3"),
                           ui_theme.get_alpha_color("window_frame_inside_1"),
                           ui_theme.get_alpha_color("window_frame_inside_2"),
                           )
示例#10
0
 def expose_item_align(self, widget, event):
     '''Expose item align.'''
     # Init.
     cr = widget.window.cairo_create()        
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("droplist_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
示例#11
0
 def expose_window(self, widget, event):
     '''Expose window.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Clear color to transparent window.
     cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
     cr.set_operator(cairo.OPERATOR_SOURCE)
     cr.paint()
     
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 2, y, w - 4, 1)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.rectangle(x, y + 2, w, h - 4)
         cr.rectangle(x + 2, y + h - 1, w - 4, 1)
         cr.rectangle(x + 1, y + h - 2, w - 2, 1)
         
         cr.clip()
         
         skin_config.render_background(cr, self, x, y)
     
         # Draw mask.
         self.draw_mask(cr, x, y, w, h)
         
     # Draw window frame.
     draw_window_frame(cr, x, y, w, h,
                       ui_theme.get_alpha_color("window_frame_outside_1"),
                       ui_theme.get_alpha_color("window_frame_outside_2"),
                       ui_theme.get_alpha_color("window_frame_outside_3"),
                       ui_theme.get_alpha_color("window_frame_inside_1"),
                       ui_theme.get_alpha_color("window_frame_inside_2"),
                       )
     
     # Propagate expose.
     propagate_expose(widget, event)
     
     return True
示例#12
0
文件: entry.py 项目: netphi/deepin-ui
    def __init__(self, content="",
                 action_button=None,
                 background_color = ui_theme.get_alpha_color("text_entry_background"),
                 acme_color = ui_theme.get_alpha_color("text_entry_acme"),
                 point_color = ui_theme.get_alpha_color("text_entry_point"),
                 frame_point_color = ui_theme.get_alpha_color("text_entry_frame_point"),
                 frame_color = ui_theme.get_alpha_color("text_entry_frame"),
                 ):
        '''Init input entry.'''
        # Init.
        gtk.VBox.__init__(self)
        self.align = gtk.Alignment()
        self.align.set(0.5, 0.5, 1.0, 1.0)
        self.action_button = action_button
        self.h_box = gtk.HBox()
        self.entry = Entry(content)
        self.background_color = background_color
        self.acme_color = acme_color
        self.point_color = point_color
        self.frame_point_color = frame_point_color
        self.frame_color = frame_color
        
        self.pack_start(self.align, False, False)
        self.align.add(self.h_box)
        self.h_box.pack_start(self.entry)
        if action_button:
            self.action_align = gtk.Alignment()
            self.action_align.set(0.0, 0.5, 0, 0)
            self.action_align.set_padding(0, 0, 0, self.entry.padding_x)
            self.action_align.add(self.action_button)
            
            self.h_box.pack_start(self.action_align, False, False)
            
            self.action_button.connect("clicked", lambda w: self.emit_action_active_signal())

        # Handle signal.
        self.align.connect("expose-event", self.expose_text_entry)
示例#13
0
 def expose_item_align(self, widget, event):
     '''
     Internal function to handle `expose-event` signal.
     
     @param widget: Droplist widget.
     @param event: Expose event.
     '''
     # Init.
     cr = widget.window.cairo_create()        
     rect = widget.allocation
     x, y, w, h = rect.x, rect.y, rect.width, rect.height
     
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("droplist_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
示例#14
0
 def expose_dragable_tabbar(self, widget, event):
     '''
     docs
     '''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     x, w, h = rect.x, rect.width, rect.height
     y = 0
     
     # Draw background.
     (offset_x, offset_y) = widget.translate_coordinates(self.get_toplevel(), 0, 0)
     with cairo_state(cr):
         cr.translate(-offset_x, -offset_y)
         
         (shadow_x, shadow_y) = get_window_shadow_size(self.get_toplevel())
         skin_config.render_background(cr, widget, shadow_x, shadow_y)
     
     # Draw inactive tab.
     draw_x_list = []
     width_offset = 0
     for (index, tab_name) in enumerate(self.names):
         draw_x_list.append(x + width_offset)
         width_offset += (self.name_widths[index] - (self.triangle_width + self.tab_radious * 2))
         
     for (index, tab_name) in enumerate(reversed(self.names)):
         tab_index = len(self.names) - index - 1
         if tab_index != self.active_index:
             self.draw_tab(cr, draw_x_list[tab_index], y, tab_name, tab_index)
             
     # Draw active tab.
     self.draw_tab(cr, draw_x_list[self.active_index], y, self.names[self.active_index], self.active_index)        
     
     # Draw bottom line.
     frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_bottom_active_frame").get_color_info())        
     cr.set_source_rgba(*frame_color)
     cr.rectangle(x, 
                  y + h - 1, 
                  draw_x_list[self.active_index],
                  1)
     cr.rectangle(x + draw_x_list[self.active_index] + self.name_widths[self.active_index], 
                  y + h - 1,
                  w - draw_x_list[self.active_index] - self.name_widths[self.active_index],
                  1)
     cr.fill()
     
     return True
示例#15
0
    def expose_item_align(self, widget, event):
        '''
        Internal function to handle `expose-event` signal.

        @param widget: Droplist widget.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            ui_theme.get_alpha_color("droplist_mask").get_color_info()))
        cr.rectangle(x, y, w, h)
        cr.fill()
示例#16
0
 def draw_menu_mask(self, cr, x, y, w, h):
     '''
     Draw mask interface.
     
     @param cr: Cairo context.
     @param x: X coordinate of draw area.
     @param y: Y coordinate of draw area.
     @param w: Width of draw area.
     @param h: Height of draw area.
     '''
     # Draw background.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("menu_mask").get_color_info()))
     cr.rectangle(x, y, w, h)    
     cr.fill()
     
     # Draw left side.
     draw_hlinear(cr, x + 1, y + 1, 16 + self.padding_x + self.padding_x * 2, h - 2,
                  ui_theme.get_shadow_color("menu_side").get_color_info())
示例#17
0
文件: menu.py 项目: masums/deepin-ui
    def draw_menu_mask(self, cr, x, y, w, h):
        '''
        Draw mask interface.

        @param cr: Cairo context.
        @param x: X coordinate of draw area.
        @param y: Y coordinate of draw area.
        @param w: Width of draw area.
        @param h: Height of draw area.
        '''
        # Draw background.
        cr.set_source_rgba(*alpha_color_hex_to_cairo(
            ui_theme.get_alpha_color("menu_mask").get_color_info()))
        cr.rectangle(x, y, w, h)
        cr.fill()

        # Draw left side.
        draw_hlinear(cr, x + 1, y + 1,
                     16 + self.padding_x + self.padding_x * 2, h - 2,
                     ui_theme.get_shadow_color("menu_side").get_color_info())
示例#18
0
 def expose_progressbar(self, widget, event):
     '''Expose progressbar.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # Draw frame.
     cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("progressbar_frame").get_color_info()))
     cr.set_operator(cairo.OPERATOR_OVER)
     draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 1)
     cr.stroke()
     
     # Draw background.
     draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, 
                  ui_theme.get_shadow_color("progressbar_background").get_color_info(), 
                  1)
 
     # Draw foreground.
     draw_vlinear(cr, rect.x, rect.y, rect.width * self.progress / 100.0, rect.height, 
                  ui_theme.get_shadow_color("progressbar_foreground").get_color_info(), 
                  1)
     
     # Draw font.
     draw_text(cr, str(self.progress) + "%", 
               rect.x, rect.y, rect.width, rect.height, 
               rect.height - 5, "#000000",
               alignment=pango.ALIGN_CENTER)
     
     # Draw light.
     light_radius = rect.height * 4
     light_offset_x = min(self.light_ticker % 150, 100) / 100.0 * (rect.width + light_radius * 2)
     with cairo_state(cr):
         cr.rectangle(rect.x, rect.y, rect.width * self.progress / 100.0, rect.height)
         cr.clip()
         draw_radial_round(cr, rect.x + light_offset_x - light_radius, rect.y - light_radius / 2, light_radius, 
                           ui_theme.get_shadow_color("progressbar_light").get_color_info())
            
     # Propagate expose.
     propagate_expose(widget, event)
     
     return True        
示例#19
0
文件: spin.py 项目: masums/deepin-ui
    def __init__(
        self,
        width=95,
        height=22,
        padding_x=5,
        is_24hour=True,
    ):
        '''
        Initialize TimeSpinBox class.

        @param width: The width of TimeSpinBox, default is 95 pixels.
        @param height: The height of TimeSpinBox, default is 22 pixels.
        @param padding_x: The padding x of TimeSpinBox, default is 5 pixels.
        @param is_24hour: Whether use 24 hours format, default is True.
        '''
        gtk.VBox.__init__(self)

        self.set_time = self.SET_NONE
        self.set_time_bg_color = "#DCDCDC"
        self.time_width = 0
        self.time_comma_width = 0
        self.__24hour = is_24hour
        self.__pressed_button = False

        self.hour_value = time.localtime().tm_hour
        self.min_value = time.localtime().tm_min
        self.sec_value = time.localtime().tm_sec

        # Init.
        self.width = width
        self.height = height
        self.padding_x = padding_x
        self.arrow_button_width = 19
        self.background_color = ui_theme.get_alpha_color(
            "text_entry_background")
        self.acme_color = ui_theme.get_alpha_color("text_entry_acme")
        self.point_color = ui_theme.get_alpha_color("text_entry_point")
        self.frame_point_color = ui_theme.get_alpha_color(
            "text_entry_frame_point")
        self.frame_color = ui_theme.get_alpha_color("text_entry_frame")

        # Widget.
        arrow_up_button = self.create_simple_button("up",
                                                    self.press_increase_button)
        arrow_down_button = self.create_simple_button(
            "down", self.press_decrease_button)
        button_box = gtk.VBox()
        button_box.pack_start(arrow_up_button, False, False)
        button_box.pack_start(arrow_down_button, False, False)
        self.time_label = Label()

        self.main_align = gtk.Alignment()
        self.main_align.set(0.5, 0.5, 0, 0)
        hbox = gtk.HBox()
        hbox.pack_start(self.time_label, False, False)
        hbox.pack_end(button_box, False, False)
        hbox_align = gtk.Alignment()
        hbox_align.set(0.5, 0.5, 1.0, 1.0)
        hbox_align.set_padding(0, 1, 0, 0)
        hbox_align.add(hbox)
        self.main_align.add(hbox_align)
        self.pack_start(self.main_align, False, False)

        # Signals.
        self.connect("size-allocate", self.size_change_cb)
        self.time_label.connect("button-press-event", self.__time_label_press)
        self.main_align.connect("expose-event", self.expose_time_spin)
        SecondThread(self).start()
示例#20
0
    def expose_button(self, widget, event):
        '''
        Internal function to handle `expose-event` signal.

        @param widget: ColorButton instance.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height

        # Get color info.
        if widget.state == gtk.STATE_NORMAL:
            border_color = ui_theme.get_color(
                "button_border_normal").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_normal").get_color_info()
        elif widget.state == gtk.STATE_PRELIGHT:
            border_color = ui_theme.get_color(
                "button_border_prelight").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_prelight").get_color_info()
        elif widget.state == gtk.STATE_ACTIVE:
            border_color = ui_theme.get_color(
                "button_border_active").get_color()
            background_color = ui_theme.get_shadow_color(
                "button_background_active").get_color_info()
        elif widget.state == gtk.STATE_INSENSITIVE:
            border_color = ui_theme.get_color("disable_frame").get_color()
            disable_background_color = ui_theme.get_color(
                "disable_background").get_color()
            background_color = [(0, (disable_background_color, 1.0)),
                                (1, (disable_background_color, 1.0))]

        # Draw background.
        draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2, background_color)

        # Draw border.
        cr.set_source_rgb(*color_hex_to_cairo(border_color))
        draw_line(cr, x + 2, y + 1, x + w - 2, y + 1)  # top
        draw_line(cr, x + 2, y + h, x + w - 2, y + h)  # bottom
        draw_line(cr, x + 1, y + 2, x + 1, y + h - 2)  # left
        draw_line(cr, x + w, y + 2, x + w, y + h - 2)  # right

        # Draw four point.
        if widget.state == gtk.STATE_INSENSITIVE:
            top_left_point = ui_theme.get_pixbuf(
                "button/disable_corner.png").get_pixbuf()
        else:
            top_left_point = ui_theme.get_pixbuf(
                "button/corner.png").get_pixbuf()
        top_right_point = top_left_point.rotate_simple(270)
        bottom_right_point = top_left_point.rotate_simple(180)
        bottom_left_point = top_left_point.rotate_simple(90)

        draw_pixbuf(cr, top_left_point, x, y)
        draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
        draw_pixbuf(cr, bottom_left_point, x,
                    y + h - top_left_point.get_height())
        draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(),
                    y + h - top_left_point.get_height())

        # Draw color frame.
        cr.set_source_rgb(*color_hex_to_cairo("#c0c0c0"))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width, self.color_area_height)
        cr.stroke()

        # Draw color.
        cr.set_source_rgb(*color_hex_to_cairo(self.color))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width, self.color_area_height)
        cr.fill()

        # Draw mask when widget is insensitive.
        if widget.state == gtk.STATE_INSENSITIVE:
            cr.set_source_rgba(*alpha_color_hex_to_cairo(
                ui_theme.get_alpha_color(
                    "color_button_disable_mask").get_color_info()))
            cr.rectangle(x + (w - self.color_area_width) / 2,
                         y + (h - self.color_area_height) / 2,
                         self.color_area_width, self.color_area_height)
            cr.fill()

        return True
示例#21
0
    def draw_tab(self, cr, x, y, tab_name, tab_index):
        # Init.
        (text_width, text_height) = get_content_size(tab_name)
        tab_x = x
        tab_y = y
        tab_height = self.height
        triangle_width = int(tab_height / math.tan(math.radians(self.tab_angle)))
        middle_width = text_width + self.tab_name_padding_x * 2
        tab_width = middle_width + self.tab_radious * 4 + triangle_width * 2
        round_radious = self.tab_radious * math.tan(math.radians((180 - self.tab_angle) / 2))
        round_angle = self.tab_angle
        
        if tab_index == self.active_index:
            frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_frame").get_color_info())        
            background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_background").get_color_info())        
            top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_active_frame").get_color_info())        
        else:
            frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_frame").get_color_info())        
            background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_background").get_color_info())        
            top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_inactive_frame").get_color_info())        
            
        # Init round coordinate.
        round_left_bottom_x = tab_x
        round_left_bottom_y = tab_y + tab_height - round_radious

        round_left_up_x = tab_x + self.tab_radious * 2 + triangle_width
        round_left_up_y = tab_y + round_radious

        round_right_bottom_x = tab_x + tab_width
        round_right_bottom_y = tab_y + tab_height - round_radious

        round_right_up_x = tab_x + tab_width - (self.tab_radious * 2 + triangle_width)
        round_right_up_y = tab_y + round_radious
        
        # Clip.
        with cairo_state(cr):
            # Clip.
            if tab_index != self.active_index and tab_index != 0:
                clip_offset_x = tab_width - (self.triangle_width + self.tab_radious * 2)
                cr.move_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height)
                cr.arc(round_right_bottom_x - clip_offset_x,
                       round_right_bottom_y,
                       round_radious,
                       math.radians(90),
                       math.radians(90 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - self.tab_radious - self.triangle_width + self.tab_radious_offset_x - clip_offset_x,
                           tab_y)
                
                cr.line_to(tab_x + tab_width, tab_y)
                cr.line_to(tab_x + tab_width, tab_y + tab_height)
                cr.line_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height)
            else:
                cr.rectangle(tab_x, tab_y, tab_width, tab_height)
            cr.clip()
                
            # Draw background.
            # Draw left area.
            with cairo_state(cr):
                cr.move_to(tab_x, tab_y + tab_height)
                cr.arc_negative(round_left_bottom_x,
                                round_left_bottom_y,
                                round_radious,
                                math.radians(90),
                                math.radians(90 - round_angle),
                                )
                
                cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x,
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc(round_left_up_x,
                       round_left_up_y,
                       round_radious,
                       math.radians(270 - round_angle),
                       math.radians(270))
            
            # Draw top area.
            with cairo_disable_antialias(cr):    
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width, tab_y + 1)
            
            # Draw right area.
            with cairo_state(cr):
                cr.arc(round_right_up_x,
                       round_right_up_y,
                       round_radious,
                       math.radians(270),
                       math.radians(270 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x),
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc_negative(round_right_bottom_x,
                                round_right_bottom_y,
                                round_radious,
                                math.radians(90 + round_angle),
                                math.radians(90))
                
            cr.line_to(tab_x, tab_y + tab_height)
            
            cr.set_source_rgba(*background_color)
            cr.fill()
            
            # Draw frame.
            # Draw left area.
            with cairo_state(cr):
                cr.move_to(tab_x, tab_y + tab_height)
                cr.arc_negative(round_left_bottom_x,
                                round_left_bottom_y,
                                round_radious,
                                math.radians(90),
                                math.radians(90 - round_angle),
                                )
                
                cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x,
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc(round_left_up_x,
                       round_left_up_y,
                       round_radious,
                       math.radians(270 - round_angle),
                       math.radians(270))
            
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.stroke()
                
            # Draw top area.
            with cairo_disable_antialias(cr):    
                offset = 1
                cr.set_source_rgba(*top_frame_color)
                cr.set_line_width(1)
                cr.move_to(tab_x + self.tab_radious * 2 + triangle_width - offset, tab_y + 1)
                cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width + offset * 2, tab_y + 1)
                cr.stroke()
            
            # Draw right area.
            with cairo_state(cr):
                cr.move_to(tab_x + tab_width - (self.tab_radious * 2 + triangle_width), tab_y)
                cr.arc(round_right_up_x,
                       round_right_up_y,
                       round_radious,
                       math.radians(270),
                       math.radians(270 + round_angle),
                       )
                
                cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x),
                           tab_y + tab_height - self.tab_radious_offset_y)
                
                cr.arc_negative(round_right_bottom_x,
                                round_right_bottom_y,
                                round_radious,
                                math.radians(90 + round_angle),
                                math.radians(90))
            
                cr.set_source_rgba(*frame_color)
                cr.set_line_width(1)
                cr.stroke()
            
            # Draw text.
            draw_text(cr, tab_name, tab_x, tab_y, tab_width, tab_height, alignment=pango.ALIGN_CENTER)
示例#22
0
    def expose_window_background(self, widget, event):
        '''
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        '''
        if self.expose_background_function:
            self.expose_background_function(widget, event)
        else:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation
            
            # Draw background.
            self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)
            
            # Save cairo context.
            if self.shadow_is_visible:
                x = rect.x + self.shadow_padding
                y = rect.y + self.shadow_padding
                w = rect.width - self.shadow_padding * 2
                h = rect.height - self.shadow_padding * 2
            else:
                x, y, w, h = rect.x, rect.y, rect.width, rect.height
                
            # Draw skin and mask.
            with cairo_state(cr):
                if self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                    cr.rectangle(x + 2, y, w - 4, 1)
                    cr.rectangle(x + 1, y + 1, w - 2, 1)
                    cr.rectangle(x, y + 2, w, h - 4)
                    cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                    cr.rectangle(x + 1, y + h - 2, w - 2, 1)
                    
                    cr.clip()
                
                # Draw background.
                self.draw_skin(cr, x, y, w, h)
            
                # Draw mask.
                self.draw_mask(cr, x, y, w, h)
                
            # Draw corner shadow.
            with cairo_state(cr):
                cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
                
                cr.rectangle(x, y + 1, 1, 1) # top-left
                cr.rectangle(x + 1, y, 1, 1)
                
                cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
                cr.rectangle(x + w - 2, y, 1, 1)
                
                cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)
                
                cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)
                
                cr.fill()
                
            # Draw background corner.
            with cairo_state(cr):
                cr.rectangle(x, y + 1, 1, 1) # top-left
                cr.rectangle(x + 1, y, 1, 1)
                
                cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
                cr.rectangle(x + w - 2, y, 1, 1)
                
                cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)
                
                cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)
                
                cr.clip()
                
                self.draw_skin(cr, x, y, w, h)
                
            # Propagate expose.
            propagate_expose(widget, event)
            
        return True
示例#23
0
    def expose_window_background(self, widget, event):
        """
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        """
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        
        # Clear color to transparent window.
        cr.set_source_rgba(*self.background_color)
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.paint()
        
        # Save cairo context.
        if self.shadow_is_visible:
            x = rect.x + self.shadow_padding
            y = rect.y + self.shadow_padding
            w = rect.width - self.shadow_padding * 2
            h = rect.height - self.shadow_padding * 2
        else:
            x, y, w, h = rect.x, rect.y, rect.width, rect.height
            
        # Draw background.
        with cairo_state(cr):
            if self.window.get_state() != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                cr.rectangle(x + 2, y, w - 4, 1)
                cr.rectangle(x + 1, y + 1, w - 2, 1)
                cr.rectangle(x, y + 2, w, h - 4)
                cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                cr.rectangle(x + 1, y + h - 2, w - 2, 1)
                
                cr.clip()
            
            skin_config.render_background(cr, self, x, y)
        
            # Draw mask.
            self.draw_mask(cr, x, y, w, h)
            
        # Draw corner shadow.
        with cairo_state(cr):
            cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
            
            cr.rectangle(x, y + 1, 1, 1) # top-left
            cr.rectangle(x + 1, y, 1, 1)
            
            cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
            cr.rectangle(x + w - 2, y, 1, 1)
            
            cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
            cr.rectangle(x + 1, y + h - 1, 1, 1)
            
            cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
            cr.rectangle(x + w - 2, y + h - 1, 1, 1)
            
            cr.fill()
            
        # Draw background corner.
        with cairo_state(cr):
            cr.rectangle(x, y + 1, 1, 1) # top-left
            cr.rectangle(x + 1, y, 1, 1)
            
            cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
            cr.rectangle(x + w - 2, y, 1, 1)
            
            cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
            cr.rectangle(x + 1, y + h - 1, 1, 1)
            
            cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
            cr.rectangle(x + w - 2, y + h - 1, 1, 1)
            
            cr.clip()
            
            skin_config.render_background(cr, self, x, y)
            
        # Propagate expose.
        propagate_expose(widget, event)
        
        return True
示例#24
0
    def expose_window_background(self, widget, event):
        '''
        Internal function to expose the window background.

        @param widget: A window of type Gtk.Widget.
        @param event: The expose event of type gtk.gdk.Event.
        @return: Always return True.
        '''
        if self.expose_background_function:
            self.expose_background_function(widget, event)
        else:
            # Init.
            cr = widget.window.cairo_create()
            rect = widget.allocation

            # Draw background.
            self.draw_background(cr, rect.x, rect.y, rect.width, rect.height)

            # Save cairo context.
            if self.shadow_is_visible:
                x = rect.x + self.shadow_padding
                y = rect.y + self.shadow_padding
                w = rect.width - self.shadow_padding * 2
                h = rect.height - self.shadow_padding * 2
            else:
                x, y, w, h = rect.x, rect.y, rect.width, rect.height

            # Draw skin and mask.
            with cairo_state(cr):
                if self.window.get_state(
                ) & gtk.gdk.WINDOW_STATE_MAXIMIZED != gtk.gdk.WINDOW_STATE_MAXIMIZED:
                    cr.rectangle(x + 2, y, w - 4, 1)
                    cr.rectangle(x + 1, y + 1, w - 2, 1)
                    cr.rectangle(x, y + 2, w, h - 4)
                    cr.rectangle(x + 2, y + h - 1, w - 4, 1)
                    cr.rectangle(x + 1, y + h - 2, w - 2, 1)

                    cr.clip()

                # Draw background.
                self.draw_skin(cr, x, y, w, h)

                # Draw mask.
                self.draw_mask(cr, x, y, w, h)

            # Draw corner shadow.
            with cairo_state(cr):
                cr.set_source_rgba(*alpha_color_hex_to_cairo(
                    ui_theme.get_alpha_color(
                        "window_shadow_corner").get_color_info()))

                cr.rectangle(x, y + 1, 1, 1)  # top-left
                cr.rectangle(x + 1, y, 1, 1)

                cr.rectangle(x + w - 1, y + 1, 1, 1)  # top-right
                cr.rectangle(x + w - 2, y, 1, 1)

                cr.rectangle(x, y + h - 2, 1, 1)  # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)

                cr.rectangle(x + w - 1, y + h - 2, 1, 1)  # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)

                cr.fill()

            # Draw background corner.
            with cairo_state(cr):
                cr.rectangle(x, y + 1, 1, 1)  # top-left
                cr.rectangle(x + 1, y, 1, 1)

                cr.rectangle(x + w - 1, y + 1, 1, 1)  # top-right
                cr.rectangle(x + w - 2, y, 1, 1)

                cr.rectangle(x, y + h - 2, 1, 1)  # bottom-left
                cr.rectangle(x + 1, y + h - 1, 1, 1)

                cr.rectangle(x + w - 1, y + h - 2, 1, 1)  # bottom-right
                cr.rectangle(x + w - 2, y + h - 1, 1, 1)

                cr.clip()

                self.draw_skin(cr, x, y, w, h)

            # Propagate expose.
            propagate_expose(widget, event)

        return True
示例#25
0
 def expose_window_background(self, widget, event):
     '''Expose window background.'''
     # Init.
     cr = widget.window.cairo_create()
     rect = widget.allocation
     
     # Clear color to transparent window.
     cr.set_source_rgba(0.0, 0.0, 0.0, 0.0)
     cr.set_operator(cairo.OPERATOR_SOURCE)
     cr.paint()
     
     # Save cairo context.
     if self.shadow_is_visible:
         x = rect.x + self.shadow_padding
         y = rect.y + self.shadow_padding
         w = rect.width - self.shadow_padding * 2
         h = rect.height - self.shadow_padding * 2
     else:
         x, y, w, h = rect.x, rect.y, rect.width, rect.height
         
     # Draw background.
     with cairo_state(cr):
         cr.rectangle(x + 2, y, w - 4, 1)
         cr.rectangle(x + 1, y + 1, w - 2, 1)
         cr.rectangle(x, y + 2, w, h - 4)
         cr.rectangle(x + 2, y + h - 1, w - 4, 1)
         cr.rectangle(x + 1, y + h - 2, w - 2, 1)
         
         cr.clip()
         
         skin_config.render_background(cr, self, x, y)
     
         # Draw mask.
         self.draw_mask(cr, x, y, w, h)
         
     # Draw corner shadow.
     with cairo_state(cr):
         cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("window_shadow_corner").get_color_info()))
         
         cr.rectangle(x, y + 1, 1, 1) # top-left
         cr.rectangle(x + 1, y, 1, 1)
         
         cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
         cr.rectangle(x + w - 2, y, 1, 1)
         
         cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
         cr.rectangle(x + 1, y + h - 1, 1, 1)
         
         cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
         cr.rectangle(x + w - 2, y + h - 1, 1, 1)
         
         cr.fill()
         
     # Draw background corner.
     with cairo_state(cr):
         cr.rectangle(x, y + 1, 1, 1) # top-left
         cr.rectangle(x + 1, y, 1, 1)
         
         cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right
         cr.rectangle(x + w - 2, y, 1, 1)
         
         cr.rectangle(x, y + h - 2, 1, 1) # bottom-left
         cr.rectangle(x + 1, y + h - 1, 1, 1)
         
         cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right
         cr.rectangle(x + w - 2, y + h - 1, 1, 1)
         
         cr.clip()
         
         skin_config.render_background(cr, self, x, y)
         
     # Propagate expose.
     propagate_expose(widget, event)
     
     return True
示例#26
0
    def __init__(self,
                 width=95,
                 height=22,
                 padding_x=5,
                 is_24hour=True,
                 ):
        '''
        Initialize TimeSpinBox class.

        @param width: The width of TimeSpinBox, default is 95 pixels.
        @param height: The height of TimeSpinBox, default is 22 pixels.
        @param padding_x: The padding x of TimeSpinBox, default is 5 pixels.
        @param is_24hour: Whether use 24 hours format, default is True.
        '''
        gtk.VBox.__init__(self)

        self.set_time = self.SET_NONE
        self.set_time_bg_color = "#DCDCDC"
        self.time_width = 0
        self.time_comma_width = 0
        self.__24hour = is_24hour
        self.__pressed_button = False

        self.hour_value = time.localtime().tm_hour
        self.min_value = time.localtime().tm_min
        self.sec_value = time.localtime().tm_sec

        # Init.
        self.width = width
        self.height = height
        self.padding_x = padding_x
        self.arrow_button_width = 19
        self.background_color = ui_theme.get_alpha_color("text_entry_background")
        self.acme_color = ui_theme.get_alpha_color("text_entry_acme")
        self.point_color = ui_theme.get_alpha_color("text_entry_point")
        self.frame_point_color = ui_theme.get_alpha_color("text_entry_frame_point")
        self.frame_color = ui_theme.get_alpha_color("text_entry_frame")

        # Widget.
        arrow_up_button = self.create_simple_button("up", self.press_increase_button)
        arrow_down_button = self.create_simple_button("down", self.press_decrease_button)
        button_box = gtk.VBox()
        button_box.pack_start(arrow_up_button, False, False)
        button_box.pack_start(arrow_down_button, False, False)
        self.time_label = Label()

        self.main_align = gtk.Alignment()
        self.main_align.set(0.5, 0.5, 0, 0)
        hbox = gtk.HBox()
        hbox.pack_start(self.time_label, False, False)
        hbox.pack_end(button_box, False, False)
        hbox_align = gtk.Alignment()
        hbox_align.set(0.5, 0.5, 1.0, 1.0)
        hbox_align.set_padding(0, 1, 0, 0)
        hbox_align.add(hbox)
        self.main_align.add(hbox_align)
        self.pack_start(self.main_align, False, False)

        # Signals.
        self.connect("size-allocate", self.size_change_cb)
        self.time_label.connect("button-press-event", self.__time_label_press)
        self.main_align.connect("expose-event", self.expose_time_spin)
        SecondThread(self).start()
示例#27
0
    def expose_button(self, widget, event):
        '''
        Internal function to handle `expose-event` signal.
        
        @param widget: ColorButton instance.
        @param event: Expose event.
        '''
        # Init.
        cr = widget.window.cairo_create()
        rect = widget.allocation
        x, y, w, h = rect.x, rect.y, rect.width, rect.height
        
        # Get color info.
        if widget.state == gtk.STATE_NORMAL:
            border_color = ui_theme.get_color("button_border_normal").get_color()
            background_color = ui_theme.get_shadow_color("button_background_normal").get_color_info()
        elif widget.state == gtk.STATE_PRELIGHT:
            border_color = ui_theme.get_color("button_border_prelight").get_color()
            background_color = ui_theme.get_shadow_color("button_background_prelight").get_color_info()
        elif widget.state == gtk.STATE_ACTIVE:
            border_color = ui_theme.get_color("button_border_active").get_color()
            background_color = ui_theme.get_shadow_color("button_background_active").get_color_info()
        elif widget.state == gtk.STATE_INSENSITIVE:
            border_color = ui_theme.get_color("disable_frame").get_color()
            disable_background_color = ui_theme.get_color("disable_background").get_color()
            background_color = [(0, (disable_background_color, 1.0)),
                                (1, (disable_background_color, 1.0))]
            
        # Draw background.
        draw_vlinear(
            cr,
            x + 1, y + 1, w - 2, h - 2,
            background_color)
        
        # Draw border.
        cr.set_source_rgb(*color_hex_to_cairo(border_color))
        draw_line(cr, x + 2, y + 1, x + w - 2, y + 1) # top
        draw_line(cr, x + 2, y + h, x + w - 2, y + h) # bottom
        draw_line(cr, x + 1, y + 2, x + 1, y + h - 2) # left
        draw_line(cr, x + w, y + 2, x + w, y + h - 2) # right
        
        # Draw four point.
        if widget.state == gtk.STATE_INSENSITIVE:
            top_left_point = ui_theme.get_pixbuf("button/disable_corner.png").get_pixbuf()
        else:
            top_left_point = ui_theme.get_pixbuf("button/corner.png").get_pixbuf()
        top_right_point = top_left_point.rotate_simple(270)
        bottom_right_point = top_left_point.rotate_simple(180)
        bottom_left_point = top_left_point.rotate_simple(90)
        
        draw_pixbuf(cr, top_left_point, x, y)
        draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
        draw_pixbuf(cr, bottom_left_point, x, y + h - top_left_point.get_height())
        draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(), y + h - top_left_point.get_height())
        
        # Draw color frame.
        cr.set_source_rgb(*color_hex_to_cairo("#c0c0c0"))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width,
                     self.color_area_height)
        cr.stroke()
        
        # Draw color.
        cr.set_source_rgb(*color_hex_to_cairo(self.color))
        cr.rectangle(x + (w - self.color_area_width) / 2,
                     y + (h - self.color_area_height) / 2,
                     self.color_area_width,
                     self.color_area_height)
        cr.fill()

        # Draw mask when widget is insensitive.
        if widget.state == gtk.STATE_INSENSITIVE:
            cr.set_source_rgba(*alpha_color_hex_to_cairo(ui_theme.get_alpha_color("color_button_disable_mask").get_color_info()))
            cr.rectangle(x + (w - self.color_area_width) / 2,
                         y + (h - self.color_area_height) / 2,
                         self.color_area_width,
                         self.color_area_height)
            cr.fill()
        
        return True
示例#28
0
文件: spin.py 项目: masums/deepin-ui
    def __init__(
        self,
        value=0,
        lower=0,
        upper=100,
        step=10,
        default_width=55,
        check_text=is_float,
    ):
        '''
        Initialize SpinBox class.

        @param value: Initialize value, default is 0.
        @param lower: Lower value, default is 0.
        @param upper: Upper value, default is 100.
        @param step: Step value, default is 10.
        @param default_width: Default with, default is 55 pixel.
        @param check_text: The check function, default is is_float to check value is float.
        '''
        gtk.VBox.__init__(self)
        self.current_value = value
        self.lower_value = lower
        self.upper_value = upper
        self.step_value = step
        self.update_delay = 100  # milliseconds
        self.increase_value_id = None
        self.decrease_value_id = None

        # Init.
        self.default_width = default_width
        self.default_height = 22
        self.arrow_button_width = 19
        self.background_color = ui_theme.get_alpha_color(
            "text_entry_background")
        self.acme_color = ui_theme.get_alpha_color("text_entry_acme")
        self.point_color = ui_theme.get_alpha_color("text_entry_point")
        self.frame_point_color = ui_theme.get_alpha_color(
            "text_entry_frame_point")
        self.frame_color = ui_theme.get_alpha_color("text_entry_frame")

        # Widget.
        arrow_up_button = self.create_simple_button("up",
                                                    self.press_increase_button)
        arrow_down_button = self.create_simple_button(
            "down", self.press_decrease_button)
        button_box = gtk.VBox()
        button_box.pack_start(arrow_up_button, False, False)
        button_box.pack_start(arrow_down_button, False, False)
        self.value_entry = Entry(str(value))
        self.value_entry.check_text = check_text
        self.value_entry.connect(
            "press-return",
            lambda entry: self.update_and_emit(int(entry.get_text())))

        self.main_align = gtk.Alignment()
        self.main_align.set(0.5, 0.5, 0, 0)
        hbox = gtk.HBox()
        hbox.pack_start(self.value_entry, False, False)
        hbox.pack_start(button_box, False, False)
        hbox_align = gtk.Alignment()
        hbox_align.set(0.5, 0.5, 1.0, 1.0)
        hbox_align.set_padding(0, 1, 0, 0)
        hbox_align.add(hbox)
        self.main_align.add(hbox_align)
        self.pack_start(self.main_align, False, False)

        # Signals.
        self.connect("size-allocate", self.size_change_cb)
        self.main_align.connect("expose-event", self.expose_spin_bg)