如何让GtkListStore连续存储对象属性?

2023-12-07

我试图使用我找到的代码片段保留 ListStore 非文本对象。这些是对象:

class Series(gobject.GObject, object):
 def __init__(self, title):
  super(Series, self).__init__()
  self.title = title

gobject.type_register(Series)

class SeriesListStore(gtk.ListStore):
 def __init__(self):
  super(SeriesListStore, self).__init__(Series)
  self._col_types = [Series]

 def get_n_columns(self):
  return len(self._col_types)

 def get_column_type(self, index):
  return self._col_types[index]

 def get_value(self, iter, column):
  obj = gtk.ListStore.get_value(self, iter, 0)
  return obj

现在我试图让 TreeView 显示它:

    ...
    liststore = SeriesListStore()
 liststore.clear()

 for title in full_conf['featuring']:
  series = Series(title)
  liststore.append([series])

 def get_series_title(column, cell, model, iter):
  cell.set_property('text', liststore.get_value(iter, column).title)
  return

 selected = builder.get_object("trvMain")
 selected.set_model(liststore)

 col = gtk.TreeViewColumn(_("Series title"))
 cell = gtk.CellRendererText()
 col.set_cell_data_func(cell, get_series_title)
 col.pack_start(cell)
 col.add_attribute(cell, "text", 0)

 selected.append_column(col)
    ...

但它失败并出现错误:

Gtk警告: gtk_tree_view_column_cell_layout_set_cell_data_func: 断言info != NULL' failed
col.set_cell_data_func(cell, get_series_title) Warning: unable to set property
文本' 类型的gchararray' from value of type数据+托盘图标+系列'
window.show_all() 警告:无法设置属性text' of typegchararray' 来自值 输入“数据+TrayIcon+系列”
gtk.main() gtk.main()

我应该怎么做才能让它发挥作用?


