class Window(object):
def NoneMethod(cls):
pass
NoneMethod = classmethod(NoneMethod)
def __init__(self, layer = "UI"):
self.hWnd = None
self.parentWindow = 0
self.onMouseLeftButtonUpEvent = None
self.RegisterWindow(layer)
self.Hide()
if app.ENABLE_SEND_TARGET_INFO:
self.mouseLeftButtonDownEvent = None
self.mouseLeftButtonDownArgs = None
self.mouseLeftButtonUpEvent = None
self.mouseLeftButtonUpArgs = None
self.mouseLeftButtonDoubleClickEvent = None
self.mouseRightButtonDownEvent = None
self.mouseRightButtonDownArgs = None
self.moveWindowEvent = None
self.renderEvent = None
self.renderArgs = None
self.overInEvent = None
self.overInArgs = None
self.overOutEvent = None
self.overOutArgs = None
self.baseX = 0
self.baseY = 0
self.SetWindowName("NONAME_Window")
def __del__(self):
wndMgr.Destroy(self.hWnd)
def RegisterWindow(self, layer):
self.hWnd = wndMgr.Register(self, layer)
def Destroy(self):
pass
def GetWindowHandle(self):
return self.hWnd
def AddFlag(self, style):
wndMgr.AddFlag(self.hWnd, style)
def IsRTL(self):
return wndMgr.IsRTL(self.hWnd)
def SetWindowName(self, Name):
wndMgr.SetName(self.hWnd, Name)
def GetWindowName(self):
return wndMgr.GetName(self.hWnd)
if app.ENABLE_SEND_TARGET_INFO:
def SetParent(self, parent):
if parent:
wndMgr.SetParent(self.hWnd, parent.hWnd)
else:
wndMgr.SetParent(self.hWnd, 0)
def SetAttachParent(self, parent):
wndMgr.SetAttachParent(self.hWnd, parent.hWnd)
else:
def SetParent(self, parent):
wndMgr.SetParent(self.hWnd, parent.hWnd)
def SetParentProxy(self, parent):
self.parentWindow=proxy(parent)
wndMgr.SetParent(self.hWnd, parent.hWnd)
def GetParentProxy(self):
return self.parentWindow
def SetPickAlways(self):
wndMgr.SetPickAlways(self.hWnd)
def SetWindowHorizontalAlignLeft(self):
wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_LEFT)
def SetWindowHorizontalAlignCenter(self):
wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_CENTER)
def SetWindowHorizontalAlignRight(self):
wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_RIGHT)
def SetWindowVerticalAlignTop(self):
wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_TOP)
def SetWindowVerticalAlignCenter(self):
wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_CENTER)
def SetWindowVerticalAlignBottom(self):
wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_BOTTOM)
def SetTop(self):
wndMgr.SetTop(self.hWnd)
def Show(self):
wndMgr.Show(self.hWnd)
def Hide(self):
wndMgr.Hide(self.hWnd)
if app.ENABLE_SEND_TARGET_INFO:
def SetVisible(self, is_show):
if is_show:
self.Show()
else:
self.Hide()
def Lock(self):
wndMgr.Lock(self.hWnd)
def Unlock(self):
wndMgr.Unlock(self.hWnd)
def IsShow(self):
return wndMgr.IsShow(self.hWnd)
def UpdateRect(self):
wndMgr.UpdateRect(self.hWnd)
def SetSize(self, width, height):
wndMgr.SetWindowSize(self.hWnd, width, height)
def GetWidth(self):
return wndMgr.GetWindowWidth(self.hWnd)
def GetHeight(self):
return wndMgr.GetWindowHeight(self.hWnd)
def GetLocalPosition(self):
return wndMgr.GetWindowLocalPosition(self.hWnd)
if app.ENABLE_SEND_TARGET_INFO:
def GetLeft(self):
x, y = self.GetLocalPosition()
return x
def GetGlobalLeft(self):
x, y = self.GetGlobalPosition()
return x
def GetTop(self):
x, y = self.GetLocalPosition()
return y
def GetGlobalTop(self):
x, y = self.GetGlobalPosition()
return y
def GetRight(self):
return self.GetLeft() + self.GetWidth()
def GetBottom(self):
return self.GetTop() + self.GetHeight()
def GetGlobalPosition(self):
return wndMgr.GetWindowGlobalPosition(self.hWnd)
def GetMouseLocalPosition(self):
return wndMgr.GetMouseLocalPosition(self.hWnd)
def GetRect(self):
return wndMgr.GetWindowRect(self.hWnd)
if app.ENABLE_SEND_TARGET_INFO:
def SetLeft(self, x):
wndMgr.SetWindowPosition(self.hWnd, x, self.GetTop())
def SetPosition(self, x, y):
wndMgr.SetWindowPosition(self.hWnd, x, y)
def SetCenterPosition(self, x = 0, y = 0):
self.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 + x, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 + y)
if app.ENABLE_SEND_TARGET_INFO:
def SavePosition(self):
self.baseX = self.GetLeft()
self.baseY = self.GetTop()
def UpdatePositionByScale(self, scale):
self.SetPosition(self.baseX * scale, self.baseY * scale)
def IsFocus(self):
return wndMgr.IsFocus(self.hWnd)
def SetFocus(self):
wndMgr.SetFocus(self.hWnd)
def KillFocus(self):
wndMgr.KillFocus(self.hWnd)
def GetChildCount(self):
return wndMgr.GetChildCount(self.hWnd)
def IsIn(self):
return wndMgr.IsIn(self.hWnd)
if app.ENABLE_SEND_TARGET_INFO:
def IsInPosition(self):
xMouse, yMouse = wndMgr.GetMousePosition()
x, y = self.GetGlobalPosition()
return xMouse >= x and xMouse < x + self.GetWidth() and yMouse >= y and yMouse < y + self.GetHeight()
def SetMouseLeftButtonDownEvent(self, event, *args):
self.mouseLeftButtonDownEvent = event
self.mouseLeftButtonDownArgs = args
def OnMouseLeftButtonDown(self):
if self.mouseLeftButtonDownEvent:
apply(self.mouseLeftButtonDownEvent, self.mouseLeftButtonDownArgs)
if app.ENABLE_SEND_TARGET_INFO:
def SetMouseLeftButtonUpEvent(self, event, *args):
self.mouseLeftButtonUpEvent = event
self.mouseLeftButtonUpArgs = args
else:
def SetOnMouseLeftButtonUpEvent(self, event):
self.onMouseLeftButtonUpEvent = ev
if app.ENABLE_SEND_TARGET_INFO:
def SetMouseLeftButtonDoubleClickEvent(self, event):
self.mouseLeftButtonDoubleClickEvent = event
def OnMouseLeftButtonDoubleClick(self):
if self.mouseLeftButtonDoubleClickEvent:
self.mouseLeftButtonDoubleClickEvent()
def SetMouseRightButtonDownEvent(self, event, *args):
self.mouseRightButtonDownEvent = event
self.mouseRightButtonDownArgs = args
def OnMouseRightButtonDown(self):
if self.mouseRightButtonDownEvent:
apply(self.mouseRightButtonDownEvent, self.mouseRightButtonDownArgs)
def SetMoveWindowEvent(self, event):
self.moveWindowEvent = event
def OnMoveWindow(self, x, y):
if self.moveWindowEvent:
self.moveWindowEvent(x, y)
def SAFE_SetOverInEvent(self, func, *args):
self.overInEvent = __mem_func__(func)
self.overInArgs = args
def SetOverInEvent(self, func, *args):
self.overInEvent = func
self.overInArgs = args
def SAFE_SetOverOutEvent(self, func, *args):
self.overOutEvent = __mem_func__(func)
self.overOutArgs = args
def SetOverOutEvent(self, func, *args):
self.overOutEvent = func
self.overOutArgs = args
def OnMouseOverIn(self):
if self.overInEvent:
apply(self.overInEvent, self.overInArgs)
def OnMouseOverOut(self):
if self.overOutEvent:
apply(self.overOutEvent, self.overOutArgs)
def SAFE_SetRenderEvent(self, event, *args):
self.renderEvent = __mem_func__(event)
self.renderArgs = args
def ClearRenderEvent(self):
self.renderEvent = None
self.renderArgs = None
def OnRender(self):
if self.renderEvent:
apply(self.renderEvent, self.renderArgs)
def OnMouseLeftButtonUp(self):
if self.onMouseLeftButtonUpEvent:
self.onMouseLeftButtonUpEvent()