Example #1
0
	def setupChilds(self):
		"If this is a container (a generic object), this does the layouting of the childs"

		self.updateSubjectObject()
		self.firstChildGuiObject = None
		self.childs = {}
		x, y = self.OuterSpace
		maxX, maxY = 0, 0
		lastControl = None

		from utils import iterUserAttribs
		for attr in iterUserAttribs(self.subjectObject):
			try:
				control = buildControl(attr, self)
			except NotImplementedError as e:
				print e
				# Skip this control and continue. The rest of the GUI might still be usable.
				continue
			if not self.firstChildGuiObject:
				self.firstChildGuiObject = control
			if attr.hasUpdateEvent():
				def controlUpdateHandler(control=control):
					do_in_mainthread(lambda: self.updateChild(control), wait=False)
				control._updateHandler = controlUpdateHandler
				attr.updateEvent(self.subjectObject).register(control._updateHandler)
			self.addChild(control)
			self.childs[attr.name] = control
			
			spaceX, spaceY = self.DefaultSpace
			if attr.spaceX is not None: spaceX = attr.spaceX
			if attr.spaceY is not None: spaceY = attr.spaceY
			
			if attr.alignRight and lastControl: # align next right
				x = lastControl.pos[0] + lastControl.size[0] + spaceX
				# y from before
				control.leftGuiObject = lastControl
				if lastControl:
					lastControl.rightGuiObject = control
				
			elif lastControl: # align next below
				x = self.OuterSpace[0]
				y = maxY + spaceY
				control.topGuiObject = lastControl
				if lastControl:
					lastControl.bottomGuiObject = control
			
			else: # very first
				pass
			
			control.pos = (x,y)

			lastControl = control
			maxX = max(maxX, control.pos[0] + control.size[0])
			maxY = max(maxY, control.pos[1] + control.size[1])
		
			control.updateContent()

		# Handy for now. This return might change.
		return (maxX + self.OuterSpace[0], maxY + self.OuterSpace[1])
Example #2
0
    def setupChilds(self):
        """
		If this is a container (a generic object), this creates + setups the child controls.
		It does some initial layouting, also to calculate a size-indication, which is then returned.
		However, you can set another size after it and you are supposed to call `layout()`
		in the end.
		"""

        #self.updateSubjectObject() # XXX: make it explicit? break simple list interface
        self.firstChildGuiObject = None
        self.childs = {}
        x, y = self.OuterSpace
        maxX, maxY = 0, 0
        lastControl = None

        from utils import iterUserAttribs
        for attr in iterUserAttribs(self.subjectObject):
            try:
                control = buildControl(attr, self)
            except NotImplementedError as e:
                print e
                # Skip this control and continue. The rest of the GUI might still be usable.
                continue
            if not self.firstChildGuiObject:
                self.firstChildGuiObject = control
            if attr.hasUpdateEvent():

                def controlUpdateHandler(control=control):
                    do_in_mainthread(lambda: self.updateChild(control),
                                     wait=False)

                control._updateHandler = controlUpdateHandler
                attr.updateEvent(self.subjectObject).register(
                    control._updateHandler)
            self.addChild(control)
            self.childs[attr.name] = control

            spaceX, spaceY = self.DefaultSpace
            if attr.spaceX is not None: spaceX = attr.spaceX
            if attr.spaceY is not None: spaceY = attr.spaceY

            if attr.alignRight and lastControl:  # align next right
                x = lastControl.pos[0] + lastControl.size[0] + spaceX
                # y from before
                control.leftGuiObject = lastControl
                if lastControl:
                    lastControl.rightGuiObject = control

            elif lastControl:  # align next below
                x = self.OuterSpace[0]
                y = maxY + spaceY
                control.topGuiObject = lastControl
                if lastControl:
                    lastControl.bottomGuiObject = control

            else:  # very first
                pass

            control.pos = (x, y)
            control.autoresize = (False, False, False, False
                                  )  # initial, might get changed in `layout()`

            lastControl = control
            maxX = max(maxX, control.pos[0] + control.size[0])
            maxY = max(maxY, control.pos[1] + control.size[1])

            control.updateContent()

        # Recalculate layout based on current size and variable width/height controls.
        # Note that there are some cases where this recalculation is not needed,
        # but its much easier to just call it always now.
        self.layout()

        # Handy for now. This return might change.
        return (maxX + self.OuterSpace[0], maxY + self.OuterSpace[1])
Example #3
0
	def setupChilds(self):
		"""
		If this is a container (a generic object), this creates + setups the child controls.
		It does some initial layouting, also to calculate a size-indication, which is then returned.
		However, you can set another size after it and you are supposed to call `layout()`
		in the end.
		"""

		self.updateSubjectObject()
		self.firstChildGuiObject = None
		self.childs = {}
		x, y = self.OuterSpace
		maxX, maxY = 0, 0
		lastControl = None

		from utils import iterUserAttribs
		for attr in iterUserAttribs(self.subjectObject):
			try:
				control = buildControl(attr, self)
			except NotImplementedError as e:
				print e
				# Skip this control and continue. The rest of the GUI might still be usable.
				continue
			if not self.firstChildGuiObject:
				self.firstChildGuiObject = control
			if attr.hasUpdateEvent():
				def controlUpdateHandler(control=control):
					do_in_mainthread(lambda: self.updateChild(control), wait=False)
				control._updateHandler = controlUpdateHandler
				attr.updateEvent(self.subjectObject).register(control._updateHandler)
			self.addChild(control)
			self.childs[attr.name] = control

			spaceX, spaceY = self.DefaultSpace
			if attr.spaceX is not None: spaceX = attr.spaceX
			if attr.spaceY is not None: spaceY = attr.spaceY
			
			if attr.alignRight and lastControl: # align next right
				x = lastControl.pos[0] + lastControl.size[0] + spaceX
				# y from before
				control.leftGuiObject = lastControl
				if lastControl:
					lastControl.rightGuiObject = control
				
			elif lastControl: # align next below
				x = self.OuterSpace[0]
				y = maxY + spaceY
				control.topGuiObject = lastControl
				if lastControl:
					lastControl.bottomGuiObject = control

			else: # very first
				pass

			control.pos = (x,y)
			control.autoresize = (False,False,False,False) # initial, might get changed in `layout()`

			lastControl = control
			maxX = max(maxX, control.pos[0] + control.size[0])
			maxY = max(maxY, control.pos[1] + control.size[1])
		
			control.updateContent()

		# Recalculate layout based on current size and variable width/height controls.
		# Note that there are some cases where this recalculation is not needed,
		# but its much easier to just call it always now.
		self.layout()

		# Handy for now. This return might change.
		return (maxX + self.OuterSpace[0], maxY + self.OuterSpace[1])