Skip to content

Commit e68f4f0

Browse files
committed
Added line numbers, fixed some bugs, fixed console, added license.
1 parent e7fb85d commit e68f4f0

11 files changed

+262
-12
lines changed

controller/TerminalConsole.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
i386ide is lightweight IDE for i386 assembly and C programming language.
33
Copyright (C) 2019 Dušan Erdeljan, Marko Njegomir
4-
Redistributed by: Mrsulja Ivan
4+
Redistributed by: Mršulja Ivan
55
66
This file is part of i386ide.
77
This program is free software: you can redistribute it and/or modify

controller/TerminalController.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
i386ide is lightweight IDE for i386 assembly and C programming language.
33
Copyright (C) 2019 Dušan Erdeljan, Marko Njegomir
4-
Redistributed by: Mrsulja Ivan
4+
Redistributed by: Mršulja Ivan
55
66
This file is part of i386ide.
77
This program is free software: you can redistribute it and/or modify

model/Autocompleter.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
from PyQt5 import QtGui,QtCore,QtWidgets
1+
"""
2+
Brick is lightweight IDE for C programming language.
3+
Copyright (C) 2020 : Mršulja Ivan
4+
5+
This file is part of Brick IDE.
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>
16+
"""
17+
18+
from PyQt5 import QtGui, QtCore, QtWidgets
219
from model.syntax import Highlighter
320
import re
421
import json
@@ -7,7 +24,7 @@
724

825
class MyTextEdit(QtWidgets.QPlainTextEdit):
926

10-
def __init__(self,*args):
27+
def __init__(self, *args):
1128
#*args to set parent
1229
QtWidgets.QLineEdit.__init__(self,*args)
1330
font=QtGui.QFont()

