rWall 3.0 "Scratchy", Now in Python!

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

Hey, folks. My other post for the bash version of this script was getting a tad old, and this is a very significant change, so I thought I'd make a new post for the folks interested in what this does (hint: it randomizes your background)! If you want a reference, the older post is here: rWall

Python 3 made this whole thing way better. I have a stable function for advancing up and down the list of backgrounds, and this works in all supported desktop environments now! rWall 3.0 supports Cinnamon 2, GNOME 3, Mate, KDE 4-5, Xfce 4.10, and Openbox, as well as a number of other window managers (as long as they can use feh's background tools).

This may look like a large script for just a wallpaper randomizer, but it does a lot, actually:
  • * auto-detects supported desktop environments
    * commandline options for up to five user-preset image directories
    * default directory setting
    * picks a random background from a commandline-supplied directory
    * cycles alphabetically through an image list of the last used directory
    * loops through backgrounds in a commandline-supplied directory
rWall requires wmctrl and feh:

Code: Select all

sudo apt-get install wmctrl feh
Make the script executable by unzipping it and changing to the script's folder in a terminal and typing:

Code: Select all

chmod +x rwall.py
Users must edit the script to add specific preset directories. Check rwall.py -h for more details. Attach the options to keyboard shortcuts, and you've got yourself an interactive background randomizer/slideshow/changer in all LinuxMint environments. It's great for people with large image libraries who haven't seen some of their images in a long time.

A note for Xfce, KDE, and Openbox users: UPDATE: Xfce is now automated; thanks, Peter Levi! KDE users just need to run the script once and change their desktop settings to slideshow and point to the [home]/.config/rwall/kde/mon1 folder. Openbox users must have feh installed, and have the line

Code: Select all

. $HOME/.fehbg &
in their autostart.sh file.

The only thing missing are the two or three GTK dialog boxes I had in the old version. While it's possible that I'll add those in the future, the real beauty of this script is in using shortcuts, not dialogs. Thanks for your time, and I welcome constructive criticism!
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 5 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

UPDATE: Xfce support is now automated; thanks, Peter Levi!
Mr. Levi's project has helped me out in the past with KDE (through following his Google group page), and his source code helped me out here.

Our projects don't actually cross over as much as you'd think at first; he's focused more on acquiring network image sources and picking specific images from them (although he's got a slideshow feature, I believe). My project assumes you like the mountain of pics you've already got and just don't want to bother choosing one among thousands!

Anyway, please go check out Variety and show your support! It's good stuff.
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

I am having trouble getting rwall.py to work on my LM17 32-bit with Cin 2.2.13
I'm a newbie to LM17 and don't understand Python. Must I download Python first?
I have been able to extract rwall.zip into a folder under my Downloads called 'rwallslideshow' but when I try the 'chmod +x rwall.py' I get no response (maybe it worked?) but when I then type in
'rwall.py -d Pictures' I get a command not found error.

Am I on the right track? What am I missing????

