I'm trying to create a volume application indicator in linux using python but I couldn't find a way to use a Gtk.Scale as child of Gtk.MenuItem. I could add Gtk.Scale object as child but the Scale widget will not be able to capture my mouse click.
Is there anyway of doing this?
Here is the simplified code to add Gtk.Scale to Gtk.MenuItem:
import gi
import signal
gi.require_version('Gtk', '3.0')
gi.require_version('AppIndicator3', '0.1')
from gi.repository import Gtk
from gi.repository import AppIndicator3 as appindicator
APPINDICATOR_ID = 'VolControl'
class volumeapplet:
def main(self):
signal.signal(signal.SIGINT, signal.SIG_DFL)
self.indicator = appindicator.Indicator.new(APPINDICATOR_ID, 'audio-volume-high', appindicator.IndicatorCategory.SYSTEM_SERVICES)
self.indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
self.indicator.set_menu(self.build_menu())
Gtk.main()
def build_menu(self):
menu = Gtk.Menu()
# volume control
slider_item = Gtk.MenuItem.new()
slider = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL,0.0,100.0,1.0)
slider_item.add(slider)
menu.append(slider_item)
menu.append(Gtk.SeparatorMenuItem())
menu.show_all()
return menu
if __name__ == "__main__":
app = volumeapplet()
app.main()