示例#1
0
def _setLocationRelativeToRegion(comp, r_, side='left', offset=(0,0), expand=(0,0,0,0), \
                                 horizontalalignment = 'center', \
                                 verticalalignment = 'center'):
    r = Region(r_)
    # Offset
    (dx, dy) = offset
    r.x += dx
    r.y += dy
    # Side
    if (side == 'right'):
        comp.setLocationRelativeToRegion(r, Layout.RIGHT)
    elif (side == 'top'):
        comp.setLocationRelativeToRegion(r, Layout.TOP)
    elif (side == 'bottom'):
        comp.setLocationRelativeToRegion(r, Layout.BOTTOM)
    elif (side == 'left'):
        comp.setLocationRelativeToRegion(r, Layout.LEFT)
    elif (side == 'inside'):
        comp.setLocationRelativeToRegion(r, Layout.INSIDE)
    # Alignment
    if (horizontalalignment == 'left'):
        comp.setHorizontalAlignmentWithRegion(r, 0.0)
    elif (horizontalalignment == 'right'):
        comp.setHorizontalAlignmentWithRegion(r, 1.0)
    if (verticalalignment == 'top'):
        comp.setVerticalAlignmentWithRegion(r, 0.0)
    elif (verticalalignment == 'bottom'):
        comp.setVerticalAlignmentWithRegion(r, 1.0)
示例#2
0
def hotspot(target, message, side='right'):
    # TODO allow hotspot's positions to be automatically updated
    r = _getRegionFromTarget(target)
    txtcomp = SikuliGuideCallout(message)
    r1 = Region(r)
    r1.x -= 10
    r1.w += 20
    _setLocationRelativeToRegion(txtcomp, r1, side)
    txtcomp.setShadow(10, 2)
    comp = SikuliGuideHotspot(r, txtcomp, _g)
    _g.addToFront(comp)
    return comp
def _show_steps(steps, timeout=None):

    # only keep callables
    steps = filter(lambda x: callable(x), steps)
    print steps
    n = len(steps)
    i = 0

    while True:
        step = steps[i]
        step()

        msg = "Step %d of %d" % (i + 1, n)
        a = rectangle(Region(100, 100, 0, 0))
        text((10, 50), msg, fontsize=10)

        if n == 1:  # only one step
            addCloseButton(a)
        elif i == 0:  # first step
            addNextButton(a)
            addCloseButton(a)
        elif i < n - 1:  # between
            addPreviousButton(a)
            addNextButton(a)
            addCloseButton(a)
        elif i == n - 1:  # final step
            addPreviousButton(a)
            addCloseButton(a)

        ret = _g.showNow()

        if (ret == "Previous" and i > 0):
            i = i - 1
        elif (ret == "Next" and i < n - 1):
            i = i + 1
        elif (ret == None and i < n - 1):  # timeout
            i = i + 1
        elif (ret == "Close"):
            return
        else:
            # some other transitions happened
            if (i < n - 1):
                i = i + 1
            else:
                return
def _adjustRegion(r_, offset=(0, 0), expand=(0, 0, 0, 0)):

    r = Region(r_)

    # Offset
    (dx, dy) = offset
    r.x += dx
    r.y += dy

    # Expansion
    if isinstance(expand, tuple):
        (dt, dl, db, dr) = expand
    else:
        (dt, dl, db, dr) = (expand, expand, expand, expand)

    r.x -= dl
    r.y -= dt
    r.w = r.w + dl + dr
    r.h = r.h + dt + db

    return r
示例#5
0
def _getRegionFromTarget(target):
    if isinstance(target, SikuliGuideComponent):
        return Region(target.getBounds())
    else:
        return s.getRegionFromPSRM(target)
示例#6
0
def _addComponentHelper(comp,
                        target,
                        side='best',
                        margin=0,
                        offset=(0, 0),
                        horizontalalignment='center',
                        verticalalignment='center',
                        font=None,
                        fontsize=0,
                        width=0,
                        shadow='default',
                        front=None,
                        back=None,
                        frame=None,
                        text=None):

    # set the component's colors
    comp.setColors(front, back, frame, text)

    # set the component's font
    comp.setFont(font, fontsize)

    # set the components width
    if width > 0: comp.setMaxWidth(width)

    # Margin
    if margin:
        if isinstance(margin, tuple):
            (dt, dl, db, dr) = margin
        else:
            (dt, dl, db, dr) = (margin, margin, margin, margin)
        comp.setMargin(dt, dl, db, dr)
    # Offset
    if offset:
        (x, y) = offset
        comp.setOffset(x, y)
    # Side
    if (side == 'right'):
        sideConstant = Layout.RIGHT
    elif (side == 'top'):
        sideConstant = Layout.TOP
    elif (side == 'bottom'):
        sideConstant = Layout.BOTTOM
    elif (side == 'left'):
        sideConstant = Layout.LEFT
    elif (side == 'inside'):
        sideConstant = Layout.INSIDE
    elif (side == 'over'):
        sideConstant = Layout.OVER
    # Alignment
#    if (horizontalalignment == 'left'):
#        comp.setHorizontalAlignmentWithRegion(r,0.0)
#    elif (horizontalalignment == 'right'):
#   if (verticalalignment == 'top'):
#       comp.setVerticalAlignmentWithRegion(r,0.0)
#   elif (verticalalignment == 'bottom'):
#        comp.setVerticalAlignmentWithRegion(r,1.0)

    if isinstance(target, Region):
        # absolute location wrt a Region
        comp.setLocationRelativeToRegion(target, sideConstant)
    elif isinstance(target, tuple):
        # absolute location wrt a point (specified as (x,y))
        comp.setLocationRelativeToRegion(Region(target[0], target[1], 1, 1),
                                         Layout.RIGHT)
    else:
        targetComponent = None
        if isinstance(target, str):
            # relative location to a string (image filename)
            targetComponent = anchor(Pattern(target))
            targetComponent.setOpacity(0)
        elif isinstance(target, Pattern):
            # relative location to a pattern
            targetComponent = anchor(target)
            targetComponent.setOpacity(0)
        elif isinstance(target, SikuliGuideComponent):
            targetComponent = target
        if targetComponent:
            comp.setLocationRelativeToComponent(targetComponent, sideConstant)
        else:
            Debug.error("GuideComponentSetup: invalid target: ", target)
            return None

    # set shadow, different sizes for different types of components


#TODO shadow handling
    if shadow == 'default':
        if (isinstance(comp, SikuliGuideCircle) or \
                isinstance(comp, SikuliGuideRectangle) or \
                isinstance(comp, SikuliGuideBracket)):
            comp.setShadow(5, 2)
        elif not (isinstance(comp, SikuliGuideSpotlight)):
            comp.setShadow(10, 2)

    # add the component to guide
    comp.updateComponent()
    _g.addToFront(comp)
    return comp
def _addComponentHelper(comp,
                        target,
                        side='best',
                        margin=0,
                        offset=(0, 0),
                        horizontalalignment='center',
                        verticalalignment='center',
                        shadow='default'):

    # Margin
    if margin:
        if isinstance(margin, tuple):
            (dt, dl, db, dr) = margin
        else:
            (dt, dl, db, dr) = (margin, margin, margin, margin)
        comp.setMargin(dt, dl, db, dr)

    # Offset
    if offset:
        (x, y) = offset
        comp.setOffset(x, y)

    # Side
    if (side == 'right'):
        sideConstant = Layout.RIGHT
    elif (side == 'top'):
        sideConstant = Layout.TOP
    elif (side == 'bottom'):
        sideConstant = Layout.BOTTOM
    elif (side == 'left'):
        sideConstant = Layout.LEFT
    elif (side == 'inside'):
        sideConstant = Layout.INSIDE
    elif (side == 'over'):
        sideConstant = Layout.OVER

    # Alignment


#    if (horizontalalignment == 'left'):
#        comp.setHorizontalAlignmentWithRegion(r,0.0)
#    elif (horizontalalignment == 'right'):
#
#   if (verticalalignment == 'top'):
#       comp.setVerticalAlignmentWithRegion(r,0.0)
#   elif (verticalalignment == 'bottom'):
#        comp.setVerticalAlignmentWithRegion(r,1.0)

    if isinstance(target, Region):
        # absolute location wrt a Region
        comp.setLocationRelativeToRegion(target, sideConstant)
    elif isinstance(target, tuple):
        # absolute location wrt a point (specified as (x,y))
        comp.setLocationRelativeToRegion(Region(target[0], target[1], 1, 1),
                                         Layout.RIGHT)
    else:

        if isinstance(target, str):
            # relative location to a string (image filename)
            targetComponent = anchor(Pattern(target))
            targetComponent.setOpacity(0)
        elif isinstance(target, Pattern):
            # relative location to a pattern
            targetComponent = anchor(target)
            targetComponent.setOpacity(0)
        elif isinstance(target, SikuliGuideComponent):
            targetComponent = target

        comp.setLocationRelativeToComponent(targetComponent, sideConstant)

    # set shadow, different sizes for different types of components
    if shadow == 'default':

        if (isinstance(comp, SikuliGuideCircle)
                or isinstance(comp, SikuliGuideRectangle)
                or isinstance(comp, SikuliGuideBracket)):
            comp.setShadow(5, 2)
        elif not (isinstance(comp, SikuliGuideSpotlight)):
            comp.setShadow(10, 2)

    # add the component to guide
    _g.addToFront(comp)

    return comp
示例#8
0
def _getRegionFromTarget(target):
    if isinstance(target, Visual):
        return Region(target.getBounds())
    else:
        return Screen().getRegionFromTarget(target)
示例#9
0
 def getRegion(self):
     
     return Region(self.x, self.y, 1, 1)
示例#10
0
 def getRegion(self):
     
     return Region(self.x1, self.y1, 1, 1).add(Location(self.x2, self.y2))