Register for your free account! | Forgot your password?

You last visited: Today at 04:48

  • Please register to post and access all features, it's quick, easy and FREE!

 

[Python] Extend modules of ScriptWindow

Reply
 
Old   #1
 
elite*gold: 10
Join Date: Jul 2013
Posts: 89
Received Thanks: 372
Thumbs up [Python] Extend modules of ScriptWindow

This module was not designed 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.

How to use GetChildList(list()):
Code:
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()):
Code:
def OnClickHideButton(self):
	self.Realloc(self.STATE_HIDE, self.GetChildList(["GuildNameValue", "GuildMasterNameValue", "CurrentExperienceValue", "LastExperienceValue", "GuildMemberCountValue", "DeclareWarButton"]))
How you can play with GetChildList, another example:
Code:
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.

Code:
#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, state_alowed = [self.STATE_HIDE, self.STATE_SHOW]):
		if (not state in state_alowed 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, state_alowed), 
					"{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)]]
English isn't my first language, so please excuse any mistakes.



VegaS ♆ is offline  
Thanks
6 Users
Old   #2
 
elite*gold: 10
Join Date: Jul 2013
Posts: 89
Received Thanks: 372
[Python] Extend modules of ScriptWindow

Quote:
Probably changing the way it indexes the data does the deal, using strings instead of numbers sounds good to me.
Now you can use it more easy, have fun.
Code:
#root/ui.py
	def GetChildDictionary(self, received_objects):
		if isinstance(received_objects, (list, tuple)):
			return {item : self.ElementDictionary.get(item, None) for item in received_objects}
		return dict()
		
	def Realloc(self, state, received_objects, allowed_type = [self.STATE_HIDE, self.STATE_SHOW]):
		if (not state in allowed_type or not isinstance(received_objects, dict)):
			import dbg
			dbg.TraceError(
				"<ScriptWindow> Failed to change state.\n{0}\n{1}".format(
					"<state '{0}'> Allowed states: {1}.".format(state, allowed_type), 
					"{0} Allowed type: {1}.".format(type(received_objects), type(dict()))))
			return

		for item in [zip for zip in received_objects.values() if (zip is not None)]:
			if state is self.STATE_HIDE:
				item.Hide()
			else:
				item.Show() 
		
#main.py (example):
self.childrenDict = self.GetChildDictionary(["LoginButton", "LoginExitButton"])
self.childrenDict["LoginButton"].SetPosition(20, 500)
self.childrenDict["LoginExitButton"].SetPosition(-300, 800)

self.Realloc(self.STATE_SHOW, childrenDict) # Use Realloc(state, object_dictionary) for a action as Hide() or Show() by state.
Small test board.
  • root/main.py
  • uiscript/main_window.py


VegaS ♆ is offline  
Old   #3
 
elite*gold: 191
Join Date: May 2009
Posts: 1,210
Received Thanks: 2,557
Quote:
Originally Posted by VegaS ♆ View Post
Code:
		[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)]]
Well, this is quite bad code style.
Try to stay to the pythonic way, list comprehensions should only be used for simple list-related methods (and only for one line, mostly) and here you could easily use a normal loop and a if, this would make your code much more readable.

Best regards
Mijago is offline  
Thanks
2 Users
Reply

Tags
epvp, python, pythonscriptloader, vegas



« Previous Thread | Next Thread »

Similar Threads
[Python] Modules after GameForge-Update (01.10.2013)
Good afternoon Elitepvpers. The update from the 01.10.2013 has changed a few things in the Metin2Client concerning Python. Some Pythonmodules have...
21 Replies - Metin2 Guides & Templates
Fatal errror: failed to load platform modules
ja ich kann kein CS:S mehr spielen/starten denn bei steam is irgendetwas kaputt, naja immer kommt die fehler meldung "Fatal errror: failed to load...
9 Replies - Counter-Strike
BotResourcePack (VB.net modules)
I was bored so I decided to try the level-bot for taos in BanditL97 cave. I noticed it lagged the system alot and didnt sit/meditate or...
58 Replies - CO2 Bots & Macros
Question about modules
This might not be the right part of the forum to ask, But i tried search so dont say use search =P I was wondering if theres a VB module around to...
0 Replies - CO2 Main - Discussions / Questions



All times are GMT +1. The time now is 04:48.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2017 elitepvpers All Rights Reserved.