|  "Add Icon" scriptForum: DSL Ideas and Suggestions
 Topic: "Add Icon" script
 started by: RoGuE_StreaK
 
  Posted by RoGuE_StreaK on Feb. 12 2005,13:15 Another "just had a thought" from my delusional brain. How about a small script, run from the "Desktop" part of the menu, to add a bit of user-friendliness to the creation of an icon, by using the inputed variables to create a .lnk file?  Say, on click of "menu / Desktop / Create icon" =>
 1.  "Icon Caption" - gives the caption, and the file name for the created .lnk
 2.  "Executable Command, eg. /usr/bin/gimp" - gives the command line, obviously may be a little too much for complete newbies, but...
 3.  "Icon Image" - gives the name of the gif or png, maybe tells them to place it in /home/dsl/.xtdesktop?
 
 Coordinates don't need to be specified, 'cause once it's made, the user can just drag the new icon to where they want it.
 
 Of course it would be good if the "Command" and "Icon Image" had a "browse" function, but I'm guessing this would complicate it a bit.
 
 The basic version should be a fairly small and simple script?  I'm not too knowledgeale about scripting, but I think I could probably figure out how to do this to some degree if need be?
 Would just add a little bit more user-friendliness for those coming from windoze who are used to being able to create icons etc by right-clicking the desktop.
 
 Hmm, actually, a similar principal could possibly apply to the menu, or at least the mydsl part of it, correct?  As each mydsl item creates it's own seperate link file under /var/temp/mydsl.menu
 ?
 
  Posted by TyphoonMentat (not logged in) on Feb. 12 2005,16:01 How about something like this: 
 
 | Code Sample |  | #!/bin/sh
 DIA="Xdialog --wmclass"
 
 $DIA --2inputsbox "Please enter a name and a command for your icon." 0 0 "Name:" "" "Command:" "" 2>/tmp/tic
 ICON_NAME=`cat /tmp/tic | perl -e '$x=<>;if($x=~/^(.*?)\/.+/{print $1}'`
 ICON_CMD=`cat /tmp/tic | perl -e '$x=<>;if($x=~/^(.*?)\/(.*)/{print $2}'`
 
 $DIA --msgbox "Now choose a picture for your icon." 0 0
 $DIA --fselect /home/knoppix/.xtdesktop 0 0 2> /tmp/tic
 ICON_PIC=`cat /tmp/tic`
 rm -f /tmp/tic
 
 cat <<EOF>/home/knoppix/.xtdesktop/$ICON_NAME.lnk
 table Icon
 Type: Program
 Caption: $ICON_NAME
 Command: $ICON_CMD
 Icon: $ICON_PIC
 X: 25
 Y: 270
 end
 EOF
 
 | 
 
 (apologies for any formatting errors)
 
  Posted by TyphoonMentat on Feb. 12 2005,18:17 Corrected version: 
 
 | Code Sample |  | #!/bin/sh DIA="Xdialog --wmclass --title Icon"
 
 $DIA --2inputsbox "Please enter a name and a command for your icon." 0 0 "Name:" "" "Command:" "" 2>/tmp/tic
 ICON_NAME=`cat /tmp/tic | perl -e '$x=<>;if($x=~/^(.*?)\/.+/{print $1}'`
 ICON_CMD=`cat /tmp/tic | perl -e '$x=<>;if($x=~/^(.*?)\/(.*)/{print $2}'`
 
 $DIA --msgbox "Now choose a picture for your icon." 0 0
 $DIA --fselect /home/dsl/.xtdesktop 0 0 2> /tmp/tic
 ICON_PIC=`cat /tmp/tic`
 rm -f /tmp/tic
 
 cat <<EOF>/home/dsl/.xtdesktop/$ICON_NAME.lnk
 table Icon
 Type: Program
 Caption: $ICON_NAME
 Command: $ICON_CMD
 Icon: $ICON_PIC
 X: 25
 Y: 270
 end
 EOF
 | 
 
  Posted by RoGuE_StreaK on Feb. 13 2005,03:56 Thanks TyphoonMentat, but couldn't get it to work - looking at the script, I assume it needs perl to work, and perl isn't on in the standard iso, correct? 
  Posted by cbagger01 on Feb. 13 2005,07:10 perl is on the standard iso 
 But xdialog ISN'T
 
 A slight rewrite with whiptail instead of xdialog is in order.
 
 But I think that the file selector is not supported in whiptail, but I could be wrong.
 
  Posted by TyphoonMentat (not logged in) on Feb. 13 2005,10:11 Well, I guess there're two options: - Don't use a file selector, and let the user type in the appropriate file within the /home/dsl/.xtdesktop directory
 - Include the XDialog binary, which is 78Kb (the Debian package is 880Kb uncompressed, but this is mostly locales and docs)
 
  Posted by clacker on Feb. 13 2005,15:33  | Quote |  | But I think that the file selector is not supported in whiptail, but I could be wrong. | 
 
 it isn't, but I believe --menu is.  you could make a menu that contained the names of all of the jpg, png, gif files in the .xtdesktop directory.
 
  Posted by mikshaw on Feb. 13 2005,17:02 Good point.  "ls *.{gif,png,jpg,xpm}" or something similar could dynamically create a list for your menu. 
 
 | Code Sample |  | ICON_DIR=$HOME/.xtdesktop ICON_CNT=0
 ICON_TMP=/tmp/xtdesk-icon.tmp
 ICON_LIST="whiptail --menu Choose_an_Icon 24 70 16"
 
 for file in `ls ${ICON_DIR}/*.{png,xpm,jpg,gif} 2>/dev/null`; do
 ICON_CNT=$((ICON_CNT+1))
 ICON_LIST="${ICON_LIST} ${file} ${ICON_CNT}"
 done
 
 ${ICON_LIST} 2>${ICON_TMP}
 
 | 
 The content of the ICON_TMP file would then be read back in as the icon filename.
 This doesn't work with filenames containing spaces.  I messed around with it for a while but didn't come up with a fix for it.  Honestly, with all the trouble I've had in the past trying to script for filename spaces I decided long ago just to never use spaces in filenames, ever.
 
 Also, This wasn't tested with Busybox, so I can't say that it will work as is in DSL.
 
 I'm thinking it might be fun to do this with Lua FLTK rather than Bash, as we might be able to display the icon choices as graphic buttons rather than choosing from a text list.
 
  Posted by Delboy on Feb. 15 2005,13:53 Has anyone tried the icon creation fluxbox plugin 'fbdesk' it can be installed from the Debian packages site using apt-get install ----?.  I suggested this a long while ago for icons but there seemed to be more resistance to 'eye candy' then. 
  Posted by mikshaw on Feb. 15 2005,21:01 I've tried it a little...doesn't seem to be much different than xtdesk. 
 I put together a Lua FLTK script for making icons.  The file browser in Lua FLTK seems to be pretty limited...it doesn't seem to have a lot of the options that are available in FLTK. There is apparently no image support, and I don't even think you can change the font.
 
 
 | Code Sample |  | #!/bin/flua
 
 -- dsl-create_icon.flua
 -- mikshaw Feb2005
 
 -- DEFAULTS
 xtdesk_dir = getenv("HOME").."/.xtdesktop/"
 xtdesk_tmp = "/tmp/xtdeskPIDtmp"
 w_main_width = 360
 w_main_height = 380
 b_w = 80        -- button width
 b_h = 25        -- button height
 b_vs = b_h+5    -- button vertical spacing
 b_hs = b_w+30   -- button horizontal spacing
 Fl_Widget.initializers = {textfont = 15, labelfont = 15, labelcolor = 15}
 Fl_Input_.initializers = {when = When.changed, color = 0, textcolor = 2, cursor_color = 15, selection_color = 8}
 Fl_Button.initializers = {box = Boxtype.thin_up, down_box = Boxtype.thin_down, color = 8, labelcolor = 2}
 Fl_Round_Button.initializers = {box = Boxtype.none, color = 8, labelcolor = 15, selection_color = 2, type = Buttontype.radio, align = Align.right}
 Fl_Window.initializers = {box = Boxtype.thin_down, color = 0}
 
 function hide_mounts()
 icon_mount_label:hide()
 icon_mount:hide()
 icon_mount_browse:hide()
 icon_umount_label:hide()
 icon_umount:hide()
 icon_umount_browse:hide()
 icon:show()
 icon_label:show()
 icon_browse:show()
 end
 
 function show_mounts()
 icon_mount_label:show()
 icon_mount:show()
 icon_mount_browse:show()
 icon_umount_label:show()
 icon_umount:show()
 icon_umount_browse:show()
 icon:hide()
 icon_label:hide()
 icon_browse:hide()
 end
 
 -- BEGIN LAYOUT
 -- HELP
 w_help = Window{w_main_width,w_main_height, "help"}
 help_text = Box{10-w_main_width,0,w_main_width,w_main_height,"link filename: The filename for your *.lnk file,\nlisted with no extension or leading path.\n\n"..
 "\choose icon: The image file(s) used for your icon.\nFor a mount icon two images are requested, one for \nthe unmounted state and one for the mounted state.\n\n"..
 "command: The full command which will be run when \nthe icon is clicked.\n\n"..
 "caption: The text which will be displayed on the \ndesktop next to the icon.\n\n"..
 "x pos & y pos: The horizontal(X) and vertical(Y) \nlocation of your icon, in pixels.\n\n"..
 "more: Additional features for the icons. Some features \nmay not work for some versions of xtdesk.\n\n\n\n"..
 "lua fltk script by mikshaw, 2005";align=Align.right}
 w_help:end_layout()
 
 w_main = Window{w_main_width,w_main_height, "dsl-create_icon"}
 
 -- NAME OF LNK FILE
 file_name_label = Box{24,10,100,20,"link filename:"}
 file_name = Input{30,30,120,20,".lnk";align=Align.right}
 
 -- SPECIFY TYPE OF ICON
 icon_type1 = Round_Button{200,30,20,20,"program"}
 function icon_type1.callback()
 if old_command_value then command.value = old_command_value end
 if old_extras_value then extras.value = old_extras_value end
 if old_caption_value then caption.value = old_caption_value end
 if old_filename_value then file_name.value = old_filename_value end
 hide_mounts()
 end
 icon_type2 = Round_Button{275,30,20,20,"mount"}
 function icon_type2.callback()
 if command.value then old_command_value = command.value end
 command.value = "mount"
 if extras.value then old_extras_value = extras.value end
 extras.value = "MenuCommand1: Mount CDROM : mount /dev/cdrom \nMenuCommand2: Umount CDROM : umount /dev/cdrom \nMenuCommand3: Eject CDROM : eject /dev/cdrom \n"
 if caption.value then old_caption_value = caption.value end
 caption.value = "/dev/cdrom"
 if file_name.value then old_filename_value = file_name.value end
 file_name.value = "cdrom"
 show_mounts()
 end
 icon_type1.value = 1 -- default is 'Program'
 
 -- SPECIFY ICON FILE
 icon_label = Box{18,50,100,20,"choose icon:"}
 icon = Input{30,70,280,20}
 icon_browse = Button{310,70,20,20,"@>";labeltype=Labeltype.symbol}
 function icon_browse.callback()
 icon.value = fl_file_chooser("Choose An Icon","*.{jpg,gif,png,xpm}",xtdesk_dir)
 end
 
 icon_umount_label = Box{39,50,100,20,"choose umount icon:"}
 icon_umount = Input{30,70,280,20}
 icon_umount_browse = Button{310,70,20,20,"@>";labeltype=Labeltype.symbol}
 function icon_umount_browse.callback()
 icon_umount.value = fl_file_chooser("Choose An Icon For Umounted Drive","*.{jpg,gif,png,xpm}",xtdesk_dir)
 end
 
 icon_mount_label = Box{36,90,100,20,"choose mount icon:"}
 icon_mount = Input{30,110,280,20}
 icon_mount_browse = Button{310,110,20,20,"@>";labeltype=Labeltype.symbol}
 function icon_mount_browse.callback()
 icon_mount.value = fl_file_chooser("Choose An Icon For Mounted Drive","*.{jpg,gif,png,xpm}",xtdesk_dir)
 end
 
 command_label = Box{90,130,100,20,"command (including options, if any):"}
 command = Input{30,150,280,20}
 command_browse = Button{310,150,20,20,"@>";labeltype=Labeltype.symbol}
 function command_browse.callback()
 command.value = fl_file_chooser("Browse For Application","*","/usr/bin/")
 end
 
 caption_label = Box{6,170,100,20,"caption:"}
 caption = Input{30,190,200,20}
 x_pos_label = Box{220,170,80,20,"x pos:"}
 x_pos = Int_Input{240,190,40,20;maximum_size=4}
 y_pos_label = Box{270,170,80,20,"y pos:"}
 y_pos = Int_Input{290,190,40,20;maximum_size=4}
 
 extras_label = Box{111,220,100,20,"more ( MenuCommand<num>: label : command ):"}
 extras = Multiline_Input{30,240,300,56}
 
 b_help = Button{30,320,b_w,b_h,"help"}
 function b_help.callback()
 w_help:show()
 end
 
 b_create = Button{w_main_width-b_hs*2,320,b_w,b_h,"CREATE ICON"}
 function b_create.callback()
 filename = xtdesk_dir..file_name.value..".lnk"
 if icon_type2.value == 1 then
 icontype = "Mount"
 command.value = "mount"
 else
 icontype = "Program"
 end
 writeto(filename)
 write("table Icon\n"..
 "Type: "..icontype.."\n"..
 "Caption: "..caption.value.."\n"..
 "Command: "..command.value.."\n")
 if icontype == "Program" then
 write("Icon: "..icon.value.."\n")
 else
 write("IconMount: "..icon_mount.value.."\n"..
 "IconUmount: "..icon_umount.value.."\n")
 end
 write("X: "..x_pos.value.."\n"..
 "Y: "..y_pos.value.."\n"..
 extras.value.."\nend")
 execute("pidof xtdesk && echo \"xtdesk_pid = `pidof xtdesk`\" >"..xtdesk_tmp.." || echo \"xtdesk_pid = 0\" >"..xtdesk_tmp)
 dofile(xtdesk_tmp)
 remove(xtdesk_tmp)
 if xtdesk_pid > 0 then
 execute("killall xtdesk")
 end
 fl_message("Some things and stuff has been written to "..filename)
 if xtdesk_pid > 0 then
 execute("xtdesk >/dev/null &")
 end
 exit(0)
 end
 
 b_exit = Button{w_main_width-b_hs,320,b_w,b_h,"exit"}
 function b_exit.callback()
 exit(0)
 end
 
 w_main:end_layout()
 hide_mounts()
 w_main:show()
 
 
 | 
 
 Be careful about copy and paste here...lines that wrap may paste as multiple lines.  You may want to stretch your browser window out a bit until lines no longer wrap
 
  Posted by newOldUser on Feb. 16 2005,03:59 You can change the font to "screen", "times", "helvetica" and "courier" by altering line 15 or there abouts like this 
 
 | Code Sample |  | Fl_Widget.initializers = {textfont = Font.times, labelfont = Font.times, labelcolor = 15}
 
 | 
 
 Nice script.  Thank you for your efforts
 
  Posted by mikshaw on Feb. 16 2005,04:17 I tried that, or something similar...no matter what settings I added seemed to make no impact on the file selector.  The font  set with Fl_Widget.initializers works fine for every widget except for the ones in the FL dialogs. 
 I think the developer did just enough work to allow use of fl_file_chooser with file filtering, but not enough to pass widget settings on to it....there was something in the docs about editing the code if we wanted to add more FLTK features to the chooser.
 
 |