Gnumeric and Python (or other scripting languages).



Hi,

Next Gnumeric will support introspection, and this changes the way
Python and gnumeric can interact. Although the Gnumeric Python interface
is still there, it is better to use introspection. In the Python
console, if you type (with a fresh new workbook):

from gi.repository import Gnm
wb=Gnm.App.workbook_get_by_index(0)
sheet=wb.sheet_by_index(0)
cell=sheet.cell_create(0,0)
cell.set_text("Hello World!")

A1 is now populated, but the view is not updated. Selecting the Gnumeric
window will show it. It is also possible to do that using Python, but it
is much more difficult.

You can also do things from a script or using Python in the terminal:

from gi.repository import GOffice
from gi.repository import Gnm
Gnm.init()
wb=Gnm.Workbook.new_with_sheets(1)
sheet=wb.sheet_by_index(0)
cell=sheet.cell_create(0,0)
cell.set_text("Hello World!")
uri=GOffice.shell_arg_to_uri("hello-world.gnumeric")
wbv=Gnm.WorkbookView.new(wb)
fs=GOffice.FileSaver.for_file_name(uri)
cc=Gnm.CmdContextStderr.new()
Gnm.wb_view_save_as(wbv,fs,uri,cc)
True
quit()

As can be seen there are some (actually many) issues with namespaces in
gnumeric code. If everything was correct, Gnm.wb_view_save_as(wbv,...)
would be wbv.save_as(...).

Things should work with other languages fof which introspection bndings
exist (see https://live.gnome.org/GObjectIntrospection/Users).

As I'm all but n Python (or any other scripting language) expert, I
didn't test, and there might be bugs around.

Regards,
Jean




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]