Hob: change the code style to enumerate a list in a for-loop

We use the more common style to enumerate a list in a for-loop
(http://docs.python.org/library/functions.html#enumerate), that is:

try to use
for item in mylist,

and try to use
for i, item in enumerate(list)
rather than
for i in range(len(mylist))

(From Poky rev: 33c21bc60bd1542f81d33c328f116dec424728cd)

(Bitbake rev: 9b168239a5d9693573438eb6514938b81de85af3)

Signed-off-by: Shane Wang <shane.wang@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Shane Wang 2012-03-16 13:40:41 +08:00 committed by Richard Purdie
parent dab638e150
commit 9ecdbc377c
3 changed files with 25 additions and 25 deletions

View File

@ -109,38 +109,38 @@ class HobViewTable (gtk.VBox):
self.toggle_columns = []
self.table_tree.connect("row-activated", self.row_activated_cb)
for i in range(len(columns)):
col = gtk.TreeViewColumn(columns[i]['col_name'])
for i, column in enumerate(columns):
col = gtk.TreeViewColumn(column['col_name'])
col.set_clickable(True)
col.set_resizable(True)
col.set_sort_column_id(columns[i]['col_id'])
if 'col_min' in columns[i].keys():
col.set_min_width(columns[i]['col_min'])
if 'col_max' in columns[i].keys():
col.set_max_width(columns[i]['col_max'])
col.set_sort_column_id(column['col_id'])
if 'col_min' in column.keys():
col.set_min_width(column['col_min'])
if 'col_max' in column.keys():
col.set_max_width(column['col_max'])
self.table_tree.append_column(col)
if (not 'col_style' in columns[i].keys()) or columns[i]['col_style'] == 'text':
if (not 'col_style' in column.keys()) or column['col_style'] == 'text':
cell = gtk.CellRendererText()
col.pack_start(cell, True)
col.set_attributes(cell, text=columns[i]['col_id'])
elif columns[i]['col_style'] == 'check toggle':
col.set_attributes(cell, text=column['col_id'])
elif column['col_style'] == 'check toggle':
cell = gtk.CellRendererToggle()
cell.set_property('activatable', True)
cell.connect("toggled", self.toggled_cb, i, self.table_tree)
self.toggle_id = i
col.pack_end(cell, True)
col.set_attributes(cell, active=columns[i]['col_id'])
self.toggle_columns.append(columns[i]['col_name'])
elif columns[i]['col_style'] == 'radio toggle':
col.set_attributes(cell, active=column['col_id'])
self.toggle_columns.append(column['col_name'])
elif column['col_style'] == 'radio toggle':
cell = gtk.CellRendererToggle()
cell.set_property('activatable', True)
cell.set_radio(True)
cell.connect("toggled", self.toggled_cb, i, self.table_tree)
self.toggle_id = i
col.pack_end(cell, True)
col.set_attributes(cell, active=columns[i]['col_id'])
self.toggle_columns.append(columns[i]['col_name'])
col.set_attributes(cell, active=column['col_id'])
self.toggle_columns.append(column['col_name'])
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)

View File

@ -105,16 +105,16 @@ class PackageSelectionPage (HobPage):
self.ins = HobNotebook()
self.tables = [] # we need to modify table when the dialog is shown
# append the tab
for i in range(len(self.pages)):
columns = self.pages[i]['columns']
for page in self.pages:
columns = page['columns']
tab = HobViewTable(columns)
filter = self.pages[i]['filter']
filter = page['filter']
tab.set_model(self.package_model.tree_model(filter))
tab.connect("toggled", self.table_toggled_cb)
if self.pages[i]['name'] == "Included":
if page['name'] == "Included":
tab.connect("row-activated", self.tree_row_activated_cb)
label = gtk.Label(self.pages[i]['name'])
label = gtk.Label(page['name'])
self.ins.append_page(tab, label)
self.tables.append(tab)

View File

@ -127,16 +127,16 @@ class RecipeSelectionPage (HobPage):
self.ins = HobNotebook()
self.tables = [] # we need modify table when the dialog is shown
# append the tabs in order
for i in range(len(self.pages)):
columns = self.pages[i]['columns']
for page in self.pages:
columns = page['columns']
tab = HobViewTable(columns)
filter = self.pages[i]['filter']
filter = page['filter']
tab.set_model(self.recipe_model.tree_model(filter))
tab.connect("toggled", self.table_toggled_cb)
if self.pages[i]['name'] == "Included":
if page['name'] == "Included":
tab.connect("row-activated", self.tree_row_activated_cb)
label = gtk.Label(self.pages[i]['name'])
label = gtk.Label(page['name'])
self.ins.append_page(tab, label)
self.tables.append(tab)