简体   繁体   English

Sikuli脚本

[英]Sikuli scripting

I want to write a sikuli script which can clear the "Recycle bin" if it is full (when executed first time) and need to check the icon if it is empty and display (Recycle bin is empty) 我想编写一个sikuli脚本,该脚本可以清除“回收站”是否已满(第一次执行时),并且需要检查该图标是否为空并显示(回收站为空)

Following is the code which I tried: 以下是我尝试过的代码:

Try 1 - while not exists("RecycleBin-1.png"): --> Image when the "Recycle bin is full" rightClick("RecycleBin-1.png") --> "Right clicking the Recycle bin" full icon. 尝试1-不存在(“ RecycleBin-1.png”):->“回收站已满”时的图像rightClick(“ RecycleBin-1.png”)->“右键单击回收站”完整图标。 click("EmptyRecycle.png") --> Image of confirmation to delete all items. click(“ EmptyRecycle.png”)->确认删除所有项目的图像。

click("1406033619416.png") --> Image of "Recycle bin" is empty
print ("Recycle bin has been emptied")
else:
while exists ("RecycleBin.png"): 
print ("Recycle bin is already empty")

Try 2 - while not exists("RecycleBin-1.png"): rightClick("RecycleBin-1.png") click("EmptyRecycle.png") 尝试2-不存在时((RecycleBin-1.png“):rightClick(” RecycleBin-1.png“)click(” EmptyRecycle.png“)

click("1406033619416.png")
print ("Recycle bin has been emptied")
else:
print ("Recycle bin is empty")

My problem is either the while loop before else gets executed (or) the else part is executed in sikuli inspite of the Recycle bin is empty (or) full, sikuli is not doing any complete analysis and executing it as necessary. 我的问题是,在回收站为空(或)已满的情况下,尽管回收站为空(或)已满,否则其他部分在sikuli中执行之前的while循环(或)else部分在sikuli中执行,sikuli没有进行任何完整的分析并根据需要执行它。

Please anybody help me out on this as I am relatively new to sikuli and python. 请有人帮我解决这个问题,因为我对sikuli和python比较陌生。

Thanks, V.Prashanth 谢谢,V.Prashanth

As a first resort, go to where the picture of the icon appears in your code in the Sikuli IDE. 首先,请转到Sikuli IDE中代码中图标图片的显示位置。 Try clicking on the picture, then go to the matching preview tab, and change the similarity from the default of .7 to something much higher (.9 or .95), and see if that resolves the issue. 尝试单击图片,然后转到匹配的预览选项卡,并将相似性从默认值.7更改为更高的值(.9或.95),然后查看是否可以解决问题。

Because the picture of the full recycle bin and the empty recycle bin are very similar, upping the similarity forces Sikuli to only allow a match when it is almost identical (90% or 95% match) to the picture you've captured in the IDE, rather than returning a match on anything that is only a 70% match. 由于完全回收站的图片和空回收站的图片非常相似,因此提高相似性会迫使Sikuli仅在与您在IDE中捕获的图片几乎完全相同(匹配90%或95%)时才允许匹配,而不是只返回70%的匹配项返回匹配项。

If that doesn't fix the issue, there may be other things to try, but I would try that first. 如果那不能解决问题,则可能还有其他尝试,但我会首先尝试。

autoKarma is spot on, you need to increase the similarity; autoKarma已经存在,您需要增加相似性; since the trash icon is static I'd push it all the way to 99%. 由于垃圾桶图标是静态的,因此我会将其一直推送到99%。 FYI, The IDE suppresses the text ".similar(0.##)" below, but if you check the .py file that the IDE generates on save it'll be there. 仅供参考,IDE会抑制下面的文本“ .similar(0。##)”,但是如果您检查IDE保存时生成的.py文件,它将保存在那里。

I revised your loops a bit more, my experience with Sikuli is that you end up with many...many loops to ensure Sikuli can handle the oddities that inevitably come into play with pattern-recognition. 我对循环进行了一些修改,我在Sikuli上的经验是,您最终会遇到很多...许多循环,以确保Sikuli可以处理模式识别不可避免地要发挥的作用。 The code below is untested code and loosely reflects a Mac, although at least mine pops up a "are you sure you want to delete this" warning before it begins clearing, so your milage may vary. 下面的代码是未经测试的代码,大致上反映了Mac,尽管至少我的在开始清除之前会弹出“您确定要删除此内容”警告,所以您的里程可能会有所不同。

def take_out_the_trash():
    while exists(Pattern("Full_RecycleBin.png").similar(0.99)):
        rightClick("Full_RecycleBin.png")
        wait 1
        while exists(Pattern("EmptyRecycle_Button.png").similar(0.99)):
            click("EmptyRecycle_Button.png")
            wait 1
        while exists (Pattern("Emptying_trash_in_progress.png").similar(0.90)):
             wait 2

take_out_the_trash()

For the "Emptying_trash_in_progress" picture, be careful not to get the progress bar in the picture; 对于“ Emptying_trash_in_progress”图片,请注意不要在该图片中看到进度条。 just find some static text/menu that'll be safe to reference. 只要找到一些可以安全引用的静态文本/菜单即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM