Пример #1
0
 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
Пример #2
0
 def __Throw(self, action=""):
     if (self.__destroyed):
         if (action == ""):
             Functions.Err("Object was destroyed")
         else:
             Functions.Err("Object was destroyed while " + action +
                           "() was happening")
Пример #3
0
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
Пример #4
0
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
Пример #5
0
 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)
Пример #6
0
 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")
Пример #7
0
 def text(self, value):
     self.__edited = True
     Functions.TypeCheck(value, [String, type(None)], "text")
     self.__text = value
     self.text._String__owner = self
     self.text._String__imageChanged = True
     TransformText(self)
Пример #8
0
 def height(self, value):
     Functions.TypeCheck(value, [float, int], "height", "Rect")
     self.__height = float(value)
     UpdateRects(self)
     if (self.__owner != None and not self.__global):
         self.__owner._Object__transformed = True
         TransformText(self.__owner)
     SetEdited(self)
Пример #9
0
 def rect(self, value):
     SetObjEdited(self)
     Functions.TypeCheck(value, Rect, "rect")
     self.__rect = value
     self.__rect._Rect__owner = self
     self.__rect._Rect__global = False
     UpdateRects(self.__rect)
     self.__transformed = True
     TransformText(self)
Пример #10
0
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]))
Пример #11
0
 def __init__(self,
              rect,
              image,
              onClick=None,
              onDrag=None,
              onClickOff=None,
              onScroll=None,
              onHover=None,
              onHoverOff=None,
              onHoverOn=None,
              enableDragOff=False,
              clickGroup=0,
              fitImage=False,
              effect=None):
     self.__destroyed = False
     self.__parent = None
     self.__children = ProtectedList("children", "Object", False, False,
                                     False, False)
     self.__variables = {}
     self.__image = None
     self.__transformedImage = None
     self.__text = None
     self.__color = None
     self.__oldPos = (0, 0, 0, 0)
     self.__edited = True
     self.__components = ProtectedList("components", "Object", False, False,
                                       False, False)
     self.__clickGroup = None
     self.__velocity = (0, 0)
     self.__index = None
     self.__rect = None
     self.__transformed = False
     self.__transformedColor = False
     self.__updateLocal = False
     self.__updateGlobal = False
     self.renderOptions = RenderOptions(fitImage=fitImage, effect=effect)
     self.__globalRect = Rect(0, 0, 0, 0)
     self.__globalRect._Rect__owner = self
     self.__globalRect._Rect__global = True
     self.__enabled = True
     self.rect = rect
     self.clickGroup = clickGroup
     if (type(image) is tuple):
         self.color = image
     elif (type(image) is String):
         self.text = image.Copy()
     elif (type(image) is pygame.Surface):
         self.image = image
     if onClick != None or onDrag != None or onScroll != None:
         self.__button = Button(onClick, onDrag, onClickOff, onScroll,
                                onHover, onHoverOff, onHoverOn,
                                enableDragOff)
     else:
         self.__button = None
     Functions.AddObject(self)
Пример #12
0
 def onClick(self, value):
     Functions.TypeCheck(
         value, [types.FunctionType, type(None)], "onClick", "Button")
     TestFuncLen(value, "onClick", ["self", "string_mouseButton"])
     self.__onClick = value
Пример #13
0
 def enableDragOff(self, value):
     Functions.TypeCheck(value, bool, "enableDragOff", "Button")
     self.__enableDragOff = value
Пример #14
0
 def left(self, value):
     Functions.TypeCheck(value, [float, int], "left", "Rect")
     self.__left = float(value)
     UpdateRects(self)
     SetEdited(self)
Пример #15
0
 def top(self, value):
     Functions.TypeCheck(value, [float, int], "top", "Rect")
     self.__top = float(value)
     UpdateRects(self)
     SetEdited(self)
Пример #16
0
 def onHoverOff(self, value):
     Functions.TypeCheck(
         value, [types.FunctionType, type(None)], "onHoverOff", "Button")
     TestFuncLen(value, "onHoverOff", ["self", "string_reason"])
     self.__onHoverOff = value
Пример #17
0
 def font(self, value):
     Functions.TypeCheck(value, str, "font", "String")
     self.__font = value
     self.__rowChanged = True
     SetEdited(self)
Пример #18
0
 def alignment(self, value):
     Functions.TypeCheck(value, int, "alignment", "String")
     self.__alignment = value
     self.__imageChanged = True
     SetEdited(self)
Пример #19
0
 def button(self, value):
     Functions.TypeCheck(value, [Button, type(None)], "button")
     self.__button = value
Пример #20
0
 def addDash(self, value):
     Functions.TypeCheck(value, bool, "addDash", "String")
     self.__addDash = value
     self.__rowChanged = True
Пример #21
0
 def rows(self, value):
     Functions.Err("can't set PythUnity.rows, you can only get it")
Пример #22
0
 def onDrag(self, value):
     Functions.TypeCheck(
         value, [types.FunctionType, type(None)], "onDrag", "Button")
     TestFuncLen(value, "onDrag")
     self.__onDrag = value
Пример #23
0
 def sizer(self, value):
     Functions.Err("can't set PythUnity.sizer, you can only get it")
Пример #24
0
 def onHoverOn(self, value):
     Functions.TypeCheck(
         value, [types.FunctionType, type(None)], "onHoverOn", "Button")
     TestFuncLen(value, "onHoverOn")
     self.__onHoverOn = value
Пример #25
0
 def fitImage(self, value):
     Functions.TypeCheck(value, type(False), "fitImage", "RenderOptions")
     self.__fitImage = value
     if (self.__owner != None):
         self.__owner._Object__imageChanged = True
     SetEdited(self)
Пример #26
0
 def fontSize(self, value):
     Functions.TypeCheck(value, [int, float], "fontSize", "String")
     self.__fontSize = value
     self.__rowChanged = True
     SetEdited(self)
Пример #27
0
 def hovering(self, value):
     Functions.Err(
         "You cant set PythUnity.Button.hovering, you can only get it")
Пример #28
0
 def text(self, value):
     Functions.TypeCheck(value, str, "text", "String")
     self.__text = value
     self.__rowChanged = True
     SetEdited(self)
Пример #29
0
 def maxRows(self, value):
     Functions.TypeCheck(value, int, "maxRows", "String")
     self.__maxRows = value
     self.__rowChanged = True
Пример #30
0
 def onScroll(self, value):
     Functions.TypeCheck(
         value, [types.FunctionType, type(None)], "onScroll", "Button")
     TestFuncLen(value, "onScroll", ["self", "int_direction"])
     self.__onScroll = value