Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from markubiak/dev
Browse files Browse the repository at this point in the history
Merge Dev into Master for 3.0.2
  • Loading branch information
markubiak authored Oct 6, 2016
2 parents 967bbdf + a515306 commit 37668c8
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 52 deletions.
103 changes: 59 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,72 @@
#About
wallpaper-reddit is a Python 3 program that sets your wallpaper to the top image of one or multiple subreddits. Version 3 has introduced many changes, such as the removal of all external dependencies, automatic DE detection for wallpaper setting, and proper setup using setuptools.
# About
wallpaper-reddit is a Python 3 program that sets your wallpaper to the top image of one or multiple subreddits. Version 3 has introduced many changes, such as the removal of all external dependencies, automatic DE detection for wallpaper setting, and proper setup using setuptools.

# Installation
RPMs for Fedora 23, Fedora 24, Ubuntu 16.04/Linux Mint 18 can be found on the [Releases Page] (https://github.com/markubiak/wallpaper-reddit/releases)

Users of Ubuntu derivatives <16.04 will have to build from source, as the version of PIL shipped with those versions of Ubuntu is outdated.

#Installation
RPMs for Fedora 23, Fedora 24, Ubuntu 16.04/Linux Mint 18 can be found on the [Releases Page] (https://github.com/markubiak/wallpaper-reddit/releases)
Users of Ubuntu derivatives <16.04 will have to build from source, as the version of PIL shipped with those versions of Ubuntu is outdated.
Arch users can get the package from the [AUR](https://aur.archlinux.org/packages/wallpaper-reddit-git/)

From Source:
* Install Pillow 3.x or the libraries necessary to compile it from scratch if the distribution you're using does not package it:
- Ubuntu <16.04/Linux Mint 17/ElementaryOS: `sudo apt-get install python3-dev python3-setuptools libjpeg8-dev zlib1g-dev libfreetype6-dev`
- Fedora: `sudo dnf install python3-imaging` (installed by default)
- Arch: `sudo pacman -S python-pillow`
- Mac OS X El Capitan:
* `xcode-select --install`
* `pip install pillow`
* Clone the repository and navigate into the directory with the setup.py file.
* Run `sudo python3 setup.py install`

#Usage
The script is very simple to use. Simply type:

wallpaper-reddit [subreddits]
1.) Install Pillow 3.x or the libraries necessary to compile it from scratch if the distribution you're using does not package it:
- Ubuntu <16.04/Linux Mint 17/ElementaryOS: `sudo apt-get install python3-dev python3-setuptools libjpeg8-dev zlib1g-dev libfreetype6-dev`
- Fedora: `sudo dnf install python3-imaging` (installed by default)
- Arch: `sudo pacman -S python-pillow`
- Mac OS X El Capitan:
* `xcode-select --install`
* `pip install pillow`

2.) Clone the repository and navigate into the directory with the setup.py file.
3.) Run `sudo python3 setup.py install`

# Usage
The script is very simple to use. Simply type:

`wallpaper-reddit [subreddits]`

If no subreddits are specified, the script will default to the top image from the subs section of the config file. There are many, many more options, all of which you can see by typing:
If no subreddits are specified, the script will default to the top image from the subs section of the config file. There are many, many more options, all of which you can see by typing:

`wallpaper-reddit --help`

# Configuration
The config file is in `~/.config/wallpaper-reddit`, and will be created automatically. Currently, the GNOME, XFCE, MATE, Unity, and Cinnamon Desktop Environments should be automatically detected and the program should set the wallpaper without any extra work. However, due to the varying nature of window managers, it is possible, even likely, that you may have to specify a custom command to set your wallpaper. The program will prompt you for this if this is the case; the exact command can be researched per desktop environment. If your desktop environment is not supported, please file an issue so that automatic support can be implemented for others.
### Config Options:
- `minwidth` and `minheight` set the minimum dimensions the program will consider a valid candidate for a wallpaper. If `--resize` is enabled, the script will resize the image to those dimensions before setting the wallpaper.
- `maxlinks` is the maximum number of links the script will go through before giving up.
- `resize` does the same thing as the `--resize` flag. It is enabled by default.
- `random` does the same thing as the `--random` flag.

