Programming and Scripting :: iconthemeswitcher in lua



hiya,

i figured it would be quite cool when DSL got the ability to switch to a different icon theme. although i do not yet have any different icon theme i could use, i made a script in lua which does what i want.
would someone plz test it on their pc? i tested it here and it works fine for me. dont think some could go wrong anyway, but still it would be nice to be sure...
its not for versions < 4.0 cos this script uses the DFM dir (though the icon dir can be changed in the script itself)
also would be nice when some people made some nice iconthemes xD

heres the code:
Code Sample
#!/bin/lua
-- Written by Jaap Broekhuizen aka Jaapz
-- This script is released under the terms of the GPL2 License

--iconthemeswitch.lua
---Switch to a different icon theme!

--Variables
home = os.getenv("HOME").."/"
backup = 1
icondir = "/usr/share/dfm/icons/"

--Main
w = fltk:Fl_Window(250,125,"Icon Theme Switcher")
w:callback(
function(w)
 os.exit(0)
end)

text = fltk:Fl_Box(110,0,30,30,[[Click browse to select the tar.gz file
where the icons are located.]])
text:labelfont(1)
text:labelsize(11)

output = fltk:Fl_Output(5,35,170,25)

browseBtn = fltk:Fl_Button(180,35,65,25,"Browse")
browseBtn:callback(
function(browseBtn)
 icontarball = fltk.fl_file_chooser("Select tarball", "Types (*.tar.gz)",home)
 output:value(icontarball)
end)

deleteOrig = fltk:Fl_Round_Button(5,70,20,20,"Delete old icons")
deleteOrig:type(fltk.FL_RADIO_BUTTON)
deleteOrig:selection_color(fltk.FL_BLUE)
deleteOrig:labelfont(1)
deleteOrig:labelsize(13)
deleteOrig:callback(
function(deleteOrig)
  backup = 0
end)

backupOrig = fltk:Fl_Round_Button(125,70,20,20,"Backup old icons")
backupOrig:type(fltk.FL_RADIO_BUTTON)
backupOrig:selection_color(fltk.FL_BLUE)
backupOrig:labelfont(1)
backupOrig:labelsize(13)
backupOrig:callback(
function(keepOrig)
  backup = 1
end)

okBtn = fltk:Fl_Return_Button(5,95,50,25,"OK")
okBtn:callback(
function(okBtn)
 if icontarball == nil then
   fltk:fl_message("No filename is given, terminating!")
   os.exit(1)
 end

 if backup == 1 then
   os.execute("sudo tar -zcvf ~/iconbackup.tar.gz " ..icondir.. "*")
 end

 os.execute("sudo tar -zxvf " ..icontarball.. " -C " ..icondir)
 fltk:fl_message("All icons in " ..icontarball.. " are added/copied to " ..icondir.. "!")
 os.exit(0)
end)

cancelBtn = fltk:Fl_Button(60,95,60,25,"Cancel")
cancelBtn:callback(
function(cancelBtn)
 os.exit(0)
end)

helpBtn = fltk:Fl_Button(195,95,50,25,"Help")
helpBtn:callback(
function(helpBtn)
 fltk:fl_message([[You can change your icon theme by using this tool.
Just select the tarball (.tar.gz) where you have your icons located,
and click the ok-button.
Then restart your window manager.]])
end)

backupOrig:value(1)
w:show()
Fl:run()

no interest in this at all?
Nope. The problem you'll have with this is conforming to a standard icon naming convention between DSL, jwm, and whatever icon sets are chosen. If DSL were to use an icon naming convention adopted by (e.g.) KDE or Gnome (Free Desktop) it might be easier. But with things as they are right now, your script won't do diddly squat unless users change their icon names to match what's already in jwmrc/dfm.

I really don't think most DSL users are all worked up about the aesthetics-thing. Function trumps form. To paraphrase (edit) Rousseau: "Let them dress up Ubuntu."

Another thing after looking at the code...
Code Sample

...
icondir = "/usr/share/dfm/icons/"
....
backupOrig = fltk:Fl_Round_Button(125,70,20,20,"Backup old icons")
backupOrig:type(fltk.FL_RADIO_BUTTON)
backupOrig:selection_color(fltk.FL_BLUE)
backupOrig:labelfont(1)
backupOrig:labelsize(13)
backupOrig:callback(
function(keepOrig)
 backup = 1
end)

okBtn = fltk:Fl_Return_Button(5,95,50,25,"OK")
okBtn:callback(
function(okBtn)
if icontarball == nil then
  fltk:fl_message("No filename is given, terminating!")
  os.exit(1)
end

if backup == 1 then
  os.execute("sudo tar -zcvf ~/iconbackup.tar.gz " ..icondir.. "*")
end

os.execute("sudo tar -zxvf " ..icontarball.. " -C " ..icondir)
fltk:fl_message("All icons in " ..icontarball.. " are added/copied to " ..icondir.. "!")
os.exit(0)
end)
...



While one certainly can go to /usr/share and first tar then delete the default icons there, it's probably a better idea to add/edit the icon path in jwmrc and the user's dfm config file for new icons. Most apps give precedence to what's in a user's own config files over system config anyway. That would prevent errors if icons are either missing or mis-named. Besides, this isn't Puppy; we don't have to do all this messy root stuff.

Finally, I have a better idea if you want to be able to switch out icons like this: UNC. Make a UNC that overlays /usr/share/dfm/icons with the icons you want using the same names of what's already there. That way you use the oversized icons you want without any hassles between jwm and dfm and whatever else leverages those particular icons in the future.
Next Page...
original here.