-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.py
More file actions
154 lines (134 loc) · 4.81 KB
/
timer.py
File metadata and controls
154 lines (134 loc) · 4.81 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import numpy as np
import ctypes
from PIL import Image, ImageDraw, ImageFont
import scipy.misc
import os
import datetime
from win32api import GetSystemMetrics
import json
dict = {}
def read_file():
"""Open data file"""
with open("data_file.json", "r") as read_file: # read data file
dict = json.load(read_file)
return dict
dict = read_file()
def data_dump(dict):
"""Take date data from file and return"""
date = datetime.datetime(int(dict.get("Год")), int(dict.get("Месяц")), int(dict.get("День")), 0, 0, 0)
today = datetime.datetime.now()
date = date - today #datetime.timedelta
string_day = " дней"
string_hour = " часов"
if ((date.days % 10) == 0) and (not (date.days % 10) == 10):
string_day = " дней"
elif (date.days) == 1:
string_day = " день"
elif (date.days) in range(10, 21, 1):
string_day = " дней"
elif (date.days % 10) in range(2, 5, 1):
string_day = " дня"
elif (date.days % 10) in range(5, 10, 1):
string_day = " дней"
if int((date.seconds / 3600)) == 21:
string_hour = " час"
elif int((date.seconds / 3600)) == 1:
string_hour = " час"
elif int((date.seconds / 3600)) in range(2, 5, 1):
string_hour = " часа"
elif int((date.seconds / 3600)) in range(22, 25, 1):
string_hour = " часа"
elif int((date.seconds / 3600)) in range(5, 10, 1):
string_hour = " чаcов"
elif int((date.seconds / 3600)) in range(10, 21, 1):
string_hour = " чаcов"
return str(date.days) + string_day + " " + str(int(date.seconds / 3600)) + string_hour + "\n"
def create_image():
"""Create white image"""
#определение разрешения экрана
monitor_width = GetSystemMetrics(0)
monitor_heitgh = GetSystemMetrics(1)
# создадим белое изображение
img = np.zeros((monitor_heitgh, monitor_width, 3), np.uint8)
img[:, :, :] = 255
return img
def default_image():
"""Using default_image"""
if dict["path"] == "Здесь пока ничего нет":
return 0
else:
path = dict.get("path")
img = Image.open(path)
img = Image.open(r'D:\Photo\IMG_4021-1920.jpg') # изображение по умолчанию
img.show()
path = dict.get("path")
img = Image.open(path)
arr = np.asarray(img, dtype='uint8')
return arr
# Choice image option
if dict["status"] == 0:
img = default_image()
else:
img = create_image()
def put_text_pil(img: np.array, txt: str):
"""Text on image"""
im = Image.fromarray(img)
font_size = dict["font"]
font = ImageFont.truetype("ofont.ru_Clear Sans Thin.ttf", size=font_size)
draw = ImageDraw.Draw(im)
# здесь узнаем размеры сгенерированного блока текста
w, h = draw.textsize(txt, font=font)
draw = ImageDraw.Draw(im)
width, height = im.size
x, y = ((width / 1.5) + 150, height / 100)
draw.text((x, y), txt, fill='rgb(0, 0, 0)', font=font)
img = np.asarray(im)
return img
def date_time():
"""Default date"""
date = datetime.datetime(2019, 11, 16, 0, 0, 0) # дата напоминания по умолчанию
today = datetime.datetime.today()
date = date - today
return date
def now_time():
"""<Now time> computing"""
today = datetime.datetime.now()
today_month = ""
if today.month == 1:
today_month = "января"
elif today.month == 2:
today_month = "февраля"
elif today.month == 3:
today_month = "марта"
elif today.month == 4:
today_month = "апреля"
elif today.month == 5:
today_month = "мая"
elif today.month == 6:
today_month = "июня"
elif today.month == 7:
today_month = "июля"
elif today.month == 8:
today_month = "августа"
elif today.month == 9:
today_month = "сентября"
elif today.month == 10:
today_month = "октября"
elif today.month == 11:
today_month = "ноября"
elif today.month == 12:
today_month = "декабря"
return str(today.day) + " " + today_month
def set_wallpaper():
"""Installation image on Desktop"""
SPI_SETDESKWALLPAPER = 20 # константа, всегда = 20
p = os.path.abspath('my.jpg')
arg = ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, p , 0)
# SystemParametersInfoW - 64 bit системы
# SystemParametersInfoA - 32 bit системы
task_text = " до " + str(dict['Задача'])
text = " " + "Сегодня " + str(now_time()) + "\n" + " " + (str(data_dump(dict))) + task_text
img = put_text_pil(img, text)
image = Image.fromarray(img, 'RGB')
image.save('my.jpg')
set_wallpaper()