Created
September 21, 2019 06:56
-
-
Save cgiannakidis70/8f174f567e5ea45c4cd381fbe3a39df1 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/env python3 | |
import gi.repository | |
import logging | |
import os | |
import os.path | |
import psutil | |
import signal | |
import subprocess | |
import sys | |
gi.require_version('Gtk', '3.0') | |
gi.require_version('Wnck', '3.0') | |
gi.require_version('Budgie', '1.0') | |
from gi.repository import Budgie, GObject, Gtk, Wnck | |
class applemenunew(GObject.GObject, Budgie.Plugin): | |
__gtype_name__ = "applemenunew" | |
def __int__(self): | |
GObject.Object.__init__(self) | |
def do_get_panel_widget(self, uuid): | |
return applemenunewApplet(uuid) | |
def get_active_window(): | |
global b | |
screen = Wnck.Screen.get_default() | |
screen.force_update() | |
active_window = screen.get_active_window() | |
pid = active_window.get_pid() | |
process = psutil.Process(pid) | |
process_name = process.name() | |
with open("/proc/{pid}/cmdline".format(pid=pid)) as f: | |
active_window_name = os.path.basename(f.read()) | |
a = process_name.replace("-", " ") | |
b = a.title() | |
if b != "Nemo Desktop": | |
a = process_name.replace("-", " ") | |
b = a.title() | |
else: | |
b = " " | |
return pid, b | |
t1, t2 = get_active_window() | |
class applemenunewApplet(Budgie.Applet): | |
def __init__(self, uuid): | |
Budgie.Applet.__init__(self) | |
self.box = Gtk.EventBox() | |
self.box.set_tooltip_text("Apple Menu") | |
self.add(self.box) | |
img = Gtk.Image.new_from_icon_name("apple", Gtk.IconSize.MENU) | |
self.box.add(img) | |
self.menu = Gtk.Menu() | |
self.create_menu() | |
self.box.show_all() | |
self.show_all() | |
def run_command(self, menuitem): | |
subprocess.Popen(["./About_This_Pc.py"]) | |
def run_command1(self, menuitem): | |
subprocess.Popen(["gnome-control-center", "wifi"]) | |
def run_command2(self, menuitem): | |
subprocess.run(["gnome-software"]) | |
def run_command4(self, menuitem): | |
t1, t2 = get_active_window() | |
os.kill(int(t1), signal.SIGTERM) | |
def run_command5(self, menuitem): | |
subprocess.run(["systemctl", "suspend"]) | |
def run_command6(self, menuitem): | |
subprocess.run(["gnome-session-quit", "--reboot"]) | |
def run_command7(self, menuitem): | |
subprocess.run(["gnome-session-quit", "--power-off"]) | |
def run_command8(self, menuitem): | |
subprocess.run(["gnome-session-quit"]) | |
def create_menu(self): | |
global item5 | |
item1 = Gtk.MenuItem('About This PC') | |
item1.connect("activate", self.run_command) | |
item2 = Gtk.MenuItem('System Settings...') | |
item2.connect("activate", self.run_command1) | |
item3 = Gtk.MenuItem('Software... ') | |
item3.connect("activate", self.run_command2) | |
item4 = Gtk.MenuItem('Recent Items') | |
re = Gtk.RecentChooserMenu() | |
re.set_limit(20) | |
re.set_show_not_found(True) | |
re.set_show_numbers(True) | |
item4.set_submenu(re) | |
re.connect('item-activated', self.on_item_activated) | |
t1, t2 = get_active_window() | |
item5 = Gtk.MenuItem('Force Quit...' + t2) | |
item6 = Gtk.MenuItem('Sleep') | |
item6.connect("activate", self.run_command5) | |
item7 = Gtk.MenuItem('Restart...') | |
item7.connect("activate", self.run_command6) | |
item8 = Gtk.MenuItem('ShutDown...') | |
item8.connect("activate", self.run_command7) | |
item9 = Gtk.MenuItem('LogOut\t\t\t\t\tCtrl Alt Del') | |
item9.connect("activate", self.run_command8) | |
for item in [item1, item2, item3, item4, item5, item6, item7, item8, item9]: | |
self.menu.append(item) | |
sep = Gtk.SeparatorMenuItem() | |
sep1 = Gtk.SeparatorMenuItem() | |
sep2 = Gtk.SeparatorMenuItem() | |
sep3 = Gtk.SeparatorMenuItem() | |
sep4 = Gtk.SeparatorMenuItem() | |
self.menu.insert(sep, 1) | |
self.menu.insert(sep1, 4) | |
self.menu.insert(sep2, 6) | |
self.menu.insert(sep3, 8) | |
self.menu.insert(sep4, 12) | |
self.menu.show_all() | |
self.box.connect("button-press-event", self.popup_menu) | |
def popup_menu(self, *args): | |
self.menu.popup(None, None, None, None, 0, Gtk.get_current_event_time()) | |
global item5 | |
t1, t2 = get_active_window() | |
self.menu.remove(item5) | |
item5 = Gtk.MenuItem('Force Quit...\t\t' + t2) | |
item5.connect("activate", self.run_command4) | |
self.menu.insert(item5, 7) | |
item5.show() | |
def on_item_activated(self, re): | |
recentitem = re.get_current_item() | |
if recentitem: | |
subprocess.call(['xdg-open', recentitem.get_uri()]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment