Advertisement
thanato1994

uipickmoney.py

Dec 7th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. import wndMgr
  2. import ui
  3. import ime
  4. import localeInfo
  5.  
  6. class PickMoneyDialog(ui.ScriptWindow):
  7. def __init__(self):
  8. ui.ScriptWindow.__init__(self)
  9.  
  10. self.unitValue = 1
  11. self.maxValue = 0
  12. self.eventAccept = 0
  13.  
  14. def __del__(self):
  15. ui.ScriptWindow.__del__(self)
  16.  
  17. def LoadDialog(self):
  18. try:
  19. pyScrLoader = ui.PythonScriptLoader()
  20. pyScrLoader.LoadScriptFile(self, "UIScript/PickMoneyDialog.py")
  21. except:
  22. import exception
  23. exception.Abort("MoneyDialog.LoadDialog.LoadScript")
  24.  
  25. try:
  26. self.board = self.GetChild("board")
  27. self.maxValueTextLine = self.GetChild("max_value")
  28. self.pickValueEditLine = self.GetChild("money_value")
  29. self.acceptButton = self.GetChild("accept_button")
  30. self.cancelButton = self.GetChild("cancel_button")
  31. except:
  32. import exception
  33. exception.Abort("MoneyDialog.LoadDialog.BindObject")
  34.  
  35. self.pickValueEditLine.SetReturnEvent(ui.__mem_func__(self.OnAccept))
  36. self.pickValueEditLine.SetEscapeEvent(ui.__mem_func__(self.Close))
  37. self.acceptButton.SetEvent(ui.__mem_func__(self.OnAccept))
  38. self.cancelButton.SetEvent(ui.__mem_func__(self.Close))
  39. self.board.SetCloseEvent(ui.__mem_func__(self.Close))
  40.  
  41. def Destroy(self):
  42. self.ClearDictionary()
  43. self.eventAccept = 0
  44. self.maxValue = 0
  45. self.pickValueEditLine = 0
  46. self.acceptButton = 0
  47. self.cancelButton = 0
  48. self.board = None
  49.  
  50. def SetTitleName(self, text):
  51. self.board.SetTitleName(text)
  52.  
  53. def SetAcceptEvent(self, event):
  54. self.eventAccept = event
  55.  
  56. def SetMax(self, max):
  57. self.pickValueEditLine.SetMax(max)
  58.  
  59. def Open(self, maxValue, unitValue=1):
  60.  
  61. if localeInfo.IsYMIR() or localeInfo.IsCHEONMA() or localeInfo.IsHONGKONG():
  62. unitValue = ""
  63.  
  64. width = self.GetWidth()
  65. (mouseX, mouseY) = wndMgr.GetMousePosition()
  66.  
  67. if mouseX + width/2 > wndMgr.GetScreenWidth():
  68. xPos = wndMgr.GetScreenWidth() - width
  69. elif mouseX - width/2 < 0:
  70. xPos = 0
  71. else:
  72. xPos = mouseX - width/2
  73.  
  74. self.SetPosition(xPos, mouseY - self.GetHeight() - 20)
  75.  
  76. if localeInfo.IsARABIC():
  77. self.maxValueTextLine.SetText("/" + str(maxValue))
  78. else:
  79. self.maxValueTextLine.SetText(" / " + str(maxValue))
  80.  
  81. self.pickValueEditLine.SetText(str(unitValue))
  82. self.pickValueEditLine.SetFocus()
  83.  
  84. ime.SetCursorPosition(1)
  85.  
  86. self.unitValue = unitValue
  87. self.maxValue = maxValue
  88. self.Show()
  89. self.SetTop()
  90.  
  91. def Close(self):
  92. self.pickValueEditLine.KillFocus()
  93. self.Hide()
  94.  
  95. def OnAccept(self):
  96.  
  97. text = self.pickValueEditLine.GetText()
  98.  
  99. if len(text) > 0 and text.isdigit():
  100.  
  101. money = long(text)
  102. money = min(money, self.maxValue)
  103.  
  104. if money > 0:
  105. if self.eventAccept:
  106. self.eventAccept(money)
  107.  
  108. self.Close()
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement