what i would do is, make a new file in the root/ folder and name it: uiCustomBtn.py
1. paste your code in
import ui
import wndMgr
import localeInfo
import item
import player
import chat
class CustomBtnWindow(ui.ScriptWindow):
def __init__(self):
super(CustomBtnWindow, self).__init__()
self.bonusList = []
def LoadWindow(self):
pyScrLoader = ui.PythonScriptLoader()
pyScrLoader.LoadScriptFile(self, "UIScript/CustomBtn.py")
self.btnClose = self.GetChild("close_button")
self.btnClose.SetEvent(ui.__mem_func__(self.Close))
self.btnExample = self.GetChild("example_button")
self.btnExample.SetEvent(ui.__mem_func__(self.OnExampleClick))
def OnExampleClick(self):
# For demo: fetch a stat and display in chat
stat = player.GetStatus(item.APPLY_MAX_HP)
chat.AppendChat(chat.CHAT_TYPE_INFO, "Max HP: %d" % stat)
def OnPressEscapeKey(self):
self.Close()
return True
def Close(self):
wndMgr.Hide(self.hWnd)
2. In the first lines of root/interfacemodule.py, where all imports are located, add the following import:
from uiCustomBtn import CustomBtnWindow
3. change the method in root/interfacemodule.py like this
def __MakeButton(self):
self.Btn = CustomBtnWindow()
self.Btn.LoadWindow()
# self.Btn.Hide()
def MakeInterface(self):
self.__MakeButton()