[英]Displaying heterogenous data in GTK+ tree view
I'm writing a music player frontend using Python bindings for GTK+. 我正在使用GTK +的Python绑定编写音乐播放器前端。 The playlist is a TreeStore, with albums represented by the top-level items, and tracks by their children.
播放列表是TreeStore,其中专辑由顶级项目表示,曲目由其子代表示。
I want to separate the scanning of the music directory and reading the tags of the music files, based on the hunch that scanning the tags is more time-consuming than just adding the item to the tree store. 我想分开扫描音乐目录和读取音乐文件的标签,是基于这样的预感:扫描标签比将项目添加到树存储要花更多的时间。 Hence, I intend to run a separate thread that goes over the playlist and fills in the tags.
因此,我打算运行一个单独的线程,该线程遍历播放列表并填充标签。 For that end, the model items will consist of the following columns:
为此,模型项将由以下几列组成:
[ 'file_path', 'tags_filled', 'album', 'title', (more items for tags) ]
When the music directory is initially traversed, only file_path
will be filled, and tags_filled
set to False
. 最初遍历音乐目录时,将仅填充
file_path
,并将tags_filled
设置为False
。 The tag-filler thread will set tags_filled
to True
and the rest of the columns to their values from the music file. 标签填充线程将把
tags_filled
设置为True
,并将其余的列设置为音乐文件中的值。
When it comes to displaying the described model, I want to display the rows differently based on the tags_filled
attribute: When it's False
, I want only the file path displayed, spanning the full widget width; 在显示所描述的模型时,我想基于
tags_filled
属性来不同地显示行:当它为False
,我只希望显示文件路径,该路径跨越整个窗口小部件宽度; and when it's True
, I want only the tag values displayed in the separate columns. 当它为
True
,我只希望标记值显示在单独的列中。
Something like this: 像这样:
| Artist | Album | Date | Title | Duration |
|--------+--------+------+----------------------------+----------|
| AC/DC | T.N.T. | 1975 | It's A Long Way To The Top | 5:15 | <-- scanned
| music/AC-DC/1975 - T.N.T/02 - Rock'N'Roll Singer.MP3 | <-- not yet scanned
Can you suggest how I can go over implementing this? 您能建议我如何解决这个问题吗?
It is not possible to merge cells of a tree view (yet). 尚无法合并树视图的单元格。 You'd have to use a table (deprecated since Gtk 3.4) or a grid for this.
为此,您必须使用表格(自Gtk 3.4起已弃用)或网格。 Here's how to use these widgets for GTK 3 or check the PyGTK 2.0 Reference Manual, if you are using PyGTK.
如果您使用的是PyGTK,请按照以下方法将这些小部件用于GTK 3或查看《 PyGTK 2.0参考手册》。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.