-
Notifications
You must be signed in to change notification settings - Fork 0
/
tossedit.py
executable file
·136 lines (109 loc) · 3.53 KB
/
tossedit.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
#!/usr/bin/env python3
import sys,os
from PyQt5 import QtCore, QtWidgets, uic
class EditorForm(QtWidgets.QWidget):
def __init__(self, filename):
super(EditorForm, self).__init__()
uic.loadUi("qtgui-files/tosseditor.ui", self)
self.setWindowTitle(filename)
self.msgobj={"echoarea":"", "to":"All", "subj":"...", "repto":"", "msgtext":""}
self.mbox=QtWidgets.QMessageBox(self)
self.filename=filename
try:
source=open(self.filename, "rb").read().decode("utf8")
self.plainTextEdit.setPlainText(source)
self.tabChanged(0)
except:
self.mbox.setText("Не могу открыть файл "+filename)
self.mbox.exec_()
self.close()
self.tabWidget.currentChanged.connect(self.tabChanged)
self.pushButton.clicked.connect(self.saveFile)
self.pushButton_2.clicked.connect(self.closeAndDelete)
self.pushButton_3.clicked.connect(self.closeWithoutSaving)
self.pushButton.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_S)
self.plainTextEdit.setFocus()
self.plainTextEdit_1.setFocus()
def getMsg_From_Source(self):
source=self.plainTextEdit.toPlainText().splitlines()
count=len(source)
try:
self.msgobj["echoarea"]=source[0]
except:
self.msgobj["echoarea"]=""
try:
self.msgobj["to"]=source[1]
except:
self.msgobj["to"]=""
try:
self.msgobj["subj"]=source[2]
except:
self.msgobj["subj"]=""
try:
str=source[4]
if str.startswith("@repto:"):
self.msgobj["repto"]=str[7:]
self.msgobj["msgtext"]="\n".join(source[5:])
else:
self.msgobj["repto"]=""
self.msgobj["msgtext"]="\n".join(source[4:])
except:
self.msgobj["repto"]=""
self.msgobj["msgtext"]=""
def getMsg_From_Visual(self):
self.msgobj["echoarea"]=self.lineEdit.text()
self.msgobj["subj"]=self.lineEdit_2.text()
self.msgobj["to"]=self.lineEdit_4.text()
self.msgobj["repto"]=self.lineEdit_3.text()
self.msgobj["msgtext"]=self.plainTextEdit_1.toPlainText()
def updateSource(self):
msgobj=self.msgobj
source=msgobj["echoarea"]+"\n"+msgobj["to"]+"\n"+msgobj["subj"]+"\n\n"
if msgobj["repto"]!="":
source+="@repto:"+msgobj["repto"]+"\n"
source+=msgobj["msgtext"]
self.plainTextEdit.setPlainText(source)
def updateVisual(self):
self.lineEdit.setText(self.msgobj["echoarea"])
self.lineEdit_2.setText(self.msgobj["subj"])
self.lineEdit_4.setText(self.msgobj["to"])
self.lineEdit_3.setText(self.msgobj["repto"])
self.plainTextEdit_1.setPlainText(self.msgobj["msgtext"])
def tabChanged(self, index):
if index==0:
self.getMsg_From_Source()
self.updateVisual()
elif index==1:
self.getMsg_From_Visual()
self.updateSource()
def saveFile(self):
index=self.tabWidget.currentIndex()
if index==0:
self.getMsg_From_Visual()
self.updateSource()
elif index==1:
self.getMsg_From_Source()
string=self.plainTextEdit.toPlainText()
try:
f=open(self.filename, "wb")
f.write(string.encode("utf8"))
f.close()
except:
self.mbox.setText("Файл "+self.filename+" сохранить не удалось =(")
self.mbox.exec_()
def closeAndDelete(self):
self.mbox.setText("Точно удалить сообщение и выйти?")
self.mbox.setStandardButtons(QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
result=self.mbox.exec_()
if result==QtWidgets.QMessageBox.Yes:
os.remove(self.filename)
self.close()
def closeWithoutSaving(self):
self.close()
if len(sys.argv[1:])>0:
app = QtWidgets.QApplication(sys.argv)
form=EditorForm(sys.argv[1])
form.show()
sys.exit(app.exec_())
else:
print("Требуется имя файла!")