No announcement yet.

Python Console

  • Filter
  • Time
  • Show
Clear All
new posts

  • Python Console

    TerminallyIll is an embedded Python console World Wind plugin.

    Name will change to something respectable once the console's capabilities are respectable. Right now you get nothing more than IronPython with IronTextBox in a World Wind plugin form (no specialized environment setup, no utilities, no examples, ...).

    First enhancement to Python support in WW on my list doesn't affect this plugin directly -- it's adding support for plugins written in IronPython.

  • #2
    Neat. To get it to load you have to delete the REFERENCES: line in the header and put the dlls in the same directory as WorldWind.exe. Now to learn how to make it do something besides calculator...


    • #3
      Oops! Heh, that's why I started the version number at 0.1

      Edit: Oh yeah, I put the dlls in the same dir as the plugin (manually created a Plugins/TerminallyIll directory and put them in there), seems to also work Sorry I was mistaken, the dlls were in the WorldWind.exe directory all along, so withak was right.
      Last edited by rghosh; 02-26-2007, 05:23 AM. Reason: wrong advice


      • #4
        Will be very interested in how this is implemented.

        An interesting note:
        IronPython is an implementation of Python that runs atop the .NET's Common Language Runtime. It's still a new project, but its initial performance is promising. Lead developer Jim Hugunin was hired by Microsoft to work on dynamic language support for the CLR, and one of his tasks will be to complete the IronPython implementation.
        Last edited by nlneilson; 02-25-2007, 09:17 PM.


        • #5
          Ah, OK, so I figured out how to get a reference to the world:

          import clr
          from WorldWind import MainApplication
          from System.Windows.Forms import Control
          app = Control.FromHandle( MainApplication.GetWWHandle() )
          world = app.WorldWindow.CurrentWorld
          This will go in some kind of environment setup script that automatically runs when the console is started so the app and world variables will be ready from the start.

          So then I can mess around:

          <WorldWind.Renderable.RenderableObjectList object at 0x000000000000002E [Earth]>
          ['Add', 'BuildContextMenu', 'ChildObjects', 'CompareTo', 'Count', 'Delete', 'Description', 'DisableExpansion', 'Dispose', 'Enable', 'Equals', 'Finalize', 'GetHashCode', 'GetObject', 'GetObjects', 'GetType', 'IconImage', 'IconImagePath', 'Initialize', 'Initialized', 'IsOn', 'MakeDynamicType', 'MemberwiseClone', 'MetaData', 'Name', 'OnDbfInfo', 'OnDeleteClick', 'OnGotoClick', 'OnInfoClick', 'OnPropertiesClick', 'Opacity', 'Orientation', 'ParentList', 'PerformSelectionAction', 'Position', 'Reduce', 'ReferenceEquals', 'RefreshTimer', 'Remove', 'RemoveAll', 'Render', 'RenderPriority', 'ShowOnlyOneLayer', 'SortChildren', 'StartRefreshTimer', 'Thumbnail', 'ThumbnailImage', 'ToString', 'TurnOffAllChildren', 'Update', 'World', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__str__', '_metaData', 'dbfIsInZip', 'dbfPath', 'isInitialized', 'isOn', 'isSelectable', 'm_children', 'm_description', 'm_iconImage', 'm_iconImagePath', 'm_opacity', 'm_propertyBrowser', 'm_renderPriority', 'm_thumbnailImage', 'm_world', 'name', 'orientation', 'position']
          So some operations that are well-suited to the command line include
          • Filter all renderable objects by a regular expression match of the name, and setting the matches to visible, everything else invisible
          • More generally, use arbitrary conditions like "object.alt > 11000"
          • Query spatial objects from a spatial database, a directory of shape files, an RSS feed, etc., filter based on a condition as above, and use WKT or WKB to create renderable objects and add them to the world

          All of these operations rely on expressions of arbitrary structure and so are possibly better suited to a console interface than an ordinary gui interface

          Edit: Oh yeah and apparently IronPython.CodeDom.PythonProvider() is incomplete and broken (admittedly so by IronPython, as it apparently breaks some of the tests that IronPython ships with, and there is debate over whether it should actually be removed since Python is a dynamic language), so adding a code provider to WorldWind/PluginEngine/PluginCompiler.cs doesn't work, so there is no clean and simple way to add support for IronPython plugins. A cruddy way that should work is to have a c# plugin that acts as a manager for all python plugins.
          Last edited by rghosh; 02-26-2007, 05:10 AM. Reason: append


          • #6
            Excellent. I got it to find the WW classes but couldn't figure out how to get the mainapplication reference.

            * Query spatial objects from a spatial database, a directory of shape files, an RSS feed, etc., filter based on a condition as above, and use WKT or WKB to create renderable objects and add them to the world
            Yeah, this will make dealing with imported shapefiles a lot easier.
            Last edited by withak; 02-26-2007, 02:38 PM.


            • #7
              Version 0.3:

              Basic env setup:
              • Now on startup of the console there is an object named env which has fields app and world. So, for example, type "dir(" to see world's members
              • The directory of the plugin is added to the python path, so you can import python modules in that directory. For example, put a python file named into the same directory as the plugin, and from the console type "import foo"


              • #8
                Downloaded v0.3, put the .dll files in the dir with WorldWind.exe
                Made a dir TerminallyIll in the plugins dir for the file
                Put TerminallyIll.cs in the WorldWind dir so a breakpoint when debugging will work
                Tried the dir( and dir( at the prompt, OK

                Opened up the Console, surprise, surprise, a help with 9 commands, GPSTracker has a help file also, there may be other plugins that have some type of help but they are in a slim minority.

                Is the Big Snake (Python) going to help in getting "Help" into WW?
                Last edited by nlneilson; 03-01-2007, 03:18 PM.


                • #9

                  The tutorial that comes with IronPython itself is pretty good, and there are a ton of other samples there as well.

                  With the environment set for you up it's basically just a matter of translating anything you would do in a C# plugin into python. It just takes a little longer because there isn't any kind of tab completion.

                  I asked the IronTextBox guy on codeproject about tab completion, he says he is looking into it.
                  Last edited by withak; 03-01-2007, 03:46 PM.


                  • #10
                    Just downloaded IronPython, the IronPython IDE and the Zeus IDE trial a few days ago and have not tinkered with it very much, may be able to use PyScripter as well as Idle. Python has byte of python, dive into python and py_grimoire that is probably applicable to IronPython also, will go thru the IPy tutorial.
                    Good job on getting this in.


                    • #11
                      Here is an example of how to create a renderable:

                      from WorldWind.Renderable import ModelFeature
                      from WorldWind.Renderable import RenderableObjectList
                      rolist = RenderableObjectList("new list")
                      model = ModelFeature("name",, r"c:\ww-trunk\bin\Debug\Data\Model\tiny.x", 10,10,0, 100,0,0,0)


                      • #12
                        Looks great for a few lines of code.
                        You might look at VPython at
                        Have not tried it but may be easier for a few function than in c#


                        • #13
                          Ok.. time to start reading up on Python now..

                          Earth is Square blog

                          PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this forum post, in any manner whatsoever, will increase the amount of disorder in the universe. Although no liability is implied herein, the consumer is warned that this process will ultimately lead to the heat death of the universe.


                          • #14
                            Regarding python libraries, unfortunately IronPython and CPython share the same language but are different technologies. IronPython can not directly use python libraries that include binary modules. Thus Numpy, SciPy, and Twisted, among others, are out of the picture unless someone ports them to IronPython. IronPython can use .NET assemblies, so, for the example of shapefile support, Shapelib's python bindings were made for CPython (the original python and the one that made python famous) and won't work with IronPython, whereas NetToplogySuite and SharpMap were designed without Python as a consideration but are readily usable in IronPython. So the way to go for extending WW's capabilities through IronPython is to look for .NET class libraries and leverage them through a console, not to look for python libraries (unless they are pure python or you feel like porting them).

                            For anyone who doesn't know python but is interested in using the console, my personal advice is to not spend much time reading about python (an intro web page that takes 5 minutes to read and isn't full of weird pythonism brainteasers might be good), but just use it. Write a line of python like you would a line of C#, if there's an error then go from there (leaving out semicolons and the "new" operator might be all you need for starters)

                            That really kills me that twisted hasn't been ported to ip though. MochiKit gave me false hope as a (quite small) subset of twisted's paradigms that is .NET compatible, but it's made for firefox xul and won't work with the microsoft.jscript code provider.


                            • #15
                              This is helpful in figuring out how to translate C# into python to start. Also this. From after that, just google the errors.
                              Last edited by withak; 03-02-2007, 05:46 AM.