How to select from a slider list that contains more than 10 values

Asked by Lara on 2017-02-17

Hi, I'm a newbie in using Sikuli , and i'm hoping that someone can help me with this. To be specific, I'm having difficulty on how can I easily change the language in Mac Os since the only way to choose a specific language is by moving the slider up and down then dragging the language upward until it reach the top.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2017-02-21
Last query:
2017-02-21
Last reply:
2017-02-21
RaiMan (raimund-hocke) said : #1

normally I do not make scripts any more for specific user requests, but this case was interesting for me, since it currently fits perfectly as a testcase for version 2 and I will put it as an example into the docs - so you are welcome in this case:

# the script macSelectLanguage.sikuli
# images used
showAll = "showAll.png"
language = "language.png"
german = "german.png"
english = "english.png"

# open or focus System Preferences
App.open("System Preferences")

# to make sure the all view is visible
click(showAll)
wait(1)

# select language view
click(language)
wait(1)

# waiting for language tab
topRef = wait(Pattern("language.png").targetOffset(29,100))
#topRef.highlight(2)

# restrict search reagion to list area
list = topRef.left(1).right(250)
list = list.below(1).below(300)
#list.highlight(2)

# find entry
entry = list.exists(english)
if (entry):
  topRef.hover()
  # remember top position
  topLoc = Mouse.at()
  wait(1)
  entry.hover()
  # remember entry position
  entryBackLoc = Mouse.at().offset(0, entry.h/2)
else:
  print "entry not visible in list"
  exit(1)

# check if entry is already at top position
if not entry.y > topLoc.y + entry.h/2:
  print "already top"
  exit()

# move selected entry to top of list
entry.click()
wait(1)
dragDrop(entry, topLoc)
wait(2)
# move entry back to its former position
dragDrop(topLoc, entryBackLoc)

# close System Prefs
wait(3)
type("q", Key.CMD)

# download from here
http://snippets.sikuli.de/examples/macSelectLanguage.sikuli.zip

RaiMan (raimund-hocke) said : #2

if there are more entries in the list, so that some are not visible, I guess one has to first use the key down, to get these entries visible.

pseudo code:
select first entry
while entry not found:
    key down

now the entry is visible and we have to repeat the drag to top, until the entry really is at the top combined with intermediate key ups.

in any case much more complicated ;-)

Best RaiMan (raimund-hocke) said : #3

ok, just checked with more entries:
dragging to the top always makes it the first entry (auto scrolls to top)

I will make a second example, where there are more languages, than fit into the window.

Lara (jhela) said : #5

I'm still having difficulty because I have 11 languages in the list

On Tue, Feb 21, 2017 at 10:53 AM, Lara <<email address hidden>
> wrote:

> Your question #464137 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/464137
>
> Status: Answered => Open
>
> You are still having a problem:
> Thank you for response, I'm still trying the scripts that you have given
> me.
> And hopefully it will work. :)
>
> On Fri, Feb 17, 2017 at 5:15 PM, RaiMan <
> <email address hidden>> wrote:
>
> > Your question #464137 on Sikuli changed:
> > https://answers.launchpad.net/sikuli/+question/464137
> >
> > RaiMan proposed the following answer:
> > ok, just checked with more entries:
> > dragging to the top always makes it the first entry (auto scrolls to top)
> >
> > I will make a second example, where there are more languages, than fit
> > into the window.
> >
> > --
> > If this answers your question, please go to the following page to let us
> > know that it is solved:
> > https://answers.launchpad.net/sikuli/+question/464137/+
> confirm?answer_id=2
> >
> > If you still need help, you can reply to this email or go to the
> > following page to enter your feedback:
> > https://answers.launchpad.net/sikuli/+question/464137
> >
> > You received this question notification because you asked the question.
> >
>
> --
> You received this question notification because you asked the question.
>

RaiMan (raimund-hocke) said : #6

what are your problems?

Lara (jhela) said : #7

Oh I'm sorry , my scripts already run well, I used different structure of script. Thank you for your help, It helps me a lot. Thanks Raiman.

Lara (jhela) said : #8

Thanks RaiMan, that solved my question.