@@ -0,0 +1,3217 @@
+%22%22%22 Pyjamas UI BuilderWidget: takes a PyJsGlade builder spec%0A    and creates a widget.%0A%0ACopyright (C) 2010 Luke Kenneth Casson Leighton %3Clkcl@lkcl.net%3E%0A%0ACreate a BuilderWidget as follows:%0A%0Afrom pyjamas.builder.Builder import Builder%0Afrom pyjamas.ui.BuilderWidget import BuilderWidget%0A%0Aeither:%0A%0Aclass ApplicationEventReceivingClassWhatever:%0A%0A    def onSomeRandomClickThing(self, sender):%0A        print %22some random widget was clicked, it was this one:%22, sender%0A%0A    app = ApplicationEventReceivingClassWhatever()%0A    b = Builder()%0A    xml = %22%3C?xml .... ?%3E%3Cpyjsglade%3E .... %3C/pyjsglade%3E%22%0A    bw = BuilderWidget(Builder=b,%0A                       EventReceiver=app,%0A                       BuilderText=xml_file,%0A                       InstanceName=%22WidgetListedInXmlFile%22)%0A%0Aor:%0A%0A    app = ApplicationEventReceivingClassWhatever()%0A    xml = %22%3C?xml .... ?%3E%3Cpyjsglade%3E .... %3C/pyjsglade%3E%22%0A    b = Builder(xml)%0A    bw = BuilderWidget(Builder=b,%0A                       EventReceiver=app,%0A                       InstanceName=%22WidgetListedInXmlFile%22)%0A%0Aor:%0A%0Aclass BuilderWidgetWithIntegratedEventHandling(BuilderWidget):%0A    def onSomeRandomClickThing(self, sender):%0A        print %22some random widget was clicked, it was this one:%22, sender%0A%0A    b = Builder(xml)%0A    bw = BuilderWidgetWithIntegratedEventHandling(Builder=b,%0A                       InstanceName=%22WidgetListedInXmlFile%22)%0A%0Aor:%0A%0A    b = Builder()%0A    bw = BuilderWidgetWithIntegratedEventHandling(Builder=b,%0A                       BuilderText=xml_file,%0A                       InstanceName=%22WidgetListedInXmlFile%22)%0A%0A%22%22%22%0A%0Afrom pyjamas.ui.Composite import Composite%0A%0A%0Aclass BuilderWidget(Composite):%0A%0A    def __init__(self, **kwargs):%0A        %0A        self.b = None%0A        self.text = None%0A        self.instance_name = None%0A        self.event_receiver = None%0A        Composite.__init__(self, **kwargs)%0A%0A    def setBuilderText(self, text):%0A        self.text = text%0A        self.autoCreateInstance()%0A%0A    def setBuilder(self, builder):%0A        self.b = builder%0A        self.autoCreateInstance()%0A%0A    def setEventReceiver(self, event_receiver):%0A        %22%22%22 sets the instance where the events named in the builder%0A            will be received (callbacks called).%0A            passing in None will set the event receiver to be this%0A            widget.%0A        %22%22%22%0A        self.event_receiver = event_receiver or self%0A        self.autoCreateInstance()%0A%0A    def setInstanceName(self, instance_name):%0A        self.instance_name = instance_name%0A        self.autoCreateInstance()%0A%0A    def autoCreateInstance(self):%0A        %22%22%22 when all the required arguments have been set, the%0A            widget instance will be created.  it's done this way%0A            because **kwargs goes through to pyjamas.ui.Applier,%0A            and the order in which the setXXX functions will be called%0A            cannot be determined or guaranteed (kwargs is a dictionary).%0A        %22%22%22%0A        if self.b:%0A            self.b.setText(self.text)%0A        if not self.b or not self.instance_name or not self.event_receiver:%0A            return%0A        if not self.b.builder_text:%0A            return%0A        widget = self.b.createInstance(self.instance_name, self.event_receiver)%0A        self.initWidget(widget)%0A%0A

add BuilderWidget class