Skip to content

Instantly share code, notes, and snippets.

@ichirou2910
Created February 7, 2020 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichirou2910/8ef60686d3ba1ed700dc1b81b8985eee to your computer and use it in GitHub Desktop.
Save ichirou2910/8ef60686d3ba1ed700dc1b81b8985eee to your computer and use it in GitHub Desktop.
Script to print notes on your desktop
#!/usr/bin/env python3
# Thanks to Jacob Vlijim for the original script, for more info please refer to the source
# Source: https://askubuntu.com/questions/556723/make-a-text-file-my-automatically-updated-background
# Edited by Ichirou2910 for personal needs
# Update 8 Feb 2020:
# - You can use tab, define your tab so it will replace the "TAB" you enter
# - Remove strip() when reading from file to be able to use tab
import subprocess
import os
import time
curr_dir = os.path.dirname(os.path.realpath(__file__))
curr_wall = curr_dir+"/"+"wallpaper.jpg"
notes = curr_dir+"/"+"notes.txt"
#-- CUSTOM PARAMETERS
shell = "/bin/zsh" # your shell binary path, I use zsh
font = "Comic-Sans-MS-Bold" # execute convert -list font for possible font choices
text_color = "black" # text color
size = "45" # text size (real size depends on the scale factor of your wallpaper)
tab = " " # Imagemagick doesn't accept \t so just define it yourself
borderX = 300 # x offset
borderY = 350 # y offset
columns = 1 # (max) number of columns
n_lines = 10 # (max) number of lines per column
set_bg_cmd = "feh --bg-scale " # your command to change background goes here, but without the path to image
#--
def run_command(cmd):
subprocess.call([shell, "-c", cmd])
def get_value(cmd):
return subprocess.check_output([shell, "-c", cmd]).decode("utf-8").strip()
def read_text(file):
with open(file) as src:
return [l.replace('\t', tab) for l in src.readlines()]
def slice_lines(lines, n_lines, columns):
markers = [i for i in range(len(lines)) if i % n_lines == 0]
last = len(lines); markers = markers+[last] if markers[-1] != last else markers
textblocks = [lines[markers[i]:markers[i+1]] for i in range(len(markers)-1)]
filled_blocks = len(textblocks)
if filled_blocks < columns:
for n in range(columns - filled_blocks):
textblocks.insert(len(textblocks), [])
for i in range(columns):
textblocks[i] = ("").join(textblocks[i])
return textblocks[:columns]
def create_section(psize, text, layer):
run_command("convert -background none"+\
" -fill "+text_color+\
" -border "+str(borderX)+"x"+str(borderY)+\
" -bordercolor none"+\
" -pointsize "+size+\
" -size "+psize+\
" -font "+font+\
" caption:"+'"'+text+'" '+layer)
def combine_sections(layers):
run_command("convert "+image_1+" "+image_2+" "+"+append "+span_image)
pass
def set_overlay():
boxes = slice_lines(read_text(notes), n_lines, columns)
resolution = get_value('identify -format "%wx%h" '+curr_wall).split("x")
w = str(int(int(resolution[0])/columns)-2*borderX)
h = str(int(resolution[1])-2*borderY)
layers = []
for i in range(len(boxes)):
layer = curr_dir+"/"+"layer_"+str(i+1)+".png"
create_section(w+"x"+h, boxes[i], layer)
layers.append(layer)
run_command("convert "+(" ").join(layers)+" "+"+append "+curr_dir+"/"+"layer_span.png")
wall_img = curr_dir+"/"+"walltext.jpg"
run_command("convert "+curr_wall+" "+curr_dir+"/"+"layer_span.png"+" -background None -layers merge "+wall_img)
run_command(set_bg_cmd+wall_img)
for img in [img for img in os.listdir(curr_dir) if img.startswith("layer_")]:
os.remove(curr_dir+"/"+img)
while True:
text_1 = read_text(notes)
time.sleep(5)
text_2 = read_text(notes)
if text_2 != text_1:
set_overlay()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment