예제 #1
0
class BuildingCtrls(Group):

    uppercaseAccents = False

    def __init__(self, posSize, uppercaseAccents, callbackAttrs, callbackCheck,
                 callbackBuild):
        super(BuildingCtrls, self).__init__(posSize)
        x, y, width, height = posSize
        self.uppercaseAccents = uppercaseAccents
        self.callbackAttrs = callbackAttrs
        self.callbackCheck = callbackCheck
        self.callbackBuild = callbackBuild

        jumpinY = 0
        self.uppercaseCheck = CheckBox(
            (0, jumpinY, width, vanillaControlsSize['CheckBoxRegularHeight']),
            'Use Uppercase accents',
            value=self.uppercaseAccents,
            callback=self.uppercaseCheckCallback)
        self.uppercaseCheck.enable(False)

        jumpinY += self.uppercaseCheck.getPosSize()[3] + MARGIN_ROW + 2
        self.checkButton = Button((0, jumpinY, width * .45,
                                   vanillaControlsSize['ButtonRegularHeight']),
                                  'Check',
                                  callback=self.checkButtonCallback)
        self.buildButton = Button((width * .55, jumpinY, width * .45,
                                   vanillaControlsSize['ButtonRegularHeight']),
                                  'Build',
                                  callback=self.buildButtonCallback)

    def getUppercaseAccents(self):
        return self.uppercaseAccents

    def uppercaseCheckCallback(self, sender):
        self.callbackAttrs(self)

    def checkButtonCallback(self, sender):
        self.callbackCheck(self)

    def buildButtonCallback(self, sender):
        self.callbackBuild(self)
예제 #2
0
파일: grids.py 프로젝트: late2game/ttools2
class SingleGridController(Group):
    """this controller takes care of canvas grid drawing"""
    def __init__(self, posSize, index, isVertical, isHorizontal, step,
                 gridColor, callback):
        Group.__init__(self, posSize)

        # from arguments to attributes
        self.ctrlX, self.ctrlY, self.ctrlWidth, self.ctrlHeight = posSize
        self.index = index
        self.isVertical = isVertical
        self.isHorizontal = isHorizontal
        self.step = step
        self.gridColor = gridColor
        self.callback = callback

        # ctrls
        jumpin_X = 12
        self.indexText = TextBox(
            (jumpin_X, 0, 16, vanillaControlsSize['TextBoxRegularHeight']),
            '{:d})'.format(index))
        jumpin_X += self.indexText.getPosSize()[2]

        self.stepCtrl = EditText(
            (jumpin_X, 0, 38, vanillaControlsSize['EditTextRegularHeight']),
            callback=self.stepCtrlCallback)
        jumpin_X += self.stepCtrl.getPosSize()[2] + 16

        self.isHorizontalCheck = CheckBox(
            (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']),
            "H",
            value=self.isHorizontal,
            callback=self.isHorizontalCheckCallback)
        jumpin_X += self.isHorizontalCheck.getPosSize()[2] + 2

        self.isVerticalCheck = CheckBox(
            (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']),
            "V",
            value=self.isVertical,
            callback=self.isVerticalCheckCallback)
        jumpin_X += self.isVerticalCheck.getPosSize()[2] + 10

        self.whichColorWell = ColorWell(
            (jumpin_X, 0, 46, self.ctrlHeight),
            color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*gridColor),
            callback=self.whichColorWellCallback)

    def enable(self, onOff):
        self.indexText.enable(onOff)
        self.stepCtrl.enable(onOff)
        self.isHorizontalCheck.enable(onOff)
        self.isVerticalCheck.enable(onOff)
        self.whichColorWell.enable(onOff)

    def get(self):
        return self.index - 1, {
            'horizontal': self.isHorizontal,
            'vertical': self.isVertical,
            'step': self.step,
            'color': self.gridColor
        }

    def stepCtrlCallback(self, sender):
        try:
            self.step = int(sender.get())
            self.callback(self)
        except ValueError as error:
            self.step = None
            self.stepCtrl.set('')

    def isHorizontalCheckCallback(self, sender):
        self.isHorizontal = bool(sender.get())
        self.callback(self)

    def isVerticalCheckCallback(self, sender):
        self.isVertical = bool(sender.get())
        self.callback(self)

    def whichColorWellCallback(self, sender):
        calibratedColor = sender.get()
        self.gridColor = (calibratedColor.redComponent(),
                          calibratedColor.greenComponent(),
                          calibratedColor.blueComponent(),
                          calibratedColor.alphaComponent())
        self.callback(self)