JustPaste.it

class Button(Window):
    def __init__(self, layer = "UI"):
        Window.__init__(self, layer)

        self.eventFunc = None
        self.eventArgs = None

        self.ButtonText = None
        self.ToolTipText = None

    def __del__(self):
        Window.__del__(self)

        self.eventFunc = None
        self.eventArgs = None

    def RegisterWindow(self, layer):
        self.hWnd = wndMgr.RegisterButton(self, layer)

    def SetUpVisual(self, filename):
        wndMgr.SetUpVisual(self.hWnd, filename)

    def SetOverVisual(self, filename):
        wndMgr.SetOverVisual(self.hWnd, filename)

    def SetDownVisual(self, filename):
        wndMgr.SetDownVisual(self.hWnd, filename)

    def SetDisableVisual(self, filename):
        wndMgr.SetDisableVisual(self.hWnd, filename)

    def GetUpVisualFileName(self):
        return wndMgr.GetUpVisualFileName(self.hWnd)

    def GetOverVisualFileName(self):
        return wndMgr.GetOverVisualFileName(self.hWnd)

    def GetDownVisualFileName(self):
        return wndMgr.GetDownVisualFileName(self.hWnd)

    def Flash(self):
        wndMgr.Flash(self.hWnd)

    def Enable(self):
        wndMgr.Enable(self.hWnd)

    def Disable(self):
        wndMgr.Disable(self.hWnd)

    def Down(self):
        wndMgr.Down(self.hWnd)

    def SetUp(self):
        wndMgr.SetUp(self.hWnd)

    def SAFE_SetEvent(self, func, *args):
        self.eventFunc = __mem_func__(func)
        self.eventArgs = args
        
    def SetEvent(self, func, *args):
        self.eventFunc = func
        self.eventArgs = args

    def SetTextColor(self, color):
        if not self.ButtonText:
            return
        self.ButtonText.SetPackedFontColor(color)

    def SetText(self, text, height = 4):

        if not self.ButtonText:
            textLine = TextLine()
            textLine.SetParent(self)
            textLine.SetPosition(self.GetWidth()/2, self.GetHeight()/2)
            textLine.SetVerticalAlignCenter()
            textLine.SetHorizontalAlignCenter()
            textLine.Show()
            self.ButtonText = textLine

        self.ButtonText.SetText(text)
                
    def GetText(self):
            if not self.ButtonText:
                    return# ""
            return self.ButtonText.GetText()
            
    def SetFormToolTipText(self, type, text, x, y):
        if not self.ToolTipText:        
            toolTip=createToolTipWindowDict[type]()
            toolTip.SetParent(self)
            toolTip.SetSize(0, 0)
            toolTip.SetHorizontalAlignCenter()
            toolTip.SetOutline()
            toolTip.Hide()
            toolTip.SetPosition(x + self.GetWidth()/2, y)
            self.ToolTipText=toolTip

        self.ToolTipText.SetText(text)

    def SetToolTipWindow(self, toolTip):        
        self.ToolTipText=toolTip        
        self.ToolTipText.SetParentProxy(self)

    def SetToolTipText(self, text, x=0, y = -19):
        self.SetFormToolTipText("TEXT", text, x, y)

    def CallEvent(self):
        snd.PlaySound("sound/ui/click.wav")

        if self.eventFunc:
            apply(self.eventFunc, self.eventArgs)

    def ShowToolTip(self):
        if self.ToolTipText:
            self.ToolTipText.Show()

    def HideToolTip(self):
        if self.ToolTipText:
            self.ToolTipText.Hide()
            
    def IsDown(self):
        return wndMgr.IsDown(self.hWnd)

    if app.ENABLE_SKILL_COLOR_SYSTEM:
        def SetTextAlignLeft(self, text, x = 27, height = 4):
            if not self.ButtonText:
                textLine = TextLine()
                textLine.SetParent(self)
                textLine.SetPosition(x, self.GetHeight()/2)
                textLine.SetVerticalAlignCenter()
                textLine.SetHorizontalAlignLeft()
                textLine.Show()
                self.ButtonText = textLine

            self.ButtonText.SetText(text)
            self.ButtonText.SetPosition(x, self.GetHeight()/2)
            self.ButtonText.SetVerticalAlignCenter()
            self.ButtonText.SetHorizontalAlignLeft()

        def SetListText(self, text, x = 8):
            if not self.ButtonText:
                textLine = TextLine()
                textLine.SetParent(self)
                textLine.SetPosition(x, self.GetHeight()/2)
                textLine.SetVerticalAlignCenter()
                textLine.SetHorizontalAlignLeft()
                textLine.Show()
                self.ButtonText = textLine

            self.ButtonText.SetText(text)