It is possible to add multiple instances to N900's desktop, but there is no documentation, describing how to do it. At least I couldn't find it. As far as such behavior would be must have for ussd-widget
which I'm writing, I had to do some research.
GoAwayStupidAI in his post
mentioned, that it is possible to change .desktop file in such a way, that hildon would allow to add multiple instances if widget to the desktop. Just add
to it. For example for ussd-widget this file would be:
Comment=Shows result of USSD query
That's good, now user can add multiple widgets, but there is no use of having several identical widgets (let's drop case of widgets with random content). So we need a way to distinguish different instances of widgets. After some time spend in google I've found in hildon sources needed function: hd_home_plugin_item_get_applet_id()
. In python it is just get_applet_id() method.
[OFFTOP] By the way, it there is wonderful doxygen comments, why there is no generated doxygen documentation?
I really like QT documentation, everything in one place and you can find answers really quickly. If everything you need to get hildon documentation is to parse it with doxygen and publish it online, why wiki is used instead?
Wiki would newer
have up to date information as source code changes quickly. OK, there is documentation. But for some unknown reason google prefers finding git changelogs and other less useful stuff instead.
But when I tried to use this method the only thing I got was segmentation fault. It occurred, that when widget constructor works (and where usually all initialization is done) identifier is not initialized. That means, that you can't do any widget instance specific initialization in constructor
. So, as a workaround, I had to find method that would be executed later, but before widget could be used. I've chosen do_show method, because if widget is hidden user can't use it.
self.ready = False
if not self.ready:
# Get ID
id = self.get_applet_id()
# Use it to make instance specific initialization
# Do not forget to call parent's do_show
If you have better ideas you are welcome to comment this solution.
When you have id everything else is easy. Use it in configuration file names or for naming sections in your configs. Having different configuration files for different instances you have different behavior for them.
Identifiers are strings of a form <your widget name>.desktop-<instance number>. For my widget first instance would get ussd-widget.desktop-0, next widget would get ussd-widget.desktop-1. If user deletes widget from desktop numeration starts from 0 again. So there should be some more trickery to allow user to delete the right widget (not the last one), but I don't want to mess with this now.
P.S. Widget resizing is possible too of course, thanks to GTK. But widget must implement resizing itself. ussd-widget