倒数第二个区块有两个错误。

  1. GtkWarning: gtk_tree_view_column_cell_layout_set_cell_data_func: assertion `info != NULL'

    在英语中,这意味着单元格渲染器不在列的单元格渲染器列表中。在调用之前,您需要先将单元格渲染器添加到列中set_cell_data_func.

  2. Warning: unable to set property `text' of type `gchararray' from value of `typedata+TrayIcon+Series'

    这是因为add_attributeline 导致 GTK+ 尝试将单元格文本设置为 Series 对象,这当然会失败。只需删除该行即可;单元格数据函数已经负责设置单元格文本。

In code:

col = gtk.TreeViewColumn(_("Series title"))
cell = gtk.CellRendererText()
col.pack_start(cell)
col.set_cell_data_func(cell, get_series_title)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让GtkListStore连续存储对象属性? 的相关文章

  • 如何查看Databricks中的所有数据库和表

    我想列出 Azure Databricks 中每个数据库中的所有表 所以我希望输出看起来像这样 Database Table name Database1 Table 1 Database1 Table 2 Database1 Table
  • 无法“安装”plpython3u - postgresql

    我正在尝试在 postgresql 中使用 python 语言 像这样的事情 create or replace function test a integer returns integer as if a 2 0 return even
  • 使用 psycopg2 在 python 中执行查询时出现“编程错误:语法错误位于或附近”

    我正在运行 Python v 2 7 和 psycopg2 v 2 5 我有一个 postgresql 数据库函数 它将 SQL 查询作为文本字段返回 我使用以下代码来调用该函数并从文本字段中提取查询 cur2 execute SELECT
  • 没有名为 crypto.cipher 的模块

    我现在正在尝试加密一段时间 我最近得到了这个基于 python 的密码器 名为PythonCrypter https github com jbertman PythonCrypter 我对 Python 相当陌生 当我尝试通过终端打开 C
  • 将数据从 python pandas 数据框导出或写入 MS Access 表

    我正在尝试将数据从 python pandas 数据框导出到现有的 MS Access 表 我想用已更新的数据替换 MS Access 表 在 python 中 我尝试使用 pandas to sql 但收到错误消息 我觉得很奇怪 使用 p
  • Python(Selenium):如何通过登录重定向/组织登录登录网站

    我不是专业程序员 所以请原谅任何愚蠢的错误 我正在做一些研究 我正在尝试使用 Selenium 登录数据库来搜索大约 1000 个术语 我有两个问题 1 重定向到组织登录页面后如何使用 Selenium 登录 2 如何检索数据库 在我解决
  • Flask 会话变量

    我正在用 Flask 编写一个小型网络应用程序 当两个用户 在同一网络下 尝试使用应用程序时 我遇到会话变量问题 这是代码 import os from flask import Flask request render template
  • PyUSB 1.0:NotImplementedError:此平台不支持或未实现操作

    我刚刚开始使用 pyusb 基本上我正在玩示例代码here https github com walac pyusb blob master docs tutorial rst 我使用的是 Windows 7 64 位 并从以下地址下载 z
  • 如何替换 pandas 数据框列中的重音符号

    我有一个数据框dataSwiss其中包含瑞士城市的信息 我想用普通字母替换带有重音符号的字母 这就是我正在做的 dataSwiss Municipality dataSwiss Municipality str encode utf 8 d
  • python 相当于 R 中的 get() (= 使用字符串检索符号的值)

    在 R 中 get s 函数检索名称存储在字符变量 向量 中的符号的值s e g X lt 10 r lt XVI s lt substr r 1 1 X get s 10 取罗马数字的第一个符号r并将其转换为其等效整数 尽管花了一些时间翻
  • 以编程方式停止Python脚本的执行? [复制]

    这个问题在这里已经有答案了 是否可以使用命令在任意行停止执行 python 脚本 Like some code quit quit at this point some more code that s not executed sys e
  • Python 函数可以从作用域之外赋予新属性吗?

    我不知道你可以这样做 def tom print tom s locals locals def dick z print z name z name z guest Harry print z guest z guest print di
  • 如何加速Python中的N维区间树?

    考虑以下问题 给定一组n间隔和一组m浮点数 对于每个浮点数 确定包含该浮点数的区间子集 这个问题已经通过构建一个解决区间树 https en wikipedia org wiki Interval tree 或称为范围树或线段树 已经针对一
  • 如何在ipywidget按钮中显示全文?

    我正在创建一个ipywidget带有一些文本的按钮 但按钮中未显示全文 我使用的代码如下 import ipywidgets as widgets from IPython display import display button wid
  • Python 的“zip”内置函数的 Ruby 等价物是什么?

    Ruby 是否有与 Python 内置函数等效的东西zip功能 如果不是 做同样事情的简洁方法是什么 一些背景信息 当我试图找到一种干净的方法来进行涉及两个数组的检查时 出现了这个问题 如果我有zip 我可以写这样的东西 zip a b a
  • 在Python中获取文件描述符的位置

    比如说 我有一个原始数字文件描述符 我需要根据它获取文件中的当前位置 import os psutil some code that works with file lp lib open path to file p psutil Pro
  • python获取上传/下载速度

    我想在我的计算机上监控上传和下载速度 一个名为 conky 的程序已经在 conky conf 中执行了以下操作 Connection quality alignr wireless link qual perc wlan0 downspe
  • Pandas:merge_asof() 对多行求和/不重复

    我正在处理两个数据集 每个数据集具有不同的关联日期 我想合并它们 但因为日期不完全匹配 我相信merge asof 是最好的方法 然而 有两件事发生merge asof 不理想的 数字重复 数字丢失 以下代码是一个示例 df a pd Da
  • 对年龄列进行分组/分类

    我有一个数据框说df有一个柱子 Ages gt gt gt df Age 0 22 1 38 2 26 3 35 4 35 5 1 6 54 我想对这个年龄段进行分组并创建一个像这样的新专栏 If age gt 0 age lt 2 the
  • 解释 Python 中的数字范围

    在 Pylons Web 应用程序中 我需要获取一个字符串 例如 关于如何做到这一点有什么建议吗 我是 Python 新手 我还没有找到任何可以帮助解决此类问题的东西 该列表将是 1 2 3 45 46 48 49 50 51 77 使用

随机推荐