Exemple #1
0
 def __init__(self, description, keyname, name):
     super(ShortcutItem, self).__init__()
     try:
         self.description = markup_escape_text(description)
     except:
         self.description = " "
     self.keyname = keyname
     self.name = name
     self.padding_x = 5
     self.accel_buffer = AccelBuffer()
     self.COLUMN_ACCEL = 1
 def __init__(self, description, keyname, name): 
     super(ShortcutItem, self).__init__()
     try:
         self.description = markup_escape_text(description)
     except:
         self.description = " "
     self.keyname = keyname
     self.name = name
     self.padding_x = 5
     self.accel_buffer = AccelBuffer()
     self.COLUMN_ACCEL = 1
Exemple #3
0
class ShortcutItem(BaseItem):
    '''a shortcut item in TreeView'''
    def __init__(self, description, keyname, name):
        super(ShortcutItem, self).__init__()
        try:
            self.description = markup_escape_text(description)
        except:
            self.description = " "
        self.keyname = keyname
        self.name = name
        self.padding_x = 5
        self.accel_buffer = AccelBuffer()
        self.COLUMN_ACCEL = 1

    def get_column_widths(self):
        return [380, -1]

    def get_column_renders(self):
        return [self.render_description, self.render_keyname]

    def render_description(self, cr, rect):
        if self.is_select:
            text_color = "#FFFFFF"
            bg_color = "#3399FF"
        else:
            text_color = "#000000"
            bg_color = MODULE_BG_COLOR
        cr.set_source_rgb(*color_hex_to_cairo(bg_color))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height - 1)
        cr.paint()
        draw_text(cr,
                  self.description,
                  rect.x + self.padding_x,
                  rect.y,
                  rect.width,
                  rect.height,
                  text_color=text_color)
        #cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
        #draw_line(cr, rect.x, rect.y-1+rect.height, rect.x+rect.width, rect.y-1+rect.height)

    def render_keyname(self, cr, rect):
        if self.is_select:
            text_color = "#FFFFFF"
            bg_color = "#3399FF"
        else:
            text_color = "#000000"
            bg_color = MODULE_BG_COLOR
        cr.set_source_rgb(*color_hex_to_cairo(bg_color))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height - 1)
        cr.paint()
        draw_text(cr,
                  self.keyname,
                  rect.x + self.padding_x,
                  rect.y,
                  rect.width,
                  rect.height,
                  text_color=text_color)
        #cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
        #draw_line(cr, rect.x, rect.y-1+rect.height, rect.x+rect.width, rect.y-1+rect.height)

    def set_accel_buffer_from_event(self, event):
        '''
        set accel buffer value from an Event
        @param event: a gtk.gdk.KEY_PRESS
        '''
        if event.type != gdk.KEY_PRESS:
            return
        self.accel_buffer.set_state(event.state)
        self.accel_buffer.set_keyval(event.keyval)

    def set_accel_buffer_from_accel(self, accelerator):
        '''
        ser accel buffer value from an accelerator string
        @parse accelerator: a accelerator string
        '''
        self.accel_buffer.set_from_accel(accelerator)

    def update_accel_setting(self):
        ''' update the system setting '''
        setting_type = self.get_data("setting-type")
        if setting_type is None:
            return False
        settings = self.get_data("settings")
        if settings is None:
            return False
        accel_data = self.accel_buffer.get_accel_name()
        if setting_type == "gsettings":
            data_type = self.get_data('setting-data-type')
            if data_type == 'string':
                settings.set_string(self.name, accel_data)
            elif data_type == 'strv':
                if accel_data:
                    settings.set_strv(self.name, [accel_data])
                else:
                    settings.set_strv(self.name, [])
        else:
            gconf_dir = self.get_data("gconf-dir")
            settings.set_string("%s/binding" % (gconf_dir), accel_data)
        self.keyname = self.accel_buffer.get_accel_label()
        if self.keyname == '':
            self.keyname = _('disable')
        if self.redraw_request_callback:
            self.redraw_request_callback(self)
        return True
class ShortcutItem(BaseItem):
    '''a shortcut item in TreeView'''
    def __init__(self, description, keyname, name): 
        super(ShortcutItem, self).__init__()
        try:
            self.description = markup_escape_text(description)
        except:
            self.description = " "
        self.keyname = keyname
        self.name = name
        self.padding_x = 5
        self.accel_buffer = AccelBuffer()
        self.COLUMN_ACCEL = 1
    
    def get_column_widths(self):
        return [380, -1]
    
    def get_column_renders(self):
        return [self.render_description, self.render_keyname]
        
    def render_description(self, cr, rect):
        if self.is_select:
            text_color = "#FFFFFF"
            bg_color = "#3399FF"
        else:
            text_color = "#000000"
            bg_color = MODULE_BG_COLOR
        cr.set_source_rgb(*color_hex_to_cairo(bg_color))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height-1)
        cr.paint()
        draw_text(cr, self.description, rect.x+self.padding_x, rect.y, rect.width, rect.height, text_color=text_color)
        #cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
        #draw_line(cr, rect.x, rect.y-1+rect.height, rect.x+rect.width, rect.y-1+rect.height)
    
    def render_keyname(self, cr, rect):
        if self.is_select:
            text_color = "#FFFFFF"
            bg_color = "#3399FF"
        else:
            text_color = "#000000"
            bg_color = MODULE_BG_COLOR
        cr.set_source_rgb(*color_hex_to_cairo(bg_color))
        cr.rectangle(rect.x, rect.y, rect.width, rect.height-1)
        cr.paint()
        draw_text(cr, self.keyname, rect.x+self.padding_x, rect.y, rect.width, rect.height, text_color=text_color)
        #cr.set_source_rgb(*color_hex_to_cairo(TREEVIEW_BORDER_COLOR))
        #draw_line(cr, rect.x, rect.y-1+rect.height, rect.x+rect.width, rect.y-1+rect.height)
    
    def set_accel_buffer_from_event(self, event):
        '''
        set accel buffer value from an Event
        @param event: a gtk.gdk.KEY_PRESS
        '''
        if event.type != gdk.KEY_PRESS:
            return
        self.accel_buffer.set_state(event.state)
        self.accel_buffer.set_keyval(event.keyval)
    
    def set_accel_buffer_from_accel(self, accelerator):
        '''
        ser accel buffer value from an accelerator string
        @parse accelerator: a accelerator string
        '''
        self.accel_buffer.set_from_accel(accelerator)
    
    def update_accel_setting(self):
        ''' update the system setting '''
        setting_type = self.get_data("setting-type")
        if setting_type is None:
            return False
        settings = self.get_data("settings")
        if settings is None:
            return False
        accel_data = self.accel_buffer.get_accel_name()
        if setting_type == "gsettings":
            data_type = self.get_data('setting-data-type')
            if data_type == 'string':
                settings.set_string(self.name, accel_data)
            elif data_type == 'strv':
                if accel_data:
                    settings.set_strv(self.name, [accel_data])
                else:
                    settings.set_strv(self.name, [])
        else:
            gconf_dir = self.get_data("gconf-dir")
            settings.set_string("%s/binding" % (gconf_dir), accel_data)
        self.keyname = self.accel_buffer.get_accel_label()
        if self.keyname == '':
            self.keyname = _('disable')
        if self.redraw_request_callback:
            self.redraw_request_callback(self)
        return True