Python Forum
Python + GTK + AppIndicator3 tray submenu Icon
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python + GTK + AppIndicator3 tray submenu Icon
#1
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()
Reply
#2
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)
Reply
#3
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.
Reply
#4
  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)
Reply
#5
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.
Reply
#6
You are using Deepin Linux?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation [PyQt] Setting icon on QAction from outside QGuiApplication gradlon93 3 1,677 Jan-04-2023, 11:37 AM
Last Post: gradlon93
  PyQt6 QAction with icon and string malonn 2 1,617 Sep-12-2022, 11:59 AM
Last Post: malonn
  how to remove icon ilyess68ysl 4 3,581 Oct-15-2021, 10:05 AM
Last Post: ilyess68ysl
  Icon in tkinter menator01 8 4,843 May-03-2020, 02:01 PM
Last Post: wuf
  [Tkinter] Password Reveal Icon Evil_Patrick 2 4,586 Nov-29-2019, 02:20 PM
Last Post: Evil_Patrick
  [Tkinter] Window Icon Evil_Patrick 6 7,978 Oct-18-2019, 11:26 AM
Last Post: Evil_Patrick
  Button with Image Icon Friend 2 6,766 Jul-25-2019, 09:39 AM
Last Post: Friend
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,264 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  [PyQt] How is this tray icon throbber done? JackDinn 7 4,736 Mar-05-2018, 02:19 PM
Last Post: JackDinn
  Please advice Linux library - tray icon, popup windows, ICQ/Skype style etc ramendik 5 3,989 Dec-03-2017, 04:35 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020