Beispiel #1
0
 def __init__(self):
     super(type(self), self).__init__(
         gobject.TYPE_PYOBJECT,
         gobject.TYPE_STRING,  # Type
         gobject.TYPE_STRING,  # Name
         gobject.TYPE_STRING,  # Email
         gobject.TYPE_STRING,  # Balance
     )
     self._total = DKK(0)
     self.observers = Observers()
Beispiel #2
0
def add_product(mainwindow, products, name, sell_val, buy_val, misc):
    if misc == "":
        misc = None
    product = Product(DKK(sell_val), DKK(buy_val), name, misc = misc)
    products.add(product)
    
    def name(col_updater):
        def send(*args): col_updater(str(product.name))
        product.observers.add("changed(name)", send)
        send()
    def count(col_updater):
        def send(*args):
            if product.count == None:
                col_updater("")
            else:
                col_updater(str(product.count))
        product.observers.add("changed(count)", send)
        send()
    def buy_val(col_updater):
        def send(*args): col_updater(str(product.buy_val))
        product.observers.add("changed(buy_val)", send)
        send()
    def sell_val(col_updater):
        def send(*args): col_updater(str(product.sell_val))
        product.observers.add("changed(sell_val)", send)
        send()
    
    def remove():
        products.discard(product)
    
        
    def edit():
        mainwindow.product_dialog(product.name, product.sell_val, product.buy_val, product.misc)

    observers = Observers()
    observers.add("remove", remove)
    observers.add("edit", edit)
        
    
    mainwindow.add_product((name, count, buy_val, sell_val), observers)
Beispiel #3
0
class AccountStore(gtk.ListStore):
    def __init__(self):
        super(type(self), self).__init__(
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_STRING,  # Type
            gobject.TYPE_STRING,  # Name
            gobject.TYPE_STRING,  # Email
            gobject.TYPE_STRING,  # Balance
        )
        self._total = DKK(0)
        self.observers = Observers()

    @property
    def total(self):
        return self.total

    @total.setter
    def total(self, new):
        old = self._buy_val
        self._buy_val = new
        self.observers.notify("changed(total)", self, old)

    def append(self, account):
        iter = gtk.ListStore.append(self)
        row = self[iter]
        row[0] = account

        for signal, callback in (
            ("changed(type)", update_type),
            ("changed(name)", update_name),
            ("changed(email)", update_email),
            ("changed(balance)", update_balance),
        ):
            account.observers.add(signal, callback, row)
            callback(row, account)

        return iter