Advertisement
Guest User

uipickmoney.py

a guest
Dec 1st, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.26 KB | None | 0 0
  1. import wndMgr
  2. import ui
  3. import ime
  4. import localeInfo
  5. import chat
  6. import app
  7.  
  8. class PickMoneyDialog(ui.ScriptWindow):
  9.     def __init__(self):
  10.         ui.ScriptWindow.__init__(self)
  11.  
  12.         self.unitValue = 1
  13.         self.maxValue = 0
  14.         self.eventAccept = 0
  15.         if app.ENABLE_CHEQUE_SYSTEM:
  16.             self.chequeMaxValue = 0
  17.  
  18.     def __del__(self):
  19.         ui.ScriptWindow.__del__(self)
  20.  
  21.     def LoadDialog(self):
  22.         try:
  23.             pyScrLoader = ui.PythonScriptLoader()
  24.             pyScrLoader.LoadScriptFile(self, "UIScript/PickMoneyDialog.py")
  25.         except:
  26.             import exception
  27.             exception.Abort("MoneyDialog.LoadDialog.LoadScript")
  28.  
  29.         try:
  30.             self.board = self.GetChild("board")
  31.             self.maxValueTextLine = self.GetChild("max_value")
  32.             self.pickValueEditLine = self.GetChild("money_value")
  33.             if app.ENABLE_CHEQUE_SYSTEM:
  34.                 self.chequeMaxValueTextLine = self.GetChild("cheque_max_value")
  35.                 self.pickChequeValueEditLine = self.GetChild("cheque_value")
  36.             self.acceptButton = self.GetChild("accept_button")
  37.             self.cancelButton = self.GetChild("cancel_button")
  38.         except:
  39.             import exception
  40.             exception.Abort("MoneyDialog.LoadDialog.BindObject")
  41.  
  42.         self.pickValueEditLine.SetReturnEvent(ui.__mem_func__(self.OnAccept))
  43.         self.pickValueEditLine.SetEscapeEvent(ui.__mem_func__(self.Close))
  44.         if app.ENABLE_CHEQUE_SYSTEM:
  45.             self.pickChequeValueEditLine.SetReturnEvent(ui.__mem_func__(self.OnAccept))
  46.             self.pickChequeValueEditLine.SetEscapeEvent(ui.__mem_func__(self.Close))
  47.         self.acceptButton.SetEvent(ui.__mem_func__(self.OnAccept))
  48.         self.cancelButton.SetEvent(ui.__mem_func__(self.Close))
  49.         self.board.SetCloseEvent(ui.__mem_func__(self.Close))
  50.  
  51.     def Destroy(self):
  52.         self.ClearDictionary()
  53.         self.eventAccept = 0
  54.         self.maxValue = 0
  55.         self.pickValueEditLine = 0
  56.         if app.ENABLE_CHEQUE_SYSTEM:
  57.             self.chequeMaxValue = 0
  58.             self.pickChequeValueEditLine = 0
  59.         self.acceptButton = 0
  60.         self.cancelButton = 0
  61.         self.board = None
  62.  
  63.     def SetTitleName(self, text):
  64.         self.board.SetTitleName(text)
  65.  
  66.     def SetAcceptEvent(self, event):
  67.         self.eventAccept = event
  68.  
  69.     def SetMax(self, max):
  70.         self.pickValueEditLine.SetMax(max)
  71.  
  72.     def Open(self, maxValue, chequeMaxValue = None, unitValue=1):
  73.  
  74.         if localeInfo.IsYMIR() or localeInfo.IsCHEONMA() or localeInfo.IsHONGKONG():
  75.             unitValue = ""
  76.  
  77.         width = self.GetWidth()
  78.         (mouseX, mouseY) = wndMgr.GetMousePosition()
  79.  
  80.         if mouseX + width/2 > wndMgr.GetScreenWidth():
  81.             xPos = wndMgr.GetScreenWidth() - width
  82.         elif mouseX - width/2 < 0:
  83.             xPos = 0
  84.         else:
  85.             xPos = mouseX - width/2
  86.  
  87.         self.SetPosition(xPos, mouseY - self.GetHeight() - 20)
  88.  
  89.         if chequeMaxValue is None:
  90.             self.chequeMaxValueTextLine.Hide()
  91.             self.pickChequeValueEditLine.Hide()
  92.         if localeInfo.IsARABIC():
  93.             self.maxValueTextLine.SetText("/" + str(maxValue))
  94.             if app.ENABLE_CHEQUE_SYSTEM and chequeMaxValue is not None:
  95.                 self.chequeMaxValueTextLine.SetText("/" + str(chequeMaxValue))
  96.         else:
  97.             self.maxValueTextLine.SetText(" / " + str(maxValue))
  98.             if app.ENABLE_CHEQUE_SYSTEM and chequeMaxValue is not None:
  99.                 self.chequeMaxValueTextLine.SetText(" / " + str(chequeMaxValue))
  100.  
  101.         if app.ENABLE_CHEQUE_SYSTEM:
  102.             self.pickChequeValueEditLine.SetText("0")
  103.         self.pickValueEditLine.SetText(str(unitValue))
  104.         self.pickValueEditLine.SetFocus()
  105.  
  106.         ime.SetCursorPosition(1)
  107.  
  108.         self.unitValue = unitValue
  109.         self.maxValue = maxValue
  110.         if app.ENABLE_CHEQUE_SYSTEM and chequeMaxValue is not None:
  111.             self.chequeMaxValue = chequeMaxValue
  112.         self.Show()
  113.         self.SetTop()
  114.  
  115.     def Close(self):
  116.         self.pickValueEditLine.KillFocus()
  117.         if app.ENABLE_CHEQUE_SYSTEM:
  118.             self.pickChequeValueEditLine.KillFocus()
  119.         self.Hide()
  120.  
  121.     def OnAccept(self):
  122.         text = self.pickValueEditLine.GetText()
  123.         if app.ENABLE_CHEQUE_SYSTEM:
  124.             text2 = self.pickChequeValueEditLine.GetText()
  125.             if (len(text) > 0 and text.isdigit()) or (len(text2) > 0 and text2.isdigit()):
  126.                 money = long(text)
  127.                 money = min(money, self.maxValue)
  128.                 cheque = int(text2)
  129.                 cheque = min(cheque, self.chequeMaxValue)
  130.                 if self.eventAccept and (money > 0 or cheque > 0):
  131.                     self.eventAccept(money, cheque)
  132.         else:
  133.             if len(text) > 0 and text.isdigit():
  134.  
  135.                 money = long(text)
  136.                 money = min(money, self.maxValue)
  137.  
  138.                 if money > 0 or cheque > 0:
  139.                     if self.eventAccept:
  140.                         self.eventAccept(money, cheque)
  141.                 else:
  142.                     chat.AppendChat(chat.CHAT_TYPE_INFO, "insert 0 if no money or won")
  143.             else:
  144.                 chat.AppendChat(chat.CHAT_TYPE_INFO, "insert value 0 or amount")
  145.  
  146.         self.Close()
  147.  
  148. class PickMoneyDialog2(ui.ScriptWindow):
  149.     def __init__(self):
  150.         ui.ScriptWindow.__init__(self)
  151.  
  152.         self.unitValue = 1
  153.         self.maxValue = 0
  154.         self.eventAccept = 0
  155.  
  156.     def __del__(self):
  157.         ui.ScriptWindow.__del__(self)
  158.  
  159.     def LoadDialog(self):
  160.         try:
  161.             pyScrLoader = ui.PythonScriptLoader()
  162.             pyScrLoader.LoadScriptFile(self, "UIScript/PickMoneyDialog2.py")
  163.         except:
  164.             import exception
  165.             exception.Abort("MoneyDialog.LoadDialog.LoadScript")
  166.  
  167.         try:
  168.             self.board = self.GetChild("board")
  169.             self.maxValueTextLine = self.GetChild("max_value")
  170.             self.pickValueEditLine = self.GetChild("money_value")
  171.             self.acceptButton = self.GetChild("accept_button")
  172.             self.cancelButton = self.GetChild("cancel_button")
  173.         except:
  174.             import exception
  175.             exception.Abort("MoneyDialog.LoadDialog.BindObject")
  176.  
  177.         self.pickValueEditLine.SetReturnEvent(ui.__mem_func__(self.OnAccept))
  178.         self.pickValueEditLine.SetEscapeEvent(ui.__mem_func__(self.Close))
  179.         self.acceptButton.SetEvent(ui.__mem_func__(self.OnAccept))
  180.         self.cancelButton.SetEvent(ui.__mem_func__(self.Close))
  181.         self.board.SetCloseEvent(ui.__mem_func__(self.Close))
  182.  
  183.     def Destroy(self):
  184.         self.ClearDictionary()
  185.         self.eventAccept = 0
  186.         self.maxValue = 0
  187.         self.pickValueEditLine = 0
  188.         self.acceptButton = 0
  189.         self.cancelButton = 0
  190.         self.board = None
  191.  
  192.     def SetTitleName(self, text):
  193.         self.board.SetTitleName(text)
  194.  
  195.     def SetAcceptEvent(self, event):
  196.         self.eventAccept = event
  197.  
  198.     def SetMax(self, max):
  199.         self.pickValueEditLine.SetMax(max)
  200.  
  201.     def Open(self, maxValue, unitValue=1):
  202.  
  203.         if localeInfo.IsYMIR() or localeInfo.IsCHEONMA() or localeInfo.IsHONGKONG():
  204.             unitValue = ""
  205.  
  206.         width = self.GetWidth()
  207.         (mouseX, mouseY) = wndMgr.GetMousePosition()
  208.  
  209.         if mouseX + width/2 > wndMgr.GetScreenWidth():
  210.             xPos = wndMgr.GetScreenWidth() - width
  211.         elif mouseX - width/2 < 0:
  212.             xPos = 0
  213.         else:
  214.             xPos = mouseX - width/2
  215.  
  216.         self.SetPosition(xPos, mouseY - self.GetHeight() - 20)
  217.  
  218.         if localeInfo.IsARABIC():
  219.             self.maxValueTextLine.SetText("/" + str(maxValue))
  220.         else:
  221.             self.maxValueTextLine.SetText(" / " + str(maxValue))
  222.  
  223.         self.pickValueEditLine.SetText(str(unitValue))
  224.         self.pickValueEditLine.SetFocus()
  225.  
  226.         ime.SetCursorPosition(1)
  227.  
  228.         self.unitValue = unitValue
  229.         self.maxValue = maxValue
  230.         self.Show()
  231.         self.SetTop()
  232.  
  233.     def Close(self):
  234.         self.pickValueEditLine.KillFocus()
  235.         self.Hide()
  236.  
  237.     def OnAccept(self):
  238.         text = self.pickValueEditLine.GetText()
  239.  
  240.         if len(text) > 0 and text.isdigit():
  241.             money = long(text)
  242.             money = min(money, self.maxValue)
  243.  
  244.             if money > 0:
  245.                 if self.eventAccept:
  246.                     self.eventAccept(money)
  247.             else:
  248.                 chat.AppendChat(chat.CHAT_TYPE_INFO, "Veuillez saisir une valeur supérieur à 0.")
  249.         else:
  250.             chat.AppendChat(chat.CHAT_TYPE_INFO, "Veuillez saisir une valeur supérieur à 0.")
  251.  
  252.         self.Close()
  253.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement