Python gtk 模块,CellRendererPixbuf() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用gtk.CellRendererPixbuf()

项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def make_pixbuf_choice(options, default=None):
    store = gtk.ListStore(gtk.gdk.Pixbuf, gobject.TYPE_STRING)
    box = gtk.ComboBox(store)

    cell = gtk.CellRendererPixbuf()
    box.pack_start(cell, True)
    box.add_attribute(cell, "pixbuf", 0)

    cell = gtk.CellRendererText()
    box.pack_start(cell, True)
    box.add_attribute(cell, "text", 1)

    _default = None
    for pic, value in options:
        iter = store.append()
        store.set(iter, 0, pic, 1, value)
        if default == value:
            _default = options.index((pic, value))

    if _default:
        box.set_active(_default)

    return box
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def __init__(self, index, preferences):
        self.index = index
        # Icons corresponding to tags, prevent unnecessary changing.
        self.icons_for_tags = preferences.copy()

        self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, str, int) # TAG_COL, ICON_COL, ICON_NAME, N_PAGES_COL
        SingleClickTreeView.__init__(self, self.model)

        cells = (('Tags', self.TAG_COL, True),
                 ('Pages', self.N_PAGES_COL, False))
        for name, col_id, expand in (cells):
            cell = gtk.CellRendererText()
            cell.set_property('ellipsize', pango.ELLIPSIZE_END)
            cell.set_property('cell-background', 'white')
            col = gtk.TreeViewColumn(name, cell)
            col.set_attributes(cell, text = col_id)
            col.set_resizable(expand)
            col.set_expand(expand)
            col.set_sort_column_id(col_id)
            self.append_column(col)

        cell = gtk.CellRendererPixbuf()
        cell.set_property('cell-background', 'white')
        col = gtk.TreeViewColumn('Icon', cell)
        col.set_attributes(cell, pixbuf = self.ICON_COL)
        col.set_resizable(False)
        col.set_expand(False)
        col.set_sort_column_id(self.ICON_NAME)
        self.append_column(col)

        self.refill_model()
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def __init__(self, index, preferences):
        self.index = index
        # Icons corresponding to tags, prevent unnecessary changing.
        self.icons_for_tags = preferences.copy()

        self.model = gtk.ListStore(str, gtk.gdk.Pixbuf, str, int) # TAG_COL, ICON_COL, ICON_NAME, N_PAGES_COL
        SingleClickTreeView.__init__(self, self.model)

        cells = (('Tags', self.TAG_COL, True),
                 ('Pages', self.N_PAGES_COL, False))
        for name, col_id, expand in cells:
            cell = gtk.CellRendererText()
            cell.set_property('ellipsize', pango.ELLIPSIZE_END)
            cell.set_property('cell-background', 'white')
            col = gtk.TreeViewColumn(name, cell)
            col.set_attributes(cell, text = col_id)
            col.set_resizable(expand)
            col.set_expand(expand)
            col.set_sort_column_id(col_id)
            self.append_column(col)

        cell = gtk.CellRendererPixbuf()
        cell.set_property('cell-background', 'white')
        col = gtk.TreeViewColumn('Icon', cell)
        col.set_attributes(cell, pixbuf = self.ICON_COL)
        col.set_resizable(False)
        col.set_expand(False)
        col.set_sort_column_id(self.ICON_NAME)
        self.append_column(col)

        self.refill_model()
