Honorable Member Owsap 8162 Posted March 27, 2023 Honorable Member Share Posted March 27, 2023 (edited) As the title indicates, I'm sharing with everyone my test script for creating UI's, systems, etc... The advantage of this tool is that you don't need to restart your client every time you make a change which time is crucial. This tool will certainly help you tremendously if you know how to use it correctly. I will not go in much detail on how to use it because it's very basic and understandable. As long as you respect the primary class name and contain the default methods in the class, you're good. Otherwise, if you know what you're doing then you can modify the script to your liking. uiTestScript.py # # File : uiTestScript.py # Author : Owsap # Copyright (C) 2023 Owsap Development # import app import ui import wndMgr import uiToolTip import localeInfo """ # Example: # uiTest.py class TestWindow(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) def __del__(self): ui.ScriptWindow.__del__(self) def Show(self): ui.ScriptWindow.Show(self) def Hide(self): ui.ScriptWindow.Hide(self) """ def LoadModule(name): import sys, imp if name in sys.modules: del sys.modules[name] if name in locals(): del locals()[name] if name in globals(): del globals()[name] module_info = imp.find_module(name) module = imp.load_module(name, *module_info) if not module in locals(): locals()[name] = module if not module in globals(): globals()[name] = module return module class TestScript(ui.BoardWithTitleBar): BOARD_WIDTH = 230 BOARD_HEIGHT = 80 SLOT_WIDTH = 150 def __init__(self): ui.BoardWithTitleBar.__init__(self) self.wndScript = None ## Item ToolTip self.tooltipItem = uiToolTip.ItemToolTip() self.tooltipItem.Hide() ## Board self.SetSize(self.BOARD_WIDTH, self.BOARD_HEIGHT) self.SetPosition(0, wndMgr.GetScreenHeight() - self.BOARD_HEIGHT) self.AddFlag("movable") self.SetTitleName("Test Script") self.SetCloseEvent(self.Hide) self.Show() ## Board > Slot Bar slotBar = ui.SlotBar() slotBar.SetParent(self) slotBar.SetSize(self.SLOT_WIDTH, 18) slotBar.SetPosition(13, 32) slotBar.Show() self.slotBar = slotBar ## Board > Slot Bar > EditLine editLine = ui.EditLine() editLine.SetParent(self.slotBar) editLine.SetSize(self.SLOT_WIDTH, 18) editLine.SetPosition(4, 3) editLine.SetMax(30) editLine.SetText("uiTest") editLine.Show() self.editLine = editLine ## Board > Load Button loadButton = ui.Button() loadButton.SetParent(self) loadButton.SetPosition(self.SLOT_WIDTH + 23, 32) loadButton.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub") loadButton.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub") loadButton.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub") loadButton.SetEvent(self.__OnClickLoadButton) loadButton.SetText("Load") loadButton.Show() self.loadButton = loadButton ## Board > TextLine (Print Mouse Position) self.textLine = ui.TextLine() self.textLine.SetParent(self) self.textLine.SetFontName(localeInfo.UI_DEF_FONT) self.textLine.SetWindowHorizontalAlignCenter() self.textLine.SetHorizontalAlignCenter() self.textLine.SetWindowVerticalAlignBottom() self.textLine.SetVerticalAlignBottom() self.textLine.SetPosition(0, 13) self.textLine.SetText("Tip: Press F10 to load / reload.") self.textLine.Show() def __del__(self): ui.BoardWithTitleBar.__del__(self) del self.tooltipItem del self.tooltipSkill self.slotBar = None self.editLine = None self.loadButton = None self.textLine = None def Show(self): ui.BoardWithTitleBar.Show(self) def Hide(self): ui.BoardWithTitleBar.Hide(self) def OnKeyDown(self, key): if key == app.DIK_F10: self.__OnClickLoadButton() def __OnClickLoadButton(self): module_name = self.editLine.GetText() if not module_name: print("Empty module name") return if self.wndScript: self.wndScript.Hide() del self.wndScript self.wndScript = None try: module = LoadModule(module_name) except Exception as error: print("Error loading module: %s" % str(error)) return self.wndScript = module.TestWindow() #self.wndScript.SetItemToolTip(self.tooltipItem) self.wndScript.Show() wndTestScript = TestScript() wndTestScript.Show() Requirements In order to use this tool, you must make sure it executes the module when the client is started, if you're familiar with loginInfo.py, it's practically the same thing. Make sure you only enable this feature on a debug build for testing purposes. Simply add the script above on your main client directory and you're ready. """ 1. @ introLogin.py """ # Search if musicInfo.loginMusic != "": snd.SetMusicVolume(systemSetting.GetMusicVolume()) snd.FadeInMusic("BGM/"+musicInfo.loginMusic) # Add above self.__LoadTestFile("uiTestScript.py") """ 2. @ introLogin.py """ # Search def PopupDisplayMessage(self, msg): # Add above def __LoadTestFile(self, fileName): try: testScriptDict = {} execfile(fileName, testScriptDict) except: pass Here is an example of the uiTest.py file that will be loaded but you can load any other module that you add in your client main directory. Spoiler # # File : uiTest.py # import ui class TestWindow(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) self.__LoadWindow() def __del__(self): ui.ScriptWindow.__del__(self) def __LoadWindow(self): try: self.__LoadScript("UIScript/SelectItemWindow.py") except: import exception exception.Abort("TestWindow.LoadWindow.LoadObject") def __LoadScript(self, fileName): pyScrLoader = ui.PythonScriptLoader() pyScrLoader.LoadScriptFile(self, fileName) def Show(self): ui.ScriptWindow.Show(self) def Hide(self): ui.ScriptWindow.Hide(self) Enjoy. Edited March 27, 2023 by Owsap 14 3 1 11 https://owsap.dev/ / https://osf.owsap.dev/ Link to comment Share on other sites More sharing options...
Premium Kraaz 621 Posted March 28, 2023 Premium Share Posted March 28, 2023 Thank you for this share, Owsap! Link to comment Share on other sites More sharing options...
Arke 5 Posted April 30, 2023 Share Posted April 30, 2023 thank you for share this amazing script with us ! I'll really try , i hope it works ! Link to comment Share on other sites More sharing options...
Evo 6 Posted June 20, 2023 Share Posted June 20, 2023 For dumb people: import os executable_path = os.path.dirname(os.path.abspath(__file__)) script_path = os.path.join(executable_path, "pisellino.py") 1 Link to comment Share on other sites More sharing options...
Honorable Member martysama0134 7174 Posted August 13, 2023 Honorable Member Share Posted August 13, 2023 (edited) Someone had an issue with it using my client. I made it working, refresh too: reload.py import app import ui import wndMgr import uiToolTip import localeInfo import dbg import sys, imp def LoadModule(name): if name in sys.modules: del sys.modules[name] if name in locals(): del locals()[name] if name in globals(): del globals()[name] # Open the module file module_file_path = "{}.py".format(name) module_file = old_open(module_file_path, 'r') # Load the module from the file module = imp.load_module(name, module_file, module_file_path, ('.py', 'r', imp.PY_SOURCE)) if not module in locals(): locals()[name] = module if not module in globals(): globals()[name] = module return module class TestScript(ui.BoardWithTitleBar): BOARD_WIDTH = 230 BOARD_HEIGHT = 80 SLOT_WIDTH = 150 def __init__(self): ui.BoardWithTitleBar.__init__(self) self.wndScript = None ## Item ToolTip self.tooltipItem = uiToolTip.ItemToolTip() self.tooltipItem.Hide() ## Board self.SetSize(self.BOARD_WIDTH, self.BOARD_HEIGHT) self.SetPosition(0, wndMgr.GetScreenHeight() - self.BOARD_HEIGHT) self.AddFlag("movable") self.SetTitleName("Test Script") self.SetCloseEvent(self.Hide) self.Show() ## Board > Slot Bar slotBar = ui.SlotBar() slotBar.SetParent(self) slotBar.SetSize(self.SLOT_WIDTH, 18) slotBar.SetPosition(13, 32) slotBar.Show() self.slotBar = slotBar ## Board > Slot Bar > EditLine editLine = ui.EditLine() editLine.SetParent(self.slotBar) editLine.SetSize(self.SLOT_WIDTH, 18) editLine.SetPosition(4, 3) editLine.SetMax(30) editLine.SetText("uibio")#"uiTest") editLine.Show() self.editLine = editLine ## Board > Load Button loadButton = ui.Button() loadButton.SetParent(self) loadButton.SetPosition(self.SLOT_WIDTH + 23, 32) loadButton.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub") loadButton.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub") loadButton.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub") loadButton.SetEvent(self.__OnClickLoadButton) loadButton.SetText("Load") loadButton.Show() self.loadButton = loadButton ## Board > TextLine (Print Mouse Position) self.textLine = ui.TextLine() self.textLine.SetParent(self) self.textLine.SetFontName(localeInfo.UI_DEF_FONT) self.textLine.SetWindowHorizontalAlignCenter() self.textLine.SetHorizontalAlignCenter() self.textLine.SetWindowVerticalAlignBottom() self.textLine.SetVerticalAlignBottom() self.textLine.SetPosition(0, 13) self.textLine.SetText("Tip: Press F10 to load / reload.") self.textLine.Show() def __del__(self): ui.BoardWithTitleBar.__del__(self) del self.tooltipItem del self.tooltipSkill self.slotBar = None self.editLine = None self.loadButton = None self.textLine = None def Show(self): ui.BoardWithTitleBar.Show(self) def Hide(self): ui.BoardWithTitleBar.Hide(self) def OnKeyDown(self, key): if key == app.DIK_F10: self.__OnClickLoadButton() def __OnClickLoadButton(self): module_name = self.editLine.GetText() if not module_name: dbg.TraceError("Empty module name") return if self.wndScript: self.wndScript.Hide() del self.wndScript self.wndScript = None dbg.TraceError("Loading module: {}".format(module_name)) try: module = LoadModule(module_name) except Exception as error: dbg.TraceError("Error loading module: {}".format(error)) return self.wndScript = module.BioWindow() #EDIT WITH THE CORRECT WINDOW NAME self.wndScript.Open() wndTestScript = TestScript() wndTestScript.Show() Edited August 13, 2023 by martysama0134 1 1 Check out my GitHub Link to comment Share on other sites More sharing options...
Bughy 5 Posted August 13, 2023 Share Posted August 13, 2023 Awesome, ty Marty Link to comment Share on other sites More sharing options...
Honorable Member martysama0134 7174 Posted August 13, 2023 Honorable Member Share Posted August 13, 2023 (edited) I created an auto-refresh feature every 5s: import app import ui import wndMgr import uiToolTip import localeInfo import dbg import sys, imp REFRESH_TIME = 5.0 MSG_STRING02 = "Tip: Press F11 to auto refresh: {}" def LoadModule(name): if name in sys.modules: del sys.modules[name] if name in locals(): del locals()[name] if name in globals(): del globals()[name] # Open the module file module_file_path = "{}.py".format(name) module_file = old_open(module_file_path, 'rb') # Load the module from the file module = imp.load_module(name, module_file, module_file_path, ('.py', 'rb', imp.PY_SOURCE)) if not module in locals(): locals()[name] = module if not module in globals(): globals()[name] = module return module class TestScript(ui.BoardWithTitleBar): BOARD_WIDTH = 230 BOARD_HEIGHT = 80+30 SLOT_WIDTH = 150 def __init__(self): ui.BoardWithTitleBar.__init__(self) self.wndScript = None self.autoRefresh = False self.nextRefresh = 0.0 ## Item ToolTip self.tooltipItem = uiToolTip.ItemToolTip() self.tooltipItem.Hide() ## Board self.SetSize(self.BOARD_WIDTH, self.BOARD_HEIGHT) self.SetPosition(0, wndMgr.GetScreenHeight() - self.BOARD_HEIGHT) self.AddFlag("movable") self.SetTitleName("Test Script") self.SetCloseEvent(self.Hide) self.Show() ## Board > Slot Bar slotBar = ui.SlotBar() slotBar.SetParent(self) slotBar.SetSize(self.SLOT_WIDTH, 18) slotBar.SetPosition(13, 32) slotBar.Show() self.slotBar = slotBar ## Board > Slot Bar > EditLine editLine = ui.EditLine() editLine.SetParent(self.slotBar) editLine.SetSize(self.SLOT_WIDTH, 18) editLine.SetPosition(4, 3) editLine.SetMax(30) editLine.SetText("bio")#"uiTest") editLine.Show() self.editLine = editLine ## Board > Load Button loadButton = ui.Button() loadButton.SetParent(self) loadButton.SetPosition(self.SLOT_WIDTH + 23, 32) loadButton.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub") loadButton.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub") loadButton.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub") loadButton.SetEvent(self.__OnClickLoadButton) loadButton.SetText("Load") loadButton.Show() self.loadButton = loadButton ## Board > TextLine (Print Mouse Position) self.textLine = ui.TextLine() self.textLine.SetParent(self) self.textLine.SetFontName(localeInfo.UI_DEF_FONT) self.textLine.SetWindowHorizontalAlignCenter() self.textLine.SetHorizontalAlignCenter() self.textLine.SetWindowVerticalAlignBottom() self.textLine.SetVerticalAlignBottom() self.textLine.SetPosition(0, 33) self.textLine.SetText("Tip: Press F10 to load / reload.") self.textLine.Show() ## Board > TextLine2 (Print Mouse Position) self.textLine2 = ui.TextLine() self.textLine2.SetParent(self) self.textLine2.SetFontName(localeInfo.UI_DEF_FONT) self.textLine2.SetWindowHorizontalAlignCenter() self.textLine2.SetHorizontalAlignCenter() self.textLine2.SetWindowVerticalAlignBottom() self.textLine2.SetVerticalAlignBottom() self.textLine2.SetPosition(0, 13) self.textLine2.SetText(MSG_STRING02.format("OFF")) self.textLine2.Show() def OnUpdate(self): if self.autoRefresh: if self.nextRefresh < app.GetTime(): self.nextRefresh = app.GetTime() + REFRESH_TIME self.__OnClickLoadButton() def __del__(self): ui.BoardWithTitleBar.__del__(self) del self.tooltipItem del self.tooltipSkill self.slotBar = None self.editLine = None self.loadButton = None self.textLine = None def Show(self): ui.BoardWithTitleBar.Show(self) def Hide(self): ui.BoardWithTitleBar.Hide(self) def OnKeyDown(self, key): if key == app.DIK_F10: self.__OnClickLoadButton() elif key == app.DIK_F11: self.__OnClickToggleAutoRefresh() def __OnClickToggleAutoRefresh(self): self.autoRefresh = not self.autoRefresh self.textLine2.SetText(MSG_STRING02.format("ON" if self.autoRefresh else "OFF")) def __OnClickLoadButton(self): module_name = self.editLine.GetText() if not module_name: dbg.TraceError("Empty module name") return if self.wndScript: self.wndScript.Hide() del self.wndScript self.wndScript = None dbg.TraceError("Loading module: {}".format(module_name)) try: module = LoadModule(module_name) except Exception as error: dbg.TraceError("Error loading module: {}".format(error)) return self.wndScript = module.BioWindow() self.wndScript.Open() wndTestScript = TestScript() wndTestScript.Show() Edited August 13, 2023 by Metin2 Dev International Core X - External 2 Internal 2 1 2 1 Check out my GitHub Link to comment Share on other sites More sharing options...
Premium DemOnJR 564 Posted August 14, 2023 Premium Share Posted August 14, 2023 Working thanks. Spoiler 17 hours ago, martysama0134 said: I created an auto-refresh feature every 5s: import app import ui import wndMgr import uiToolTip import localeInfo import dbg import sys, imp REFRESH_TIME = 5.0 MSG_STRING02 = "Tip: Press F11 to auto refresh: {}" def LoadModule(name): if name in sys.modules: del sys.modules[name] if name in locals(): del locals()[name] if name in globals(): del globals()[name] # Open the module file module_file_path = "{}.py".format(name) module_file = old_open(module_file_path, 'rb') # Load the module from the file module = imp.load_module(name, module_file, module_file_path, ('.py', 'rb', imp.PY_SOURCE)) if not module in locals(): locals()[name] = module if not module in globals(): globals()[name] = module return module class TestScript(ui.BoardWithTitleBar): BOARD_WIDTH = 230 BOARD_HEIGHT = 80+30 SLOT_WIDTH = 150 def __init__(self): ui.BoardWithTitleBar.__init__(self) self.wndScript = None self.autoRefresh = False self.nextRefresh = 0.0 ## Item ToolTip self.tooltipItem = uiToolTip.ItemToolTip() self.tooltipItem.Hide() ## Board self.SetSize(self.BOARD_WIDTH, self.BOARD_HEIGHT) self.SetPosition(0, wndMgr.GetScreenHeight() - self.BOARD_HEIGHT) self.AddFlag("movable") self.SetTitleName("Test Script") self.SetCloseEvent(self.Hide) self.Show() ## Board > Slot Bar slotBar = ui.SlotBar() slotBar.SetParent(self) slotBar.SetSize(self.SLOT_WIDTH, 18) slotBar.SetPosition(13, 32) slotBar.Show() self.slotBar = slotBar ## Board > Slot Bar > EditLine editLine = ui.EditLine() editLine.SetParent(self.slotBar) editLine.SetSize(self.SLOT_WIDTH, 18) editLine.SetPosition(4, 3) editLine.SetMax(30) editLine.SetText("bio")#"uiTest") editLine.Show() self.editLine = editLine ## Board > Load Button loadButton = ui.Button() loadButton.SetParent(self) loadButton.SetPosition(self.SLOT_WIDTH + 23, 32) loadButton.SetUpVisual("d:/ymir work/ui/public/small_button_01.sub") loadButton.SetOverVisual("d:/ymir work/ui/public/small_button_02.sub") loadButton.SetDownVisual("d:/ymir work/ui/public/small_button_03.sub") loadButton.SetEvent(self.__OnClickLoadButton) loadButton.SetText("Load") loadButton.Show() self.loadButton = loadButton ## Board > TextLine (Print Mouse Position) self.textLine = ui.TextLine() self.textLine.SetParent(self) self.textLine.SetFontName(localeInfo.UI_DEF_FONT) self.textLine.SetWindowHorizontalAlignCenter() self.textLine.SetHorizontalAlignCenter() self.textLine.SetWindowVerticalAlignBottom() self.textLine.SetVerticalAlignBottom() self.textLine.SetPosition(0, 33) self.textLine.SetText("Tip: Press F10 to load / reload.") self.textLine.Show() ## Board > TextLine2 (Print Mouse Position) self.textLine2 = ui.TextLine() self.textLine2.SetParent(self) self.textLine2.SetFontName(localeInfo.UI_DEF_FONT) self.textLine2.SetWindowHorizontalAlignCenter() self.textLine2.SetHorizontalAlignCenter() self.textLine2.SetWindowVerticalAlignBottom() self.textLine2.SetVerticalAlignBottom() self.textLine2.SetPosition(0, 13) self.textLine2.SetText(MSG_STRING02.format("OFF")) self.textLine2.Show() def OnUpdate(self): if self.autoRefresh: if self.nextRefresh < app.GetTime(): self.nextRefresh = app.GetTime() + REFRESH_TIME self.__OnClickLoadButton() def __del__(self): ui.BoardWithTitleBar.__del__(self) del self.tooltipItem del self.tooltipSkill self.slotBar = None self.editLine = None self.loadButton = None self.textLine = None def Show(self): ui.BoardWithTitleBar.Show(self) def Hide(self): ui.BoardWithTitleBar.Hide(self) def OnKeyDown(self, key): if key == app.DIK_F10: self.__OnClickLoadButton() elif key == app.DIK_F11: self.__OnClickToggleAutoRefresh() def __OnClickToggleAutoRefresh(self): self.autoRefresh = not self.autoRefresh self.textLine2.SetText(MSG_STRING02.format("ON" if self.autoRefresh else "OFF")) def __OnClickLoadButton(self): module_name = self.editLine.GetText() if not module_name: dbg.TraceError("Empty module name") return if self.wndScript: self.wndScript.Hide() del self.wndScript self.wndScript = None dbg.TraceError("Loading module: {}".format(module_name)) try: module = LoadModule(module_name) except Exception as error: dbg.TraceError("Error loading module: {}".format(error)) return self.wndScript = module.BioWindow() self.wndScript.Open() wndTestScript = TestScript() wndTestScript.Show() 1 Link to comment Share on other sites More sharing options...
AndreiS 2 Posted October 29, 2023 Share Posted October 29, 2023 The script does not load for me.. Link to comment Share on other sites More sharing options...
Recommended Posts