def __Throw(self, action=""): if (self.__destroyed): if (action == ""): Functions.Err("Object was destroyed") else: Functions.Err("Object was destroyed while " + action + "() was happening")
def SetColor(value, varName, className): Functions.TypeCheck(value, [tuple, type(None)], varName, className) output = None if (value != None): temp = [] max = -1 for i in value: if (i < 0): Functions.Err("color cant have a negative value") if (i > max): max = i temp.append(i) value = temp if (max > 255): for i in range(len(value)): value[i] = value[i] / max * 255 if (value == None or len(value) == 4): output = (float(value[0]), float(value[1]), float(value[2]), float(value[3])) elif (len(value) == 3): output = (float(value[0]), float(value[1]), float(value[2]), 255.0) else: Functions.Err( className + "." + varName + " must have a length of 3 or 4 in RGBA or RGB format") return output
def RectItemHelp(self, i): options = ["left", "top", "width", "height"] if (type(i) is not int): Functions.Err("in PythUnity.Rect[index], index must be a " + str(int) + " not " + str(type(i))) if (i > 4 or i < 0): Functions.Err( "in PythUnity.Rect[index], index must be between values 0 and " + str(len(options))) return options
def Move( self, newIndex ): #components can have their update function skipped on accident if ran in another comp.update self.__Throw("Object.Move") SetObjEdited(self) children = self.GetParentChildren() if (newIndex < 0): Functions.Err("Object.Move failed, index less than 0") elif (newIndex > len(children)): Functions.Warn( "Object.Move incorrect, index is greater than parent.children count" ) oldIndex = self.index self.__index = newIndex del children._ProtectedList__val[oldIndex] children._ProtectedList__val.insert(newIndex, self) i = oldIndex if (newIndex > oldIndex): while (i < newIndex): children[i]._Object__index = i i = i + 1 elif (newIndex < oldIndex): while (i >= newIndex): children[i]._Object__index = i i = i - 1
def __setitem__(self, i, newvalue): if (type(newvalue) is not int and type(newvalue) is not float): Functions.Err( "in PythUnity.Rect[index] = newValue, newValue must be a " + str(int) + " or " + str(float) + " not " + str(type(newvalue))) options = RectItemHelp(self, i) attr = setattr(self, options[i], newvalue)
def DelComp(self, index): self.__Throw("Object.DelComp") if (len(self.__components) > index): del self.__components._ProtectedList__val[index] else: Functions.Err( "Object.DelComp failed, index greater than comp index")
def TestFuncLen(func, name, neededArgs=["self"], className="Button"): if (func != None): length = len(inspect.getargspec(func)[0]) if (length != len(neededArgs)): Functions.Err("PythUnity." + className + "." + name + " must have an argument length of " + str(len(neededArgs)) + " not " + str(length) + "\nfunction: " + str(func) + "\nneeded arguments: " + str(neededArgs) + "\nrecieved arguments: " + str(inspect.getargspec(func)[0]))
def rows(self, value): Functions.Err("can't set PythUnity.rows, you can only get it")
def sizer(self, value): Functions.Err("can't set PythUnity.sizer, you can only get it")
def hovering(self, value): Functions.Err( "You cant set PythUnity.Button.hovering, you can only get it")
def index(self, value): Functions.Err("Cant set Object.index")
def destroyed(self, value): Functions.Err("Cant set Object.destroyed")
def transformedImage(self, value): Functions.Err("Cant set Object.transformedImage")
def variables(self, value): Functions.Err( "Cant set Object.variables, add each variable individualy")
def components(self, value): Functions.Err( "Cant set Object.components, use Object.AddComp or Object.DelComp")
def children(self, value): Functions.Err("Cant set Object.children")
def parent(self, value): Functions.Err("Cant set Object.parent")