Python Forum
Python + GTK + AppIndicator3 tray submenu Icon - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Python + GTK + AppIndicator3 tray submenu Icon (/thread-22906.html)



Python + GTK + AppIndicator3 tray submenu Icon - nodefive - Dec-02-2019

I do not program in python, therefore the question. With some help from another post I was able to put this tray menu together, works ok.

How can I set icons to the sub-menu items (appstore, control center, etc)?

Thanks

#!/usr/bin/python
import os
from gi.repository import Gtk as gtk, AppIndicator3 as appindicator

def main():
  indicator = appindicator.Indicator.new("customtray", "/home/unix/Bin/share/preferences/preferences.03.png", appindicator.IndicatorCategory.APPLICATION_STATUS)
  indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
  indicator.set_menu(menu())
  gtk.main()

def menu():
  menu = gtk.Menu()

  appstore = gtk.MenuItem('AppStore')
  appstore.connect('activate', appStore)
  menu.append(appstore)

  controlcenter = gtk.MenuItem('Control Center')
  controlcenter.connect('activate', CtrlCenter)
  menu.append(controlcenter)

  Separator = gtk.SeparatorMenuItem()
  menu.append(Separator)
    
  exittray = gtk.MenuItem('Quit')
  exittray.connect('activate', quit)
  menu.append(exittray)

  menu.show_all()
  return menu

def appStore(_):
  os.system("deepin-appstore %U")
      
def CtrlCenter(_):
  os.system("dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.Show")

def quit(_):
  gtk.main_quit()

if __name__ == "__main__":
  main()



RE: Python + GTK + AppIndicator3 tray submenu Icon - Larz60+ - Dec-02-2019

use (for example):
syntax may be slightly off, cannot test since I don't have gi library
menu.add_command(label='AppStore', image=imagename, compound='left', command=appStore)


RE: Python + GTK + AppIndicator3 tray submenu Icon - nodefive - Dec-02-2019

finally got it. Was a gtk thing. :/

controlcenter = gtk.ImageMenuItem.new_with_label('Control Center')
controlcenter.set_image(gtk.Image.new_from_file('/home/unix/Bin/share/ddefm.png'))
controlcenter.connect('activate', CtrlCenter)
controlcenter.set_always_show_image(True)
menu.append(controlcenter)

Thanks for the help mate.


RE: Python + GTK + AppIndicator3 tray submenu Icon - Axel_Erfurt - Dec-02-2019

  img = gtk.Image()
  img.set_from_icon_name("preferences-desktop", 20)
  controlcenter = gtk.ImageMenuItem('Control Center')
  controlcenter.set_image(img)
  controlcenter.connect('activate', CtrlCenter)
  menu.append(controlcenter)



RE: Python + GTK + AppIndicator3 tray submenu Icon - nodefive - Dec-03-2019

Hi Axel, your solution works as well, as long as I add

controlcenter.set_always_show_image(True)
Apparently that defaults to false in my system, so I have to force it with true.

Thanks mate.


RE: Python + GTK + AppIndicator3 tray submenu Icon - Axel_Erfurt - Dec-03-2019

You are using Deepin Linux?