Hi Darrell,
I assume from your message that you have no programming experience. If
this is the case I'll be straight up with you: programming NVDA is going
to be a tough road to hoe. I don't want to discourage you. But if you
decide to take it on be prepared to work very hard at it. Here's why and
why I was able to do it in only a few weeks.
1. In Window-Eyes we have a component object model. This is essentially
an interface that defines everything Window-Eyes can do. And along with
that interface we have encyclopedic documentation that shows us how to
do everything, or at least defines how everything works.
Conversely, NVDA is written primarily in Python and has no such
interface. The so-called documentation is the proverbial tip of the
iceberg. So much so that I'm not sure anyone could do anything but the
most simplistic tasks after reading it. The bottom line is that we have
to delve into the code-base of NVDA itself, figure out how it works, and
try to figure out what to do with it. This is not an easy task because
NVDA is very unconventional in my opinion. It tries to do a lot of
"pre-processing" on everything in order to make things generic so they
can fit them into all of the several ways we can access and work with
things, i.e. windows, IAccessible, IAccessible2, UIA, and Java access
bridge. Window-Eyes is much more cut and dry on this front.
Consequently, unlike with Window-Eyes where we get exactly what is
there, we can get illogical problems right up front with NVDA. For
example, in Sound forge there are several non-standard vertical sliders
and horizontal track bars. Window-Eyes just tells me that they are
custom controls, I figure out what they do, and write the necessary code
to make them read the values they change. NVDA's attempt to figure them
out before hand decided that they were edit boxes. This makes absolutely
no sense given the nature of the controls. And I had no idea how to undo
it. Fortunately it was the one question I got the correct answer for on
the NVDA add-ons mailing list. Otherwise, most of what I thought were
basic questions either went unanswered, I got a wrong answer and wasted
days researching it, or I got an "I think so" answer on a real core
component of how NVDA programming works. To be blunt, they've been of
almost no help to me. I still can't believe I got an enormous suite like
Sound forge working.
2. This raises another problem beyond the fact that we have to read a
lot of core code to figure out how NVDA works and how to work with it.
This is another big difference between NVDA and Window-Eyes. When we
write a Window-Eyes script it is a program that Window-Eyes is calling
and running as an external process. The result is that while your script
can crash and burn, it cannot take down Window-Eyes with it. Typically
an error message dialog pops up telling you about the error, where it
is, and gives you the choice to stop or edit the script. Stop the script
and the world is round again.
With NVDA you're in a double-down game of Russian-roulette. Firstly,
writing what they call an "add-on" is writing code that will be injected
into the NVDA program. Break something and you break NVDA. The saving
grace is that if you're writing a program add-on, versus a global
add-on, you can simply close the program. This will unload your add-on
and things should go back to normal. But it's not always that easy,
depending on what the problem with your code was.
I've locked it up completely and had to bail myself out with Window-Eyes
or Narrator and then reload NVDA. Other times I've landed somewhere
in-between where closing the program would bring NVDA back, but, it
would be acting very strange. So I'd have to reload it.
3. One of the things I don't like about Python is the fact that there is
no error checking going on other than that which you explicitly write in
your code. This means that while big problems are big problems, small
problems are also big problems. That is to say, while Mrs. Bladdersplat
might have only taken two points off of your essay for a missing comma,
colon, period, or closing parentheses, in programming it is either right
or wrong. And just one missing punctuation mark is more often than not
deadly. Again, in Window-Eyes and VBScript, an error message would pop
up and tell you what the problem was.
There are two remedies for this. One is something you'll see in most of
the online tutorials on Python. That is the fact that we have a Python
console where we can write code one line at a time or even run a
program. Within the console error checking is done and we'll get error
messages. The problem is that we're not writing stand alone programs. So
we can only do very basic coding in the console because we're writing
programs that need to integrate with both NVDA and the program we're
scripting. Therefore we can't write a script and run it in the console.
It has to be run by NVDA when the program we're scripting is launched.
the other option is an elaborate integrated development environment
(IDE) such as Eclipse or Visual Studio. I have heard these mentioned,
but I haven't used either. And the folks at NVDA recommend Notepad++
which is a much less elaborate code editor. So I assume accessibility is
the typical roadblock we face here and the big development environments
are more trouble than they're worth.
The only real thing we can do is set NVDA's logging to debug mode. This
basically logs everything NVDA is doing. Then you have to plow through
that file to track down the error. Once you get the hang of it you'll
know what to search for in order to get close to where you were. There's
also a log handler module you can import into your program and use to
write messages to the log. So you can write when something begins and
search the log for that message.
4. So how was I able to write such a program in such a short time? The
answer lies in the fact that I've been programming for almost thirty
years now. And while I've never used Python, I have used a few other
languages. And once you do that it's all pretty much the same, at least
conceptually. So I really just had to skim through the Python
documentation, a couple books, and Google things here and there.
And given my understanding of programming I was able to decrypt the
endless lines of NVDA code I had to read in order to figure out what was
going on and what to do to make things work.
Now to be brutally honest, I must admit that I just about went out of my
mind trying to figure out what to do with this mess. And I don't say
that lightly. In my opinion it is a mess. The circular references are
endless and you end up on a wild goose chase and reading three-hundred
lines of code in order to figure out how to write the next three in your
program.
I don't think the NVDA developers really want people writing scripts.
The reasons are as follows. The injected nature of scripts makes it too
easy to break NVDA. They've done none of the tiny amount of
documentation available. It's all been done by one user until very
recently when another user jumped in and wanted to help. And there's
another mailing list, the developers list. It's open to anyone. But I
gave up after asking a few questions and getting not a single answer.
And finally, there's one last bump in this rocky road. NVDA uses Python
version 2.7. While it's not unusual for languages, or more precisely,
implementations of languages, to be updated, such changes are always
backward compatible. But due to insurmountable problems Python did
something I've never before seen. They made core changes in the language
that made Python 3 incompatible with Python 2. That was years ago. And
they continued to support Python 2 because there were billions of lines
of code running everywhere from the web to databases to corporate
networks. But the last real release was in 2009. All they've done since
is release bug and security fixes. Consequently, NVDA is right now in
the process of converting it's code-base to Python 3. And while it won't
be a big jump from one to the other, it will nonetheless still be a
jump. So whatever code you write now will have to be reworked when the
NVDA changeover is complete.
It is possible to write code compatible with both now. But of course as
a beginner that's another whole ditch to dig yourself into while trying
to figure out how to get started in the first place. So, for myself,
I've yet to even take a look at it. My crazy attempt to script Sound
forge was just a, pardon the pun, wild shot in the dark to see if I
could do anything with it. And as I've said, it's a miracle that I was
able to.
However, for the sake of not ending on a dark note, I'll say this. If
what you need to do is script programs wherein the data you need is
there but not being presented (spoken or braille) correctly, or at all,
it's not that hard to access and manipulate such data once you get the
swing of it. This is the idea behind NVDA's approach of trying to fit
everything into a generic box. It gives you at least the basic
properties of anything that they can make fit correctly. However, in my
narrow experience with Sound forge, every what Window-Eyes calls a
custom control and NVDA calls an unknown, was either classified
incorrectly or as unknown. And unknowns are more difficult to work with
in NVDA.
Okay. Enough blabbering for now. Here are a few resources.
The main developer guide.
https://www.nvaccess.org/files/nvda/documentation/developerGuide.html
The add-on developer guide.
https://github.com/nvdaaddons/DevGuide/wiki/NVDA-Add-on-Development-Guide
The add-ons Google mailing list.
https://nvda-addons.groups.io/g/nvda-addons
Hope this helps. And don't worry. As I've said, it's a piece of cake.
Hahaahaaha!
Regards,
Tom
On 6/28/2019 6:58 AM, Darrell Bowles via Talk wrote:
Hello,
I am interested to know how you learned to code in python, and how you managed
to make the add-on. I want to learn to code myself, so if you have any advice
or resources, I'd greatly appreciate it.
Thanks,
Darrell
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/talk-window-eyes.com/tom.kingston%40charter.net.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/talk-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/talk-window-eyes.com
_______________________________________________
Any views or opinions presented in this email are solely those of the author
and do not necessarily represent those of Ai Squared.
For membership options, visit
http://lists.window-eyes.com/options.cgi/talk-window-eyes.com/archive%40mail-archive.com.
For subscription options, visit
http://lists.window-eyes.com/listinfo.cgi/talk-window-eyes.com
List archives can be found at
http://lists.window-eyes.com/private.cgi/talk-window-eyes.com