Example #1
0
    def fromDict(d: dict) -> 'Token':
        """
		Creates a token from a dictionary.

		:param d: The dictionary that represents the Component.
		:type d: dict
		:return: The Token object that was constructed from the dictionary
		:rtype: Token
		"""

        if d is None:
            return None

        t = Token.__new__(Token)

        if d['pic']:
            d["pic"] = Image.fromarray(np.uint8(np.asarray(d["picture"])))

        if d['rectangle']:
            r = RECT()
            r.left = d['rectangle'][0]
            r.top = d['rectangle'][1]
            r.right = d['rectangle'][0] + d['rectangle'][2]
            r.bottom = d['rectangle'][1] + d['rectangle'][3]
            d['rectangle'] = r

        t.__dict__ = d
        return t
def MissalignmentTest(windows):
    "Run the test on the windows passed in"
    refAlignments = {}

    #find the controls alligned along each axis
    for win in windows:
        if not win.ref:
            continue


        for side in ("top", "left", "right", "bottom"):
            sideValue = getattr(win.ref.Rectangle(), side)

            # make sure that the side dictionary has been created
            sideAlignments = refAlignments.setdefault(side, {})

            # make sure that the array of controls for this
            # alignment line has been created and add the current window
            sideAlignments.setdefault(sideValue, []).append(win)

    bugs = []
    for side in refAlignments:
        for alignment in refAlignments[side]:
            controls = refAlignments[side][alignment]
            sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]
            sides = set(sides)

            if len(sides) > 1:

                overAllRect = RECT()
                overAllRect.left = min(
                    [ctrl.Rectangle().left for ctrl in controls])
                overAllRect.top = min(
                    [ctrl.Rectangle().top for ctrl in controls])
                overAllRect.right = max(
                    [ctrl.Rectangle().right for ctrl in controls])
                overAllRect.bottom = max(
                    [ctrl.Rectangle().bottom for ctrl in controls])


                bugs.append((
                    controls,
                    {
                        "AlignmentType": side.upper(),
                        "AlignmentRect": overAllRect
                    },
                    testname,
                    0)
                )

    return bugs
def MissalignmentTest(windows):
    "Run the test on the windows passed in"
    refAlignments = {}

    #find the controls alligned along each axis
    for win in windows:
        if not win.ref:
            continue


        for side in ("top", "left", "right", "bottom"):
            sideValue = getattr(win.ref.Rectangle(), side)

            # make sure that the side dictionary has been created
            sideAlignments = refAlignments.setdefault(side, {})

            # make sure that the array of controls for this
            # alignment line has been created and add the current window
            sideAlignments.setdefault(sideValue, []).append(win)

    bugs = []
    for side in refAlignments:
        for alignment in refAlignments[side]:
            controls = refAlignments[side][alignment]
            sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]
            sides = set(sides)

            if len(sides) > 1:

                overAllRect = RECT()
                overAllRect.left = min(
                    [ctrl.Rectangle().left for ctrl in controls])
                overAllRect.top = min(
                    [ctrl.Rectangle().top for ctrl in controls])
                overAllRect.right = max(
                    [ctrl.Rectangle().right for ctrl in controls])
                overAllRect.bottom = max(
                    [ctrl.Rectangle().bottom for ctrl in controls])


                bugs.append((
                    controls,
                    {
                        "AlignmentType": side.upper(),
                        "AlignmentRect": overAllRect
                    },
                    testname,
                    0)
                )

    return bugs
