-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
123 lines (100 loc) · 4.27 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
122
123
# Import necessary libraries
import sys
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QMouseEvent
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QTextCursor
from UI.mainwindow_ui import Ui_MainWindow
# Import Qt's core module
from PyQt5.QtCore import Qt
# Declare widgets variable
widgets = None
# Define the MainWindow class that inherits from QMainWindow
class MainWindow(QMainWindow,Ui_MainWindow):
# Constructor method for the MainWindow class
def __init__(self):
super(MainWindow,self).__init__()
self.setupUi(self)
# Connect the maximizeRestoreAppBtn button to the maximize_window method
self.maximizeRestoreAppBtn.clicked.connect(self.maximize_window)
# Connect the closeAppBtn button to the close method
self.closeAppBtn.clicked.connect(self.close)
# Connect the minimizeAppBtn button to the showMinimized method
self.minimizeAppBtn.clicked.connect(self.showMinimized)
# Set the window flag to remove the window frame
self.setWindowFlag(Qt.FramelessWindowHint)
# Connect the btnSubmit button to the save_text_to_file method
self.btnSubmit.clicked.connect(self.save_text_to_file)
# Connect the btnBullet button to the bullet_points method
self.btnBullet.clicked.connect(self.bullet_points)
# Call the readData method to display the saved text, if any
self.readData()
# Define the readData method to read the data from the text file
def readData(self):
try:
# Open the text file and read its contents
with open('data/output.txt', 'r') as file:
self.txtData.setPlainText(file.read())
# If the file does not exist, do nothing
except FileNotFoundError:
pass
# Define the bullet_points method to format selected text as bullet points
def bullet_points(self):
# Get the selected text
cursor = self.txtData.textCursor()
selected_text = cursor.selectedText()
# Check if the selected text is already in bullet points format
if "• " in selected_text:
# Remove bullet points and replace with plain text
plain_text = selected_text.replace("• ", "")
cursor.insertText(plain_text)
else:
# Convert the selected text into bullet points
bullet_points = "• " + selected_text.replace("\n", "\n• ")
cursor.insertText(bullet_points)
# Move the cursor to the end of the inserted text
cursor.movePosition(QTextCursor.End)
self.txtData.setTextCursor(cursor)
# Define the close_Window method to close the window
def close_Window(self):
self.Close()
# Define the maximize_window method to maximize or restore the window
def maximize_window(self):
# If the window is already maximized, restore it
if self.isMaximized():
self.showNormal()
# Otherwise, maximize it
else:
self.showMaximized()
# Define the mousePressEvent method to handle mouse button press events
def mousePressEvent(self, event: QMouseEvent) -> None:
if event.button() == Qt.LeftButton:
self.dragPos = event.globalPos() - self.pos()
event.accept()
def mouseMoveEvent(self, event: QMouseEvent) -> None:
if event.buttons() == Qt.LeftButton:
self.move(event.globalPos() - self.dragPos)
event.accept()
def save_text_to_file(self):
# Saving the text in a txt file
text = self.txtData.toPlainText()
# Save the text to a file
with open("data/output.txt", "w") as file:
file.write(text)
self.show_text()
def show_text(self):
# Show the text on the label
self.lblSavedOption.setText("Saved Successfully")
# Create a QTimer to hide the label after 3 seconds
timer = QTimer(self)
timer.timeout.connect(self.hide_text)
timer.start(3000)
def hide_text(self):
# Hide the text on the label
self.lblSavedOption.setText("")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())