I attach an enhanced patch to the python shell.
This one is a bigger change than the previous patch. But it moves the
code to the point where the whole shell is contained as an external
python file, which makes it a lot easier to develop and enhance.
Explanation of the changes:
- I created a "pcbnew/scripting/kicad_pyshell" directory to contain the
shell python code. So i added the required installer directives.
- I don't need or use "scripting/python_console_frame.h" so all
reference to its removed from the code, but the file still exists in the
source tree.
- I changed the Bundled search path to be "scripting" not
"scripting/plugins". "plugins" is only one type of possible scripting
and also common to all 3 platforms, so its handled lower down. This
means its possible to have other types of "scripting". The directory it
produces is therefore just the scripting "bundled" search path, and
doesn't need to be over-ridden by the end user, as far as i can tell. So
I removed the comments about that being desirable.
- I removed the TODO comments, the way the code works now, there are a
bunch of default search paths added, some referencing the kicad install
path, some from the KICAD_PATH environment variable and some from the
users root directory and users kicad config directory. Its also easily
possible for a user to add their own include paths, all they need to do
is add python code to a module in the search path to do it, and the
python interpreter will load that and execute it in the process of
initialising the plugins. Note, these search paths are only possible
search paths, they dont get added if they dont exist.
- I modified LoadPlugins in kicadplugins.i to properly add all the
scripting paths, including plugin paths.
The full list of possible default search paths is now:
+ # The Scripts bundled with Kicad:
+ # <bundlepath>
+ # <bundlepath>/plugins
+ #
+ # The Scripts relative to the Kicad environment variable search path:
+ # <kicad_path>/scripting
+ # <kicad_path>/scripting/plugins
+ #
+ # The Scripts relative to the Kicad Users configuration:
+ # <config_path>/scripting
+ # <config_path>/scripting/plugins
+ #
+ # And on Linux, extra paths relative to the home directory:
+ # ~/.kicad_plugins
+ # ~/.kicad/scripting
+ # ~/.kicad/scripting/plugins
And i include that as a comment in the code.
- I changed some names from <blah>PluginsPath to <blah>ScriptingPath to
make the parameters reflect their current use.
- I reduced the python code embedded within CreatePythonShellWindow to
the bare minimum, which eases maintenance, as further changes or
enhancements to the python shell are all in pure python. I also renamed
it from pycrust_panel to pcbnew_shell to better reflect what it is. Its
possible in future the shell wont be based on pycrust, there is no need
to do it, except that currently its already a dependency of Kicad and
easy enough to leverage.
It also seemed to make sense to refer it to pcbnew, where it is embedded
because i could imagine a time when eeschema has python scripting and
its own shell. And, at that time both programs could share a lot of the
same python shell code.
Steven
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp