-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyschoolEdit.py
158 lines (130 loc) · 5.21 KB
/
pyschoolEdit.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
#!/usr/bin/python3
__author__ = "Komarov Alexander"
__version__ = "0.1"
__license__ = "GPL"
__email__ = "ignusius@gmail.com"
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import os
import codecs
# import PyQt4 QtCore and QtGui modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
from PyQt4 import Qsci
from PyQt4.Qsci import QsciScintilla, QsciScintillaBase, QsciLexerPython
import webbrowser
from AboutUI import AboutWindow
( Ui_MainWindow, QMainWindow ) = uic.loadUiType('MainUI.ui')
class MainWindow(QMainWindow):
"""MainWindow inherits QMainWindow"""
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.editor = self.ui.editor
font = QFont()
font.setFamily('Courier')
font.setFixedPitch(True)
font.setPointSize(12)
self.editor.setFont(font)
self.editor.setMarginsFont(font)
self.editor.setMarginsFont(font)
self.lexer = QsciLexerPython()
self.lexer.setDefaultFont(font)
self.api = Qsci.QsciAPIs(self.lexer)
self.editor.setLexer(self.lexer)
self.editor.setAutoCompletionThreshold(1)
self.editor.setMarginLineNumbers(1,True)
self.editor.setMarginWidth(1,"0000")
self.editor.setIndentationWidth(4)
self.editor.setFolding(QsciScintilla.BoxedTreeFoldStyle)
self.editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)
self.editor.setCaretLineBackgroundColor(QColor("#fbf6f6"))
self.editor.setAutoCompletionSource(self.editor.AcsAPIs)
self.editor.setAutoIndent(True)
self.editor.setUtf8(True)
self.ui.find_bar.hide()
self.filename=""
def __del__(self):
self.ui = None
def new(self):
if self.filename !="":
self.save()
self.open()
def open(self):
try:
self.filename = QFileDialog.getOpenFileName(self, 'Открыть файл', '', ".py(*py)")
self.editor.setText(codecs.open(self.filename,'r',"utf-8").read())
self.setWindowTitle('PySchoolEdit - ['+self.filename+']')
except(FileNotFoundError):
pass
def save(self):
if self.filename == "":
self.filename = QFileDialog.getSaveFileName(self, 'Сохранить файл', '', ".py(*.py)")
with codecs.open(self.filename,"w","utf-8") as f:
f.write(self.editor.text())
self.ui.statusBar.showMessage("Сохранено")
self.setWindowTitle('PySchoolEdit - ['+self.filename+']')
else:
with codecs.open(self.filename,"w","utf-8") as f:
f.write(self.editor.text())
self.ui.statusBar.showMessage("Сохранено")
def save_as(self):
self.filename = QFileDialog.getSaveFileName(self, u'Сохранить файл', '', ".py(*.py)")
with codecs.open(self.filename,"w","utf-8") as f:
f.write(self.editor.text())
self.ui.statusBar.showMessage("Сохранено")
self.setWindowTitle('PySchoolEdit - ['+self.filename+']')
def run(self):
self.save()
if sys.platform=='linux':
filename=self.filename.replace(r" ","\ ")
os.system('xterm -geometry 50x15 -fa \'terminal\' -e bash -c \'python3 '+filename+' \
; read -p "Для продолжения нажмите любую клавишу . . ."\'')
if sys.platform=='win32':
os.system('C:\Python33\python "'+self.filename+'"& pause')
def find_bar_show(self,status):
if status==True:
self.ui.find_bar.show()
else:
self.ui.find_bar.hide()
def find_text(self):
if self.ui.case_cmbox.checkState()==0:
status=False
else:
status=True
self.editor.findFirst(self.ui.find_field.text(),True,status,True,True,True)
def app_quit(self):
QApplication.quit()
def app_site(self):
webbrowser.open_new("http://python-rutour.rhcloud.com/")
def app_about(self):
self.about_window = AboutWindow(self)
self.about_window.show()
def text_changed(self):
self.ui.statusBar.showMessage("Текст изменён")
#-----------------------------------------------------#
if __name__ == '__main__':
# create application
app = QApplication(sys.argv)
app.setApplicationName('PySchoolEdit')
# create widget
w = MainWindow()
w.setWindowTitle('PySchoolEdit')
w.show()
# connection
QObject.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
# execute application
sys.exit(app.exec_())