so I have a Python script that sync's files to my NAS every x minutes. I am trying to write an app indicator (ubuntu) to follow the process of the above script.
If I embed the indicator code into the script and use GLib.timeout_add(10, handler_timeout) then the indicator cannot be updated until sync is done - i.e see the layout below:
*
setupIndicator()
sync():
update app indicastor to say currently syncing
sync to nas - takes say 5mins
update app indicator - sync comlplete
GLib.timeout_add(30minutes, self.sync)
Gtk.main()
*
This is what I want to do but of course doesn't work like this. My trouble is I don't know where to go from here - how can I achieve this?
I think you need to put the NAS functionality into a thread and that thread is kicked off at each update.
The first/last thing the thread does is update the indicator to say busy/idle.
I've written an appindicator (Python 3, GTK+ 3) for Ubuntu called
indicator-ppa-download-statistics
, found here which implements a similar concept to what (I understand) you want. I'm not sure if you'd need to use the locking mechanism or the global flag which I've used in my instance, but at the very least a threaded approach will allow the NAS stuff to happen in the background without blocking the indicator being used by a user.