model/SaveNode.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Brick is lightweight IDE for C programming language.
3+
Copyright (C) 2020 : Mršulja Ivan
4+
5+
This file is part of Brick IDE.
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>
16+
"""
17+
118
class SaveNode(object):
219
def __init__(self, path):
320
self.data = ""
@@ -8,5 +25,3 @@ def save(self):
825
with open(self.path, "w") as file:
926
file.write(self.data)
1027

11-
def get_data(self):
12-
return self._data

model/Terminal.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
i386ide is lightweight IDE for i386 assembly and C programming language.
33
Copyright (C) 2019 Dušan Erdeljan, Marko Njegomir
4-
Redistributed by: Mrsulja Ivan
4+
Redistributed by: Mršulja Ivan
55
66
This file is part of i386ide.
77
This program is free software: you can redistribute it and/or modify

model/syntax.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Brick is lightweight IDE for C programming language.
3+
Copyright (C) 2020 : Mršulja Ivan
4+
5+
This file is part of Brick IDE.
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>
16+
"""
17+
118
from PyQt5.QtCore import QFile, QRegExp, Qt
219
from PyQt5.QtGui import QFont, QSyntaxHighlighter, QTextCharFormat, QColor
320
from PyQt5.QtWidgets import (QApplication, QFileDialog, QMainWindow, QMenu,

structures/CommandHistoryStack.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
i386ide is lightweight IDE for i386 assembly and C programming language.
33
Copyright (C) 2019 Dušan Erdeljan, Marko Njegomir
4+
Redistributed by: Mršulja Ivan
45
56
This file is part of i386ide.
67
This program is free software: you can redistribute it and/or modify

viewer/CompilationDialog.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
Brick is lightweight IDE for C programming language.
3+
Copyright (C) 2020 : Mršulja Ivan
4+
5+
This file is part of Brick IDE.
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>
16+
"""
17+
118
from PyQt5 import QtWidgets
219
import os
320

@@ -59,9 +76,11 @@ def compile_c(self):
5976
print(full_path)
6077
self.window.name = os.path.split(self.window.form.save_path)[1]
6178
command = "gcc -g " + full_path + " -o '" + self.window.name + "'"
62-
print(command)
63-
os.system(command)
64-
self.window.status_label.setText("Compiled successfully !")
79+
if self.window.form.terminal.executeCommand(command):
80+
self.window.status_label.setText("Compiled successfully !")
81+
else:
82+
self.window.status_label.setText("Compilation terminated.")
83+
self.window.name = None
6584
self.close()
6685

6786

viewer/NumberBar.py

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
from PyQt5.Qt import QFrame, QWidget, QHBoxLayout, QPainter, QPlainTextEdit, QFont
2+
from PyQt5 import QtWidgets
3+
import sys
4+
5+
6+
7+
class NumberBar(QWidget):
8+
9+
def __init__(self, *args):
10+
QWidget.__init__(self, *args)
11+
self.edit = None
12+
# This is used to update the width of the control.
13+
# It is the highest line that is currently visibile.
14+
self.highest_line = 0
15+
16+
def setTextEdit(self, edit):
17+
self.edit = edit
18+
19+
def update(self, *args):
20+
'''
21+
Updates the number bar to display the current set of numbers.
22+
Also, adjusts the width of the number bar if necessary.
23+
'''
24+
# The + 4 is used to compensate for the current line being bold.
25+
width = self.fontMetrics().width(str(self.highest_line)) + 4
26+
if self.width() != width:
27+
self.setFixedWidth(width)
28+
QWidget.update(self, *args)
29+
30+
def paintEvent(self, event):
31+
contents_y = self.edit.verticalScrollBar().value()
32+
page_bottom = contents_y + self.edit.viewport().height()
33+
font_metrics = self.fontMetrics()
34+
current_block = self.edit.document().findBlock(self.edit.textCursor().position())
35+
36+
painter = QPainter(self)
37+
38+
line_count = 0
39+
# Iterate over all text blocks in the document.
40+
block = self.edit.document().begin()
41+
while block.isValid():
42+
line_count += 1
43+
44+
# The top left position of the block in the document
45+
position = self.edit.document().documentLayout().blockBoundingRect(block).topLeft()
46+
47+
# Check if the position of the block is out side of the visible
48+
# area.
49+
if position.y() > page_bottom:
50+
break
51+
52+
# We want the line number for the selected line to be bold.
53+
bold = False
54+
if block == current_block:
55+
bold = True
56+
font = painter.font()
57+
font.setBold(True)
58+
painter.setFont(font)
59+
60+
# Draw the line number right justified at the y position of the
61+
# line. 3 is a magic padding number. drawText(x, y, text).
62+
font = QFont()
63+
font.setPointSize(self.edit.font().pointSize())
64+
font.setWordSpacing(20)
65+
painter.setFont(font)
66+
if line_count == 1:
67+
painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3, 1 + 17 * line_count, str(line_count))
68+
else:
69+
painter.drawText(self.width() - font_metrics.width(str(line_count)) - 3,
70+
1 + 17 * line_count + (self.edit.font().pointSize() - 10) * line_count * 2,
71+
str(line_count))
72+
#print(self.width() - font_metrics.width(str(line_count)) - 3 , " " , round(position.y()) - contents_y + font_metrics.ascent(), str(line_count))
73+
74+
# Remove the bold style if it was set previously.
75+
if bold:
76+
font = painter.font()
77+
font.setBold(False)
78+
painter.setFont(font)
79+
80+
block = block.next()
81+
82+
self.highest_line = line_count
83+
painter.end()
84+
85+
QWidget.paintEvent(self, event)
86+
87+
88+
class TestWidget(QtWidgets.QWidget):
89+
def __init__(self):
90+
super(TestWidget, self).__init__()
91+
#window = LineTextWidget()
92+
self.edit = QPlainTextEdit()
93+
self.number_bar = NumberBar()
94+
self.number_bar.setTextEdit(self.edit)
95+
l = QHBoxLayout()
96+
l.addWidget(self.number_bar)
97+
l.addWidget(self.edit)
98+
self.setLayout(l)
99+
self.edit.installEventFilter(self)
100+
self.edit.viewport().installEventFilter(self)
101+
self.show()
102+
103+
def eventFilter(self, object, event):
104+
# Update the line numbers for all events on the text edit and the viewport.
105+
# This is easier than connecting all necessary singals.
106+
if object in (self.edit, self.edit.viewport()):
107+
self.number_bar.update()
108+
return False
109+
return QFrame.eventFilter(object, event)
110+
111+
if __name__ == '__main__':
112+
app = QtWidgets.QApplication(sys.argv)
113+
wind = TestWidget()
114+
sys.exit(app.exec_())

viewer/editor.py

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
"""
2+
Brick is lightweight IDE for C programming language.
3+
Copyright (C) 2020 : Mršulja Ivan
4+
5+
This file is part of Brick IDE.
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>
16+
"""
17+
118
import shutil
219
from model.SaveNode import *
320
from PyQt5.QtCore import Qt, pyqtRemoveInputHook
21+
from PyQt5.Qt import QFrame
422
import os
523
import qdarkstyle
624
from model.Terminal import Terminal
725
from model.Autocompleter import *
26+
from viewer.NumberBar import NumberBar
827

928

1029
class TextEditor(QtWidgets.QWidget):
@@ -37,9 +56,12 @@ def init_ui(self):
3756
self.tree.doubleClicked.connect(self.tree_clk)
3857
self.get_open_path()
3958
self.init_text_edit()
59+
self.text_edit_layout = QtWidgets.QHBoxLayout()
60+
self.text_edit_layout.addWidget(self.number_bar)
61+
self.text_edit_layout.addWidget(self.text)
4062

4163
self.grid = QtWidgets.QGridLayout()
42-
self.grid.addWidget(self.text, 0, 2, 4, 6)
64+
self.grid.addLayout(self.text_edit_layout, 0, 2, 4, 6)
4365
self.grid.addWidget(self.tree, 0, 0, 4, 2)
4466
self.grid.addWidget(self.terminal, 4, 0, 2, 8)
4567

@@ -60,10 +82,14 @@ def open_menu(self, position):
6082
action_refresh = QtWidgets.QAction("Refresh", None)
6183
action_refresh.triggered.connect(self.refresh_table)
6284

85+
action_rename = QtWidgets.QAction("Rename", None)
86+
action_rename.triggered.connect(self.rename_node)
87+
6388
if self.tree.currentIndex().internalPointer() is not None:
6489
self.contextMenu.addAction(actionNewFolder)
6590
self.contextMenu.addAction(actionNewFile)
6691
self.contextMenu.addAction(action_delete)
92+
self.contextMenu.addAction(action_rename)
6793
self.contextMenu.addAction(action_refresh)
6894

6995

@@ -91,6 +117,16 @@ def delete_node(self):
91117
os.remove(del_path)
92118
self.refresh_table()
93119

120+
def rename_node(self):
121+
ret_text, ok_button = QtWidgets.QInputDialog.getText(self, "Rename", "Insert new name: ")
122+
if ok_button:
123+
if ret_text.strip() == "":
124+
QtWidgets.QMessageBox.critical(self, "Error", "Empty directory name! ")
125+
return
126+
path = self.get_path_for_making(self.open_path)
127+
os.rename(path, os.path.join(os.path.split(path)[0], ret_text))
128+
self.tree.repaint()
129+
94130
def make_new_folder(self):
95131
base_path = self.open_path
96132
if self.tree.currentIndex().parent() != self.tree.rootIndex() or not "." in self.tree.currentIndex().data():
@@ -132,6 +168,9 @@ def init_text_edit(self):
132168
self.text.setCompleter(self.completer)
133169
self.text.setStyleSheet("QPlainTextEdit { color: rgb(169, 183, 198) }")
134170

171+
self.number_bar = NumberBar()
172+
self.number_bar.setTextEdit(self.text)
173+
135174
self.font = QtGui.QFont()
136175
self.font.setFamily('Ariel')
137176
self.font.setFixedPitch(True)
@@ -153,6 +192,17 @@ def init_text_edit(self):
153192
new_completer = check_for_header_files(self.text.toPlainText(), self.completer.my_keywords)
154193
self.text.setCompleter(new_completer)
155194

195+
self.text.installEventFilter(self)
196+
self.text.viewport().installEventFilter(self)
197+
198+
def eventFilter(self, object, event):
199+
# Update the line numbers for all events on the text edit and the viewport.
200+
# This is easier than connecting all necessary singals.
201+
if object in (self.text, self.text.viewport()):
202+
self.number_bar.update()
203+
return False
204+
return QFrame.eventFilter(object, event)
205+
156206
def set_font(self, value):
157207
if int(value) >= 8 and int(value) <= 50:
158208
self.font.setPointSize(int(value))

0 commit comments

Comments
 (0)