Thanks
:( :(
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

gbone,
You should already have everything you need for basic usage in Cinnamon. I see three possible issues:
  1. Right-click 'rwall.py' and click properties, then click the 'Permissions' tab. Are all the "execute' check boxes checked? If not, check each one now then click 'close'.
  2. You need to launch rwall.py either with the full path (~/Downloads/rwallslideshow/rwall.py), relative path after changing directories to where rwall.py is located (./rwall.py), or copying rwall.py to a directory in your path (easiest is ~/bin [create it if you don't have it])
  3. Last, when you typed 'rwall.py -d Pictures' you left out the '~/' at the beginning of the path. This is necessary. Although, that is the default directory, so you may not need to even use '-d' option at all. Just try executing 'rwall.py' with no options.
Good luck, and thanks for trying my script!
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

So I tried your suggestion of
~/Downloads/rwallslideshow/rwall.py
and I get a message: /bin/sh: 1: wmctrl: not found Usage:gsettings [--schemadir] set SCHEMA[:PATH] KEY VALUE
Arguments:
SCHEMADIR A directory to search for additional schemas
SCHEMA The name of the schema
PATH The path, for relocatable schemas
KEY The key within the schema
VALUE The value to set

Moreover, I did verify that the file 'rwall.py' is mark as executable.
Thanks
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

I might add to the previous message that when that message about '/bin/sh' that my desktop background reverts to the default LM17 background.
Also, in rwall.py is there an adjustment for time interval between slides?

Thanks
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

You are getting that message because it seems you don't have wmctrl installed. The easy solution is to simply install it:

Code: Select all

sudo apt-get install wmctrl
That's an oversight on my part. My apologies. I'll add it to the requirements list and the first post.

As for the time interval between slides, if you are referring to the --loop option, then it goes like so:

Code: Select all

rwall.py --loop X Y Z
Where X is the directory, Y is the number of loops, and Z is the interval in seconds. There is no other control in rWall for intervals of any kind.

Also, reverting back to the Mint17 wallpaper is expected behavior when background image application fails.
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

rockhazard wrote: Also, reverting back to the Mint17 wallpaper is expected behavior when background image application fails.
I'm getting closer to success :!: :!:
The wmctrl installed just fine, :D :D but I still revert to the default LM17 background. :(

I chose a Preference >Background and when I enter '~/Downloads/rwallslideshow/rwall.py' I still get the revert to default LM17 background.
However, I then tried '~/Downloads/rwallslideshow/rwall.py -l ./Pictures 2 5' and I now get my Preference background with no looping. :shock: :shock:

Thanks for your assistance
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

I really highly recommend putting the script in your path (create a directory 'bin' in your home directory, and put it there, then log out and log back in). Then you can type rwall.py anywhere and it will work. More importantly, you need to use an absolute path with any option that requires a directory, so in your example:

Code: Select all

~/Downloads/rwallslideshow/rwall.py -l ./Pictures 2 5
Should read:

Code: Select all

~/Downloads/rwallslideshow/rwall.py -l ~/Pictures 2 5
Note the deletion of the period and addition of the tilde.

I used the reference script in a fresh install of Mint17 in a virtual machine with wmctrl installed, and it worked as expected with the corrected command above. It only reverted to default background when I gave it an incorrect path. Hopefully that will solve your problem!

BTW, I may not have internet for a week, so I'm not ignoring anyone with an issue. :wink:
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

Thanks for your help.
I created the bin directory as you suggested and restarted. Yes the file rwall.py does execute now from anywhere, but still no visible results. :? :?
I tried rwall.py -l ~/Pictures 5 10 in my half-shrunken terminal (so I could see parts of the background) and it went away for about a minute, then the prompt returned with no visible background changes. I have over 100 jpg images in /Pictures and not one is displayed. Unless the output is going to some invisible screen??

I've tried several different parameters, and rwall.py -s gave a message that feh is not installed.

Sorry to be a PITA but I would like to get it working :( :(
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

Sorry for the delay. I'm a bit at a loss. What edition of Mint17 do you have? Although I've tested it on all of them, it could help knowing the answer.

Also, you could try my old script, mentioned at the top of the first post. It won't allow you to use --next/--previous in anything but Cinnamon and Gnome, but no one has had problems with it either, far as I can tell.

Feh isn't necessary, unless you are using Openbox. I just used it to let people view their background with -s because it reduced dependencies. For functionality in the official editions of Mint17, all you need are Python 3 and wmctrl. I've tried it on several machines and with many virtual machines (and several different Linux distros), and I've never had your problems, which is weird.

I will say that it won't display anything other than files with jpg, jpeg, and png extensions, so if your files have none-compliant extension names that would break the script's functionality. You should also check that your images don't have odd characters in their filenames, like: #,$,%,&,*,@, ~, `, ^, or (). Some of those could work, but I've seen both this and my older script break when trying filenames of that nature.

Good luck.
gbone
Level 3
Level 3
Posts: 144
Joined: Wed Aug 20, 2014 7:55 am

Re: rWall 3.0 "Scratchy", Now in Python!

Post by gbone »

After looking closely at this thread I figured that I must be messing up somehow. I checked that rwall.py was being properly invoked and that my system is a very standard 32-bit LM17 Cinnamon. I then checked my Panasonic camera and discovered that it records its pictures with extension ".JPG" not ".jpg", so I renamed 3 files to the ".jpg" format and VOILA :!: :!: I'm getting background changes :D :D

So my last question (hopefully) is how can I quickly alter my 420 photos in ~/Pictures to the lowercase extension ".jpg" :?: :?:

Thank you again for your patience in helping

PS (I knew there'd be more questions): Is there a way to have rwall.py operate in continuous mode, for example continuously rotating through all photos in the specified directories while displaying each one for a specified interval? I'm thinking maybe having special effects for transitions could be added later :wink: :wink:
JohnBobSmith

Re: rWall 3.0 "Scratchy", Now in Python!

Post by JohnBobSmith »

gbone wrote: ...
So my last question (hopefully) is how can I quickly alter my 420 photos in ~/Pictures to the lowercase extension ".jpg" :?: :?:
...
Try searching for a "Bulk Rename" tool. In XFCE at least, you would easily be able to change the extension of all those files. Not sure if your DE has this tool. It may be in the software or package manager if you don't have it by default.


On a different note, would you, rockhazard, be willing to PM me a copy of the source code? I love python (although I may be a bit rusty at it) and would like to see how other people code. :)

EDIT:

Doh! I mentioned I would be a bit rusty at python. I forgot that python scripts generally are not compiled. Disregard my request for source code, as I already have it. :lol:
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

gbone,
Glad that worked out. To answer your question: cronttab is your friend.

Code: Select all

crontab -e
Then paste this in the resulting editor:

Code: Select all

SHELL=/bin/bash
PATH=/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# randomize wallpaper every 2 minutes
*/2 * * * * export DISPLAY=:0 && /home/username/bin/rwall.py &>/tmp/mycommand.log
You may or may not need to include the "export DISPLAY=:0 &&" or even the PaTH line, but I had to. Modify the "/2" bit with the number corresponding to your desired interval in minutes. If you want different stuff here, then there are plenty of crontab tutorials floating around.

JohnBobSmith,
Thanks for your interest. I hope my code doesn't put you in the funny farm. ;)
JohnBobSmith

Re: rWall 3.0 "Scratchy", Now in Python!

Post by JohnBobSmith »

Hello rockhazard,
I have some questions I would like you to answer, if you don't mind.

First question: Why did you choose python 3 over python 2.7? While both are supported just fine in Linux, python 2.7 is the "standard" so to speak. That said, I actually prefer python 3 over python 2.7 when writing my personal scripts (have none on this PC as its a fresh install, will need to get on that...) Python 3 is more modern, and supports more features. Its kinda like C++11 vs the previous versions. All in all, I'm wondering what made you go with python 3 instead of python 2.7.

Second question: Why GPL v3.0 instead of GPL v2.0? Once again, GPL v2.0 is the standard license, while v3.0 is generally frowned upon do its restrictions. Also, nearly everything in Linux is licensed under GPL v2.0. It's your choice in the matter, but generally the v2.0 license is prefered. I would like to know your reasons behind chosing the license that you did.

Third question: Do you have a github account? It's free, and it lets you work with your code better. Basically, you can edit everything locally, save snapshots, and then upload everything to github. I think it also has some neat version control system, not sure on that one. Github also lets you work in groups. I say, github is a must have for hobbyist programmers!


Now, for a code review! I think you did really well writing your rwall.py script. It's very clean, uses classes, and was easy to follow along with. You use a lot of system functions, which I find interesting. That said, for a python script it seems a bit complex, but not complicated! However as I have not done python in a little bit now, maybe it needs to be complex? Not sure. All in all, your coding practices are very good! :)

Thats about it. Keep up the good work! :D
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

JohnBobSmith wrote:Hello rockhazard,
I have some questions I would like you to answer, if you don't mind.

First question: Why did you choose python 3 over python 2.7? While both are supported just fine in Linux, python 2.7 is the "standard" so to speak. That said, I actually prefer python 3 over python 2.7 when writing my personal scripts (have none on this PC as its a fresh install, will need to get on that...) Python 3 is more modern, and supports more features. Its kinda like C++11 vs the previous versions. All in all, I'm wondering what made you go with python 3 instead of python 2.7.
Because it feels better, for lack a of a more precise term. For instance, the text formatting is more powerful and much easier to understand. And since python3 is in LinuxMint, the platform I'm focused on, it's pretty meaningless to worry about what most people use. Anyway, someday the 2.x branch will die, even if it's a long and slow death, so why not develop in the version that has the legs? Even if that weren't the case, I enjoy it more.
JohnBobSmith wrote: Second question: Why GPL v3.0 instead of GPL v2.0? Once again, GPL v2.0 is the standard license, while v3.0 is generally frowned upon do its restrictions. Also, nearly everything in Linux is licensed under GPL v2.0. It's your choice in the matter, but generally the v2.0 license is prefered. I would like to know your reasons behind chosing the license that you did.
It covers more bases:
http://www.ifross.org/en/what-differenc ... -and-gplv3
JohnBobSmith wrote: Third question: Do you have a github account? It's free, and it lets you work with your code better. Basically, you can edit everything locally, save snapshots, and then upload everything to github. I think it also has some neat version control system, not sure on that one. Github also lets you work in groups. I say, github is a must have for hobbyist programmers!
I use bitbucket right now. However, I'm not yet used to git commands, so I don't really use it all that much at the moment.
JohnBobSmith wrote: Now, for a code review! I think you did really well writing your rwall.py script. It's very clean, uses classes, and was easy to follow along with. You use a lot of system functions, which I find interesting. That said, for a python script it seems a bit complex, but not complicated! However as I have not done python in a little bit now, maybe it needs to be complex? Not sure. All in all, your coding practices are very good! :)
Thank you. It is a practical certainty that the code can be simplified, since this is my first Python project. There are places where I know I could have made things more "pythonic", but I strove for clarity over simply being concise, for example. It's not clear that being more concise leads to less complexity, though. Also, I did what was obvious to me, rather than sifting through configurations that could have reduced the lines of code; if it worked, and wasn't ridiculous, I kept it. My shell script that I translated this from has maybe around 400 more lines of code, which you can examine from the link in the first post. I don't know any other languages except Shell scripting.
JohnBobSmith wrote: Thats about it. Keep up the good work! :D
Thanks for your review. I appreciate it!
rockhazard
Level 1
Level 1
Posts: 43
Joined: Wed May 04, 2011 1:44 pm

Re: rWall 3.0 "Scratchy", Now in Python!

Post by rockhazard »

I have updated the script for KDE5. It still works with the 4.x branch. Remember to install and setup feh if you are using either Openbox or another environment not mentioned in the help. Be happy!
Locked

Return to “Scripts & Bash”