VegaS1234

Extend modules of ScriptWindow

Nov 17th, 2017
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.05 KB | None | 0 0
  1. """
  2.    Extend modules of ScriptWindow
  3.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4.     This module was not projected for people who don't know nothing about python.
  5.    
  6.     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.
  7.     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.
  8.    
  9.     self.OBJECT_MAX_NUM = 25 | You can change how many max objects you can send into list.
  10.     self.Realloc(state, objectList) | You can run a action (Hide() / Show()) for all objects what you sended on list.
  11.  
  12.     I do not offer any support for this.
  13.     Copyright: (c) 2017 VegaS ♆
  14.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. """
  16.  
  17. # How to use GetChildList(list()):
  18. class TestWindow(ui.ScriptWindow):
  19.     def __init__(self):
  20.         ui.ScriptWindow.__init__(self)
  21.         ui.PythonScriptLoader().LoadScriptFile(self, "uiscript/guildwindow.py")
  22.         self.childrenList = self.GetChildList(["GuildNameValue", "DeclareWarButton", "Board"])
  23.  
  24.     def Reference(self):
  25.         self.childrenList[0].SetText("GUARDIANS")
  26.         self.childrenList[1].SetPosition(100, 200)
  27.         self.childrenList[2].SetSize(500, 1000)
  28.  
  29. #How to use self.Realloc(int, list()):
  30. def OnClickHideButton(self):
  31.     self.Realloc(self.STATE_HIDE, self.GetChildList(["GuildNameValue", "GuildMasterNameValue", "CurrentExperienceValue", "LastExperienceValue", "GuildMemberCountValue", "DeclareWarButton"]))
  32.  
  33. #How you can play with GetChildList, another example:
  34. for (key, object) in enumerate(self.GetChildList(["TextLineA", "TextLineB", "TextLineC"])):
  35.     object.SetText("Format line: {0}".format(key))
  36.  
  37. #Code isn't so wow, because i was write on some minutes for test something and i don't use it so, enjoy.
  38. #root/ui.py
  39. #1.) Search for:
  40. class ScriptWindow(Window):
  41.     def __init__(self, layer = "UI"):
  42.         Window.__init__(self, layer)
  43.         self.Children = []
  44.         self.ElementDictionary = {}
  45. #2.) Add after:
  46.         self.STATE_HIDE = 1
  47.         self.STATE_SHOW = 2
  48.         self.OBJECT_MAX_NUM = 25
  49.  
  50. #1.) Search for:
  51.     def GetChild(self, name):
  52.         return self.ElementDictionary[name]
  53. #2.) Add after:
  54.     def GetChildList(self, received_objects):
  55.         return [self.ElementDictionary.get(item, None) for item in received_objects] if (isinstance(received_objects, (list, tuple))) else list()
  56.  
  57.     def Realloc(self, state, received_objects, allowed_state = [self.STATE_HIDE, self.STATE_SHOW]):
  58.         if (not state in allowed_state or not isinstance(received_objects, (list, tuple))):
  59.             import dbg
  60.             dbg.TraceError(
  61.                 "<ScriptWindow> Failed to change state.\n{0}\n{1}".format(
  62.                     "<state '{0}'> Allowed states: {1}.".format(state, allowed_state),
  63.                     "{0} Allowed type: tuple or a list.".format(type(received_objects))
  64.             ))
  65.             return
  66.  
  67.         [item.Hide() if (state is self.STATE_HIDE) else item.Show()
  68.             for item in [object for object in (received_objects
  69.                 if len(received_objects) < self.OBJECT_MAX_NUM else
  70.                     received_objects[:self.OBJECT_MAX_NUM])
  71.                         if (object is not None)]]
Advertisement
Add Comment
Please, Sign In to add comment