项目:python-3-for-absolute-begs    作者:Apress    | 项目源码 | 文件源码
def create_treelist(self):
        """create_treelist

        Create list of options
        """ 
        # Add some messages to the window
        self.liststore = gtk.ListStore(str,str,'gboolean')
        # we'll add some data now
        self.liststore.append(['Kernel', gtk.STOCK_OPEN, True])
        self.liststore.append(['CPU', gtk.STOCK_OPEN, True])
        self.liststore.append(['RAM', gtk.STOCK_OPEN, True])
        self.liststore.append(['Sound Modules', gtk.STOCK_OPEN, True])
        self.liststore.append(['Sound Devices', gtk.STOCK_OPEN, True])
        self.liststore.append(['Asound', gtk.STOCK_OPEN, True])

        # create the TreeViewColumn to display the data
        self.tvcolumn = gtk.TreeViewColumn('Categories')

        # Append liststore model to treeview
        self.treeview1.set_model(model=self.liststore)   

        # add tvcolumn to treeview
        self.treeview1.append_column(self.tvcolumn)

        # create a CellRendererText to render the data
        self.cell = gtk.CellRendererText()
        self.cell0 = gtk.CellRendererPixbuf()

        # add the cell to the tvcolumn and allow it to expand
        self.tvcolumn.pack_start(self.cell0, True)
        self.tvcolumn.pack_start(self.cell, True)

        # set the cell "text" attribute to column 0 - retrieve text
        # from that column in treestore
        self.tvcolumn.set_cell_data_func(self.cell0, self.make_pixbuf)
        self.tvcolumn.add_attribute(self.cell, 'text', 0)
        return
项目:gnome-connection-manager    作者:mjun    | 项目源码 | 文件源码
def initLeftPane(self):
        global groups       

        self.treeModel = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gtk.gdk.Pixbuf)
        self.treeServers.set_model(self.treeModel)

        self.treeServers.set_level_indentation(5)
        #Force the alternating row colors, by default it's off with one column
        self.treeServers.set_property('rules-hint', True)
        gtk.rc_parse_string( """
                style "custom-treestyle"{
                    GtkTreeView::allow-rules = 1
                }
                widget "*treeServers*" style "custom-treestyle"
            """)
        column = gtk.TreeViewColumn()
        column.set_title('Servers')
        self.treeServers.append_column( column )

        renderer = gtk.CellRendererPixbuf()
        column.pack_start(renderer, expand=False)
        column.add_attribute(renderer, 'pixbuf', 2)

        renderer = gtk.CellRendererText()
        column.pack_start(renderer, expand=True)
        column.add_attribute(renderer, 'text', 0)

        self.treeServers.set_has_tooltip(True)
        self.treeServers.connect('query-tooltip', self.on_treeServers_tooltip)
        self.loadConfig()
        self.updateTree()
项目:linux-pentest-util    作者:fikr4n    | 项目源码 | 文件源码
def _create_treeview(self, model):
        cell_text = gtk.CellRendererText()
        cell_icon = gtk.CellRendererPixbuf()
        column = gtk.TreeViewColumn()
        column.pack_start(cell_icon, False)
        column.add_attribute(cell_icon, 'stock_id', 1)
        column.pack_start(cell_text, True)
        column.set_cell_data_func(cell_text, self.render_name_cell)
        treeview = gtk.TreeView(model)
        treeview.append_column(column)
        treeview.set_headers_visible(False)
        treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
        treeview.connect('key_press_event', self.on_treeview_key_press)
        return treeview
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def _PageTreeView_init_(self, ui):
        '''
        This is a slightly modified copy of PageTreeView constructor 
        with one additional column for icons.
        '''
        BrowserTreeView.__init__(self)
        self.set_name('zim-pageindex')
        self.ui = ui
        self._cleanup = None # temporary created path that needs to be removed later

        column = gtk.TreeViewColumn('_pages_')
        self.append_column(column)

        # Added Icon column.
        cr0 = gtk.CellRendererPixbuf()
        column.pack_start(cr0, expand = False)
        column.set_attributes(cr0, pixbuf = ICON_COL)

        cr1 = gtk.CellRendererText()
        cr1.set_property('ellipsize', pango.ELLIPSIZE_END)
        column.pack_start(cr1, True)
        column.set_attributes(cr1, text=NAME_COL,
                              style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL)

        cr2 = self.get_cell_renderer_number_of_items()
        column.pack_start(cr2, False)
        column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL)

        if gtk.gtk_version >= (2, 12) \
           and gtk.pygtk_version >= (2, 12):
            self.set_tooltip_column(TIP_COL)

        self.set_headers_visible(False)

        self.set_enable_search(True)
        self.set_search_column(0)

        self.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET,),
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE )
        self.enable_model_drag_dest(
            (INTERNAL_PAGELIST_TARGET,),
            gtk.gdk.ACTION_MOVE )
