Exemple #1
0
 class ConfigCard(NodePath):
     def __init__(self, parent=None, layoutMargin=.05):
         self.parent = parent or aspect2d
         NodePath.__init__(self, 'config_card')
         self.layout = VLayout(parent=self, margin=layoutMargin)
         self.layout.setPos(-1.25, 0, 0.67)
         self.reparentTo(self.parent)
Exemple #2
0
 class ConfigCard(NodePath):
     def __init__(self, parent = None, layoutMargin = .05):
         self.parent = parent or aspect2d
         NodePath.__init__(self, 'config_card')
         self.layout = VLayout(parent = self, margin = layoutMargin)
         self.layout.setPos(-1.25, 0, 0.67)
         self.reparentTo(self.parent)
Exemple #3
0
class SogalDialog(SogalForm):
    '''
    A dialog that derived from SogalForm
    (Which contains a DirectDialog)
    '''
    def __init__(
            self,
            enableMask=True,  #NOTE THAT IT IS TRUE BY DEFAULT
            autoDestroy=True,
            sortType=0,  #0 for horizontal, 1 for vertical
            margin=0.2,
            textList=['OK', 'Cancel'],
            enablesList=None,
            command=None,
            frameSize=(-0.6, 0.6, -0.45, 0.45),
            buttonSize=BUTTON_SIZE,
            text='',
            textPos=(0, 0.2),
            startPos=(-0.4, 0, -0.2),
            extraArgs=[],
            style=None,
            fadeScreen=0.5,
            backgroundColor=None,
            **kwargs):
        if backgroundColor:
            bgColor = backgroundColor
        elif fadeScreen is not None:
            bgColor = (0, 0, 0, fadeScreen)
        else:
            bgColor = None

        SogalForm.__init__(self,
                           enableMask=enableMask,
                           backgroundColor=bgColor,
                           **kwargs)
        if enableMask:
            self.reparentTo(aspect2d, sort=1000)
        if not style:
            self.__style = base.getStyle()
        else:
            self.__style = color_themes.styles[style]

        self.__frame = DirectFrame(parent=self,
                                   frameSize=frameSize,
                                   **self.__style['hardframe'])
        self.__buttonList = []  #DirectButton(parent = self, s)
        self.__text = OnscreenText(parent=self,
                                   text=text,
                                   pos=textPos,
                                   **self.__style['text'])
        self.__command = command
        self.__autoDestroy = autoDestroy
        self._extraArgs = extraArgs

        if sortType == 0:
            self.__box = HLayout(margin=margin)
        else:
            self.__box = VLayout(margin=margin)
        self.__box.reparentTo(self)
        self.__box.setPos(startPos)

        for i in range(len(textList)):
            btn = DirectButton(text=textList[i],
                               command=self.buttonCommand(i),
                               frameSize=buttonSize,
                               **self.__style['button'])
            self.__buttonList.append(btn)
            self.__box.append(btn)

        if enablesList:
            for i in range(len(enablesList)):
                if i >= len(self.__buttonList):
                    break
                if enablesList[i]:
                    self.__buttonList[i]['state'] = DGG.NORMAL
                else:
                    self.__buttonList[i]['state'] = DGG.DISABLED

        self.show()

    def buttonCommand(self, i):
        commandindex = i

        def process():
            if self.__command:
                self.__command(commandindex, *self._extraArgs)
            if self.__autoDestroy:
                self.close()

        return process

    def close(self):
        for btn in self.__buttonList:
            btn['state'] = DGG.DISABLED
        if self._getFading():
            seq = Sequence(
                Func(self.hide),
                Wait(self._getFadingDuration() + 2),
                Func(self.destroy),
            )
            seq.start()
        else:
            self.destroy()

    def destroy(self):
        for btn in self.__buttonList:
            btn.destroy()
        self.__frame.destroy()
        self.__box.removeNode()
        SogalForm.destroy(self)
Exemple #4
0
class SogalDialog(SogalForm):
    '''
    A dialog that derived from SogalForm
    (Which contains a DirectDialog)
    '''
    def __init__(self,
                 enableMask = True, #NOTE THAT IT IS TRUE BY DEFAULT
                 autoDestroy = True,
                 sortType = 0, #0 for horizontal, 1 for vertical
                 margin = 0.2,
                 textList = ['OK','Cancel'],
                 enablesList = None,
                 command = None,
                 frameSize = (-0.6,0.6,-0.45,0.45),
                 buttonSize = BUTTON_SIZE,
                 text = '',
                 textPos = (0,0.2),
                 startPos = (-0.4,0,-0.2),
                 extraArgs = [],
                 style = None,
                 fadeScreen = 0.5,
                 backgroundColor = None,
                 **kwargs):
        if backgroundColor:
            bgColor = backgroundColor
        elif fadeScreen is not None:
            bgColor = (0,0,0,fadeScreen)
        else:
            bgColor = None
        
        SogalForm.__init__(self,enableMask = enableMask,backgroundColor=bgColor, **kwargs)
        if enableMask:
            self.reparentTo(aspect2d, sort = 1000)
        if not style:
            self.__style = base.getStyle()
        else:
            self.__style = color_themes.styles[style]
        
        self.__frame = DirectFrame(parent = self,frameSize = frameSize,**self.__style['hardframe'])
        self.__buttonList = []#DirectButton(parent = self, s)
        self.__text = OnscreenText(parent = self,text = text ,pos = textPos, **self.__style['text'])
        self.__command = command
        self.__autoDestroy = autoDestroy
        self._extraArgs = extraArgs
        
        if sortType == 0:
            self.__box = HLayout(margin = margin)
        else: self.__box = VLayout(margin = margin)
        self.__box.reparentTo(self)
        self.__box.setPos(startPos)
        
        for i in range(len(textList)):
            btn = DirectButton(text = textList[i], command = self.buttonCommand(i),frameSize = buttonSize, **self.__style['button'])
            self.__buttonList.append(btn)
            self.__box.append(btn)
            
        if enablesList:
            for i in range(len(enablesList)):
                if i >= len(self.__buttonList):
                    break
                if enablesList[i]:
                    self.__buttonList[i]['state'] = DGG.NORMAL
                else: self.__buttonList[i]['state'] = DGG.DISABLED
                
        self.show()
        
    def buttonCommand(self, i):
        commandindex = i
        def process():
            if self.__command:
                self.__command(commandindex, *self._extraArgs)
            if self.__autoDestroy:
                self.close()
        return process

    def close(self):
        for btn in self.__buttonList:
            btn['state'] = DGG.DISABLED
        if self._getFading():
            seq = Sequence(Func(self.hide),
                           Wait(self._getFadingDuration()+2),
                           Func(self.destroy),
                           )
            seq.start()
        else: self.destroy()        
    
            
    def destroy(self):
        for btn in self.__buttonList:
            btn.destroy()
        self.__frame.destroy()
        self.__box.removeNode()
        SogalForm.destroy(self)