简体   繁体   English

动态将行添加到GTK列表PyGObject

[英]Dynamically add rows to GTK List PyGObject

I'm trying to add items dynamically detected into a PyGTK listview. 我正在尝试将动态检测到的项目添加到PyGTK列表视图中。

I'm using Python 3 and PyGObject. 我正在使用Python 3和PyGObject。

Here are some example lists: 以下是一些示例列表:

['MomAndKids', 'ddwrt', 'Squirt', 'blurb']
['WPA1', 'Open', 'WPA2', 'WEP']
['44/70', '38/70', '66/70', '55/70']

I want it to make a row for each one, that would turn out like this: 我希望它为每一行排成一行,结果是这样的:

['MomAndKids', 'WPA1', '44/70']
['ddwrt', 'Open', '38/70']
['Squirt', 'WPA2', '66/70']
['blurb', 'WEP', '55/70']

And then add each of these rows into a GTK List view. 然后将所有这些行添加到GTK List视图中。 I am using this code, and it almost works: 我正在使用此代码,并且几乎可以正常工作:

for i in range(len(output)):
    string1 = output[i]
    for i in range(len(output2)):
        string2 = output2[i]
        for i in range(len(output3)):
            string3 = output3[i]
            row = [string1, string2, string3]
            self.APStore.append([string1, string2, string3])

It makes something like this: http://pastebin.com/sXNnKfaf (sorry for external link, it makes the posting here not nearly as long.) 它的内容如下: http : //pastebin.com/sXNnKfaf (对不起,对于外部链接,它使此处的发布时间不长。)

I understand why, so I tried this: 我了解原因,因此尝试了以下操作:

for i in range(len(output)):
    string1 = output[i]
    for i in range(len(output2)):
        string2 = output2[i]
        for i in range(len(output3)):
            string3 = output3[i]
row = [string1, string2, string3]
self.APStore.append([string1, string2, string3])

but it makes this: 但这使得:

['blurb', 'WEP', '55/70']

if it matters, I am detecting this using grep. 如果有关系,我正在使用grep检测到这一点。

This did it. 做到了。 I'm not sure if it is the most efficient way, but it worked exactly like I planned. 我不确定这是否是最有效的方法,但是它的工作方式完全符合我的计划。

    i = 0
    for network in output:
        aps["row" + str(i)] = self.APStore.append([network, "", "", ""])
        i = i + 1
    i = 0
    for encrypt in output2:
        self.APStore.set(aps["row" + str(i)], 1, encrypt)
        i = i + 1
    i = 0
    for quality in output3:
        self.APStore.set(aps["row" + str(i)], 2, quality)
        i = i + 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM