← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #253923]: Broke my script using alt editor for sikuli IDE

 

Question #253923 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/253923

RaiMan proposed the following answer:
**1 thanks for kind feedback. Have fun with Sikuli.

**2 basic knowledge needed
Sikuli is attractive for "newbees" (meaning no experience with common scripting languages like Python, Ruby, JavaScript, ... or even programming at all), since the IDE allows to have success with some basic visual workflows very fast. 
At this level, the newbee tends to add more and more actions to the workflow so it gets crowded more and more and hence in-transparent and  error prone. 
At this level, it is normal to copy and paste code and to capture needed images more than once (which currently internally still leads to multiple copies of the same (in most cases not exactly with respect to width and height)).
Conclusion: Before beginning to invest in more complex coding (where this begins depends on your current knowledge) you MUST have some knowledge of the basic language features of Python, which is used as the primary scripting language with Sikuli.
(that Jython internally is used as interpreter is only a technical aspect with no relevance for the newbee). faq 1858
Python is a modern object oriented language, that has all needed features, to structure your code and support the DRY (Don't repeat yourself) design pattern:
- variables to reuse content
- functions (def name(parameters): body) to reuse code that at runtime is modified by the given parameters
- modules to separate the code base into files, that are imported at runtime

of course it has the basic features to route through your workflow: faq 1437
- make decisions based on evaluations what to do next: if ...: else ...:
- repeat code until a condition is met or for a given number of times: while ....: for i in range(): including continue and break

There are three more basics to know:
- exception handling try: ... except: ...

- the dotted notation to tell, that something should be used, that is contained in something_else: something_else.something (which in fact is a basic for all modern languages to encapsulate and use items in a tree like structure)
(sidestep: this a bad mojo with Sikuli especially for newbees: If you want to search or click something on the primary screen, you simply have to write find(image) or click(image). this is a convenience, since behind the scenes, this is used as SCREEN.find() and SCREEN.click() where screen is the preset constant representing the region "primary screen". So a beginner is not forced at start to understand Sikuli's region concept (which is really basic, to understand Sikuli at all), which only gets obvious at a later level of usage)

- indentation: this is the oddest but most elegant feature of Python
(and it is Python only). (All) other languages need some special
characters to tell, that some lines of code belong together (form a
block): e.g. the if and else branches, the body of a function or a loop.
in Python you simply indent the next and all following lines after a
block header (if, else, while, for, def, try, ...) with the same amount
of whitespace characters with the only rule: every line belonging to the
block must start with the same amount and type of whitespaces. this
leads to relative lean code, but you have to get used to it faq 1800

**3 Sikuli documentation
the docs (the maintained version: http://sikulix-2014.readthedocs.org/en/latest/index.html) was written 4 years ago and was my first contribution to Sikuli (... and sorry: yes it does not address the real newbee and in most parts is too technical and has too little real life examples and ... feel free to add more caveats as you already have done ;-)
When I took over the development of Sikuli 2 years ago, I decided the following priority row (decreasing): 
- enhance and develop further (currently 1.1.0-Beta4)
- help others to get on the road (Q&A here + faq section)
- accept and evaluate bugs including workarounds (bug section here)
- complete the Java docs (which is the internal heart of the Sikuli features)
- maintain the new webpage sikulix.com
- make the docs up-to-date
- write a tutorial for beginners 

I guess this answers all your questions about the docs ;-)

**4 recommended editor
The newbee should stick with the SikuliX IDE as long as possible, since no other editor or IDE has all features needed to setup and run scripts. (I only use NetBeans for the SikuliX development. For scripting (mainly tests and evaluations for other users) I use the Sikuli IDE). Especially for the newbee every other editor has some caveats, that Sikuli uses a folder as container for the script file and the associated images. These containers are only acted on as a compound entity by the Sikuli IDE.
(I have a favorite for an alternate Sikuli IDE based on JEdit with a SikuliX plugin, but this will only ready somewhen next year).
conclusion: living the concepts under **2, the best IDE/Editor for you is Sikuli IDE.

But if you really know, what you are doing, editors, that I have already looked at and use myself for other purposes:
NotePad++
JEdit 

and IDE's supporting Python scripting and debugging:
Eclipse/PyDev
PyCharm

Netbeans6.9 has a Python plugin, but this is not officially available
for versions 7 and 8, so I do not recommend it for beginners.

BTW: if you use one of these, then the best choice is to use the Sikuli
IDE in parallel for image management and quick testing. This requires
some conceptual investment in module structure and naming conventions
based on the understanding of Sikuli's image concept.

** 5 App class (vs openApp, ...)
The App class (everything that uses App.xxx) is not recommended for beginners. 
openApp, switchApp and closeApp deliver the basic features to start an application, to switch to the frontmost window of an application and to close the app again.
The App class only is of interest, if you want to deal with different windows of an application and get the window area as a region.
I admit that the docs might not express this currently.
Since the implementation of the feature is very system dependent, you have to carefully read the docs.

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.