-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout2.py
313 lines (246 loc) · 11.3 KB
/
layout2.py
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'layout.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import os
import time
import ctypes
from cgitb import enable
from turtle import width
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from PyQt5 import QtCore, QtGui, QtWidgets
# Handle high resolution displays:
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
#import tkinter as tk
#from tkinter import *
list_of_work = {}
user_name = os.getlogin()
def homework_to_wallpaper(folder_location, text):
#tk setup
#root = Tk()
#root.title("Homework on Wallpaper!")
#
#def myClick():
# myClick = Label(root, text ="Enter you wallpaper save location")
# myClick.grid(row=3)
#
#myLabel1 = Label(root, text="WARNING: THIS PROGRAM WILL CHANGE YOUR WALLPAPER INSTANTLY AFTER IT'S FINISHED. PLS REMEMBER TO RECORD THE OLD WALLPAPER FILE LOCATION")
#myLabel2 = Label(root, text="Copyright to Leo Yu")
#
#save_location = Entry(root, width=50)
#
#subject1 = Label(root, text = 'Subject #1')
#detail1 = Entry(root, width=100)
#
#
#myLabel1.grid(row=0, columnspan=3)
#myLabel2.grid(row=1, columnspan=3)
#myClick()
#save_location.grid(row=4) #griding the textinput
#
#subject1.grid(row=5) #griding the first subject
#detail1.grid(row=6) #griding the first detail of the subject
#
#root.mainloop()
#script_dir = os.path.dirname(file_loc) #<-- absolute dir the script is in
#rel_path = "/works.png"
#abs_file_path = os.path.join(script_dir, rel_path)
#Copyright to https://www.codegrepper.com/code-examples/python/text+to+image+python
print("WARNING: THIS PROGRAM WILL CHANGE YOUR WALLPAPER INSTANTLY AFTER IT'S FINISHED. PLS REMEMBER TO RECORD THE OLD WALLPAPER FILE LOCATION")
def text_to_image(text):
def getSize(txt, font):
testImg = Image.new('RGB', (1, 1))
testDraw = ImageDraw.Draw(testImg)
return testDraw.textsize(txt, font)
if __name__ == '__main__':
fontname = "arial.ttf"
fontsize = 30
colorText = "black"
colorOutline = "white"
colorBackground = "white"
font = ImageFont.truetype(fontname, fontsize)
width, height = getSize(text, font)
img = Image.new('RGB', (width+1920, height+1080), colorBackground)
d = ImageDraw.Draw(img)
d.text((750, height/2), text, fill=colorText, font=font)
d.rectangle((0, 0, width+1920, height+1080), outline=colorOutline)
img.save(file_loc)
#omg that part is finally done.
#code for funny person. I guess i will never put this into use
#edit: after 5 months, i still don's have any plan of adding this into the code
def personality():
personality = input('This is just a funny question: Are you a funny person? y/n')
if personality == 'y':
print('ok guess u r a funny person. YaY')
return 'y'
elif personality == 'yes':
print('...i told you to answer with y or n and you answered yes... I guess u r a funny person then! :)')
return 'y'
elif personality == 'n':
print('Sorry for that ridiculous quesion. Here is the code:')
return 'n'
elif personality == 'no':
print('...i told you to answer with y or n and you answered no... I guess u r a funny person then! :)')
return 'y'
#here is the code for NOT funny person
#edit: This part has lots of comments. Which are the original code. They need to be ignored for the GUI
#def ur_homework():
#
# #subject_abbr = {'Social Studies' : 'sos', 'French' : 'fre', 'Technology' : 'tec', 'Science' : 'sci', 'Math' : 'mat', 'Christian Education' : 'ce', 'English' : 'eng'}
# subject_q = str(input('Subject: '))
#
# detail = str(input('Detail: '))
#
#
# list_of_work[subject_q] = detail
#
# more = str(input('Do u have more? y/n: '))
#
# if more == 'y':
# #print('k, gald to hear that! *evil laugh*')
# #print(list_of_work)
# ur_homework()
#
# elif more == 'yes':
# #print('...i told you to answer with y or n and you answered yes... I guess u have more stuff then! :)')
# #print(list_of_work)
# ur_homework()
#
# elif more == 'n':
# #print('Ok then, pls check ur wallpaper!')
# #print('Please check your wallpaper.')
# #print(list_of_work)
# return list_of_work
#
# elif more == 'no':
# #print('...i told you to answer with y or n and you answered no... Too bad...')
# #print('Please check your wallpaper.')
# #print(list_of_work)
# return list_of_work
#def dic_to_text(works):
#
# with open(txt_file_loc, 'w') as f:
# for title, detail in works.items():
# f.write(f'{title.upper()}:\n{detail}\n\n')
#
# with open(txt_file_loc, 'r') as f:
# pass
# #print(f.read())
#using defs
folder_location = folder_path
#if folder_location == '':
# folder_location = r"C:\Users" + "\\" + user_name + "\\" + r"Desktop\Homeworks"
txt_file_loc = folder_location + '\\homeworks.txt'
if not os.path.exists(folder_location):
os.makedirs(folder_location)
if __name__ == '__main__':
file_loc = folder_location + '\\' + 'homeworks.png'
print(folder_location)
#ur_homework()
#dic_to_text(list_of_work)
homeworks = open(txt_file_loc, 'r')
text_to_image(text)
print("Please check your wallpaper!")
print("Press ctrl c to quit the program :)")
ctypes.windll.user32.SystemParametersInfoW(20, 0, file_loc , 0)
#time.sleep(100000)
#Main GUI window
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
def pick_folder():
dialog = QtWidgets.QFileDialog()
global folder_path
folder_path = dialog.getExistingDirectory(None, "Select Folder")
self.lineEdit.insert(folder_path)
print(folder_path)
return folder_path
def gui_text_to_txt():
global gui_text
gui_text = self.textEdit.toPlainText()
print(gui_text)
return gui_text
MainWindow.setObjectName("MainWindow")
MainWindow.setWindowModality(QtCore.Qt.WindowModal)
MainWindow.resize(589, 419)
MainWindow.setMinimumSize(QtCore.QSize(589, 419))
MainWindow.setMaximumSize(QtCore.QSize(589, 419))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(-10, 0, 591, 41))
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setEnabled(True)
self.lineEdit.setGeometry(QtCore.QRect(150, 60, 341, 20))
self.lineEdit.setObjectName("lineEdit")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 60, 131, 21))
self.label_2.setObjectName("label_2")
#browse button
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: pick_folder())
self.pushButton_2.setGeometry(QtCore.QRect(500, 60, 81, 21))
self.pushButton_2.setObjectName("pushButton_2")
self.textEdit = QtWidgets.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(10, 110, 571, 231))
self.textEdit.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.textEdit.setObjectName("textEdit")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(10, 90, 401, 16))
self.label_3.setObjectName("label_3")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(430, 350, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
#pick_folder = pick_folder()
#gui_text_to_txt = gui_text_to_txt()
print(pick_folder())
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget, clicked = lambda: homework_to_wallpaper(pick_folder, gui_text_to_txt()))
print(gui_text_to_txt())
self.pushButton_4.setGeometry(QtCore.QRect(510, 350, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(-10, 20, 591, 41))
font = QtGui.QFont()
font.setPointSize(10)
self.label_4.setFont(font)
self.label_4.setAlignment(QtCore.Qt.AlignCenter)
self.label_4.setObjectName("label_4")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 589, 22))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Homework to Wallpaper"))
self.label.setText(_translate("MainWindow", "WARNING: THIS PROGRAM WILL CHANGE YOUR WALLPAPER INSTANTLY AFTER IT\'S FINISHED"))
self.label_2.setText(_translate("MainWindow", "Enter Save Folder Location"))
self.pushButton_2.setText(_translate("MainWindow", "Browse"))
self.label_3.setText(_translate("MainWindow", "Please enter your homework by following the exact format as the example below:"))
self.pushButton_3.setText(_translate("MainWindow", "Save Text"))
self.pushButton_4.setText(_translate("MainWindow", "Apply"))
self.label_4.setText(_translate("MainWindow", " PLS REMEMBER TO RECORD THE OLD WALLPAPER FILE LOCATION"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())