示例#1
0
 def perform_change(self, change):
     if isinstance(change, bind.InsertItem):
         if change.item.widget.parent:
             raise Exception("Can't add a widget that already has a parent")
         if isinstance(self.widget, gtk.Bin) and len(self.children) == 1:
             raise Exception("Can't add more than one child to a bin")
         self.children.insert(change.index, change.item)
         self.widget.add(change.item.widget)
         if change.index < (len(self.children) - 1):
             self.widget.reorder_child(change.item.widget, change.index)
         # Create a ChildPropertyDict for this child
         self.child_prop_dicts.insert(change.index, ChildPropertyDict(self.widget, change.item.widget))
         # Copy all of the child's current child properties that we know about
         for k in self.child_prop_dicts[change.index].keys():
             if k in change.item.child_props:
                 self.child_prop_dicts[change.index][k] = change.item.child_props[k]
         # Then bind the child dict to the child's child dict
         bind.bind(change.item.child_props, self.child_prop_dicts[change.index]) 
         return lambda: self.perform_change(bind.DeleteItem(change.index))
     elif isinstance(change, bind.ReplaceItem):
         with bind.Log() as l:
             l.add(self.perform_change(bind.DeleteItem(change.index)))
             l.add(self.perform_change(bind.InsertItem(change.index, change.item)))
             return l
     elif isinstance(change, bind.DeleteItem):
         item = self.children[change.index]
         del self.children[change.index]
         # Unbind our ChildPropertyDict from the widget's child dict
         bind.unbind(item.child_props, self.child_prop_dicts[change.index])
         # Disconnect our ChildPropertyDict and then delete it
         self.child_prop_dicts[change.index].disconnect()
         del self.child_prop_dicts[change.index]
         # Then remove the actual widget
         self.widget.remove(item.widget)
         return lambda: self.perform_change(bind.InsertItem(change.index, item))
     elif isinstance(change, bind.SetValue):
         # TODO: Really ought to split this out for other widgets too lazy
         # to do any special processing to make use of
         with bind.Log() as l:
             for n in reversed(range(len(self.children))):
                 l.add(self.perform_change(bind.DeleteItem(n)))
             for i, v in enumerate(change.value):
                 l.add(self.perform_change(bind.InsertItem(i, v)))
             return l
     else:
         raise TypeError
示例#2
0
 def __init__(self):
     DWidget.__init__(self, gtk.Entry())
     bind.key_bind(self, "text", self.props, "text")
     bind.key_bind(self, "placeholder", self.props, "placeholder")
     self._delayed = bind.DelayController()
     bind.bind(self._delayed.model, bind.MemoryValue(""))
     bind.bind(self._delayed.view, bind.value_for_dict_key(self, "text"))
     bind.bind(self._delayed.model, bind.value_for_dict_key(self, "delayed_text"))
     self._delayed.save()
     self.widget.connect("focus-out-event", self._save_and_false)
     self.widget.connect("activate", self._save_and_false)
     self.widget.connect("key-press-event", self._key_press)
示例#3
0
文件: test2.py 项目: hzmmzl/afn
 def __init__(self, task_list):
     g.DVBox.__init__(self)
     self.task_list = task_list
     template = bind.ListTranslator(TaskView, None)
     bind.bind(template.a, task_list)
     bind.bind(self.children, template.b)