-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
121 lines (109 loc) · 4.04 KB
/
Main.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
#GitHub : @CodeYard01
#YouTUbe : @CodeYard
from PyQt5 import QtWidgets, uic,QtCore, QtGui
from PyQt5.QtWidgets import *
import sys
from NotesUI import Ui_MainWindow
import random
import os
def Last_window_id():
file_path = 'window_id.notes'
try:
with open(file_path,'r') as file:
id = file.read()
global window_id
window_id = id
except FileNotFoundError:
with open(file_path,'w') as file_write:
window_id = 1
file_write.write(str(window_id))
windows = [1]
Last_window_id()#change icon,
def Update_window_id():
file_path = 'window_id.notes'
with open(file_path,'w') as file:
global window_id
window_id = int(window_id)
file.write(str(window_id))
def del_window_id():
file_path= 'window_id.notes'
with open(file_path,'w') as file_del:
global window_id
if int(window_id) > 1:
window_id = int(window_id) - 1
file_del.write(str(window_id))
else:
file_del.write('1')
class Main(QtWidgets.QMainWindow):
def __init__(self,window_id):
super().__init__()
self.Ui = Ui_MainWindow()
self.Ui.setupUi(self)
self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
self.setGeometry(random.randint(400,900), random.randint(100,500), 260, 360)
self.Ui.addbtn.clicked.connect(self.addNewWindow)
self.window_id = window_id
self.Ui.delbtn.clicked.connect(self.delete)
self.Ui.pushButton.clicked.connect(self.changeTextEditBackground)
self.dragging = False
self.offset = QtCore.QPoint()
random_color = QtGui.QColor(random.randint(23, 232), random.randint(27, 237), random.randint(29, 235))
self.Ui.textEdit.setStyleSheet(f"background-color: {random_color.name()};border:transparent;")
self.loadTextFromFile()
self.Ui.textEdit_2.textChanged.connect(self.autoSave)
def addNewWindow(self):
global window_id
window_id = int(window_id)+1
new_window = Main(window_id)
windows.append(new_window)
new_window.show()
Update_window_id()
def delete(self):
self.close()
del_window_id()
n = 1
file_path = f'notes_{self.window_id}.notes'
with open (file_path, 'w') as file:
file.write('')
with open(file_path, 'r') as file_r:
text_content = file_r.read()
if len(text_content) < 2:
for i in range(int(window_id)+900):
try:
os.rename(f'notes_{self.window_id+n}.notes',f'notes_{self.window_id+n-1}.notes')
n += 1
except FileNotFoundError:
pass
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.offset = event.pos()
self.dragging = True
def mouseMoveEvent(self, event):
if self.dragging:
self.move(event.globalPos() - self.offset)
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.dragging = False
def changeTextEditBackground(self):
random_color = QtGui.QColor(random.randint(20, 230), random.randint(20, 230), random.randint(20, 230))
self.Ui.textEdit.setStyleSheet(f"background-color: {random_color.name()};border:transparent;")
def autoSave(self):
file_path = f"notes_{self.window_id}.notes"
with open(file_path, 'w') as file:
file.write(self.Ui.textEdit_2.toPlainText())
def loadTextFromFile(self):
file_path = f"notes_{self.window_id}.notes"
try:
with open(file_path, 'r') as file:
text_content = file.read()
self.Ui.textEdit_2.setPlainText(text_content)
except FileNotFoundError:
pass
app = QtWidgets.QApplication(sys.argv)
id = 1
for i in range(int(window_id)):
window = Main(id)
windows.append(window)
window.show()
id += 1
app.exec_()