forked from errorundefined/getspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetspace_linux.py
More file actions
105 lines (79 loc) · 2.63 KB
/
getspace_linux.py
File metadata and controls
105 lines (79 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
import os
import subprocess
def dosetbackground(path):
# http://stackoverflow.com/questions/32264960/how-to-use-change-desktop-wallpaper-using-python-in-ubuntu-14-04-with-unity
# http://askubuntu.com/questions/85162/how-can-i-change-the-wallpaper-using-a-python-script
# https://gist.github.com/mtrovo/1110370
#!/usr/bin/env python
#-*- coding:utf-8 -*-
# import commands
# import os.path
# from sys import argv
# def set_gnome_wallpaper(file_path):
# command = "gconftool-2 --set \
# /desktop/gnome/background/picture_filename \
# --type string '%s'" % file_path
# status, output = commands.getstatusoutput(command)
# return status
# if __name__ == '__main__':
# if len(argv) <= 1:
# print "usage: %s img_path" % argv[0]
# else:
# img_path = os.path.abspath(argv[1])
# if not set_gnome_wallpaper(img_path):
# print "Wallpaper changed with success."
# else:
# print "An error ocurred while setting a new wallpaper."
def notify(title, subtitle, text, kind):
# CHECK FOR COMMON NOTIFICATION SERVERS
notifysrv = False
# CHECK FOR NOTIFY-SEND
try:
subprocess.call(['notify-send'])
except OSError as e:
if e.errno == os.errno.ENOENT:
pass
else:
notifysrv = 'notify-send'
# CHECK FOR KDIALOG
if not notifysrv:
try:
subprocess.call(['kdialog'])
except OSError as e:
if e.errno == os.errno.ENOENT:
print 'No compatible notification server found.'
else:
notifysrv = 'kdialog'
# PREPARE VARS WITH DOUBLE TICKS
if notifysrv:
quotes = '"'
title = quotes + title + quotes
text = quotes + text + quotes
# SEND A NOTIFICATION TO THE notifysrv FOUND
# PREPARE FOR AND SENT TO notify-send
if notifysrv == 'notify-send':
if kind == 'error':
urgency = 'critical'
else:
urgency = 'normal'
# or subprocess.Popen?
subprocess.call(['notify-send', '-u', urgency, '-t', 500, title, text])
# OR PREPARE FOR AND SENT TO kdialog
elif notifysrv == 'kdialog':
# or subprocess.Popen?
subprocess.call(['kdialog', '--passivepopup', '--title', title, text, 5])
def getscreensize():
# add stuff
# http://stackoverflow.com/questions/2035657/what-is-my-current-desktop-environment
def getfontvars(height, explanation):
from PIL import ImageFont
from math import floor
import textwrap
# SET SIZING VARS
fsizehead = int(floor(height / 36))
fsizetext = int(floor(height / 65))
wrapped = textwrap.fill(explanation, 100)
# SET FONT VARS
headfont = ImageFont.truetype("/Library/Fonts/Futura.ttc",fsizehead,index=2)
textfont = ImageFont.truetype("/System/Library/Fonts/Avenir.ttc",fsizetext)