PageRenderTime 203ms CodeModel.GetById 46ms RepoModel.GetById 0ms app.codeStats 0ms

/beercalc/old/tabs/accounts/table.py

https://github.com/bjornua/beercalc
Python | 54 lines | 40 code | 13 blank | 1 comment | 3 complexity | d808ba0d9c95a577b900edfabd1333a4 MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. import gtk
  3. from beercalc.lib.objects import Account, DKK
  4. class AccountTable(gtk.TreeView):
  5. def __init__(self, store):
  6. super(type(self), self).__init__(model=store)
  7. self.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
  8. self.store = store
  9. self.set_property("rules-hint" , True )
  10. self.set_property("rubber-banding", True )
  11. self.set_property("enable-search" , False)
  12. for n, (title, xalign, expand) in enumerate((
  13. (u"Type" , 0., False),
  14. (u"Navn" , 0., True ),
  15. (u"Email" , 0., False),
  16. (u"Balance", 0., False),
  17. )):
  18. coll = gtk.TreeViewColumn()
  19. cell = gtk.CellRendererText()
  20. coll.pack_start(cell)
  21. coll.set_property("title", title)
  22. coll.set_property("sizing", gtk.TREE_VIEW_COLUMN_AUTOSIZE)
  23. coll.set_property("expand", expand)
  24. coll.add_attribute(cell, 'text', n+1)
  25. cell.set_property("xalign", 0)
  26. self.append_column(coll)
  27. self.connect("focus-in-event", self.OnFocusIn)
  28. self.connect("focus-out-event", self.OnFocusOut)
  29. def OnFocusIn(self, treeview, event):
  30. self.get_toplevel().acg.connect_group(65535, 0, 0, self.OnPressDelete)
  31. def OnFocusOut(self, treeview, event):
  32. acg = self.get_toplevel().acg.disconnect_key(65535,0)
  33. def OnPressDelete(self, *args):
  34. self.remove_selected()
  35. def remove_selected(self):
  36. store, paths = self.get_selection().get_selected_rows()
  37. references = [gtk.TreeRowReference(store, path) for path in paths]
  38. for reference in references:
  39. path = reference.get_path()
  40. iter = store.get_iter(path)
  41. store.remove(iter)