Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Extend modules of ScriptWindow
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- This module was not projected for people who don't know nothing about python.
- Here is a simple functions which gives you the chance to be able to turn all objects of script loader (uiScript) into a a simple list and control all very simple.
- This is more easy if you have a lot a objects and want to do some actions with them like set multiples text, load images etc. do a simple loop by range start:end and you can play with it.
- self.OBJECT_MAX_NUM = 25 | You can change how many max objects you can send into list.
- self.Realloc(state, objectList) | You can run a action (Hide() / Show()) for all objects what you sended on list.
- I do not offer any support for this.
- Copyright: (c) 2017 VegaS ♆
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- """
- # How to use GetChildList(list()):
- class TestWindow(ui.ScriptWindow):
- def __init__(self):
- ui.ScriptWindow.__init__(self)
- ui.PythonScriptLoader().LoadScriptFile(self, "uiscript/guildwindow.py")
- self.childrenList = self.GetChildList(["GuildNameValue", "DeclareWarButton", "Board"])
- def Reference(self):
- self.childrenList[0].SetText("GUARDIANS")
- self.childrenList[1].SetPosition(100, 200)
- self.childrenList[2].SetSize(500, 1000)
- #How to use self.Realloc(int, list()):
- def OnClickHideButton(self):
- self.Realloc(self.STATE_HIDE, self.GetChildList(["GuildNameValue", "GuildMasterNameValue", "CurrentExperienceValue", "LastExperienceValue", "GuildMemberCountValue", "DeclareWarButton"]))
- #How you can play with GetChildList, another example:
- for (key, object) in enumerate(self.GetChildList(["TextLineA", "TextLineB", "TextLineC"])):
- object.SetText("Format line: {0}".format(key))
- #Code isn't so wow, because i was write on some minutes for test something and i don't use it so, enjoy.
- #root/ui.py
- #1.) Search for:
- class ScriptWindow(Window):
- def __init__(self, layer = "UI"):
- Window.__init__(self, layer)
- self.Children = []
- self.ElementDictionary = {}
- #2.) Add after:
- self.STATE_HIDE = 1
- self.STATE_SHOW = 2
- self.OBJECT_MAX_NUM = 25
- #1.) Search for:
- def GetChild(self, name):
- return self.ElementDictionary[name]
- #2.) Add after:
- def GetChildList(self, received_objects):
- return [self.ElementDictionary.get(item, None) for item in received_objects] if (isinstance(received_objects, (list, tuple))) else list()
- def Realloc(self, state, received_objects, allowed_state = [self.STATE_HIDE, self.STATE_SHOW]):
- if (not state in allowed_state or not isinstance(received_objects, (list, tuple))):
- import dbg
- dbg.TraceError(
- "<ScriptWindow> Failed to change state.\n{0}\n{1}".format(
- "<state '{0}'> Allowed states: {1}.".format(state, allowed_state),
- "{0} Allowed type: tuple or a list.".format(type(received_objects))
- ))
- return
- [item.Hide() if (state is self.STATE_HIDE) else item.Show()
- for item in [object for object in (received_objects
- if len(received_objects) < self.OBJECT_MAX_NUM else
- received_objects[:self.OBJECT_MAX_NUM])
- if (object is not None)]]
Advertisement
Add Comment
Please, Sign In to add comment