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

/beercalc/old/tabs/accounts/store.py

https://github.com/bjornua/beercalc
Python | 53 lines | 44 code | 8 blank | 1 comment | 1 complexity | 26de7402cbd00ade5cf3301a0478d78b MD5 | raw file
  1. # -*- coding: utf-8 -*-
  2. import gtk
  3. import gobject
  4. from beercalc.lib.objects import DKK
  5. from beercalc.lib import Observers
  6. class AccountStore(gtk.ListStore):
  7. def __init__(self):
  8. super(type(self), self).__init__(
  9. gobject.TYPE_PYOBJECT,
  10. gobject.TYPE_STRING, # Type
  11. gobject.TYPE_STRING, # Name
  12. gobject.TYPE_STRING, # Email
  13. gobject.TYPE_STRING, # Balance
  14. )
  15. self._total = DKK(0)
  16. self.observers = Observers()
  17. @property
  18. def total(self):
  19. return self.total
  20. @total.setter
  21. def total(self, new):
  22. old = self._buy_val
  23. self._buy_val = new
  24. self.observers.notify("changed(total)", self, old)
  25. def append(self, account):
  26. iter = gtk.ListStore.append(self)
  27. row = self[iter]
  28. row[0] = account
  29. for signal, callback in (
  30. ("changed(type)" , update_type ),
  31. ("changed(name)" , update_name ),
  32. ("changed(email)" , update_email ),
  33. ("changed(balance)", update_balance),
  34. ):
  35. account.observers.add(signal, callback, row)
  36. callback(row, account)
  37. return iter
  38. def update_type(row, account, *args):
  39. row[1] = account.type
  40. def update_name(row, account, *args):
  41. row[2] = account.name
  42. def update_email(row, account, *args):
  43. row[3] = account.email
  44. def update_balance(row, account, *args):
  45. row[4] = account.get_balance()