コード例 #1
0
class MenueItem():
    def __init__(self, resourceName, fontProperties):
        assert isinstance(fontProperties, FontProperties)
        self.id = None
        self.image = None
        self.TargetView = None
        self.action = None
        self.animation = None
        self._resourceName = resourceName
        self._actionObject = None
        self.text = None
        self._textSurface = None
        self._fontProperties = fontProperties
      

    def configure(self):
        if self.image:
            self.animation = MenuAnimationInfo(self._resourceName, self.image)
        if self.text:
            self._textSurface = TextLabelSurface(self.text, self._fontProperties)
    def executeAction(self):
        if self.TargetView:
            changeviewEvent = pygame.event.Event(EVENT_CHANGEVIEW, ViewName=self.TargetView)
            pygame.event.post(changeviewEvent)

        if self.action:
            actionObject = self.actionFactory(self.action)
            actionObject.doAction()

    def actionFactory(self, actionName):
        module_name = "Actions.{0}".format(actionName)
        actionClass = getattr(importlib.import_module(module_name), actionName)
        return actionClass()

    def getImage(self, imageMinWidth=None):
        result = None
        if self.animation and self._textSurface:
            #merge text and image
            result = self.animation.ImageSurface
            rect = result.get_rect()
            result.blit(self._textSurface.render(rect.width), (0,0))
        elif self.animation:
            return self.animation.ImageSurface
        elif self._textSurface:
            return self._textSurface.render(imageMinWidth)
        return result

    def getItemRect(self):
        img = self.getImage()
        return img.get_rect()
コード例 #2
0
 def configure(self):
     if self.image:
         self.animation = MenuAnimationInfo(self._resourceName, self.image)
     if self.text:
         self._textSurface = TextLabelSurface(self.text, self._fontProperties)