1. import app
  2. import ui
  3. import localeInfo
  4. import uiScriptLocale
  5. class MarkItem(ui.ListBoxEx.Item):
  6. def __init__(self, fileName):
  7. ui.ListBoxEx.Item.__init__(self)
  8. self.imgWidth=0
  9. self.imgHeight=0
  10. self.canLoad=0
  11. self.textLine=self.__CreateTextLine(fileName)
  12. self.imgBox=self.__CreateImageBox("upload/"+fileName)
  13. def __del__(self):
  14. ui.ListBoxEx.Item.__del__(self)
  15. def GetText(self):
  16. return self.textLine.GetText()
  17. def SetSize(self, width, height):
  18. ui.ListBoxEx.Item.SetSize(self, 20 + 6*len(self.textLine.GetText()) + 4, height)
  19. def __CreateTextLine(self, fileName):
  20. textLine=ui.TextLine()
  21. textLine.SetParent(self)
  22. textLine.SetPosition(20, 0)
  23. textLine.SetText(fileName)
  24. textLine.Show()
  25. return textLine
  26. def __CreateImageBox(self, fileName):
  27. (self.canLoad, self.imgWidth, self.imgHeight)=app.GetImageInfo(fileName)
  28. if 1==self.canLoad:
  29. if 16==self.imgWidth and 12==self.imgHeight:
  30. imgBox=ui.ImageBox()
  31. imgBox.AddFlag("not_pick")
  32. imgBox.SetParent(self)
  33. imgBox.SetPosition(0, 2)
  34. imgBox.LoadImage(fileName)
  35. imgBox.Show()
  36. return imgBox
  37. else:
  38. return 0
  39. else:
  40. return 0
  41. class SymbolItem(ui.ListBoxEx.Item):
  42. def __init__(self, fileName):
  43. ui.ListBoxEx.Item.__init__(self)
  44. self.textLine=self.__CreateTextLine(fileName)
  45. (self.canLoad, self.imgWidth, self.imgHeight)=app.GetImageInfo("upload/"+fileName)
  46. def __del__(self):
  47. ui.ListBoxEx.Item.__del__(self)
  48. def GetText(self):
  49. return self.textLine.GetText()
  50. def SetSize(self, width, height):
  51. ui.ListBoxEx.Item.SetSize(self, 6*len(self.textLine.GetText()) + 4, height)
  52. def __CreateTextLine(self, fileName):
  53. textLine=ui.TextLine()
  54. textLine.SetParent(self)
  55. textLine.SetPosition(1, 2)
  56. textLine.SetText(fileName)
  57. textLine.Show()
  58. return textLine
  59. class PopupDialog(ui.ScriptWindow):
  60. def __init__(self, parent):
  61. print "NEW POPUP WINDOW ----------------------------------------------------------------------------"
  62. ui.ScriptWindow.__init__(self)
  63. self.__Load()
  64. self.__Bind()
  65. def __del__(self):
  66. ui.ScriptWindow.__del__(self)
  67. print "---------------------------------------------------------------------------- DELETE POPUP WINDOW"
  68. def __Load(self):
  69. try:
  70. pyScrLoader = ui.PythonScriptLoader()
  71. pyScrLoader.LoadScriptFile(self, "UIScript/PopupDialog.py")
  72. except:
  73. import exception
  74. exception.Abort("PopupDialog.__Load")
  75. def __Bind(self):
  76. try:
  77. self.textLine=self.GetChild("message")
  78. self.okButton=self.GetChild("accept")
  79. except:
  80. import exception
  81. exception.Abort("PopupDialog.__Bind")
  82. self.okButton.SetEvent(ui.__mem_func__(self.__OnOK))
  83. def Open(self, msg):
  84. self.textLine.SetText(msg)
  85. self.SetCenterPosition()
  86. self.Show()
  87. self.SetTop()
  88. def __OnOK(self):
  89. self.Hide()
  90. class MarkSelectDialog(ui.ScriptWindow):
  91. def __init__(self):
  92. print "NEW MARK LIST WINDOW ----------------------------------------------------------------------------"
  93. ui.ScriptWindow.__init__(self)
  94. self.selectEvent=None
  95. self.isLoaded=0
  96. def __del__(self):
  97. ui.ScriptWindow.__del__(self)
  98. print "---------------------------------------------------------------------------- DELETE MARK LIST WINDOW"
  99. def Show(self):
  100. if self.isLoaded==0:
  101. self.isLoaded=1
  102. self.__Load()
  103. ui.ScriptWindow.Show(self)
  104. def Open(self):
  105. self.Show()
  106. self.SetCenterPosition()
  107. self.SetTop()
  108. if self.markListBox.IsEmpty():
  109. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_PATH)
  110. def Close(self):
  111. self.popupDialog.Hide()
  112. self.Hide()
  113. def OnPressEscapeKey(self):
  114. self.Close()
  115. return True
  116. def SAFE_SetSelectEvent(self, event):
  117. self.selectEvent=ui.__mem_func__(event)
  118. def __CreateMarkListBox(self):
  119. markListBox=ui.ListBoxEx()
  120. markListBox.SetParent(self)
  121. markListBox.SetPosition(15, 50)
  122. markListBox.Show()
  123. return markListBox
  124. def __Load(self):
  125. self.popupDialog=PopupDialog(self)
  126. try:
  127. pyScrLoader = ui.PythonScriptLoader()
  128. pyScrLoader.LoadScriptFile(self, "UIScript/MarkListWindow.py")
  129. except:
  130. import exception
  131. exception.Abort("MarkListBox.__Load")
  132. try:
  133. self.markListBox=self.__CreateMarkListBox()
  134. self.markListBox.SetScrollBar(self.GetChild("ScrollBar"))
  135. self.popupText = self.popupDialog.GetChild("message")
  136. self.popupDialog.GetChild("accept").SetEvent(ui.__mem_func__(self.popupDialog.Hide))
  137. self.board=self.GetChild("board")
  138. self.okButton=self.GetChild("ok")
  139. self.cancelButton=self.GetChild("cancel")
  140. self.refreshButton=self.GetChild("refresh")
  141. except:
  142. import exception
  143. exception.Abort("MarkListBox.__Bind")
  144. self.refreshButton.SetEvent(ui.__mem_func__(self.__OnRefresh))
  145. self.cancelButton.SetEvent(ui.__mem_func__(self.__OnCancel))
  146. self.okButton.SetEvent(ui.__mem_func__(self.__OnOK))
  147. self.board.SetCloseEvent(ui.__mem_func__(self.__OnCancel))
  148. self.UpdateRect()
  149. self.__RefreshFileList()
  150. def __PopupMessage(self, msg):
  151. self.popupDialog.Open(msg)
  152. def __OnOK(self):
  153. selItem=self.markListBox.GetSelectedItem()
  154. if selItem:
  155. if selItem.canLoad!=1:
  156. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_FILE_FORMAT)
  157. elif selItem.imgWidth!=16:
  158. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_16_WIDTH)
  159. elif selItem.imgHeight!=12:
  160. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_12_HEIGHT)
  161. else:
  162. self.selectEvent(selItem.GetText())
  163. self.Hide()
  164. else:
  165. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_SELECT)
  166. def __OnCancel(self):
  167. self.Hide()
  168. def __OnRefresh(self):
  169. self.__RefreshFileList()
  170. def __RefreshFileList(self):
  171. self.__ClearFileList()
  172. self.__AppendFileList("bmp")
  173. self.__AppendFileList("tga")
  174. self.__AppendFileList("jpg")
  175. def __ClearFileList(self):
  176. self.markListBox.RemoveAllItems()
  177. def __AppendFileList(self, filter):
  178. fileNameList=app.GetFileList("upload/*."+filter)
  179. for fileName in fileNameList:
  180. self.__AppendFile(fileName)
  181. def __AppendFile(self, fileName):
  182. self.markListBox.AppendItem(MarkItem(fileName))
  183. class SymbolSelectDialog(ui.ScriptWindow):
  184. def __init__(self):
  185. print "NEW SYMBOL LIST WINDOW ----------------------------------------------------------------------------"
  186. ui.ScriptWindow.__init__(self)
  187. self.selectEvent=None
  188. self.isLoaded=0
  189. def __del__(self):
  190. ui.ScriptWindow.__del__(self)
  191. print "---------------------------------------------------------------------------- DELETE SYMBOL LIST WINDOW"
  192. def Show(self):
  193. if self.isLoaded==0:
  194. self.isLoaded=1
  195. self.__Load()
  196. ui.ScriptWindow.Show(self)
  197. def Open(self):
  198. self.Show()
  199. self.SetCenterPosition()
  200. self.SetTop()
  201. if self.symbolListBox.IsEmpty():
  202. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_PATH)
  203. def Close(self):
  204. self.popupDialog.Hide()
  205. self.Hide()
  206. def OnPressEscapeKey(self):
  207. self.Close()
  208. return True
  209. def SAFE_SetSelectEvent(self, event):
  210. self.selectEvent=ui.__mem_func__(event)
  211. def __CreateSymbolListBox(self):
  212. symbolListBox=ui.ListBoxEx()
  213. symbolListBox.SetParent(self)
  214. symbolListBox.SetPosition(15, 50)
  215. symbolListBox.Show()
  216. return symbolListBox
  217. def __Load(self):
  218. self.popupDialog=PopupDialog(self)
  219. try:
  220. pyScrLoader = ui.PythonScriptLoader()
  221. pyScrLoader.LoadScriptFile(self, "UIScript/MarkListWindow.py")
  222. except:
  223. import exception
  224. exception.Abort("SymbolListBox.__Load")
  225. try:
  226. self.symbolListBox=self.__CreateSymbolListBox()
  227. self.symbolListBox.SetScrollBar(self.GetChild("ScrollBar"))
  228. self.popupText = self.popupDialog.GetChild("message")
  229. self.popupDialog.GetChild("accept").SetEvent(ui.__mem_func__(self.popupDialog.Hide))
  230. self.board=self.GetChild("board")
  231. self.okButton=self.GetChild("ok")
  232. self.cancelButton=self.GetChild("cancel")
  233. self.refreshButton=self.GetChild("refresh")
  234. except:
  235. import exception
  236. exception.Abort("SymbolListBox.__Bind")
  237. self.refreshButton.SetEvent(ui.__mem_func__(self.__OnRefresh))
  238. self.cancelButton.SetEvent(ui.__mem_func__(self.__OnCancel))
  239. self.okButton.SetEvent(ui.__mem_func__(self.__OnOK))
  240. self.board.SetCloseEvent(ui.__mem_func__(self.__OnCancel))
  241. self.board.SetTitleName(localeInfo.SYMBOLLIST_TITLE)
  242. self.UpdateRect()
  243. self.__RefreshFileList()
  244. def __PopupMessage(self, msg):
  245. self.popupDialog.Open(msg)
  246. def __OnOK(self):
  247. selItem=self.symbolListBox.GetSelectedItem()
  248. if selItem:
  249. if selItem.canLoad!=1:
  250. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_FILE_FORMAT)
  251. elif selItem.imgWidth!=64:
  252. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_64_WIDTH)
  253. elif selItem.imgHeight!=128:
  254. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_128_HEIGHT)
  255. else:
  256. self.selectEvent(selItem.GetText())
  257. self.Hide()
  258. else:
  259. self.__PopupMessage(localeInfo.GUILDMARK_UPLOADER_ERROR_SELECT)
  260. def __OnCancel(self):
  261. self.Hide()
  262. def __OnRefresh(self):
  263. self.__RefreshFileList()
  264. def __RefreshFileList(self):
  265. self.__ClearFileList()
  266. self.__AppendFileList("jpg")
  267. def __ClearFileList(self):
  268. self.symbolListBox.RemoveAllItems()
  269. def __AppendFileList(self, filter):
  270. fileNameList=app.GetFileList("upload/*."+filter)
  271. for fileName in fileNameList:
  272. self.__AppendFile(fileName)
  273. def __AppendFile(self, fileName):
  274. self.symbolListBox.AppendItem(SymbolItem(fileName))