Created
July 12, 2021 20:07
-
-
Save Axel-Erfurt/8b1f799a258546539fbf1d94bb2b2a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import gi | |
gi.require_versions({'Gtk': '3.0','XApp': '1.0'}) | |
from gi.repository import Gtk, XApp | |
import warnings | |
warnings.filterwarnings("ignore") | |
class MyStatusIconApp: | |
def __init__(self): | |
self.create_left_menu() | |
self.create_right_menu() | |
self.status_icon = XApp.StatusIcon() | |
self.status_icon.set_icon_name("folder") | |
self.status_icon.props.icon_size = 16 | |
self.status_icon.connect("scroll-event", self.scroll_event) | |
self.status_icon.set_primary_menu (self.left_menu) | |
self.status_icon.set_secondary_menu (self.right_menu) | |
self.status_icon.set_tooltip_text("XAppStatusIcon Example") | |
def create_left_menu(self): | |
self.left_menu = Gtk.Menu() | |
about = Gtk.ImageMenuItem(label="About", image=Gtk.Image.new_from_icon_name("help-about", 16)) | |
about.connect("activate", self.show_about_dialog) | |
self.left_menu.append(about) | |
quit = Gtk.ImageMenuItem(label="Quit", image=Gtk.Image.new_from_icon_name("application-exit", 16)) | |
quit.connect("activate", Gtk.main_quit) | |
self.left_menu.append(quit) | |
self.left_menu.show_all() | |
def create_right_menu(self): | |
self.right_menu = Gtk.Menu() | |
about = Gtk.ImageMenuItem(label="About", image=Gtk.Image.new_from_icon_name("help-about", 16)) | |
about.connect("activate", self.show_about_dialog) | |
self.right_menu.append(about) | |
self.right_menu.show_all() | |
def show_about_dialog(self, widget): | |
about_dialog = Gtk.AboutDialog() | |
about_dialog.set_destroy_with_parent(True) | |
about_dialog.set_name("XAppStatusIcon Example") | |
about_dialog.set_version("1.0") | |
about_dialog.set_authors(["Axel Schneider"]) | |
about_dialog.run() | |
about_dialog.destroy() | |
def scroll_event(self, widget, amount, direction, time): | |
if(direction == 0): | |
print("scrolled up") | |
elif(direction == 1): | |
print("scrolled down") | |
app = MyStatusIconApp() | |
Gtk.main() |
On the other hand, the management of the "scroll-event" signal does not work.
I made the following changes and now it works :
self.status_icon.connect("scroll-event", self.scroll_event)
def create_left_menu(self):
self.left_menu = Gtk.Menu()
self.left_menu.connect("scroll-event", self.scroll_event)
def scroll_event(self, widget, amount):
direction = amount.direction
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On Ubuntu 22.04, I added the two lines to show the images in the menu items :
settings = Gtk.Settings.get_default()
settings.set_property("gtk-menu-images", True) # this line allows to show images of menu items
Thanks