08-11-2015, 04:56 AM
I'll start with an idea to use a little python script to display a tray icon instead of the xfce panel plugin. This way it will run not only in xfce but on cinnamon, mate and other.
I've created 2 applications and one desktop file for this.
The first application will launch a tray icon and right click menu. I've added a few right-click menu items: about dialog, Start Control Center, Settings and Quit.
/usr/share/litecc/litecc-tray-icon.py
Left click will open the control center.
The second application launches a gtk3 widnow which is used to set tray icon autostart. This window is launched from a tray icon's right click menu -> Settings
/usr/share/litecc/litecc-tray.py
The last part is a desktop file in /usr/share/applications which is going to be symlinked in order to autostart the tray icon
/usr/share/applications/litecc-tray-icon.desktop
I've noticed that Hidden=true in the desktop file prevents it from starting.
P.S. Don't forget to make scripts and desktop file executable.
Here is how this looks:
I've created 2 applications and one desktop file for this.
The first application will launch a tray icon and right click menu. I've added a few right-click menu items: about dialog, Start Control Center, Settings and Quit.
/usr/share/litecc/litecc-tray-icon.py
Code:
#!/usr/bin/env python3
import subprocess
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import os
licon = "/usr/share/pixmaps/lite-controlcenter.png"
class LiteCCTray():
def __init__(self):
self.tray = Gtk.StatusIcon()
self.tray.set_from_file(licon)
self.tray.connect('popup-menu', self.on_right_click)
self.tray.connect('activate', self.on_left_click)
self.tray.set_tooltip_text('Linux Lite Control Center')
def on_right_click(self, icon, button, time):
self.menu = Gtk.Menu()
about = Gtk.MenuItem()
about.set_label("About")
run = Gtk.MenuItem()
run.set_label("Start Control Center")
settings = Gtk.MenuItem()
settings.set_label("Settings")
quit = Gtk.MenuItem()
quit.set_label("Quit")
about.connect("activate", self.show_about_dialog)
run.connect("activate", self.run_lite_cc)
settings.connect("activate", self.settings_lite_cc)
quit.connect("activate", Gtk.main_quit)
self.menu.append(about)
self.menu.append(run)
self.menu.append(settings)
self.menu.append(quit)
self.menu.show_all()
def pos(menu, icon):
return (Gtk.StatusIcon.position_menu(menu, icon))
self.menu.popup(None, None, pos, self.tray, button, time)
#open lite cc
def on_left_click(self, event):
subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'])
def run_lite_cc(self, event):
subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'])
def settings_lite_cc(self, event):
subprocess.Popen(['python3', '/usr/share/litecc/litecc-tray.py'])
def show_about_dialog(self, widget):
about_dialog = Gtk.AboutDialog()
about_dialog.set_destroy_with_parent (True)
about_dialog.set_program_name("Linux Lite Control Center Tray Icon")
about_dialog.set_website('http://linuxliteos.com')
about_dialog.set_website_label('linuxliteos.com')
about_dialog.set_icon(Pixbuf.new_from_file(licon))
about_dialog.set_logo(Pixbuf.new_from_file(licon))
about_dialog.set_copyright('Copyright 2015')
about_dialog.set_comments((u'Tool for Launching Liunx Lite Control Center'))
about_dialog.set_license('''This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. ''')
about_dialog.set_authors([u'Milos Pavlovic <[email protected]>'])
about_dialog.run()
about_dialog.destroy()
if __name__ == '__main__':
LiteCCTray()
Gtk.main()The second application launches a gtk3 widnow which is used to set tray icon autostart. This window is launched from a tray icon's right click menu -> Settings
/usr/share/litecc/litecc-tray.py
Code:
#!/usr/bin/env python3
#litecc tray settings, Misko
from gi.repository import Gtk
import os
import sys
from subprocess import Popen
from gi.repository.GdkPixbuf import Pixbuf
#Temporary window icon don't forget to change!
icon="/usr/share/pixmaps/lite-controlcenter.png"
autostart_path = os.path.expanduser('~/.config/autostart/litecc-tray-icon.desktop')
class LiteccTrayWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Linux Lite Control Center Settings")
self.set_default_size(-1, 200)
self.set_border_width(10)
self.grid = Gtk.Grid()
self.add(self.grid)
self.create_label()
self.create_buttons()
def create_label(self):
label = Gtk.Label()
label.set_markup("Linux Lite Control Center settings")
label.set_line_wrap(True)
label.set_size_request(200, -1)
table = Gtk.Table(1, 1, False)
table.set_border_width(10)
table.attach(label, 0, 1, 0, 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL)
self.grid.attach(table, 1, 0, 2, 1)
def create_buttons(self):
label1 = Gtk.Label("Tray Icon Autostart ", xalign=1)
self.grid.attach(label1, 1, 1, 1, 1)
button1 = Gtk.Switch()
button1.connect("notify::active", self.on_switch_activateda)
button1.set_name('button')
if not os.path.exists(autostart_path):
button1.set_active(False)
else:
button1.set_active(True)
self.grid.attach_next_to(button1, label1, Gtk.PositionType.RIGHT, 1, 1)
buttonc = Gtk.Button(label="_Close", use_underline=True)
buttonc.set_border_width(8)
buttonc.connect("clicked", self.on_close_clicked)
self.grid.attach(buttonc, 2, 7, 1, 1)
def on_switch_activateda(self, switch, gparam):
state = ""
if switch.get_active():
try:
os.symlink( '/usr/share/applications/litecc-tray-icon.desktop', autostart_path)
state = "on"
except OSError as e:
print(e)
pass
else:
try:
os.unlink(autostart_path)
state = "off"
except OSError as e:
print(e)
pass
print("Lite CC Tray Icon Autostart is set", state)
def on_close_clicked(self, button):
print("Closing Lite CC Settings")
Gtk.main_quit()
window = LiteccTrayWindow()
window.connect("delete-event", Gtk.main_quit)
window.set_resizable(False)
window.set_position(Gtk.WindowPosition.CENTER)
window.set_icon(Pixbuf.new_from_file("{0}".format(icon)))
window.set_name('DesktopIcons')
window.show_all()
Gtk.main()The last part is a desktop file in /usr/share/applications which is going to be symlinked in order to autostart the tray icon
/usr/share/applications/litecc-tray-icon.desktop
Code:
[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Name=Linux Lite Control Center Tray Icon
Comment=Linux Lite Control Center Tray Icon
Exec=/usr/share/litecc/litecc-tray-icon.py
Icon=lite-controlcenter
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=falseP.S. Don't forget to make scripts and desktop file executable.
Here is how this looks:


![[Image: X5qGkCg.png]](https://imgur.com/X5qGkCg.png)
![[Image: 0op1GNe.png]](https://i.imgur.com/0op1GNe.png)
![[Image: LgJ2mtP.png]](https://i.imgur.com/LgJ2mtP.png)
![[Image: vLZcFUE.png]](https://imgur.com/vLZcFUE.png)
![[Image: lrUHro3.jpg]](https://i.imgur.com/lrUHro3.jpg)