Created
October 16, 2019 16:39
-
-
Save ylmrx/7a2eff2295f07449b4de6e3da78489a3 to your computer and use it in GitHub Desktop.
Tend une main fraternelle.
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/env python3 | |
import os | |
import signal | |
import gi | |
gi.require_version('Gtk', '3.0') | |
gi.require_version('AppIndicator3', '0.1') | |
from gi.repository import Gtk, AppIndicator3 | |
import threading | |
from os import path | |
import time | |
import i3ipc | |
class Indicator(): | |
def __init__(self): | |
self.i3 = i3ipc.Connection(auto_reconnect=True) | |
self.app = 'show_proc' | |
self.testindicator = AppIndicator3.Indicator.new( | |
self.app, 'non-starred', | |
AppIndicator3.IndicatorCategory.OTHER) | |
self.testindicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) | |
def watcher(): | |
while True: | |
time.sleep(1) | |
self.i3_scratch = self.i3.get_tree().scratchpad() | |
self.testindicator.set_menu(self.create_menu()) | |
if len(self.i3_scratch.leaves()) == 0: | |
self.testindicator.set_icon('non-starred') | |
else: | |
self.testindicator.set_icon('starred') | |
thread = threading.Thread(target=watcher) | |
thread.daemon = True | |
thread.start() | |
def create_menu(self): | |
menu = Gtk.Menu() | |
for leaf in self.i3_scratch.leaves(): | |
item = Gtk.MenuItem(leaf.window_title) | |
item.connect('activate', self.switch_to, leaf) | |
menu.append(item) | |
item_quit = Gtk.MenuItem(label='Quit') | |
item_quit.connect('activate', self.stop) | |
menu.append(item_quit) | |
menu.show_all() | |
return menu | |
def switch_to(self, source, leaf): | |
leaf.command('focus') | |
def stop(self, source): | |
Gtk.main_quit() | |
Indicator() | |
signal.signal(signal.SIGINT, signal.SIG_DFL) | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't work.