wallpaper-reddit --help
# Overlay Titles
The program has an option to overlay the title of the image directly onto the image itself, so using conky to constantly read the title of the image from `~/.wallpaper/title.txt` is no longer necessary (although it still works, and is recommended if not using the "resize" option). This function is not enabled by default, but it can be enabled with either the `--settitle` command line flag or more permanently in the config under the `[Title Overlay]` section. There are five options for setting titles: size, x/y alignment, and x/y offset.

#Configuration
The config file is in ~/.config/wallpaper-reddit, and will be created automatically. Currently, the GNOME, XFCE, MATE, Unity, and Cinnamon Desktop Environments should be automatically detected and the program should set the wallpaper without any extra work. However, due to the varying nature of window managers, it is possible, even likely, that you may have to specify a custom command to set your wallpaper. The program will prompt you for this if this is the case; the exact command can be researched per desktop environment. If your desktop environment is not supported, please file an issue so that automatic support can be implemented for others.
Config Options:
- minwidth and minheight set the minimum dimensions the program will consider a valid candidate for a wallpaper. If --resize is enabled, the script will resize the image to those dimensions before setting the wallpaper.
- maxlinks is the maximum number of links the script will go through before giving up.
- resize does the same thing as the --resize flag. It is enabled by default.
- random does the same thing as the --random flag.
### Overlay Title Configuration Options
Options for the overlay title can only be set in the config file. They are under the [Title Overlay] section.
- `titlesize` sets the font height at which the title will be rendered, in pixels.
- `titlealignx` sets the horizontal alignment of the title, and can be either `left`, `center` or `right`.
- `titlealigny` sets the vertical alignment, and can be `top` or `bottom`.
- `titleoffsetx` and `titleoffsety` allow you to set an additional offset from the edge of the image, in pixels.

#Startup
If wallpaper-reddit is run with the --startup flag, the program will wait on an internet connection. Options for the startup can only be set in the config file. They are under the [Startup] section: interval and attempts. The script will try to make a connection to reddit.com up to $attempts times at every $interval seconds. For example, the default setting is an interval of 3 and 10 attempts, so the script will try to connect to reddit every 3 seconds for up to 10 tries, giving a total of 30 seconds before the scrpit gives up. As a reminder, this feature is only activated by the --startup flag
# Startup
If wallpaper-reddit is run with the `--startup` flag, the program will wait on an internet connection. Once startup is activated, the script will try to connect to Reddit to download new wallpaper upon startup. The default setting is an interval of 3 and 10 attempts, which means that the script will try to connect to Reddit every 3 seconds for up to 10 tries, giving a total of 30 seconds before the script gives up.

#Overlay Titles
The program has an option to overlay the title of the image directly onto the image itself, so using conky to constantly read the title of the image from ~/.wallpaper/title.txt is no longer nexessary (although it still works, and is recommended if not using the "resize" option). This function is not enabled by default, but it can be enabled with either the --settitle command line flag or more permanently in the config under the "Title Overlay" section. There are five options for setting titles: size, x/y alignment, and x/y offset. The size (titlesize) is the height of the text in pixels. To set where the title is aligned (replaces titlegravity) titlealignx can be left, center, or right; titlealigny can be top or bottom. To offset the title slightly, titleoffsetx and titleoffsety are offsets from the edge of the screen in pixels. All of these options can only be set in the config file.
### Startup Configuration Options
Options for the startup can only be set in the config file. They are under the [Startup] section.
- `interval` describes the amount of time, in seconds, between wallpaper-reddit's attempts to procure new wallpaper.
- `attempts` describes the number of attempts that will be made to connect to Reddit. After this number of attempts has failed, wallpaper-reddit will cease to try downloading wallpaper during the current startup.

