add wallpaper tool


Forum: Programming and Scripting
Topic: add wallpaper tool
started by: jaapz

Posted by jaapz on Mar. 25 2008,15:07
hi,

im making a addWallpaper.lua tool, wich ads a wallpaper to /opt/.backgrounds. Now i got the problem that the fltk filechooser returns a full path of the selected wallpaper, like /home/dsl/image.png. I just need the image.png piece of that... It should be possible with regexes, but i have no clue how i would do it. Can anybody help me? (mikshaw :P)

Thanks for your help,
Jaapz

Posted by lucky13 on Mar. 25 2008,15:19
Are you using Robert's wallpaper.lua as a base (not sure if it's still in DSL 4, but probably still in DSL 3)?
Posted by roberts on Mar. 25 2008,15:39
We already have a wallpaper.lua.

There are many examples for the  question you are asking. Do you know how to use grep?

Just grep for the lua construct over /usr/local/bin/*.lua

Posted by ^thehatsrule^ on Mar. 25 2008,16:13
If you just wanted some kind of simple matching pattern, you could use something like [^\/]*$ with string:match (not sure if you'll need to escape the / )

I think these need to be asked:
- is this for personal learning?
- if not, are you adding anything that the current wallpaper tool doesn't do?

Posted by mikshaw on Mar. 25 2008,18:46
Quote
the fltk filechooser returns a full path of the selected wallpaper, like /home/dsl/image.png. I just need the image.png piece of that

use fl_filename_name()
Code Sample
image_path=fltk.fl_file_chooser("Choose an image","Image Files (*.{jp{,e}g,png,bmp,xbm,xpm,gif})",nil, nil)
if image_path then
   my_image=fltk.fl_filename_name(image_path)
   print(my_image)
end

Posted by jaapz on Mar. 25 2008,19:52
@lucky13: yes im  improving the wallpaper.lua in dsl 4

@roberts: ur right but it doesnt have a add-wallpaper option, thats what im now trying to implement

@thatstherule: its for personal learning but also for improving the wallpaper.lua, so it can also add wallpapers, wich it cant now.

@mikshaw: thx, that will help me :)

EDIT:
im somewhat finished with the add&remove functions in wallpaper.lua, where can i post the code so u can use or modify it? just in the forums?

Posted by jaapz on Mar. 26 2008,22:12
ok here are the modified wallpaper.lua and my addWallpaper.lua. it would be nicce if some people would test it, and even nicer when roberts adds it to DSL. but i do not count on that :;):. its good practise to modify existing scripts.
ill add a refresh or restart function in a newer version... it's working great for me now :)

the link where i put the tar.gz with wallpaper.lua and addWallpaper.lua:
< http://jaapz.fambro.nl/dump/wallpapertool.tar.gz >

Posted by jaapz on Mar. 27 2008,20:03
well? what do u think of it? i'd really like some comments on this, i'll learn from it.
Posted by mikshaw on Mar. 28 2008,01:21
Oh-oh! Een 404!
Posted by jaapz on Mar. 28 2008,08:17
Oh, shit...
I'm at school now, when im at home i'll fix it, sorry!

EDIT:
Oh, lol it was wallpapertool.tar.gz :P Fixed now!
< http://jaapz.fambro.nl/dump/wallpapertool.tar.gz >

Posted by mikshaw on Mar. 28 2008,13:28
I haven't looked at the modified wallpaper.lua yet, but I have a couple of suggestions for addWallpaper.lua

The next DSL release (including the new RC), will have file copy built into murgaLua:
murgaLua.fileCopy(source,target)
I suppose it's mostly a matter of personal preference which to choose, but if in the future you have it built to handle multiple files, the built-in copy function will probably use fewer system resources than os.execute(command).

I would seriously consider reorganizing the script to use two functions. One function is the copy, and the other is the file selector. The way you have it now is an uncommon way to present a graphical  interface and commandline/drag-and-drop as two options to perform the same task. GUIs tend to be interactive and perform tasks only when the user chooses.
I would make the file selector a function triggered by a button, rather than have it be automatic and quit if you cancel.

The interface would show only if this isn't a drag/drop or filename given as a commandline parameter. Having the copy as a function would allow you to simply run that function and quit if arg[1] is present. It also provides a way for the user to browse for and copy a file, and then copy another without having to restart the program.

A minor thing that is also more personal preference, it's not necessary to specify home. Applications tend to use the current directory as the default working directory, which in DSL and other Linux systems is almost always $HOME.
Specifying that you want the file selector to start at home will force it to go back to home every time it's opened. If instead you use nil (or don't specify that option at all), it will open in the current directory anyway, but the second time around will open in the last directory chosen. When the program is restarted, it goes back to the current directory.

Posted by roberts on Mar. 28 2008,14:54
Sorry, I think a file mamager is the proper tool for the management of files. What if I don't want to copy, but move? What if I want to rename? All file manager functions that are best done with the already provided two file managers, dfm or emelfm.
Posted by jaapz on Mar. 28 2008,22:17
@mikshaw: for now, ill wont use those functions, but when v4.3 of DSL is released, ill try to change the code. Also, its a good idea of you to make an input box where people can put the filename, and a button where u can select a file. I'll make that.

@robert: i made this patch/script/whatever to overcome a shortcoming in wallpaper.lua, cos a wallpaper GUI tool is just not complete without the function to add and remove wallpapers, and also, i dont think everybody wants to rename their wallpaper filenames, cos they wont see it!
Even though, if u dont want to add it to DSL, doesnt matter to me (although im a very little bit dissapointed off course ;-)) its been good learning to make this.

EDIT:
Ok, now changed addWallpaper.lua a bit. Now with browser button and an output box showing the selected wallpaper filename.
< http://jaapz.fambro.nl/dump/wallpapertool.tar.gz >

Posted by roberts on Mar. 28 2008,23:34
Here's the senaniro, user downloads very large background to home directory. Take for example the original background that you made. Then copy to /opt/.backgrounds via your mod. Now they have two copies of a very large file in their backup. To add only copy/delete functions therefore means that the use will still have to use a file manager to avoid this situation, i.e, (to delete the duplicate in home/dsl, therfore, it would be more efficent to move it. Therefore the filemanager is the more appropriate tool. Always thinking of small machines having duplicates (especially large ones) only magifies this situation, longer, slower backups, or even "broken pipe" backup situation.

Everything I write I try to keep in mind the intended use and possible ramificatons. To you, it may seem incomplete. But that is your opinion. I write in script so you can read and learn how I did things. You are free to modify and even post here, etc.

There are many GUIs that still need to be made. However as developer of DSL I reserve the right on what will be included in core DSL. There are many users whose murgaLua scripts (ucitool.lua, netcardconf.lua, flrun.lua, editor.lua, slide_puzzle.lua, and mydslBrowser.lua) have been accepted.



Posted by mikshaw on Mar. 29 2008,00:28
roberts: If you have the time, maybe you'd consider posting a list of "GUIs that still need to be made". Some of us might attack one or two of them. Typically I only come up with ideas for gui projects I know I will personally use (even though some of those projects eventually get replaced by shell scripts, file manager configs, etc). maybe there's something I haven't thought about that might be an interesting project. maybe others will feel the same.

One thing I've had in the back of my mind for some time is a wget gui, since my experiences with gwget have been anything but pleasant. The main thing that has kept me from that, though, is that I kinda want to use a murgaLua browser or progress to keep track of the download instead of opening a terminal window, but i have no idea how to do that.

Still, any Lua script that you hope to eventually put into DSL, but can't find the time or desire for any time soon, might be worth mentioning to the rest of us.

Posted by roberts on Mar. 29 2008,00:56
A GUI, even a simple one for recording (burning cdroms).
We used to have bashburn, then switched to cdw. Still those are not very friendly. We recently had a question on how to set the image for a simple burn. Even if we start with a simple version it would be a start. Features can always be added later.

Apsfilter setup is another one. Currently it is very cumbersome to use with so many screens. Again even a simple version with the basics. Typically gimp-print is the one that works.

The issue, perhaps, will be trying to read the current bash scripts and /or whiptail dialogs. But even a simple version that does only gimp-print setup would be a very useful start. Sometimes, just seeing the user interface and knowing the command line usage, one can develop without ever studying the old existing code.

Posted by roberts on Mar. 29 2008,01:24
Dialup modem configuration is another one. Many modem users have had difficulty with the initial configuration. If I recall they miss the "write configuration" option. Many of the issues are related to the flow. It is different than modern GUIs. With each update of murgaLua come new capabilities.
Posted by curaga on Mar. 29 2008,07:42
Would X-cd-roast take too much space? It's a gtk1 burning app after all..
Posted by jaapz on Mar. 29 2008,21:33
Quote (roberts @ Mar. 28 2008,18:34)
Here's the senaniro, user downloads very large background to home directory. Take for example the original background that you made. Then copy to /opt/.backgrounds via your mod. Now they have two copies of a very large file in their backup. To add only copy/delete functions therefore means that the use will still have to use a file manager to avoid this situation, i.e, (to delete the duplicate in home/dsl, therfore, it would be more efficent to move it. Therefore the filemanager is the more appropriate tool. Always thinking of small machines having duplicates (especially large ones) only magifies this situation, longer, slower backups, or even "broken pipe" backup situation.

There are many GUIs that still need to be made. However as developer of DSL I reserve the right on what will be included in core DSL. There are many users whose murgaLua scripts (ucitool.lua, netcardconf.lua, flrun.lua, editor.lua, slide_puzzle.lua, and mydslBrowser.lua) have been accepted.

Of course, and u probably know it, it's not that hard to make some checkboxes in the gui where the user can select what happens to the original copy of the wallpaper he wants to add, options like "Delete Original", and "Keep Original". So that the user can choose his own. (with of course the Delete Original as default option)

And sure, u reserve the right of deciding what comes with DSL xD. I'm not blaming u for the fact u dont add my script ;-).

And i think its a good idea for u (roberts) to make a new topic with a list of GUI's that need to be made, i'll try to make some then.

@mikshaw: lol, yesterdayi thought about how cool it would be if i made a wget/download GUI script with Lua. I'll try to make some like that too.

EDIT:
again updated addWallpaper.lua, you can now select if u want to delete or keep the original image.
< http://jaapz.fambro.nl/dump/wallpapertool.tar.gz >

(oh, and keep in mind these are my first steps in developing ((very)little) apps ;-) )

Posted by roberts on Mar. 31 2008,18:13
"Add" Program aborts when OK selected without a file selection.
Should catch the error and beep or display message.

Posted by jaapz on April 01 2008,21:30
Thx, the add tool now stops with an error (in fl_message() form) that there was no file specified.
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.