Excel RTD server in Python not updating data - python

I've got the excelRTDserver.py up and running in Excel 2010 (32bit) by changing the EXCEL_TLB_MINOR value to 7. I can see the server in the add-ins list and if I enter =RTD("Python.RTD.TimeServer","","seconds","5") into a cell, I get the current time. But it never updates. If I change the "5" to another number, I get an update but after the initial change it never changes again.
How do I get it to update? I found someone else with a similar problem here, but no solution.
UPDATE: I've got a little further - there is an exception raised within ServerStart when casting the PyIDispatch callback object into a IRTDUpdateEvent callback object. Using this method to capture the error message, I get "Cannot create a file when that file already exists.". If I follow the suggestion here and use win32com.client.CastTo(CallbackObject,'IRTDUpdateEvent') I get "This COM object can not automate the makepy process - please run makepy manually for this object", but I have already run makepy for Microsoft Excel 12.0 Object Library (1.6).
Any help would be greatly appreciated.

To work around this problem I've created a new project on github for pythoncom excel types:
https://github.com/pyxll/exceltypes
This includes a slightly modified version of excelRTDServer.py that uses the new type PyIRTDUpdateEvent instead of the win32com makepy wrapper, and so it now works in Excel 2010 (look for the comments 'EXCELTYPES_MODIFICATION' in exceltypes/demos/excelRTDServer.py).
To build the project you will need visual studio installed (it won't build with gcc) and you can build it using the setup.py included in the project as follows:
python setup.py install
If you need to force it to use visual studio instead of gcc use the "--compiler=msvc" option, if you're using anaconda for example.
If you want to use Visual Studio 2012 instead of the default 2010 add the following lines to setup.py:
from distutils import msvc9compiler
msvc9compiler.VERSION = 11

I think you may be out of luck.
According to the author of excelRTDServer.py in a recent python-win32 thread:
The message that this is in response to describes your exact problem, and it's recent, so maybe you already got this info directly, but in case you didn't...
I fear that things with IRTDUpdateEvent have changed with recent versions
of excel (since Excel 2007? I guess that's not so 'recent' anymore...).
While hunting around for news of interface changes, I came across this
thread in a java forum:
http://www.nevaobject.com/phpbb3/viewtopic.php?t=516
The part that worries me is this comment:
"Apparently in Excel 12 (Excel 2007) the RTD callback object that
implements dual IRTDUpdateEvent interface throws exception (generic COM
exception 0x80020009) when is called via IDispatch. If you use v-table
binding the call to UpdateNotify succeeds. I don't really know whether it
is a bug in Excel 12 or a feature."
So far I haven't been able to confirm this against the MSDN information...
But if this is true, it does explain the problem being seen. Many older
examples on the web, and pywin32+makepy treat this interface as IDispatch,
and wrap it accordingly.
I don't think we can fix this with pywin32 as it is right now. My
understanding is that it relies on IDispatch support. May need to look at
comtypes (http://starship.python.net/crew/theller/comtypes/) to wrap the
(new?) IRTDUpdateEvent objects, or maybe a C extension. :(

Python:
I get "This COM object can not automate the makepy process - please run makepy manually for this object", but I have already run makepy for Microsoft Excel 12.0 Object Library (1.6).
Yesterday at work after a while reading your question, I forgot that is python and not java :)).. Well, the only thing I think now is that seems you need to run the PIA for office 2010.
Edit later: if you steel have problems after what i told you., please comment and not downvote, because this issue is uncommon.
JAVA:
This happen because is missing the option to generate v-tables.
You need to modify ServerStart method and also IRTDServer interface and IRTDServer_Impl class., so CallbackObject is COMIUnknown. Then you need to generate IRTDServer_Skel class by runing the IBuilder.
Now you can generate a new java wrapper for IRTDUpdateEvent to request v-table:

That error message sometimes is raised when u put it in something like 'for'-loop,here is a hackly solution 4u:import time,and use 'sleep()' in your loop

The IRTDUpdateEvent problem (throwing exception) as described in here should be fixed in the latest Office 365 version.
"Apparently in Excel 12 (Excel 2007) the RTD callback object that implements dual IRTDUpdateEvent interface throws exception (generic COM exception 0x80020009) when is called via IDispatch. If you use v-table binding the call to UpdateNotify succeeds. I don't really know whether it is a bug in Excel 12 or a feature."
Therefore excelRTDserver.py should work fine with the latest version of Office. In other words, =RTD("Python.RTD.TimeServer","","seconds","5") should continuously get updated as expected.

Related

Exception during Fiji/ImageJ launching from Python

I want to write some code in Python that will be used for manipulating data in Fiji. I followed the instructions to install the library "imagej" so that I can access Fiji via Anaconda-Python. This is how the two lines look like:
import imagej
ij = imagej.init('C:\Program Files\Fiji\Fiji.app')
However, when I run these two lines the following error shows:
JavaException: JVM exception occurred: net/imagej/updater/UpdateService
Apparently Python is trying to access Fiji Updater but it cannot (that's what I understand...)
How can I run Fiji correctly without such an error? Is there any way to disable this?
I'm no expert, and actually have no experience with interfacing via Python, but my best guess is to try turning off "check for update on start" to see if that changes anything. It may be that Python is successfully getting FIJI to run, but the first thing FIJI needs is for you to tell it whether you want to update, etc.

DAO connection to Access .accdb database using Python

I’m having an issue with one of my Python apps that has been working fine with an older .mdb Access Databases. After converting to Access 2010 and the file being converted to the new .accdb format nothing seems to be working. I do have the 32 bit Access version loaded on a new 64 bit Win 7 OS. I believe my problem is with the first two lines of my code. I believe I need to update them to reference the "Microsoft Office 14.0 Access Database Engine Object" but I’m unclear how to do this. Can I get some help on this one? I have searched high and low for DAO info regarding this scenario but to avail.
import win32com.client
engine = win32com.client.Dispatch("DAO.DBEngine.36")
db=engine.OpenDatabase(r"c:\temp\Tracker.accdb")
table = db.OpenRecordset("select * from Event_Log")
print table.RecordCount
An answer probably too late for the OP, but in case anyone else stumbles in here looking for an answers in the area of DAO with Python:
The OP is correct that the immediate issue lies with the string used in the Dispatch method. Office 2010 (Office 14?) installs "DAO.DBEngine.120", which is I think the earliest version that works with .accdb files. In general, one can research this issue by using RegEdit to search the registry for the substring "DAO.DBEngine", and see what components have been registered that add a version number to that string.
It should also be noted that the 32/64 bitness of the version of python to be used needs to match the 32/64 bitness of the DAO version, which in turn matches the 32/64 bitness of Office that installed it.
A further note: If you are using an IDE and make use of autocomplete, it's useful to generate and import a module corresponding to the DAO API. This can be done by running the MakePy utility (in the PythonWin program) on the Library in question, here "Microsoft Office 14.0 Access Database Engine Object Library". This produces a module file in site-packages\win32com\gen_py\, with a long GUID name... you can rename it to "DAO_120-64.py" or somesuch. Then add the gen_py directory to the Python path (or add a .pth file in sitepackages), so that import can find the new module.
Once imported, you can do whatever your IDE recognizes to associate a type with variables for DAO.Database, DAO.Recordset, and so on.
Additionally, the generated DAO module is a useful reference for what objects, methods, properties and constants are available. Possibly a more helpful reference is to simply open an Excel/Word/Access VBA project, Reference (import) this same library, and use the VBA Object browser on it.
In general, any tutorials or articles about using DAO in Access (in VBA or VB) will describe the objects, methods and properties involved in common operations, which can be transcribed almost verbatim into python. The main difference is that in the python version, some of the COM "default method" mechanisms don't work. So, for example, the VBA
MyRecordset("SomeColumn") = "NewValue"
... corresponds in python to:
MyRecordset.Fields("SomeColumn").Value = "NewValue"
Hope that helps.

Gnumeric Python plugin : service file_opener and file_saver

Is it possible to write a gnumeric python plugin for the file_opener and file_saver service?
It seems implemented in the python-loader plugin, there are corresponding sections in the Gnome documentation.
But the example plugin gnome-glossary, which is python file_saver plugin, raises an error ImportError: No module named gsf and I can't write in the output object given by the API:
def so_file_save(wb, output):
output.props.write("toto")
produces the error :
Exception Python (<type 'exceptions.AttributeError'> : 'gobject.GProps' object has no attribute 'write')
And this gobject.GProps object claim to be of __gtype__ : GsfOutputStdio
The python bindings for 'libgsf' are unsupported since a long time ago. As you can read in the old README-python:
I wrote these bindings in 2002, and they haven't been updated since.
They were never part of a standard build, but it was possible to build
them by following the instructions below. It will probably take some
work to make them work with current versions of autotools and
pygobject. Bindings would have to be revalidated, and extended to
match the current API of libgsf.
I do not plan to do further work on these bindings. If anybody wants
to pick them up, please feel free.
Jon K Hellan [...] 2006-02-24
That explaines why gnome-glossary fails. Also, it seems to be a problem with the parameter output, which is shown as a GObject, but not as GsfOutputStdio (you only can see the properties, but you do not have access to any method.
This is not the solution you are looking for, but an attempt of explanation of what you are seeing.

random: not enough state (1 bytes); ignored

Not sure what the above error means. I just installed ghmm on my mac and get this error every time I do a import ghmm. I do not get this message on my ghmm install on my linux machine and other than that all functions appear to be fine.
I wondering if anyone has seen this before and if there's anything I can do to get rid of this. The only thing I did different between the two installs was the autogen.sh file was refering to "libtoolize" which doesn't exist on my mac so I changed it to its replacement "glibtoolize" which allowed it to compile and install fine.
Any suggestions on what this error actually means(and hopefully how I can solve it) would be great.
(I couldn't find the answer on google but this program does not appear to be specific to ghmm)
I'm willing to be corrected on this, but at a guess I'd say this has nothing to do directly with ghmm or your compile tools. I think the error message you're seeing is coming from the BSD random number functions that OSX uses (they are documented here).
Assuming that ghmm is causing the warning (and not python), it might be possible to configure the build process to use plain old rand or some other PRNG. Alternatively, maybe you can find the right place to add a call to initstate() (see above doc link) to provide the state information it wants.
This bit from the man page probably points to your problem:
If initstate() is called with less than 8 bytes of state information, or if setstate() detects that the state information has been garbled, error messages are printed on the standard error output.
eaj is correct that initstate needs more than 8 bytes for state information. The best way to do this for ghmm is with either the --enable-gsl or --with-rng=bsd option for ./configure. --with-rng=bsd makes the type "ghmm_rng_state_t" 8 bytes instead of 1. See rng.h in the ghmm directory.
The ghmm web site says this about "libtoolize":
Mac OS X: 10.6 ships with a broken libtool which breaks the installation (and it also ships with Python 2.5, so you need an update for that). James Howard posted a solution on the mailing list: [Ghmm-list] Compiling in OS X 10.6
http://sourceforge.net/mailarchive/message.php?msg_id=25874107
HTH

Execute Python script (that reads user data on computer) in Google Chrome extension - NPAPI

http://code.google.com/chrome/extensions/npapi.html
I have read through this, and am thoroughly confused. I have built the sample npapi .so plugin from http://www.firebreath.org/display/documentation/Building+on+Linux
Everything worked fine (plugin is installed correctly and recognized) until I went to use it in my popup.html in my unpacked extension, which threw:
<embed type="application/x-sample" id="sample">
<script>
console.log((document.getElementById("sample"))().echo("asdf"));
popup.html:18Uncaught ReferenceError: NPObject deleted
From various testing, it appears calling the constructor on the plugin object throws the error. I have no idea what's going on here.
All I really want to do is to compile a .py file using Cython into a .so or .dll, and then be able to call its methods in my extension.
Does anyone know of an easy way to do this? / Can anyone provide a simple 'hello, world' example of this working?
where is your extra () coming from? Most likely it should be this:
console.log(document.getElementById("sample").echo("asdf"));
What you were trying to do would probably end up trying to call the "default" method on the NPObject, which is probably nonexistent and will thus throw an exception.

Categories