Python Menu Panel Applet?

Ive been trying to find source code or examples on how to make a Menu applet in python for mate… Im starting to wonder if its not possible, because the libraries i did find which were from 2010 had dead site links. Any example code anyone can share?

Also i found this website which explains how to make a panel indicator, but im pretty sure thats entirely different from a panel menu: http://candidtim.github.io/appindicator/2014/09/13/ubuntu-appindicator-step-by-step.html

Here is the example applet in python :
http://wiki.mate-desktop.org/docs:devel:mate-panel

Keep in ming that you need to know :
Python2 / Python3
GTK 2 for Mate Gtk 2 and Gtk 3 for Mate Gtk 3 .

For a better undestarding I am gonna walk you thought the code .

testapplet.py

""" This decides the python interpreter (Better use python2 and python3 since both versions of python may be installed and difirent sysems have difirent versions set as default) """

#!/usr/bin/env python
 
# Here we import GTK's introspection module
import gi

# Here we specify the major version of Gtk . (Change to 3.0 if you have GTK 3 version of mate) 
gi.require_version("Gtk", "2.0")
# Finaly we import Gtk and MatePanelApplet modules
from gi.repository import Gtk
from gi.repository import MatePanelApplet
 
""" This is the applet fill method . It is used for the actual applet structure . Everything that you create a Gtk.ActionMenu , Buttons and etc. should go here """
def applet_fill(applet):
 
    # you can use this path with gio/gsettings
    settings_path = applet.get_preferences_path()
    # Here we create a Gtk.Label
    label = Gtk.Label("My MATE applet in Python")
    # this tells  the applet to add the created label to the panel.
    applet.add(label)
    # this tells the applet to show all gtk widget created in the process (Couse every Gtk widget has to be shown)
    applet.show_all()
# This is the factory method in this function we are getting the applet iid and if it is not TestApplet to return false
def applet_factory(applet, iid, data):
    if iid != "TestApplet":
       return False
 
    applet_fill(applet)
 
    return True

""" In this function basicly we are telling mate panel to initialize the applet if the Factory method returns true.
       this function is from MatePanelApplet module""" 
MatePanelApplet.Applet.factory_main("TestAppletFactory", True,
                                    MatePanelApplet.Applet.__gtype__,
                                    applet_factory, None)

Now for org.mate.panel.TestApplet.mate-panel-applet . This files tells the id of the applet . Its main module testapplet.py location , the iid . The name wich is gonna be displayed in the Panel add dialogue window and the comment to it .

The last is a dbus service file . org.mate.panel.applet.TestAppletFactory.service . This file calls the main method and the Factory file (previous file we mentioned).

You can look my applet src on github for example of the code :
https://github.com/IKRadulov/mate-window-buttons-applet
wich is farely simple and easly understandable

2 Likes