예제 #1
0
파일: __init__.py 프로젝트: giflw/afn-tools
 def __init__(self, type, parent, **kwargs):
     object.__setattr__(self, "_resident_ready", False)
     self.type = type
     self.id = libautobus.get_next_id()
     if isinstance(parent, Connection):
         self.parent = None
         self.connection = parent
     else:
         self.parent = parent
         self.connection = parent.connection
     self._schema = self.connection.schema[type]
     self.children = [] # Create even for non-container types to make some
     # iteration stuff simpler. This will just be empty for such types.
     self.server_name, self.doc, self.category = self._schema[0:3]
     if self.parent is None and self.category != TOPLEVEL:
         raise Exception("Containers and widgets must have a container or "
                 "a toplevel specified as the parent when creating the "
                 "widget.")
     if self.parent is not None and self.category == TOPLEVEL:
         raise Exception("Toplevels must not have a parent specified (or "
                 "the parent must be a connection).")
     if self.category != TOPLEVEL and self.parent.category == WIDGET:
         raise Exception("Containers and widgets can only be added to "
                 "toplevels and containers, not other widgets.")
     (self.widget_schema, self.layout_schema, self.state_schema,
     self.call_schema, self.event_schema) = self._schema[3:8]
     for key, (name, doc, writable, default) in self.widget_schema.items():
         if default is None and key not in kwargs:
             raise Exception("Widget property " + key + " is required to "
                     "construct a widget of type " + type + ", but this "
                     "property was unspecified.")
     if self.parent is not None:
         self.parent.validate_layout_attributes(kwargs)
     # At this point we've validated everything, so we can do ahead and
     # start setting stuff up.
     self.connection.widgets[self.id] = self
     self.widget_properties = dict([(k, kwargs.get(k, d)) 
             for k, (n, doc, w, d) in self.widget_schema.items()])
     if self.parent is not None:
         self.layout_properties = dict([(k, kwargs.get(k, d)) 
                 for k, (n, doc, w, d) in self.parent.layout_schema.items()])
     else:
         self.layout_properties = {}
     self.state_properties = dict([(k, d)
             for k, (n, doc, d,) in self.state_schema.items()])
     self.state_events = dict([(k, Event()) for k in self.state_schema.keys()])
     self.events = dict([(k, Event()) for k in self.event_schema.keys()])
     for k in self.events:
         if k in kwargs:
             self.events[k].listen(kwargs[k])
     self.owner.add_child(self)
     self._resident_ready = True
예제 #2
0
파일: __init__.py 프로젝트: giflw/afn-tools
 def __init__(self, socket):
     self.socket = socket
     self.interfaces = []
     self.listeners = [] # List of tuples, each of which contains an
     # interface name and an event name.
     self.watches = [] # List of tuples, each of which contains an
     # interface name and an object name.
     self.message_queue = Queue()
     self.id = get_next_id()
     self.pending_responses = {} # Maps message ids of commands sent to this
     # connection to tuples consisting of the id of a connection that the
     # response should be forwarded to and the message id that the response
     # should have
     self.input_thread = InputThread(socket, self.message_arrived,
                                     self.input_closed)
     self.output_thread = OutputThread(socket, self.read_next_message)