iconthemeswitcher in lua


Forum: Programming and Scripting
Topic: iconthemeswitcher in lua
started by: jaapz

Posted by jaapz on April 09 2008,21:45
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()

Posted by jaapz on April 10 2008,20:28
no interest in this at all?
Posted by lucky13 on April 10 2008,20:59
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."

Posted by lucky13 on April 10 2008,21:28
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.

Posted by lucky13 on April 11 2008,01:33
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.
Posted by jaapz on April 11 2008,22:09
Quote (lucky13 @ April 10 2008,16:59)
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.

of course the icon set used with this iconthemeswitcher should be made ready for DSL, so the theme will contain all icons with the same name as the default ones.

But, if nobody got interest in this, i wont make this script bigger anyway. Good learning again though xD

Posted by roberts on April 12 2008,03:19
jaapz wrote:
Quote
... Good learning again though xD


Glad to see you are learning and writing murgaLua. Not much interest in the icon area, is likely due to lack of many small .xpm icons that DSL uses.

I know that I have asked for some .xpm icons to be contributed and so far, I have received very few.

mikshaw even wrote a really cool icon editor. I would stiil like someone who is artisic to do a database xpm icon.

Posted by jaapz on April 12 2008,21:37
roberts, why not post a list of xpm's that have to be made? i'll be glad to make some!

and hows the list of murgaLua gui's that have to be made? also would like to do some of that :)

but that icon editor, is it iconview.lua? if it is, its not an editor, but it is cool anyway xD

Posted by mikshaw on April 13 2008,00:16
You're right, it isn't an editor. But it does launch mtpaint with the selected icon, which is an excellent xpm icon editor. In that sense it is sort of tied into icon editing.

I'm interested in knowing what a "database icon" would be linked to. If it's an icon for the mydsl database, that would be more of a mydsl icon and not too difficult to create, but if it's something more general for applications that use a database, it would be more difficult in my opinion.

Posted by roberts on April 13 2008,03:05
Most of the xpm icons are very small - around 1500 or so.
So just doing a ls -Sr /usr/share/dfm/icons will show the fat icons. These could be reduced to save space and probably look nicer too. So here is a list that needs to be reduced or replaced:

Size   Name
------   ---------------
2413  console4.xpm
2578  wireless.xpm
2596  file.xpm
2606  edit.xpm
2805  home.xpm
3687  files-yellow.xpm
3909  files-red.xpm
4310  exit.xpm
4581  nicq.xpm
4801  naim.xpm
4806  calc.xpm
4842  daemons.xpm
5066  document_spreadsheet.xpm
5250  spreadsheet.xpm
5525  xvesa.xpm
5720  sshfs.xpm
5906  package3.xpm
6028  msword.xpm
6088  fetch.xpm
6139  calendar.xpm
6388  nirq.xpm
6392  USB-Drive.xpm
6394  smbclient.xpm
6497  files-blue.xpm
6658  files-green.xpm
6673  xpdf.xpm
7917  pdf.xpm
7926  vnc.xpm
7928  dillo.xpm
7942  files-yellow-exec.xpm


Re: The database icon would be generic for sqlite databases.
I have seen "disk-pack" looking icons used or ?  

Just note that the icon should look good at dfm 32x32 but also by jwm automatic size reduction used in jwm menu and jwm tray.

Posted by mikshaw on April 13 2008,10:21
In other words, stick with simple shapes and lines no smaller than 2-pixels wide. As I noticed with one of my own XPMs, if a 32-px icon gets scaled to 16, 1-px lines will either get horribly mutilated or disappear entirely.

Quote
I have seen "disk-pack" looking icons used or ?

Does that mean a stack of disks or ?

Posted by jaapz on April 13 2008,12:18
@mikshaw: I think a database icon won't be too hard to create.

And i'll try too make some nice icons, starting with the console icon :)

Posted by mikshaw on April 13 2008,13:28
Quote
@mikshaw: I think a database icon won't be too hard to create.
It isn't so much the creation itself that I think would be more difficult, but the initial design. "mydsl" is a pretty specific subject when compared to "database", a much more ambiguous term.  Ideally an icon conveys a descriptive and intuitive concept using a very simple image, which is a more difficult task for general concepts that are applied to many unrelated applications.
As an example, the first google hit for a database icon reference was this:
< http://www.aha-soft.com/stock-icons/database-icons.htm >
Personally I don't see "database" when I look at these icons....I see an oil drum. But apparently this disk stack concept has somehow come to represent database.  Does that mean this representation is accurate?

In my eyes it is one of the biggest problems with an icon-centric desktop. Only after the user learns to associate a given image with a given concept does that image serve a useful purpose, and some concepts are much easier to associate with an image than others.

Posted by lucky13 on April 13 2008,13:42
mikshaw:
Quote
Personally I don't see "database" when I look at these icons....I see an oil drum. But apparently this disk stack concept has somehow come to represent database.  Does that mean this representation is accurate?

In my eyes it is one of the biggest problems with an icon-centric desktop. Only after the user learns to associate a given image with a given concept does that image serve a useful purpose, and some concepts are much easier to associate with an image than others.

Concur on the point that a MyDSL icon is probably better than stacked disk icons. Two icons might work, one for the app (MyDSL db Browser) and one for database MIME-type association. The latter is probably easier because it could use an existing icon and edit in SQL/SQLite (or just "db") in place of whatever is on a stock icon -- and then it would stay relatively small in size. The former is still a puzzle unless it's specific to MyDSL. I thought of something like a penguin with a waiter's tray but I would associate that more with some other server application. Plus that would be a bloated icon since it would have too many lines and colors.


jaapz:
Quote
And i'll try too make some nice icons, starting with the console icon

Please remember the preference is smaller. The more lines and the more colors, the bigger it will be.:)

Posted by curaga on April 13 2008,14:59
I made an executable icon, and reduced colors on the xpdf one. The executable could replace files-yellow-exec.xpm.

Sizes:
executable.xpm   3032
xpdf.xpm            2245

< Png previews > (that don't look quite right, seems shareapic crops a bit)

The icons themselves: < http://rapidshare.com/files/107170976/icons.tgz.html >

Posted by roberts on April 13 2008,16:31
Thanks curaga! I got them in for the next cut.

mikshaw, you are probably right, the disk-pack shows my age. Most you young'ns would see it as relating to oil. Even more since the price of such is on everyone's mind. But that is another topic not suited to be dicussed here. So... perhaps something with db or sql that looks nice and sizes nice too.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.