Using curses module with sikuli

Asked by Brad

Hi, I've tried for a long time to figure out how to build a meaningful output for the console window while my script is running. I'm hoping someone here can help. I found some nice features in the curses module https://docs.python.org/2/howto/curses.html and would like to know if there is a way I can use that in my sikuli modules?

I program entirely in the sikuli IDE.
I run the script from the sikuli IDE -OR- from the command line.
I am dealing only with Windows 7 machines.

Can anyone give me instructions on how I can get these two to play nice?
----OR----
If curses isn't going to work for whatever reason, is there a way to control cursor location etc from within sikuli?
I only know the \r trick to over-write the same line cursor is currently on, but would love to be able to clear the screen and build a small output window like:

========================
== Loop 000032 | 1456hrs ==
========================
No Problems found

The formatting will probably be wrong, but I hope you can see what I'm trying there.
Then on the next Loop, the console window is cleared and printed again so it stays neat.
The "No Problems Found" will be an array of the last X Debug or similar notifications, so when looking at screen, I can see a bit about what's going on etc. That part I'm ok with, it's just getting the console formatted.

Help us Internet-kenobi, you're our only hope.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

  • by Brad
Revision history for this message
RaiMan (raimund-hocke) said :
#1

what about just issuing a clear command using run("clear")?

... and then start writing your stuff again, now from top of the window again.

Revision history for this message
Brad (blueoni) said :
#2

Tried that and got following error:
[error] ResourceLoaderBasic: runcmd: fatal error: Cannot run program "clear": CreateProcess error=2, The system cannot find the file specified.

I also tried run("cls") which if I type directly into the command window, it does clear the window, but if used in sikuli, gets the same output above:
[error] ResourceLoaderBasic: runcmd: fatal error: Cannot run program "cls": CreateProcess error=2, The system cannot find the file specified.

I'm not going to lie, I slapped my head when you replied with that, thinking "omg, so simple".
Any other ideas?

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

ok, i guess, cls is an internal command.

try this instead:
run("cmd /c cls")

Revision history for this message
Brad (blueoni) said :
#4

Here's something that might help. I took what you said and researched it and came across this bit of code...

import os
#define
def clearscreen():
    os.system('cls' if os.name=='nt' else 'clear')
# now, to clear the screen
clearscreen()

Tried that and didn't work (I have added import os to the top of my script), I then modified to...
def clearscreen():
    if os.name=='nt': os.system('cls')
    else: os.system('clear')

still no luck and then I added this...
print os.name

and it prints out...
java

I then started looking through java console commands to clear the screen and have tried
def clearscreen():
    print os.name
    if os.name=='nt': os.system('cls')
    elif os.name == 'java':
        print "\u001b[2J\u001b[H",
        print "\033[2J",
        print "\x1B[H\x1B[J",
    else: os.system('clear')

No errors anymore, it prints java and then the three java print lines (which I just copied and pasted from a "Clear console in java" search) don't print anything and script continues as normal. I'm surprised the os.name responds with java.

Revision history for this message
Brad (blueoni) said :
#5

Wow, your response time is Quick! sorry, I was typing and testing all that while you responded...

Tried what you said, I now have:
def clearscreen():
    run("cmd /c cls")

and then call clearscreen() but still nothing happens. No error message either.
again, I tested it from command window, and typing cmd /c cls directly into the prompt does clear the screen.

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

Response time: I am just sitting in front of my MacBook Air and trying to answer "easier" SikuliX questions fits inbetween ;-)

... but in this case I tried to make my life a bit easy ;-)

what I suggested is not targeted towards the running command window, but is just processed internally in a subprocess and hence does nothing.

--- I'm surprised the os.name responds with java.
this is because SikuliX is a java application and hence the system environment seen by Jython is Java by design (this is why Java programs run on every system, that has a suitable JVM available).

So the only possible solution with SikuliX seems to be to use type("cls"+Key.ENTER) to the command window:

def clearscreen(myApp):
    App.focus("command prompt") # use a suitable part of the command window title
    wait(1)
    type("cls"+Key.ENTER)
    App.focus(myApp)
    wait(1)

clearscreen("myApp title") # use a suitable part of your target app's window title

about App.focus() just have a look at the docs

Revision history for this message
Brad (blueoni) said :
#7

Sorry about the delay, I have been overseas.
I've tried your above suggestion without success - and I think it's because while the script is running there is no command input.

def clearscreen():
    Cmd = App("Sikuli Command Prompt")
    Cmd.focus()
    wait(1)
    type("cls"+Key.ENTER)
    OriginalApp.focus()
    wait(1)

Where OriginalApp is already defined as the window I'm generally working with.
It swaps focus, but as there is no prompt, the type("cls"+Key.ENTER) has no effect.

Is there a way to utilise the curses library (or anything similar) or would I have to start programming through a different IDE?

Revision history for this message
Launchpad Janitor (janitor) said :
#8

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Brad (blueoni) said :
#9

Yes, still seeking a solution
On 12 Mar 2016 5:17 pm, "Launchpad Janitor" <
<email address hidden>> wrote:

> Your question #284732 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/284732
>
> Status: Open => Expired
>
> Launchpad Janitor expired the question:
> This question was expired because it remained in the 'Open' state
> without activity for the last 15 days.
>
> --
> If you're still having this problem, you can reopen your question either
> by replying to this email or by going to the following page and
> entering more information about your problem:
> https://answers.launchpad.net/sikuli/+question/284732
>
> You received this question notification because you asked the question.
>

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

I do not think that there is a short term solution for your request.

What you see in the command line window is simply the continuous output line by line to stdout produced by the Python print statement or internally by Java's System.out.println().

A possible solution would be to setup a JFrame window in your script, that sits somewhere on the screen in a place, where it does not interfere with the automation workflow and that you fill with whatever you want.

A SikuliX integrated solution for this will only be available with version 2.

Can you help with this problem?

Provide an answer of your own, or ask Brad for more information if necessary.

To post a message you must log in.