项目:zim-icontags-plugin    作者:Pl-M    | 项目源码 | 文件源码
def _PageTreeView_init_(self, ui):
        '''
        This is a slightly modified copy of PageTreeView constructor
        with one additional column for icons.
        '''
        BrowserTreeView.__init__(self)
        self.set_name('zim-pageindex')
        self.ui = ui
        self._cleanup = None # temporary created path that needs to be removed later

        column = gtk.TreeViewColumn('_pages_')
        self.append_column(column)

        # Added Icon column.
        cr0 = gtk.CellRendererPixbuf()
        column.pack_start(cr0, expand = False)
        column.set_attributes(cr0, pixbuf = ICON_COL)

        cr1 = gtk.CellRendererText()
        cr1.set_property('ellipsize', pango.ELLIPSIZE_END)
        column.pack_start(cr1, True)
        column.set_attributes(cr1, text=NAME_COL,
                              style=STYLE_COL, foreground=FGCOLOR_COL, weight=WEIGHT_COL)

        cr2 = self.get_cell_renderer_number_of_items()
        column.pack_start(cr2, False)
        column.set_attributes(cr2, text=N_CHILD_COL, weight=WEIGHT_COL)

        if gtk.gtk_version >= (2, 12) \
           and gtk.pygtk_version >= (2, 12):
            self.set_tooltip_column(TIP_COL)

        self.set_headers_visible(False)

        self.set_enable_search(True)
        self.set_search_column(0)

        self.enable_model_drag_source(
            gtk.gdk.BUTTON1_MASK, (INTERNAL_PAGELIST_TARGET,),
            gtk.gdk.ACTION_LINK | gtk.gdk.ACTION_MOVE )
        self.enable_model_drag_dest(
            (INTERNAL_PAGELIST_TARGET,),
            gtk.gdk.ACTION_MOVE )
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def create_treeview(self):
        self.treeview = gtk.TreeView(self.treestore)
        self.treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_VERTICAL)
        self.builder.get_object("feat_scrolledwindow").add(self.treeview)

        self.treeview.add_events(gdk.BUTTON_PRESS_MASK)
        self.treeview.connect('button-press-event', self.pop_menu)
        self.treeview.connect('row_activated', self.tv_row_activated)
        self.treeview.connect('key_press_event', self.tv_key_pressed_event)

        # icon and name
        col = gtk.TreeViewColumn(_("Name"))
        cell = gtk.CellRendererPixbuf()
        cell.set_fixed_size(treeview_icon_size, treeview_icon_size)
        self.tv1_icon_cell = cell
        col.pack_start(cell, expand = False)
        col.set_cell_data_func(cell, self.get_col_icon)
        col.set_min_width(int(self.col_width_adj.get_value()))

        self.name_cell = gtk.CellRendererText()
        col.pack_start(self.name_cell, expand = True)
        col.set_cell_data_func(self.name_cell, self.get_col_name)
        col.set_resizable(True)
        self.name_cell.set_property('ellipsize', self.pref.name_ellipsis)
        self.name_cell.set_property('xpad', 2)

        self.treeview.append_column(col)

        # value
        col = gtk.TreeViewColumn(_("Value"))

        cell = CellRendererMx(self.treeview)
        cell.edited = self.edited
        cell.set_preediting(self.get_editinfo)
        cell.set_refresh_fn(self.get_selected_feature)
        col.pack_start(cell, expand = True)
        col.set_cell_data_func(cell, self.get_col_value)
        col.set_min_width(200)
        col.set_resizable(True)
        self.treeview.append_column(col)

        self.treeview.set_tooltip_column(1)
        self.treeview.connect("cursor-changed", self.get_selected_feature)

        self.treeview.set_model(self.master_filter)
