· 9 years ago · Oct 11, 2016, 12:10 AM
1# -*- coding: utf-8 -*-
2
3# Form implementation generated from reading ui file 'gui.ui'
4#
5# Created by: PyQt4 UI code generator 4.11.4
6#
7# WARNING! All changes made in this file will be lost!
8
9from PyQt4 import QtCore, QtGui
10from PyQt4 import Qsci
11import os, sys, subprocess, sqlite3
12
13try:
14 _fromUtf8 = QtCore.QString.fromUtf8
15except AttributeError:
16 def _fromUtf8(s):
17 return s
18
19try:
20 _encoding = QtGui.QApplication.UnicodeUTF8
21 def _translate(context, text, disambig):
22 return QtGui.QApplication.translate(context, text, disambig, _encoding)
23except AttributeError:
24 def _translate(context, text, disambig):
25 return QtGui.QApplication.translate(context, text, disambig)
26class MainWindowGUI(object):
27 font = QtGui.QFont()
28 font.setFamily(_fromUtf8("Courier New"))
29 font.setPointSize(10) ## FONT
30 bold = QtGui.QFont()
31 bold.setPointSize(10)
32 bold.setFamily(_fromUtf8("Courier New"))
33 bold.setBold(True)
34
35 defaultStyle = {
36 'STYLE': [font, "PyCharm"],
37 'UnclosedString': [font, '#008000'],
38 'Decorator': [font, '#00cc00'],
39 'Default': [font, '#ffffff'],
40 'HighlightedIdentifier': [font, '#900090'],
41 'CommentBlock': [font, '#008000'],
42 'FunctionMethodName': [font, '#990000'],
43 'DoubleQuotedString': [font, '#008000'],
44 'Operator': [bold, '#000000'],
45 'TripleSingleQuotedString': [font, '#008000'],
46 'Number': [font, '#009999'],
47 'Keyword': [bold, '#000000'],
48 'Identifier': [font, '#000000'],
49 'ClassName': [bold, '#445588'],
50 'SingleQuotedString': [font, '#008000'],
51 'TripleDoubleQuotedString': [font, '#008000'],
52 'Comment': [font, '#008000']}
53
54 IDLEStyle = {
55 'STYLE': [font, "IDLE"],
56 'UnclosedString': [font, '#008000'],
57 'Decorator': [font, '#00cc00'],
58 'Default': [font, '#ffffff'],
59 'HighlightedIdentifier': [font, '#900090'],
60 'CommentBlock': [font, '#DD0000'],
61 'FunctionMethodName': [font, '#0000FF'],
62 'DoubleQuotedString': [font, '#00AA00'],
63 'Operator': [bold, '#000000'],
64 'TripleSingleQuotedString': [font, '#00AA00'],
65 'Number': [font, '#000000'],
66 'Keyword': [font, '#FF7700'],
67 'Identifier': [font, '#000000'],
68 'ClassName': [bold, '#0000FF'],
69 'SingleQuotedString': [font, '#00AA00'],
70 'TripleDoubleQuotedString': [font, '#00AA00'],
71 'Comment': [font, '#DD0000']}
72
73 PyCharmStyle = {
74 'STYLE' : [font , "PyCharm"],
75 'UnclosedString': [font, '#008000'],
76 'Decorator': [font, '#00cc00'],
77 'Default': [font, '#ffffff'],
78 'HighlightedIdentifier': [font, '#900090'],
79 'CommentBlock': [font, '#008000'],
80 'FunctionMethodName': [font, '#990000'],
81 'DoubleQuotedString': [font, '#008000'],
82 'Operator': [bold, '#000000'],
83 'TripleSingleQuotedString': [font, '#008000'],
84 'Number': [font, '#009999'],
85 'Keyword': [bold, '#000000'],
86 'Identifier': [font, '#000000'],
87 'ClassName': [bold, '#445588'],
88 'SingleQuotedString': [font, '#008000'],
89 'TripleDoubleQuotedString': [font, '#008000'],
90 'Comment': [font, '#008000']}
91
92 tabs = []
93 appdata = os.getenv('APPDATA')
94
95
96 def __init__(self):
97 setup = False
98 if not os.path.exists("cfg"):
99 os.makedirs("cfg")
100 if not os.path.exists("cfg/conf.db"):
101 setup = True
102 self.db = sqlite3.connect("cfg/conf.db")
103 self.SQL = self.db.cursor()
104
105 self.SQL.execute("CREATE TABLE IF NOT EXISTS Style(Type TEXT, Bold INTEGER, Color STRING);")
106 if setup:
107 for k, v in self.defaultStyle.items():
108 if v[0] == self.bold:
109 b = 1
110 else:
111 b = 0
112 self.SQL.execute("INSERT INTO Style (Type, Bold, Color) VALUES (?, ?, ?)",
113 (k, b, v[1]))
114 self.db.commit()
115 self.getStyle()
116
117 def find(self, qsci):
118 Frame = QtGui.QFrame(self.centralwidget)
119 Frame.setObjectName(_fromUtf8("Frame"))
120 Frame.resize(790, 43)
121 Frame.setFrameShape(QtGui.QFrame.StyledPanel)
122 Frame.setFrameShadow(QtGui.QFrame.Raised)
123 Frame.setStyleSheet("QFrame{ background: #e6e6e6; }")
124 print(self.centralwidget.geometry())
125 self.gridLayout = QtGui.QGridLayout(Frame)
126 self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
127 self.label = QtGui.QLabel(Frame)
128 self.label.setObjectName(_fromUtf8("label"))
129 self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
130 self.lineEdit = QtGui.QLineEdit(Frame)
131 self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
132 self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1)
133 self.pushButton = QtGui.QPushButton(Frame)
134 self.pushButton.setObjectName(_fromUtf8("pushButton"))
135 self.exitButton = QtGui.QPushButton("X", Frame)
136 self.exitButton.setFixedWidth(30)
137 self.exitButton.clicked.connect(Frame.close)
138 self.gridLayout.addWidget(self.pushButton, 0, 2, 1, 1)
139 self.gridLayout.addWidget(self.exitButton, 0, 3, 1 ,1)
140 Frame.setWindowTitle(_translate("Frame", "Frame", None))
141 self.label.setText(_translate("Frame", "Find:", None))
142 self.pushButton.setText(_translate("Frame", "Search", None))
143
144 def setStyle(self, dict):
145 self.settingsDiag.close()
146 QtGui.QMessageBox.information(self.MainWindow, "Restart", "Changes have been made, please restart Pyrite for them to take effect", QtGui.QMessageBox.Ok)
147 dict = eval("self."+dict+"Style")
148 for k, v in dict.items():
149 if v[0] == self.bold:
150 b = 1
151 else:
152 b = 0
153 self.SQL.execute("INSERT INTO Style (Type, Bold, Color) VALUES (?, ?, ?)",
154 (k, b, v[1]))
155 self.db.commit()
156
157 def getStyle(self):
158 data = self.SQL.execute("SELECT * FROM Style")
159 self.defaultStyle = {}
160 for row in data:
161 if row[1] == 1:
162 f = self.bold
163 else:
164 f = self.font
165 if row[2] == "PyCharm":
166 self.STYLE_ID = 0
167 elif row[2] == "IDLE":
168 self.STYLE_ID = 1
169 else:
170 self.defaultStyle[row[0]] = [f, row[2]]
171 print(row)
172
173 def setupUi(self, MainWindow):
174 self.PROJECT_VIEW = False
175 self.MainWindow = MainWindow
176 QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("windowsvista"))
177
178 MainWindow.setObjectName(_fromUtf8("MainWindow"))
179 MainWindow.resize(1335, 708)
180 MainWindow.setWindowIcon(QtGui.QIcon("ToolBar/icon.png"))
181 self.centralwidget = QtGui.QWidget(MainWindow)
182 self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
183 self.gridLayout = QtGui.QGridLayout(self.centralwidget)
184 self.gridLayout.setMargin(0)
185 self.gridLayout.setSpacing(0)
186 self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
187 self.tabWidget = QtGui.QTabWidget(self.centralwidget) #### CREATING THE ENTIRE TAB WIDGET
188 self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
189 self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)####################
190 MainWindow.setCentralWidget(self.centralwidget)
191
192 self.mainMenu = QtGui.QMenuBar(MainWindow)
193 self.mainMenu.setGeometry(QtCore.QRect(0, 0, 1335, 21))
194 self.mainMenu.setObjectName(_fromUtf8("mainMenu"))
195 self.fileMenu = QtGui.QMenu(self.mainMenu)
196 self.fileMenu.setObjectName(_fromUtf8("fileMenu"))
197 self.menuEdit = QtGui.QMenu(self.mainMenu)
198 self.menuEdit.setObjectName(_fromUtf8("menuEdit"))
199 self.menuView = QtGui.QMenu(self.mainMenu)
200 self.menuView.setObjectName(_fromUtf8("menuView"))
201 MainWindow.setMenuBar(self.mainMenu)
202 self.statusbar = QtGui.QStatusBar(MainWindow)
203 self.statusbar.setStyleSheet(_fromUtf8("background:rgb(209, 209, 209);border: 1px solid rgb(176, 176, 176);\n"
204""))
205 self.leftstatus = QtGui.QLabel(MainWindow)
206 self.statusbar.addPermanentWidget(self.leftstatus, 2)
207 self.statusbar.setObjectName(_fromUtf8("statusbar"))
208 MainWindow.setStatusBar(self.statusbar)
209 self.newProjectAction = QtGui.QAction(QtGui.QIcon("Toolbar/new.png"), "New Project", MainWindow)
210 self.newProjectAction.setObjectName(_fromUtf8("newProjectAction"))
211 self.newProjectAction.setStatusTip("Create new project")
212 self.newProjectAction.triggered.connect(lambda: self.newProject(MainWindow))
213 self.openProjectAction = QtGui.QAction(QtGui.QIcon("Toolbar/open.png"), "Open Project", MainWindow)
214 self.openProjectAction.setObjectName(_fromUtf8("openProjectAction"))
215 self.openProjectAction.setStatusTip("Open an existing project")
216 self.openProjectAction.triggered.connect(lambda: self.openProject(MainWindow))
217 self.newAction = QtGui.QAction(QtGui.QIcon("Toolbar/new_file.png"), "New File..", MainWindow)
218 self.newAction.setObjectName(_fromUtf8("newAction"))
219 self.newAction.triggered.connect(lambda: self.newFile(MainWindow))
220 self.saveAction = QtGui.QAction(QtGui.QIcon("Toolbar/save.png"), "Save Current Tab", MainWindow)
221 self.saveAction.setObjectName(_fromUtf8("saveAsAction"))
222 self.saveAllAction = QtGui.QAction("Save All", MainWindow)
223 self.saveAllAction.triggered.connect(self.saveAll)
224 self.saveAction.triggered.connect(self.save)
225 self.settingsAction = QtGui.QAction(MainWindow)
226 self.settingsAction.setObjectName(_fromUtf8("settingsAction"))
227 self.settingsAction.triggered.connect(self.settings)
228 self.exitAction = QtGui.QAction(MainWindow)
229 self.exitAction.setObjectName(_fromUtf8("exitAction"))
230 self.exitAction.triggered.connect(MainWindow.close)
231 self.undoAction = QtGui.QAction(QtGui.QIcon("Toolbar/undo.png"), "Undo", MainWindow)
232 self.undoAction.setObjectName(_fromUtf8("undoAction"))
233 self.redoAction = QtGui.QAction(QtGui.QIcon("Toolbar/redo.png"), "Redo", MainWindow)
234 self.redoAction.setObjectName(_fromUtf8("redoAction"))
235 self.cutAction = QtGui.QAction(QtGui.QIcon("Toolbar/cut.png"), "Cut", MainWindow)
236 self.cutAction.setObjectName(_fromUtf8("cutAction"))
237 self.copyAction = QtGui.QAction(QtGui.QIcon("Toolbar/copy.png"), "Copy", MainWindow)
238 self.copyAction.setObjectName(_fromUtf8("copyAction"))
239 self.pasteAction = QtGui.QAction(QtGui.QIcon("Toolbar/paste.png"), "Paste", MainWindow)
240 self.pasteAction.setObjectName(_fromUtf8("pasteAction"))
241 self.viewExplorerAction = QtGui.QAction(MainWindow)
242 self.viewExplorerAction.setObjectName(_fromUtf8("viewExplorerAction"))
243 self.viewExplorerAction.triggered.connect(lambda: self.addExplorerDock(MainWindow))
244 self.viewToolbarAction = QtGui.QAction(MainWindow)
245 self.viewToolbarAction.triggered.connect(self.showToolbar)
246 self.viewToolbarAction.setObjectName(_fromUtf8("viewToolbarAction"))
247 self.viewLinenumbersAction = QtGui.QAction(MainWindow)
248 self.viewLinenumbersAction.setObjectName(_fromUtf8("viewLinenumbersAction"))
249 self.runAction = QtGui.QAction(QtGui.QIcon("Toolbar/run.png"), "Run Current Tab", MainWindow)
250 self.runAction.setObjectName(_fromUtf8("runAction"))
251 self.closeTabAction = QtGui.QAction(QtGui.QIcon("Toolbar/close.png"), "Close Current Tab", MainWindow)
252 self.closeTabAction.triggered.connect(self.closeTab)
253 self.runAction.triggered.connect(self.run)
254 self.explorerDock = QtGui.QDockWidget(MainWindow)
255 self.explorerDock.setMinimumSize(QtCore.QSize(120, 111))
256 self.explorerDock.setObjectName(_fromUtf8("explorerDock"))
257 self.explorerDockContents = QtGui.QWidget()
258 self.explorerDockContents.setObjectName(_fromUtf8("explorerDockContents"))
259 self.gridLayout_3 = QtGui.QGridLayout(self.explorerDockContents)
260 self.gridLayout_3.setMargin(0)
261 self.gridLayout_3.setSpacing(0)
262 self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
263 self.explorerTree = QtGui.QTreeView(self.explorerDockContents)
264 self.explorerTree.doubleClicked.connect(self.dclick)
265 self.explorerTree.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
266 self.explorerTree.customContextMenuRequested.connect(self.explorerContextMenu)
267 self.explorerTree.setObjectName(_fromUtf8("explorerTree"))
268 self.explorerTree.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
269 self.model = QtGui.QFileSystemModel()
270 self.model.setReadOnly(False)
271 self.explorerTree.setSortingEnabled(True)
272 self.explorerTree.sortByColumn(2)
273 self.model.directoryLoaded.connect(self._fetchAndExpand)
274 self.gridLayout_3.addWidget(self.explorerTree, 0, 0, 1, 1)
275 self.explorerDock.setWidget(self.explorerDockContents)
276 self.dockWidgetContents_2 = QtGui.QWidget()
277 self.dockWidgetContents_2.setObjectName(_fromUtf8("dockWidgetContents_2"))
278 self.fileMenu.addAction(self.newProjectAction)
279 self.fileMenu.addAction(self.openProjectAction)
280 self.fileMenu.addAction(self.newAction)
281 self.fileMenu.addAction(self.saveAction)
282 self.fileMenu.addAction(self.saveAllAction)
283 self.fileMenu.addSeparator()
284 self.fileMenu.addAction(self.runAction)
285 self.fileMenu.addSeparator()
286 self.fileMenu.addAction(self.settingsAction)
287 self.fileMenu.addSeparator()
288 self.fileMenu.addAction(self.exitAction)
289 self.menuEdit.addAction(self.undoAction)
290 self.menuEdit.addAction(self.redoAction)
291 self.menuEdit.addSeparator()
292 self.menuEdit.addAction(self.cutAction)
293 self.menuEdit.addAction(self.copyAction)
294 self.menuEdit.addAction(self.pasteAction)
295 self.menuView.addAction(self.viewExplorerAction)
296 self.menuView.addAction(self.viewToolbarAction)
297 self.mainMenu.addAction(self.fileMenu.menuAction())
298 self.mainMenu.addAction(self.menuEdit.menuAction())
299 self.mainMenu.addAction(self.menuView.menuAction())
300 self.addExplorerDock(MainWindow)
301 self.retranslateUi(MainWindow)
302 self.tabWidget.setCurrentIndex(0)
303
304 self.toolBar = QtGui.QToolBar("Toolbar", MainWindow)
305 MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar)
306
307 self.toolBar.addAction(self.openProjectAction)
308 self.toolBar.addAction(self.saveAction)
309 self.toolBar.addAction(self.newProjectAction)
310 self.toolBar.addAction(self.newAction)
311 self.toolBar.addSeparator()
312 self.toolBar.addAction(self.undoAction)
313 self.toolBar.addAction(self.redoAction)
314 self.toolBar.addSeparator()
315 self.toolBar.addAction(self.cutAction)
316 self.toolBar.addAction(self.copyAction)
317 self.toolBar.addAction(self.pasteAction)
318 self.toolBar.addSeparator()
319 self.toolBar.addAction(self.closeTabAction)
320 self.toolBar.addAction(self.runAction)
321
322 QtCore.QMetaObject.connectSlotsByName(MainWindow)
323
324 self.openInExplorerAction = QtGui.QAction("&Open Project in Explorer", MainWindow)
325
326 def settings(self):
327 self.settingsDiag = QtGui.QDialog(self.MainWindow)
328 self.settingsDiag.setObjectName(_fromUtf8("self.settingsDiag"))
329 self.settingsDiag.setFixedSize(368, 69)
330 self.settingsDiag.setWindowTitle("Settings")
331 self.formLayout = QtGui.QFormLayout(self.settingsDiag)
332 self.formLayout.setObjectName(_fromUtf8("formLayout"))
333 self.styleLabel = QtGui.QLabel("Editor Style", self.settingsDiag)
334 self.styleLabel.setObjectName(_fromUtf8("styleLabel"))
335 self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.styleLabel)
336 self.styleComboBox = QtGui.QComboBox(self.settingsDiag)
337 self.styleComboBox.setObjectName(_fromUtf8("styleComboBox"))
338 self.styleComboBox.addItem("PyCharm")
339 self.styleComboBox.addItem("IDLE")
340 self.styleComboBox.setCurrentIndex(self.STYLE_ID)
341 self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.styleComboBox)
342 self.btnLayout = QtGui.QHBoxLayout()
343 self.btnLayout.setContentsMargins(100, -1, -1, -1)
344 self.btnLayout.setObjectName(_fromUtf8("btnLayout"))
345 self.okBtn = QtGui.QPushButton("Confirm", self.settingsDiag)
346 self.okBtn.clicked.connect(lambda: self.setStyle(self.styleComboBox.currentText()))
347 self.okBtn.setObjectName(_fromUtf8("okBtn"))
348 self.btnLayout.addWidget(self.okBtn)
349 self.closeBtn = QtGui.QPushButton("Cancel", self.settingsDiag)
350 self.closeBtn.setObjectName(_fromUtf8("closeBtn"))
351 self.closeBtn.clicked.connect(self.settingsDiag.close)
352 self.btnLayout.addWidget(self.closeBtn)
353 self.formLayout.setLayout(1, QtGui.QFormLayout.FieldRole, self.btnLayout)
354 self.settingsDiag.show()
355
356 def newFile(self, MainWindow):
357 file, confirm = QtGui.QInputDialog.getText(MainWindow, 'New File', 'File Name:')
358 if confirm:
359 if os.path.exists(file):
360 QtGui.QMessageBox.warning(MainWindow, "Error", "A file with that name already exists!", QtGui.QMessageBox.Ok)
361 else:
362 open(self.path+"\\"+file, "w").close()
363 self.newTab(file, MainWindow)
364
365 def run(self):
366 tab, path = self.tabs[self.tabWidget.currentIndex()]
367 text = [i for i in self.getEditorText(tab).split("\n")]
368 self.save()
369 python_path = sys.executable.replace("pythonw.exe", "python.exe")
370 subprocess.call(["start", "cmd", "/K", python_path, path], shell = True)
371
372 def save(self):
373 tab, path = self.tabs[self.tabWidget.currentIndex()]
374 text = [h+"\n" for h in [i for i in self.getEditorText(tab).split("\n")]]
375 file = open(path, "w")
376 for i in text:
377 file.write(i)
378 file.close
379 self.statusbar.showMessage("Saved to " + path, 10000)
380
381 def saveAll(self):
382 try:
383 self.statusbar.showMessage("Saving files..")
384 print(self.tabs)
385 for tab, path in self.tabs.items():
386 self.statusbar.showMessage("Saving file " + str(self.tabs.index(tab)+1) + "/" + str(len(self.tabs)))
387 text = [h+"\n" for h in [i.rstrip() for i in self.getEditorText(tab).split("\n")]]
388 file = open(path, "w")
389 file.writelines(text)
390 file.close
391 self.statusbar.showMessage("Saved All Files", 10000)
392 except Exception as e:
393 self.statusbar.showMessage(str(e), 5000)
394
395 def newProject(self, MainWindow):
396 project, confirm = QtGui.QInputDialog.getText(MainWindow, 'New Project', 'Project Name:')
397 if confirm:
398 if self.PROJECT_VIEW:
399 os.chdir("..\\..")
400 while True:
401 if len(self.tabs) > 0:
402 self.closeTab()
403 else:
404 break
405 try:
406 self.path = os.getcwd()+"\\Projects\\"+project
407 os.makedirs(self.path)
408 print(self.path)
409 self.model.setRootPath(self.path)
410 self.explorerTree.setModel(self.model)
411 self.explorerTree.setRootIndex(self.model.index(self.path))
412 self.openInExplorerAction.triggered.connect(lambda: os.system("explorer.exe " + self.path))
413 projectsFile = open("projects.txt", "a")
414 projectsFile.write(project+"\n")
415 projectsFile.close()
416 os.chdir(self.path)
417 print(self.path)
418 except Exception as e:
419 print(e)
420 QtGui.QMessageBox.warning(MainWindow, "Error", "A project with that name already exists!", QtGui.QMessageBox.Ok)
421 print("test")
422 self.PROJECT_VIEW = True
423
424 def openProject(self, MainWindow):
425 if self.PROJECT_VIEW:
426 os.chdir("..\\..")
427 projectsList =[i.strip() for i in open("projects.txt", "r").readlines()]
428 print(projectsList)
429
430 formLayout = QtGui.QFormLayout()
431 self.diag = QtGui.QDialog(MainWindow)
432 self.diag.setFixedSize(400, 69)
433 self.diag.setWindowTitle("Open")
434 openProjectLabel = QtGui.QLabel("Open Project: ", self.diag)
435 formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, openProjectLabel)
436 self.projectCombobox = QtGui.QComboBox(self.diag)
437 formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.projectCombobox)
438 horizontalLayout = QtGui.QHBoxLayout()
439 horizontalLayout.setContentsMargins(100, -1, -1, -1)
440 openProjectBtn = QtGui.QPushButton("Open", self.diag)
441 openProjectBtn.clicked.connect(self.opnProj)
442 horizontalLayout.addWidget(openProjectBtn)
443 cancelOpenBtn = QtGui.QPushButton("Cancel", self.diag)
444 cancelOpenBtn.clicked.connect(self.diag.close)
445 horizontalLayout.addWidget(cancelOpenBtn)
446 formLayout.setLayout(1, QtGui.QFormLayout.FieldRole, horizontalLayout)
447 self.diag.setLayout(formLayout)
448
449 self.projectCombobox.addItems(projectsList)
450
451 self.diag.show()
452
453 def opnProj(self, proj):
454 project = self.projectCombobox.currentText()
455 self.path = os.getcwd() + "\\Projects\\" + project
456 self.model.setRootPath(self.path)
457 self.explorerTree.setModel(self.model)
458 self.explorerTree.setRootIndex(self.model.index(self.path))
459 self.openInExplorerAction.triggered.connect(lambda: os.system("explorer.exe " + self.path))
460 self.diag.close()
461 os.chdir(self.path)
462 print(self.path)
463 while True:
464 if len(self.tabs) > 0:
465 self.closeTab()
466 else:
467 break
468 self.PROJECT_VIEW = True
469
470 def dclick(self, index):
471 indexItem = self.model.index(index.row(), 0, index.parent())
472 fileName = self.model.fileName(indexItem)
473 filePath = self.model.filePath(indexItem)
474
475 print(fileName)
476 print(filePath)
477 self.newTab(filePath, self.MainWindow)
478
479 def explorerContextMenu(self, position):
480 indexes = self.explorerTree.selectedIndexes()
481 if len(indexes) > 0:
482 level = 0
483 index = indexes[0]
484 while index.parent().isValid():
485 index = index.parent()
486 level += 1
487
488 menu = QtGui.QMenu()
489 menu.addAction(self.openInExplorerAction)
490 menu.exec_(self.explorerTree.viewport().mapToGlobal(position))
491
492 def getEditorText(self, tab):
493 tab = tab.split(".")[0]
494 tab = tab.replace(" ", "_")
495 tab = tab.replace("\\", "_")
496 tab = tab.replace("/", "_")
497 tab = tab.replace(":", "_")
498 tab = tab.replace("*", "_")
499 tab = tab.replace("?", "_")
500 tab = tab.replace('"', "_")
501 tab = tab.replace("<", "_")
502 tab = tab.replace(">", "_")
503 tab = tab.replace("|", "_")
504 text = eval('self.'+tab+'TabTextEdit.text()')
505 return text
506
507 def newTab(self, tab, MainWindow):
508 contents = "".join([i + "\n" for i in [i.rstrip() for i in open(tab).read().split("\n")]]).rstrip()
509 print(contents)
510 path = tab
511 tab = tab.split("/")[-1]
512 tab, ext = tab.split(".")
513 tabv = tab.replace(" ", "_")
514 tabv = tabv.replace("\\", "_")
515 tabv = tabv.replace("/", "_")
516 tabv = tabv.replace(":", "_")
517 tabv = tabv.replace("*", "_")
518 tabv = tabv.replace("?", "_")
519 tabv = tabv.replace('"', "_")
520 tabv = tabv.replace("<", "_")
521 tabv = tabv.replace(">", "_")
522 tabv = tabv.replace("|", "_")
523 print(tabv)
524
525 if ext == "py":
526 pythonFile = True
527 else:
528 pythonFile = False
529
530 if len(ext)<1:
531 QtGui.QMessageBox.warning(MainWindow, "Error", "The filename you entered was not valid!",
532 QtGui.QMessageBox.Ok)
533
534 lexer = Qsci.QsciLexerPython()
535
536 for t, attr in self.defaultStyle.items():
537 type = eval("Qsci.QsciLexerPython."+t)
538 lexer.setFont(attr[0], type)
539 lexer.setColor(QtGui.QColor(attr[1]), type)
540
541 self.tabs.append([tab+"."+ext, path])
542 exec('''
543self.'''+tabv+'''Tab = QtGui.QWidget() ### CREATING A TAB####################################
544self.'''+tabv+'''TabButton = QtGui.QToolButton(MainWindow)
545self.'''+tabv+'''TabButton.setText('x')
546gridLayout_2 = QtGui.QGridLayout(self.'''+tabv+'''Tab) ### ADDING A GRID LAYOUT IN THE TAB
547gridLayout_2.setMargin(0)
548gridLayout_2.setSpacing(0)
549gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
550self.'''+tabv+'''TabTextEdit = Qsci.QsciScintilla(self.'''+tabv+'''Tab) ### CREATING THE TEXT EDIT
551self.'''+tabv+'''TabTextEdit.setMarginLineNumbers(0, True)
552self.'''+tabv+'''TabTextEdit.setMarginsBackgroundColor(QtGui.QColor("#cccccc"))
553self.'''+tabv+'''TabTextEdit.setBraceMatching(Qsci.QsciScintilla.SloppyBraceMatch)
554self.'''+tabv+'''TabTextEdit.setCaretLineVisible(True)
555self.'''+tabv+'''TabTextEdit.setCaretLineBackgroundColor(QtGui.QColor("#e6e6e6"))
556self.'''+tabv+'''TabTextEdit.setTabWidth(4)
557if pythonFile:
558 self.'''+tabv+'''TabTextEdit.setLexer(lexer)
559self.font.setFixedPitch(True)
560self.'''+tabv+'''TabTextEdit.setMarginsFont(self.font)
561fontmetrics = QtGui.QFontMetrics(self.font)
562self.'''+tabv+'''TabTextEdit.setMarginsFont(self.font)
563self.'''+tabv+'''TabTextEdit.setMarginWidth(0, fontmetrics.width("00000") + 2)
564self.'''+tabv+'''TabTextEdit.setMarginLineNumbers(0, True)
565self.'''+tabv+'''TabTextEdit.setMarginsBackgroundColor(QtGui.QColor("#ffffff"))
566self.'''+tabv+'''TabTextEdit.setFont(self.font) ## SET FONT
567self.'''+tabv+'''TabTextEdit.setToolTip(_fromUtf8(""))
568self.'''+tabv+'''TabTextEdit.setWhatsThis(_fromUtf8(""))
569self.'''+tabv+'''TabTextEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) ## TEXT EDITOR SCROLL
570self.'''+tabv+'''TabTextEdit.setObjectName(_fromUtf8("textEdit"))
571self.'''+tabv+'''TabTextEdit.setAutoIndent(True)
572self.'''+tabv+'''TabTextEdit.setIndentationGuides(True)
573self.'''+tabv+'''TabTextEdit.setIndentationsUseTabs(True)
574self.'''+tabv+'''TabTextEdit.setText(contents)
575gridLayout_2.addWidget(self.'''+tabv+'''TabTextEdit, 0, 0, 1, 1) ## ADDING TEXT EDIT TO GRID
576self.tabWidget.addTab(self.'''+tabv+'''Tab, _fromUtf8("")) ## ADDING THE TAB#############################
577self.tabWidget.setTabText(self.tabWidget.indexOf(self.'''+tabv+'''Tab), tab+'.'+ext)
578self.undoAction.triggered.connect(self.'''+tabv+'''TabTextEdit.undo)
579self.redoAction.triggered.connect(self.'''+tabv+'''TabTextEdit.redo)
580self.copyAction.triggered.connect(self.'''+tabv+'''TabTextEdit.copy)
581self.cutAction.triggered.connect(self.'''+tabv+'''TabTextEdit.cut)
582self.pasteAction.triggered.connect(self.'''+tabv+'''TabTextEdit.paste)
583''')
584
585 def closeTab(self):
586 del self.tabs[self.tabWidget.indexOf(self.tabWidget.currentWidget())]
587 self.tabWidget.removeTab(self.tabWidget.indexOf(self.tabWidget.currentWidget()))
588 print(self.tabs)
589
590
591
592
593 def addExplorerDock(self, MainWindow):
594 MainWindow.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.explorerDock)
595 self.explorerDock.setVisible(True)
596
597 def showToolbar(self):
598 self.toolBar.setVisible(True)
599
600 def _fetchAndExpand(self, path):
601 index = self.model.index(path)
602 self.explorerTree.expand(index) # expand the item
603 for i in range(self.model.rowCount(index)):
604 # fetch all the sub-folders
605 child = index.child(i, 0)
606 if self.model.isDir(child):
607 self.model.setRootPath(self.model.filePath(child))
608
609 def retranslateUi(self, MainWindow):
610 MainWindow.setWindowTitle(_translate("MainWindow", "Pyrite - Version 0.1", None))
611 self.fileMenu.setTitle(_translate("MainWindow", "File", None))
612 self.menuEdit.setTitle(_translate("MainWindow", "Edit", None))
613 self.menuView.setTitle(_translate("MainWindow", "View", None))
614 self.explorerDock.setWindowTitle(_translate("MainWindow", "Explorer", None))
615 self.newProjectAction.setText(_translate("MainWindow", "New Project", None))
616 self.openProjectAction.setText(_translate("MainWindow", "Open Project", None))
617 self.newAction.setText(_translate("MainWindow", "New File..", None))
618 self.newAction.setStatusTip(_translate("MainWindow", "Create a new file..", None))
619 self.newAction.setShortcut(_translate("MainWindow", "Ctrl+N", None))
620 self.saveAction.setText(_translate("MainWindow", "Save", None))
621 self.saveAction.setStatusTip(_translate("MainWindow", "Save project as..", None))
622 self.saveAction.setShortcut(_translate("MainWindow", "Ctrl+S", None))
623 self.saveAllAction.setShortcut("Ctrl+Shift+S")
624 self.settingsAction.setText(_translate("MainWindow", "Settings", None))
625 self.settingsAction.setStatusTip(_translate("MainWindow", "View settings", None))
626 self.exitAction.setText(_translate("MainWindow", "Exit", None))
627 self.exitAction.setStatusTip(_translate("MainWindow", "Exit Pyrite", None))
628 self.exitAction.setShortcut(_translate("MainWindow", "Ctrl+Q", None))
629 self.undoAction.setText(_translate("MainWindow", "Undo", None))
630 self.undoAction.setStatusTip(_translate("MainWindow", "Undo last operation", None))
631 self.undoAction.setShortcut(_translate("MainWindow", "Ctrl+Z", None))
632 self.redoAction.setText(_translate("MainWindow", "Redo", None))
633 self.redoAction.setStatusTip(_translate("MainWindow", "Redo last operation", None))
634 self.redoAction.setShortcut(_translate("MainWindow", "Ctrl+Shift+Z", None))
635 self.cutAction.setText(_translate("MainWindow", "Cut", None))
636 self.cutAction.setStatusTip(_translate("MainWindow", "Cut to clipboard", None))
637 self.cutAction.setShortcut(_translate("MainWindow", "Ctrl+X", None))
638 self.copyAction.setText(_translate("MainWindow", "Copy", None))
639 self.copyAction.setStatusTip(_translate("MainWindow", "Copy to clipboard", None))
640 self.copyAction.setShortcut(_translate("MainWindow", "Ctrl+C", None))
641 self.pasteAction.setText(_translate("MainWindow", "Paste", None))
642 self.pasteAction.setStatusTip(_translate("MainWindow", "Paste from clipboard", None))
643 self.pasteAction.setShortcut(_translate("MainWindow", "Ctrl+V", None))
644 self.viewExplorerAction.setText(_translate("MainWindow", "Project View", None))
645 self.viewExplorerAction.setStatusTip(_translate("MainWindow", "View the explorer window", None))
646 self.viewToolbarAction.setText(_translate("MainWindow", "Tool Bar", None))
647 self.viewToolbarAction.setStatusTip(_translate("MainWindow", "View the toolbar", None))
648 self.viewLinenumbersAction.setText(_translate("MainWindow", "Line Numbers", None))
649 self.viewLinenumbersAction.setStatusTip(_translate("MainWindow", "View line numbers", None))
650 self.runAction.setText(_translate("MainWindow", "Run", None))
651 self.runAction.setStatusTip(_translate("MainWindow", "Run the current file", None))
652 self.runAction.setShortcut(_translate("MainWindow", "F5", None))
653
654if __name__ == "__main__":
655 print("To use Pyrite, please run the pyrite.py file")