简体   繁体   中英

Dynamically add rows to GTK List PyGObject

I'm trying to add items dynamically detected into a PyGTK listview.

I'm using Python 3 and 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. 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.)

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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