hopefully (2) easy questions (region.focus & code consolidation)

Asked by Mike Praeuner

First question:

I am using app.open (to launch Nox) then app.focus (to go to the "Nox Player" window)
How do I set the region to the Nox window (only one window open)?
#sample code
App.open("D:\\Program Files\\Nox\\bin\\Nox.exe")
sleep(15)
App.focus("NoxPlayer")
#

Second question:
I have my first sikuli script mostly working (it should take ~30m to run, currently ~1.5 hours, so it needs optimized)
I load Nox, clear android app data, load the app, select the google ID, select the account (1 of 5 potential) then perform the desired action (my first test is just to open and close the app for all 8 Google IDs, 25 accounts -- 60s global app timer between accounts)

Currently this script is 1600+ lines, with a large amount of repeat content (indicating my lack of coding skills) I am pretty certain I did this the hardest way possible, so where would I start to simplify and consolidate?

Regretfully I am not near my personal computer, but I will gladly load any files (.skl?) for reference when I get home this evening
Updated Source File:
https://www.dropbox.com/s/9eahdut5szxhsh0/DailyLogon.skl?dl=0

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Mike Praeuner (eris667) said :
#1

I am currently reading up on Python Loops...
https://www.geeksforgeeks.org/loops-in-python/
Just need to wrap my head around how to implement / structure

Revision history for this message
RaiMan (raimund-hocke) said :
#2

at 1---
App.open("D:\\Program Files\\Nox\\bin\\Nox.exe")
sleep(15)
App.focus("NoxPlayer")
reg = App.focusedWindow()

or
app = App("D:\\Program Files\\Nox\\bin\\Nox.exe")
app.open(15) # does the focus as well
reg = app.window(0)

... the docs are showing ;-)
https://sikulix-2014.readthedocs.io/en/latest/appclass.html#the-application-class-app

at 2---
your problem surely is, that you have too many waits in your code, that are absolute.
example from above:
App.open("D:\\Program Files\\Nox\\bin\\Nox.exe")
sleep(15)
App.focus("NoxPlayer")
... sleep(15) waits 15 seconds, no matter what really happens
better:
app = App("D:\\Program Files\\Nox\\bin\\Nox.exe")
app.open(15) # does the focus as well
reg = app.window(0)
... open waits MAX. 15 seconds for the app to open. script continues at the moment, the app is open (might be after 3 seconds)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

... same goes for image searches
instead of:
click(whatEver)
wait(5)

better:
click(whatEver)
wait(forSomeImage, 5) # might continue after 1 second if image is there

Revision history for this message
Mike Praeuner (eris667) said :
#4

Thank You RaiMan - I appreciate your patience & response. I will make the suggested corrections

for second question...to structure a loop?

My normal sequence is
Run Script (scheduled task)
Load Nox
Load app
  do stuff to:
    Select Google ID
      do stuff to:
        Select Account
          perform action on account
           do stuff to:
             Select next account (1-5 possible)
Exit app inside Nox
Clear app data (via shell script shortcut)
Load app
  do stuff to:
    Select (next) Google ID (8 possible)
      repeat for all 25 accounts
Exit Nox
Exit Script

So would this be a for loop with the "select portion" as a set of variables? (my terminology is probably wrong, hopefully you can understand what I am trying to ask)

What I really want to accomplish is (end goal) create 4-5 scripts that "perform different action(s) on account" based on the initial building blocks of being able to load and switch accounts

Revision history for this message
Mike Praeuner (eris667) said :
#5

clarification / correction
this:
        Select Account
          perform action on account
           do stuff to:
             Select next account (1-5 possible)
Exit app inside Nox

should be:
        Select Account
          perform action on account
           do stuff to:
             Select next account (1-5 possible)
               perform action on account
Exit app inside Nox

Revision history for this message
Mike Praeuner (eris667) said :
#6

...or am I still thinking about this wrong (structure) and I should be "storing" the do stuff / action and "calling" it when needed?

nOOb - thanks!

Revision history for this message
Mike Praeuner (eris667) said :
#7
Revision history for this message
Best RaiMan (raimund-hocke) said :
#8

As far as I understand:

def doSomething(gid, acc):
    setup app environment using gid and acc
    do something for an account
    tear down app environment

you have
8 google-id
with each having 1 - 5 accounts

googleIDs = [g1, g2, g3, g4, g5, g6, g7, g8]
accounts{g1:[a1, a2, a3, ...], g2:[a5, a6, ...], ...}

for gid in googleIDs:
    for acc in accounts[gid]:
        doSomething(gid, acc)

Revision history for this message
Mike Praeuner (eris667) said :
#9

thank you - my knowledge now surpasses my skill - so I will go experiment and practice for a bit
I "get" the function part, so I will start there, then work towards utilizing a for loop

Revision history for this message
Mike Praeuner (eris667) said :
#10

Thanks RaiMan, that solved my question.