#Saving
If wallpaper-reddit is run with the --save flag, no wallpaper will be downloaded. The current wallpaper will be copied to the save directory, as specified in the config file (default is ~/Pictures/Wallpapers on Linux, ~/My Pictures/Wallpapers on Windows), and its title will be put into a titles.txt file inside the same directory.
# Saving
If wallpaper-reddit is run with the `--save` flag, no wallpaper will be downloaded. The current wallpaper will be copied to the save directory, as specified in the config file (default is `~/Pictures/Wallpapers` on Linux, `~/My Pictures/Wallpapers` on Windows), and its title will be put into a titles.txt file inside the same directory.

#Blacklists
There is a function to blacklist a certain wallpaper from the script if it is particularly ugly. Simply run the script with the --blacklist flag. The script will run as usual, but additionally blacklist your current wallpaper. You'll get a new wallpaper and never see the old one again.
# Blacklists
There is a function to blacklist a certain wallpaper from the script if it is particularly ugly. Simply run the script with the `--blacklist` flag. The script will run as usual, but additionally blacklist your current wallpaper. You'll get a new wallpaper and never see the old one again.

#External commands and wallpaper info
Because more information is always better, much more than the wallpaper itself exists in ~/.wallpaper.
- blacklist.txt contains the urls of blacklisted wallpapers, one can manually add urls without issue.
- url.txt is the url of the current wallpaper
- title.txt is the title of the current wallpaper (useful if you want to put the title into conky)
- external.sh is a bash script that is run at the end of every execution of the script (Linux only). Any extra commands to deal with the wallpaper can be safely placed in this bash script. I personally have mine darken my xfce4-panel if the wallpaper is too bright at the top, and set the wallpaper as my SLiM/xscreensaver background.
# External commands and wallpaper info
Because more information is always better, much more than the wallpaper itself exists in `~/.wallpaper`.
- `blacklist.txt` contains the urls of blacklisted wallpapers, one can manually add urls without issue.
- `url.txt` is the url of the current wallpaper
- `title.txt` is the title of the current wallpaper (useful if you want to put the title into conky)
- `external.sh` is a bash script that is run at the end of every execution of the script (Linux only). Any extra commands to deal with the wallpaper can be safely placed in this bash script. I personally have mine darken my xfce4-panel if the wallpaper is too bright at the top, and set the wallpaper as my SLiM/xscreensaver background.

#Contact
If there is an issue with the program, please file a github issue. If you need more specific help troubleshooting a specific desktop or have an issue that isn't worthy of github, feel free to reach out to me on Reddit: [/u/wallpaper-reddit](https://www.reddit.com/u/wallpaper-reddit)
# Contact
If there is an issue with the program, please file a GitHub issue. If you need more specific help troubleshooting a specific desktop or have an issue that isn't worthy of GitHub, feel free to reach out to me on Reddit: [/u/wallpaper-reddit](https://www.reddit.com/u/wallpaper-reddit)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

