show/hide xfdesktop icons

Misko_2083

Member
Joined
Mar 15, 2015
Messages
306
Reaction score
18
Pronašao sam jedan script na disku, pa reših da ga podelim. Ovo liči malo na podešavanja desktop ikona iz poslednjeg Cinnamon-a, a služi za XFCE/xfdesktop ikone. Ne radi dobro sve dok se ne kreiraju xfconf poroperties (pokazuje da su neke ikone isključene). Ali nakon što se kreiraju, tako što se aktiviraju on-off prekidači, trebalo bi da radi.
Kada XFCE dobije punu podršku za GTK3+ možda će baš ovako izgledati dijalog za ikone. 😉
View attachment 2128

Code:
#!/usr/bin/env python3
#xfce4-desktop icons switch, Misko, GPLv2
from gi.repository import Gtk, Gdk
import os
import sys
import shlex
import subprocess
from gi.repository.GdkPixbuf import Pixbuf

#Temporary window icon don’t forget to change!
icon=“/usr/share/trios-art/icons/t19-red.png”

def execute(command):
“”“function to exec everything”“”
p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return p.stdout

class XfDesktopIconsWindow(Gtk.Window):
[CODE]def __init__(self):
    Gtk.Window.__init__(self, title="Desktop Icons")

    self.set_default_size(-1, 210)
    self.set_border_width(10)

    self.grid = Gtk.Grid()
    self.grid.set_row_spacing(8)
    self.grid.set_column_spacing(8)
    self.add(self.grid)


    self.label = Gtk.Label()
    self.label.set_name('label')
    self.label.set_markup("To show and hide desktop icons\nuse the switch next to the name")
    self.label.set_line_wrap(True)
    self.label.set_size_request(200, -1)

    self.grid.attach(self.label, 1, 0, 2, 1)

    self.label1 = Gtk.Label("File System", xalign=1)
    self.label2 = Gtk.Label("Home", xalign=1)
    self.label3 = Gtk.Label("Trash", xalign=1)
    self.label4 = Gtk.Label("Removable Devices", xalign=1)
    self.label5 = Gtk.Label("Network Shares", xalign=1)
    self.label6 = Gtk.Label("Removable Drives", xalign=1)
    self.label7 = Gtk.Label("Other Devices", xalign=1)
   
    self.grid.attach(self.label1, 1, 1, 1, 1)
    self.grid.attach(self.label2, 1, 2, 1, 1)
    self.grid.attach(self.label3, 1, 3, 1, 1)
    self.grid.attach(self.label4, 2, 4, 1, 1)
    self.grid.attach(self.label5, 1, 6, 1, 1)
    self.grid.attach(self.label6, 1, 7, 1, 1)
    self.grid.attach(self.label7, 1, 8, 1, 1)

    button1 = Gtk.Switch()
    button1.connect("notify::active", self.on_switch_activated_filesystem)
    cmd = 'xfconf-query --channel xfce4-desktop --property "/desktop-icons/file-icons/show-filesystem" | grep -c "true"'
    result = os.popen(cmd)
    result = result.readline()
    if int(result) == 0:
       button1.set_active(False)
    elif int(result) == 1:
       button1.set_active(True)
    else:
       button1.set_active(False)

    self.grid.attach_next_to(button1, self.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"'

    if int(result) == 0:
       button2.set_active(False)
    else:
       button2.set_active(True)

    self.grid.attach_next_to(button2, self.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"'
    result = os.popen(cmd)
    result = result.readline()
    if int(result) == 0:
       button3.set_active(False)
    else:
       button3.set_active(True)

    self.grid.attach_next_to(button3, self.label3, Gtk.PositionType.RIGHT, 1, 1)

    self.button4= Gtk.Switch()
    self.button4.connect("notify::active", self.on_switch_activatede)
    cmd = 'xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-removable" | grep -c "true"'
    removable = os.popen(cmd)
    removable = removable.readline()
    if int(removable) == 0:
       self.button4.set_active(False)
    else:
       self.button4.set_active(True)

    self.grid.attach_next_to(self.button4, self.label4, Gtk.PositionType.LEFT, 1, 1)

    self.button5 = Gtk.Switch()
    self.button5.connect("notify::active", self.on_switch_activated_network)
    cmd = 'xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-network-removable" | grep -c "true"'
    result = os.popen(cmd)
    result = result.readline()
    if int(result) == 0:
       self.button5.set_active(False)
    else:
       self.button5.set_active(True)

    self.grid.attach_next_to(self.button5, self.label5, Gtk.PositionType.RIGHT, 1, 1)

    if int(removable) == 0:
        self.button5.set_sensitive(False)

    self.button6= Gtk.Switch()
    self.button6.connect("notify::active", self.on_switch_activatedf)
    cmd = 'xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-device-removable" | grep -c "true"'
    result = os.popen(cmd)
    result = result.readline()
    if int(result) == 0:
       self.button6.set_active(False)
    else:
       self.button6.set_active(True)

    self.grid.attach_next_to(self.button6, self.label6, Gtk.PositionType.RIGHT, 1, 1)

    if int(removable) == 0:
        self.button6.set_sensitive(False)

    self.button7= Gtk.Switch()
    self.button7.connect("notify::active", self.on_switch_activated_unknown)
    cmd = 'xfconf-query --channel xfce4-desktop -n --property "/desktop-icons/file-icons/show-unknown-removable" | grep -c "true"'
    result = os.popen(cmd)
    result = result.readline()
    if int(result) == 0:
       self.button7.set_active(False)
    else:
       self.button7.set_active(True)

    self.grid.attach_next_to(self.button7, self.label7, Gtk.PositionType.RIGHT, 1, 1)

    if int(removable) == 0:
        self.button7.set_sensitive(False)

    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, 9, 1, 1)

    button_about = Gtk.Button(label="_About", use_underline=True)
    button_about.set_border_width(10)
    button_about.connect("clicked", self.show_about_dialog)
    self.grid.attach(button_about,  1, 9, 1, 1)

def on_switch_activated_filesystem(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-filesystem" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-filesystem" --set "false"')
        state = "off"
    return print("File System icon is set", state)

def on_switch_activatedb(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-home" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-home" --set "false"')
        state = "off"
    return print("Home icon is", state)

def on_switch_activatedc(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-trash" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-trash" --set "false"')
        state = "off"
    return print("Trash icon is", state)

   
def on_switch_activated_network(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-network-removable" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-network-removable" --set "false"')
        state = "off"
    return print("Network icon is", state)

def on_switch_activatede(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-removable" --set "true"')
        state = "on"
        try:
              self.button5.set_sensitive(True)
              self.button6.set_sensitive(True)
              self.button7.set_sensitive(True)
        except: pass
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-removable" --set "false"')
        state = "off"
        self.button5.set_sensitive(False)
        self.button6.set_sensitive(False)
        self.button7.set_sensitive(False)
    return print("Show Removable is", state)

def on_switch_activatedf(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-device-removable" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-device-removable" --set "false"')
        state = "off"
    return print("Show Removable drive is", state)

def on_switch_activated_unknown(self, switch, gparam):
    if switch.get_active():
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-unknown-removable" --set "true"')
        state = "on"
    else:
        execute('xfconf-query --channel xfce4-desktop --create --type="bool" --property "/desktop-icons/file-icons/show-unknown-removable" --set "false"')
        state = "off"
    return print("Show Unknown Device is", state)

def on_close_clicked(self, button):
    print("Closing Xfce Desktop Icons")
    Gtk.main_quit()

def show_about_dialog(self, widget):
    about_dialog = Gtk.AboutDialog()
    about_dialog.set_destroy_with_parent (True)
    about_dialog.set_program_name("Desktop Icons")
    #about_dialog.set_website('http://')
    #about_dialog.set_website_label('')
    about_dialog.set_icon(Pixbuf.new_from_file(icon))
    about_dialog.set_logo(Pixbuf.new_from_file(icon))
    about_dialog.set_copyright('Copyright 2015')
    about_dialog.set_comments((u'A tool to show/hide icons on xfdesktop'))
    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()

def main():
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’)
Code:
window.show_all()
Gtk.main()
if name == ‘main’:
try:
main()
except (Exception, AttributeError, FileNotFoundError) as e:
print(“Exiting due to error: {0}”.format(e))
sys.exit(1)
[/CODE]
 
Last edited:
Top