Example #4
0
def MissalignmentTest(windows):
    "Run the test on the windows passed in"
    refAlignments = {}

    #find the controls alligned along each axis
    for win in windows:
        if not win.ref:
            continue

        for side in ("top", "left", "right", "bottom"):
            sideValue = getattr(win.ref.Rectangle(), side)

            # make sure that the side dictionary has been created
            sideAlignments = refAlignments.setdefault(side, {})

            # make sure that the array of controls for this
            # alignment line has been created and add the current window
            sideAlignments.setdefault(sideValue, []).append(win)

    bugs = []
    for side in refAlignments:
        for alignment in refAlignments[side]:
            # get the controls that were alligned
            controls = refAlignments[side][alignment]

            # get the sides of the current controls
            sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]

            # if one or more of the controls have a differnt value for this
            # side
            if len(set(sides)) > 1:
                if side in ("top bottom"):
                    # find how far away from each other the controls are...
                    lefts = [c.ref.Rectangle().left for c in controls]
                    rights = [c.ref.Rectangle().right for c in controls]

                    nearest = []
                    for i, c1 in enumerate(controls):
                        for c2 in controls[i + 1:]:
                            dist = min(
                                abs(c1.Rectangle().right -
                                    c2.Rectangle().left),
                                abs(c1.Rectangle().left -
                                    c2.Rectangle().right))

                            if dist < 40 and getattr(c1.Rectangle(),
                                                     side) != getattr(
                                                         c2.Rectangle(), side):
                                buggy_controls.append((c1, c2))

            else:
                if side in ("left right"):
                    # find how far away from each other the controls are...
                    lefts = [c.ref.Rectangle().left for c in controls]
                    rights = [c.ref.Rectangle().right for c in controls]

                    for left in left:
                        for right in rights:
                            if min(abs(right - left), abs(left - right)) > 40:
                                continue

            sides = set(sides)

            if len(sides) > 1:

                overAllRect = RECT()
                overAllRect.left = min(
                    [ctrl.Rectangle().left for ctrl in controls])
                overAllRect.top = min(
                    [ctrl.Rectangle().top for ctrl in controls])
                overAllRect.right = max(
                    [ctrl.Rectangle().right for ctrl in controls])
                overAllRect.bottom = max(
                    [ctrl.Rectangle().bottom for ctrl in controls])

                bugs.append((controls, {
                    "AlignmentType": side.upper(),
                    "AlignmentRect": overAllRect
                }, testname, 0))

    return bugs
def MissalignmentTest(windows):
    "Run the test on the windows passed in"
    refAlignments = {}

    #find the controls alligned along each axis
    for win in windows:
        if not win.ref:
            continue


        for side in ("top", "left", "right", "bottom"):
            sideValue = getattr(win.ref.Rectangle(), side)

            # make sure that the side dictionary has been created
            sideAlignments = refAlignments.setdefault(side, {})

            # make sure that the array of controls for this
            # alignment line has been created and add the current window
            sideAlignments.setdefault(sideValue, []).append(win)

    bugs = []
    for side in refAlignments:
        for alignment in refAlignments[side]:
            # get the controls that were alligned
            controls = refAlignments[side][alignment]

            # get the sides of the current controls
            sides = [getattr(ctrl.Rectangle(), side) for ctrl in controls]

            # if one or more of the controls have a differnt value for this
            # side
            if len(set(sides)) > 1:
                if side in ("top bottom"):
                    # find how far away from each other the controls are...
                    lefts = [c.ref.Rectangle().left for c in controls]
                    rights = [c.ref.Rectangle().right for c in controls]

                    nearest = []
                    for i, c1 in enumerate(controls):
                        for c2 in controls[i+1:]:
                            dist = min (
                                abs(c1.Rectangle().right - c2.Rectangle().left),
                                abs(c1.Rectangle().left - c2.Rectangle().right))

                            if dist < 40 and getattr(c1.Rectangle(), side) != getattr(c2.Rectangle(), side):
                                buggy_controls.append((c1, c2))


            else:
                if side in ("left right"):
                    # find how far away from each other the controls are...
                    lefts = [c.ref.Rectangle().left for c in controls]
                    rights = [c.ref.Rectangle().right for c in controls]

                    for left in left:
                        for right in rights:
                            if min (abs(right - left), abs(left - right)) > 40:
                                continue




            sides = set(sides)

            if len(sides) > 1:

                overAllRect = RECT()
                overAllRect.left = min(
                    [ctrl.Rectangle().left for ctrl in controls])
                overAllRect.top = min(
                    [ctrl.Rectangle().top for ctrl in controls])
                overAllRect.right = max(
                    [ctrl.Rectangle().right for ctrl in controls])
                overAllRect.bottom = max(
                    [ctrl.Rectangle().bottom for ctrl in controls])


                bugs.append((
                    controls,
                    {
                        "AlignmentType": side.upper(),
                        "AlignmentRect": overAllRect
                    },
                    testname,
                    0)
                )

    return bugs