I am trying to write some panel apps for ubuntu Mate. I know C/C++, and SDL reasonably well. I have seen the Mate-University panel apps github page, but i cannot get it to work properly / Im having a though time with it.
I am just wondering, if there is some easy avenue to write panel apps? I am not talking about using the custom application launcher, I would like to add new functionality, to the panel, but Im not sure how to. A tutorial, or description about writing panel apps could be really helpful.
Since what seems to be the occasion to ask this question already has an answer, I am answering this question as an extended explanation on how it was done (in
python
)Basic static indicator
Since Ubuntu Mate, from 15,10, supports indicators, there is not much difference between writing an indicator and a panel app for Mate. Therefore, this link is a good starting point for a basic indicator in
python
, using theAppIndicator3
API. The link is a nice start, but does not provide any information on how to show text on the indicator, let alone how to update the text (or icon). Nevertheless, with a few additions, this leads to a basic "frame" of an indicator as below. It will show an icon, a text label and a menu:In the line
AppIndicator3.IndicatorCategory.OTHER
, the category is defined, as explaned in this (partially outdated) link. Setting the right category is important, a.o. to put the indicator in an appropriate position in the panel.The main challenge; how to update the indicator text and/or icon
The real challenge is not how to write a basic indicator, but how to periodically update the text and/or icon of your indicator, since you want to have it show the (textual) time. To make the indicator work properly, we cannot simply use
threading
to start a second process to periodically update the interface. Well, actually we can, but on a longer run, it will lead to conflicts, as I found out.Here is where
GObject
comes in, to, as it is put in this (also outdated) link:call
gobject.threads_init()
at applicaiton initialization. Then you launch your threads normally, but make sure the threads never do any GUI tasks directly. Instead, you usegobject.idle_add
to schedule GUI task to executed in the main threadWhen we replace
gobject.threads_init()
byGObject.threads_init()
andgobject.idle_add
byGObject.idle_add()
, we pretty much have the updated version of how to run threads in aGtk
application. A simplified example, showing an increasing number of Monkeys:That's the principle. In the actual indicator in this answer, both the loop time and the indicator text were determined by a secondary module, imported in the script, but the main idea is the same.