Após testar vários cenários, a solução mais simples (além do próprio bug sendo corrigido, supondo que seja um bug) é alternar a nomeação do arquivo de ícone para frente e para trás ...
#!/usr/bin/env python3
from gi.repository import AppIndicator3, GLib, Gtk
import glob, os
class IndicatorTestIcon:
NAME = "indicator-test-icon"
ICON_STATE = True
def __init__( self ):
self.count = 0
for file in glob.glob( os.getenv( "HOME" ) + "/." + IndicatorTestIcon.NAME + "*.svg" ):
print(file)
os.remove( file )
self.indicator = AppIndicator3.Indicator.new( IndicatorTestIcon.NAME, "", AppIndicator3.IndicatorCategory.APPLICATION_STATUS )
self.indicator.set_icon_theme_path( os.getenv( "HOME" ) )
self.indicator.set_status( AppIndicator3.IndicatorStatus.ACTIVE )
def main( self ):
self.update()
GLib.timeout_add_seconds( 3, self.update )
Gtk.main()
def update( self ):
print( self.count )
self.buildMenu()
self.createIcon()
self.indicator.set_label( "static label", "" )
self.indicator.set_icon_full( self.getIconName(), "" )
self.count += 1
self.toggleIconState()
return True
def buildMenu( self ):
menu = Gtk.Menu()
quitMenuItem = Gtk.ImageMenuItem.new_from_stock( Gtk.STOCK_QUIT, None )
quitMenuItem.connect( "activate", Gtk.main_quit )
menu.append( quitMenuItem )
self.indicator.set_menu( menu )
menu.show_all()
def createIcon( self ):
header = '<?xml version="1.0" standalone="no"?>' \
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' \
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 100 100">'
text = '<g>' \
'<text x="0" y="75" font-family="Verdana" font-size="100" fill="white" >' + str( self.count ) + '</text>' \
'</g>'
footer = '</svg>'
with open( self.getIconFile(), "w" ) as f:
f.write( header + text + footer )
f.close()
def getIconName( self ):
if IndicatorTestIcon.ICON_STATE: return "." + IndicatorTestIcon.NAME + "-1"
return "." + IndicatorTestIcon.NAME + "-2"
def getIconFile( self ):
if IndicatorTestIcon.ICON_STATE: return os.getenv( "HOME" ) + "/." + IndicatorTestIcon.NAME + "-1.svg"
return os.getenv( "HOME" ) + "/." + IndicatorTestIcon.NAME + "-2.svg"
def toggleIconState( self ): IndicatorTestIcon.ICON_STATE = not IndicatorTestIcon.ICON_STATE
if __name__ == "__main__": IndicatorTestIcon().main()