PyGobject(六十七)Gtk.Widget之Gtk.CellView

本文介绍Gtk.CellView组件的使用方法,展示如何通过Gtk.CellView显示Gtk.TreeModel中的一行数据,并提供了一个Python示例程序来演示如何创建和配置Gtk.CellView。

Gtk.CellView

Gtk.CellView用来显示Gtk.TreeModel中的一行数据,多个Gtk.CellView连在一起,就可以显示出和Gtk.TreeView类似的效果

继承关系

这里写图片描述

Methods

方法修饰词方法名及参数
staticnew ()
staticnew_with_context (area, context)
staticnew_with_markup (markup)
staticnew_with_pixbuf (pixbuf)
staticnew_with_text (text)
get_displayed_row ()
get_draw_sensitive ()
get_fit_model ()
get_model ()
get_size_of_row (path)
set_background_color (color)
set_background_rgba (rgba)
set_displayed_row (path)
set_draw_sensitive (draw_sensitive)
set_fit_model (fit_model)
set_model (model)

Virtual Methods

Properties

NameTypeFlagsShort Description
backgroundstrwBackground color as a string
background-gdkGdk.Colord/r/wBackground color as a Gdk.Color deprecated
background-rgbaGdk.RGBAr/wBackground color as a Gdk.RGBA
background-setboolr/wWhether this tag affects the background color
cell-areaGtk.CellArear/w/coThe Gtk.CellArea used to layout cells
cell-area-contextGtk.CellAreaContextr/w/coThe Gtk.CellAreaContext used to compute the geometry of the cell view
draw-sensitiveboolr/w/enWhether to force cells to be drawn in a sensitive state
fit-modelboolr/w/enWhether to request enough space for every row in the model
modelGtk.TreeModelr/wThe model for cell view

Signals

NameShort Description

例子

这里写图片描述
代码:

#!/usr/bin/env python3
# Created by xiaosanyu at 16/7/14
# section 108
# 
# author: xiaosanyu
# website: yuxiaosan.tk \
#          http://blog.youkuaiyun.com/a87b01c14
# created: 16/7/14

TITLE = "CellView"
DESCRIPTION = """
A Gtk.CellView displays a single row of a Gtk.TreeModel using a Gtk.CellArea and Gtk.CellAreaContext
"""
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk, Gio, GLib


class CellViewWindow(Gtk.Window):
    def __init__(self, *args, **kwargs):
        Gtk.Window.__init__(self, title="CellView Example")
        self.set_size_request(250, 200)
        box = Gtk.VBox(spacing=6)
        liststore = Gtk.ListStore(str, str)
        liststore.append(["New", "document-new"])
        liststore.append(["Open", "document-open"])
        liststore.append(["Save", "document-save"])

        cv = Gtk.CellView.new_with_text("New")
        box.add(cv)
        pixbuf = Gtk.IconTheme.get_default().load_icon("document-new", Gtk.IconSize.MENU, 0)
        cv = Gtk.CellView.new_with_pixbuf(pixbuf)
        box.add(cv)
        # create Gtk.CellArea
        cb = Gtk.CellAreaBox()
        renderer_text = Gtk.CellRendererText()
        cb.pack_start(renderer_text, False, False, 0)
        cb.add_attribute(renderer_text, "text", 0)

        renderer_pixbuf = Gtk.CellRendererPixbuf()
        cb.pack_start(renderer_pixbuf, False, False, 0)
        cb.add_attribute(renderer_pixbuf, "icon_name", 1)

        # create Gtk.CellAreaContext
        ctx = cb.create_context()
        for i in range(3):
            cv = Gtk.CellView.new_with_context(cb, ctx)
            cv.set_model(liststore)
            cv.set_background_rgba(Gdk.RGBA((1, 0)[i == 0], (1, 0)[i == 1], (1, 0)[i == 2], 1))
            cv.set_displayed_row(Gtk.TreePath(i))
            box.add(cv)

        # model = cv.get_model()
        # for row in model:
        #     print(row[:])
        self.add(box)


def main():
    win = CellViewWindow()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()


if __name__ == "__main__":
    main()




代码下载地址:http://download.youkuaiyun.com/detail/a87b01c14/9594728

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanxiaochengyu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值