项目:NativeCAM    作者:FernV    | 项目源码 | 文件源码
def create_second_treeview(self):
        self.treeview2 = gtk.TreeView()
        self.treeview2.add_events(gdk.BUTTON_PRESS_MASK)
        self.treeview2.connect('button-press-event', self.pop_menu)
        self.treeview2.connect('cursor-changed', self.tv2_selected)
        self.treeview2.connect('row_activated', self.tv_row_activated)
        self.treeview2.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_VERTICAL)
        self.treeview2.set_show_expanders(self.pref.tv2_expandable)
        if self.pref.tv2_expandable :
            self.treeview2.set_level_indentation(-5)
        else :
            self.treeview2.set_level_indentation(12)

        # icon and name
        col = gtk.TreeViewColumn(_("Name"))
        cell = gtk.CellRendererPixbuf()
        cell.set_fixed_size(treeview_icon_size, treeview_icon_size)
        self.tv2_icon_cell = cell

        col.pack_start(cell, expand = False)
        col.set_cell_data_func(cell, self.get_col_icon)

        self.name_cell2 = gtk.CellRendererText()
        self.name_cell2.set_property('xpad', 2)
        self.name_cell2.set_property('ellipsize', self.pref.name_ellipsis)
        col.pack_start(self.name_cell2, expand = True)
        col.set_cell_data_func(self.name_cell2, self.get_col_name)
        col.set_resizable(True)
        col.set_min_width(int(self.col_width_adj.get_value()))
        self.treeview2.append_column(col)

        # value
        col = gtk.TreeViewColumn(_("Value"))
        cell = CellRendererMx(self.treeview2)
        cell.set_property("editable", True)
        cell.edited = self.edited
        cell.set_preediting(self.get_editinfo)
        cell.set_refresh_fn(self.get_selected_feature)

        col.pack_start(cell, expand = False)
        col.set_cell_data_func(cell, self.get_col_value)
        col.set_resizable(True)
        col.set_min_width(200)
        self.treeview2.append_column(col)

        self.treeview2.set_tooltip_column(1)
        self.treeview2.set_model(self.treestore)
        self.treeview2.set_model(self.details_filter)
        self.params_scroll.add(self.treeview2)
        self.treeview2.connect('key-press-event', self.tv_key_pressed_event)
项目:wahcade    作者:sairuk    | 项目源码 | 文件源码
def setup_iconview(self, columns, column_types, container, changed_cb=None, activate_cb=None, text_style='text'):
        """ Create a ready-to-use (list based) iconview widget (GTK+2.6 and baove)
        Parameters:
            columns      : List of column names (should only be two - one for icon & one for description)
            column_types : List of variable types for each column
                           (eg. [gobject.TYPE_STRING, gobject.TYPE_LONG])
            container    : reference to widget that is to contain list,
                           almost always a scrolled window - gtk.ScrolledWindow()
            changed_cb   : the callback function for the "changed" TreeViewSelection signal
            activate_cb  : the callback function for the "changed" TreeViewSelection signal
            text_style   : 'text' for normail plain text,
                           'markup' for pango marked-up text
        Returns:
            Reference to IconView and ListStore widgets

        e.g. to create a four column (first two displayed, rest hidden) icon view...
            self.tvwProjects, self.lsProjects, self.tvwsProjects = self.setup_treeview(
                ['Picture', 'Desc'],
                [gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_LONG, gobject.TYPE_STRING],
                self.scwPictures,
                self.on_tvwsPictures_changed,
                None
                'text')
        """
        #create the ListStore and IconView objects
        ls = gtk.ListStore(*column_types)
        ivw = gtk.IconView(ls)
        #set columns
        for i in range(len(columns)):
            if column_types[i] != gtk.gdk.Pixbuf:
                #create text renderer
                tvwRendererText = gtk.CellRendererText()
                tvwRendererText.set_property('yalign', 0.0)
                if text_style == 'markup':
                    #markup text rendering
                    column = gtk.TreeViewColumn(columns[i], tvwRendererText, markup=i)
                    ivw.set_markup_column(i)
                else:
                    #default text rendering
                    column = gtk.TreeViewColumn(columns[i], tvwRendererText, text=i)
                    ivw.set_text_column(i)
            else:
                #create pixbuf renderer
                tvwRendererPixbuf = gtk.CellRendererPixbuf()
                column = gtk.TreeViewColumn(columns[i], tvwRendererPixbuf, pixbuf=i)
                ivw.set_pixbuf_column(i)
        #display it (add iconview to given widget)
        container.add(ivw)
        ivw.show()
        #connect callbacks
        if changed_cb:
            ivw.connect('selection_changed', changed_cb)
        if activate_cb:
            ivw.connect('item_activated', activate_cb)
        #done
        return ivw, ls