08-03-2015, 02:20 PM
Guys, decided to write a python3 script which will open a gtk3+ window from which desktop icons can be added and removed by simply clicking the switch.
There are quite a few icons in the desktop tab this could save some space.
Also added and option to show/hide removable drives.
Might need some work but this is working fine so far.
What do you think guys?
There are quite a few icons in the desktop tab this could save some space.
Code:
#!/usr/bin/env python3
#xfce4-desktop icons switch, 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/Thunar/Thunar-about-logo.png"
class XfDesktopIconsWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Xfce Desktop Icons")
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("To show and hide desktop icons use the switch on the right")
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("File System ", xalign=1)
label2 = Gtk.Label("Home ", xalign=1)
label3 = Gtk.Label("Trash ", xalign=1)
label4 = Gtk.Label("Network ", xalign=1)
label5 = Gtk.Label("Removable Drives ", xalign=1)
self.grid.attach(label1, 1, 1, 1, 1)
self.grid.attach(label2, 1, 2, 1, 1)
self.grid.attach(label3, 1, 3, 1, 1)
self.grid.attach(label4, 1, 4, 1, 1)
self.grid.attach(label5, 1, 5, 1, 1)
button1 = Gtk.Switch()
button1.connect("notify::active", self.on_switch_activateda)
button1.set_name('button')
cmd = 'xfconf-query --channel xfce4-desktop --property "/desktop-icons/file-icons/show-filesystem" | grep -c "true"'
wicdd = os.popen(cmd)
wicdd = wicdd.readline()
if int(wicdd) == 0:
button1.set_active(False)
else:
button1.set_active(True)
self.grid.attach_next_to(button1, label1, Gtk.PositionType.RIGHT, 1, 1)
button2 = Gtk.Switch()
button2.connect("notify::active", self.on_switch_activatedb)
cmd = 'xfconf-query --channel xfce4-desktop --property "/desktop-icons/file-icons/show-home" | grep -c "true"'
wicdb = os.popen(cmd)
wicdb = wicdb.readline()
if int(wicdb) == 0:
button2.set_active(False)
else:
button2.set_active(True)
self.grid.attach_next_to(button2, label2, Gtk.PositionType.RIGHT, 1, 1)
button3= Gtk.Switch()
button3.connect("notify::active", self.on_switch_activatedc)
cmd = 'xfconf-query --channel xfce4-desktop --property "/desktop-icons/file-icons/show-trash" | grep -c "true"'
wicdb = os.popen(cmd)
wicdb = wicdb.readline()
if int(wicdb) == 0:
button3.set_active(False)
else:
button3.set_active(True)
self.grid.attach_next_to(button3, label3, Gtk.PositionType.RIGHT, 1, 1)
button4= Gtk.Switch()
button4.connect("notify::active", self.on_switch_activatedd)
cmd = 'ls ~/Desktop | grep -c "networks.desktop"'
wicdb = os.popen(cmd)
wicdb = wicdb.readline()
if int(wicdb) == 0:
button4.set_active(False)
else:
button4.set_active(True)
self.grid.attach_next_to(button4, label4, Gtk.PositionType.RIGHT, 1, 1)
button5= Gtk.Switch()
button5.connect("notify::active", self.on_switch_activatede)
cmd = 'xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-device-removable" | grep -c "true"'
wicdb = os.popen(cmd)
wicdb = wicdb.readline()
if int(wicdb) == 0:
button5.set_active(False)
else:
button5.set_active(True)
self.grid.attach_next_to(button5, label5, Gtk.PositionType.RIGHT, 1, 1)
buttonc = Gtk.Button(label="_Close", use_underline=True)
buttonc.set_border_width(10)
buttonc.connect("clicked", self.on_close_clicked)
self.grid.attach(buttonc, 2, 7, 1, 1)
def on_switch_activateda(self, switch, gparam):
if switch.get_active():
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-filesystem" --set "true"')
state = "on"
else:
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-filesystem" --set "false"')
state = "off"
print("File System icon is set", state)
def on_switch_activatedb(self, switch, gparam):
if switch.get_active():
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-home" --set "true"')
state = "on"
else:
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-home" --set "false"')
state = "off"
print("Home icon is", state)
def on_switch_activatedc(self, switch, gparam):
if switch.get_active():
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-trash" --set "true"')
state = "on"
else:
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-trash" --set "false"')
state = "off"
print("Trash icon is", state)
def on_switch_activatedd(self, switch, gparam):
if switch.get_active():
os.system('cp /usr/share/litecc/frontend/icons/desktop/networks.desktop ~/Desktop')
state = "on"
else:
os.system('rm -rf ~/Desktop/networks.desktop')
state = "off"
print("Network icon is", state)
def on_switch_activatede(self, switch, gparam):
if switch.get_active():
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-device-removable" --set "true"')
state = "on"
else:
os.system('xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-device-removable" --set "false"')
state = "off"
print("Show Removable is", state)
def on_close_clicked(self, button):
print("Closing Xfce Desktop Icons")
Gtk.main_quit()
window = XfDesktopIconsWindow()
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()
Might need some work but this is working fine so far.
What do you think guys?