setup(
name='wallpaper-reddit',
version='3.0.1',
version='3.0.2',
packages=find_packages(),
url='https://www.github.com/markubiak/wallpaper-reddit',
author='Mark Kubiak',
author_email='[email protected]',
description='A utility that downloads wallpapers from reddit',
install_requires=['Pillow>=3.0'],
package_data={
'wpreddit': ['fonts/*.otf', 'conf_files/*.conf']
'wpreddit': ['fonts/*.otf', 'conf_files/*.conf', 'conf_files/*.desktop']
},
entry_points={
'console_scripts': [
Expand Down
6 changes: 6 additions & 0 deletions wpreddit/conf_files/linux-autostart.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=wallpaper-reddit
Comment=Downloads and sets the top wallpaper from the news aggregation website Reddit.
Exec=wallpaper-reddit --startup
Type=Application
StartupNotify=true
5 changes: 5 additions & 0 deletions wpreddit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# global vars
verbose = False
startup = False
autostartup = False
force_dl = False
startupinterval = 0
startupattempts = 0
Expand Down Expand Up @@ -130,6 +131,8 @@ def parse_args():
action="store_true")
parser.add_argument("--startup", help="runs the program as a startup application, waiting on internet connection",
action="store_true")
parser.add_argument("--auto-startup", help="sets the program to automatically run on every login (Linux only)",
action="store_true")
parser.add_argument("--save",
help='saves the current wallpaper (does not download a wallpaper)',
action="store_true")
Expand All @@ -148,6 +151,7 @@ def parse_args():
global save
global force_dl
global startup
global autostartup
global resize
global settitle
global randomsub
Expand All @@ -157,6 +161,7 @@ def parse_args():
verbose = args.verbose
save = args.save
startup = args.startup
autostartup = args.auto_startup
force_dl = args.force
if args.resize:
resize = True
Expand Down
3 changes: 0 additions & 3 deletions wpreddit/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ def set_image_title(img, title):
elif config.titlealign_y == "bottom":
text_y = font.getsize(title)[1]
y = img.size[1] - text_y - config.titleoffset_y
# shadow = Image.new('RGBA', img.size, (255,255,255,0))
# shadowdraw = ImageDraw.Draw(shadow)
# shadowdraw.text((x+2, y+2), title, font=font, fill=(255,255,255))
draw.text((x+2, y+2), title, font=font, fill=(0, 0, 0, 127))
draw.text((x, y), title, font=font)
del draw
Expand Down
12 changes: 12 additions & 0 deletions wpreddit/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
from pkg_resources import resource_string

from wpreddit import config, connection, download, reddit, wallpaper

Expand All @@ -14,6 +15,17 @@ def run():
if config.save:
wallpaper.save_wallpaper()
sys.exit(0)
if config.autostartup:
if config.opsys == "Linux":
dfile = resource_string(__name__, 'conf_files/linux-autostart.desktop')
path = os.path.expanduser("~/.config") + "/autostart/wallpaper-reddit.desktop"
with open(path, "wb") as f:
f.write(dfile)
print("Autostart file created at " + path)
sys.exit(0)
else:
print("Automatic startup creation only currently supported on Linux")
sys.exit(1)
if config.startup:
connection.wait_for_connection(config.startupattempts, config.startupinterval)
# make sure you're actually connected to reddit
Expand Down
6 changes: 3 additions & 3 deletions wpreddit/wallpaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def set_wallpaper():
if config.opsys == "Windows":
ctypes.windll.user32.SystemParametersInfoW(0x14, 0, config.walldir + "\\wallpaper.bmp", 0x3)
elif config.opsys == "Darwin":
path = os.path.expanduser("~/.wallpaper/wallpaper.jpg")
path = os.path.expanduser(config.walldir + "/wallpaper.jpg")
os.system("sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db \"update data set value = '" + path + "'\" && killall Dock")
else:
linux_wallpaper()
Expand All @@ -22,7 +22,7 @@ def set_wallpaper():

def linux_wallpaper():
de = os.environ.get('DESKTOP_SESSION')
path = os.path.expanduser("~/.wallpaper/wallpaper.jpg")
path = os.path.expanduser(config.walldir + "/wallpaper.jpg")
if config.setcmd != '':
os.system(config.setcmd)
elif de in ["gnome", "gnome-wayland", "unity", "ubuntu"]:
Expand All @@ -35,7 +35,7 @@ def linux_wallpaper():
if re.search('wallpaper[0-9]+\.jpg', file) is not None:
os.remove(config.walldir + "/" + file)
randint = random.randint(0, 65535)
randpath = os.path.expanduser("~/.wallpaper/wallpaper%s.jpg" % randint)
randpath = os.path.expanduser(config.walldir + "/wallpaper%s.jpg" % randint)
shutil.copyfile(path, randpath)
os.system("gsettings set org.gnome.desktop.background picture-uri file://%s" % randpath)
elif de in ["mate"]:
Expand Down

0 comments on commit 37668c8

Please sign in to comment.