pygtk - 有关 ListViews 的问题:更新/附加值

发布于 2024-10-19 13:27:24 字数 928 浏览 4 评论 0原文

我对使用 ListViewListStore 等有一些常见问题。

我的程序包含一个 ToDo 列表,它是 Task 列表 -对象。 Task 对象有两个属性:titleprogress。现在我想在 ListView 中显示这些待办事项列表,在第一列中显示任务的 title ,在第二列中显示progress

所以我可以创建一个带有两个TreeViewColumnListView,每个都有一个CellRendererText和一个数据函数(set_cell_data_func)设置适当的列文本(Task-对象的title-或progress-属性)。

当然,任务的进度可以在另一个线程中随着时间的推移而改变。因此,应该更新进度单元格以显示新值。但是我如何告诉 ListView Task 对象已更改并且视图应该更新?

跟踪列表更改的最简单方法是什么?例如,一个新的Task对象被添加到ToDo列表中。我是否需要自己将新添加的 Task 对象附加到 ListStore 还是有更简单的方法? ...因为我有两个列表:原始的待办事项列表和 ListStore 这似乎是不必要的。

那么在 ListView 中显示我的待办事项列表的最佳/最简单/最简单的方法是什么? :-)

最好的问候,
Biggie

i have some general questions about using ListViews and ListStores etc..

My program contains a ToDo-list which is a list of Task-objects. A Task-object has two attributes: title and progress. Now i want to display these ToDo-list in a ListView showing the title of the task in the first column and the progress in the second column.

So i could create a ListView with two TreeViewColumns, each with a CellRendererText and a data function (set_cell_data_func) to set the appropriate column-text (title- or progress-attribute of the Task-object).

Of course, the progress of a task can change over time in another thread. So the progress-cells should be updated to show the new value. But how can i tell the ListView that the Task-object has changed and the view should be updated?

And what is the simplest way to keep track of list-changes? For example a new Task-object is added to the ToDo-list. Do i need to append the new added Task-object to the ListStore by myself or is there an easier way? ... because i would have two lists: the original ToDo-list and the ListStore which seems to be unnecessary.

So what is the best/simplest/easiest way to show my ToDo-list in a ListView? :-)

Best regards,
Biggie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洋洋洒洒 2024-10-26 13:27:24

我宁愿使用 gtk.ListStore 作为您的列表模型和主要\仅“TODO 列表”数据源,一旦您更改模型中的值,您的列表视图内容应该更新,如下所示:

# get first row of the list store
iter = self.model.get_iter_first()
# set new values to the first column
self.model.set_value(iter, 1, 'new value')
# set new values to columns 0 and 1
self.model.set(iter, 0, 'new 0', 1, 'new 1')

如果您需要跟踪您的更改模型字段,连接到“row-changed ”信号:

self.model.connect("row-changed", self.on_model_changed, 0)
...   
def on_model_changed(self, treemodel, path, iter, user_param1):
    print 'model_changed ' + treemodel.get_value(iter, 0)

希望这有帮助,问候

I would rather use gtk.ListStore as your list model and primary\only "TODO list" data source , once you change values in the model, your list view content should be updated, smth like this:

# get first row of the list store
iter = self.model.get_iter_first()
# set new values to the first column
self.model.set_value(iter, 1, 'new value')
# set new values to columns 0 and 1
self.model.set(iter, 0, 'new 0', 1, 'new 1')

if you need to track changes for your model fields, connect to the "row-changed" signal:

self.model.connect("row-changed", self.on_model_changed, 0)
...   
def on_model_changed(self, treemodel, path, iter, user_param1):
    print 'model_changed ' + treemodel.get_value(iter, 0)

hope this helps, regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文