quote start The code is well-documented and organized quote end
-ohloh.net

Applying Python introspection

Content

Now, let me show you one of the most powerful tool to debug and to help developers while they are coding other tools or directly in the Nathive core. (slide-4a)

The runtime console, witch is just another plugin, allow you to browse all the Nathive objects and attributes in real time. Let me run it to do a real time demostration.

This is a Python pseudo-interpreter that allow you runtime introspection into Nathive, enjoy it!
>>> dir(main)
['__doc__', '__module__', 'args', 'cfgpath', 'clipboard', 'color', 'config', 'documents', 'gui', 'home', 'imgpath', 'language', 'level', 'log', 'main', 'options', 'palpath', 'path', 'phase', 'plugins', 'potpath', 'presets', 'shortcuts', 'userpalpath', 'userplgpath', 'version']

As you can see is like open a terminal and run python, these are all the available modules and attributes in the main object, it has full syntax compatibility...

>>> 2+3
5
>>> 2**3
8
>>> 'LGM' + ' rules!'
LGM rules!

Store variables...

>>> n = 17
>>> n + 10
27

Load and use modules...

>>> import os
>>> os.getcwd()
/home/markos

Even throw errors...

>>> 17 / 0
integer division or modulo by zero
>>> import asdf
No module named asdf

But it simply prints the error message instead of print the traceback and halt the program, also it saves and loads the command history, well, basically you feel like if you are using a real python interpreter, but really it's just a command send-and-get interface.

And now it's time to do some real test, now I'm getting the active document...

>>> document = main.documents.active
>>> document
<nathive.lib.document.Document object at 0x205eb90>

Getting the active layer...

>>> layer = document.layers.active
>>> layer
<nathive.lib.layer.Layer object at 0x2066050>

Printing its attributes...

>>> layer.__dict__
{'xpos': 0, 'name': 'Original', 'pixbuf': <gtk.gdk.Pixbuf object at 0x2064a50 (GdkPixbuf at 0x7fb3340b34a0)>, 'ypos': 0, 'height': 300, 'width': 400, 'alpha': True, 'pointer': 140407648990144, 'id': 0}

I'm going to move the layer x coordinate to 100...

>>> layer.xpos
0
>>> layer.xpos += 100
>>> layer.xpos
100

The layer was moved but we still need to refresh the canvas, first getting the canvas associated to this document, and then just calling the redraw method...

>>> canvas = document.canvas
>>> canvas
<nathive.gui.canvas.Canvas object at 0x2066110>
>>> canvas.redraw_all()

And doing the same we can manipulate absolutely all in real time, even the the smaller aspects of Nathive, so if something is failing or you only want to test how the application is working internally, this is a powerful tool, enjoy it.

Previous page | Next page