mirror of
https://github.com/Apress/foundations-of-pygtk-development.git
synced 2025-07-21 20:01:08 +02:00
27 lines
1.0 KiB
Python
27 lines
1.0 KiB
Python
def remove_row(self, ref, model):
|
|
# Convert the tree row reference to a path and retrieve the iterator.
|
|
path = ref.get_path()
|
|
iter = model.get_iter(path)
|
|
# Only remove the row if it is not a root row.
|
|
parent = model.iter_parent(iter)
|
|
if parent:
|
|
(buy, quantity) = model.get(iter, BUY_IT, QUANTITY)
|
|
(pnum,) = model.get(parent, QUANTITY)
|
|
if (buy):
|
|
pnum -= quantity
|
|
model.set(parent, QUANTITY, pnum)
|
|
iter = model.get_iter(path)
|
|
model.remove(iter)
|
|
|
|
def remove_products(self, button, treeview):
|
|
selection = treeview.get_selection()
|
|
model = treeview.get_model()
|
|
rows = selection.get_selected_rows(model)
|
|
# Create tree row references to all of the selected rows.
|
|
references = []
|
|
for data in rows:
|
|
ref = Gtk.TreeRowReference.new(model, data)
|
|
references.append(ref)
|
|
for ref in references:
|
|
self.remove_row(ref, model)
|