Skip to content

Commit 34ea8eb

Browse files
committed
Snippets DB
1 parent 90740dc commit 34ea8eb

16 files changed

Lines changed: 885 additions & 289 deletions

Icons/Add.png

226 Bytes
Loading

Icons/Load.png

682 Bytes
Loading

Icons/Remove.png

162 Bytes
Loading

PyRun.pro

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ TEMPLATE = app
1616
SOURCES += main.cpp\
1717
mainview.cpp \
1818
pythonsyntaxhighlighter.cpp \
19-
codeeditor.cpp
19+
codeeditor.cpp \
20+
snippets.cpp
2021

2122
HEADERS += mainview.h \
2223
pythonsyntaxhighlighter.h \
23-
codeeditor.h
24+
codeeditor.h \
25+
snippets.h
2426

2527
FORMS += mainview.ui
2628

29+
QMAKE_CXXFLAGS += -std=c++11
2730

2831
win32: LIBS += -L$$PWD/../../TermPack/data/python/libs/ -lpython27
2932

PyRunResources.qrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77
<file>Icons/Save.png</file>
88
<file>Icons/Snippets.png</file>
99
<file>Icons/Run.png</file>
10+
<file>Icons/Add.png</file>
11+
<file>Icons/Load.png</file>
12+
<file>Icons/Remove.png</file>
13+
<file>el.png</file>
1014
</qresource>
1115
</RCC>

codeeditor.cpp

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@
3939
****************************************************************************/
4040

4141
#include <QtWidgets>
42-
4342
#include "codeeditor.h"
4443

45-
//![constructor]
46-
4744
CodeEditor::CodeEditor(QWidget* parent)
4845
: QPlainTextEdit(parent)
4946
{
@@ -57,10 +54,6 @@ CodeEditor::CodeEditor(QWidget* parent)
5754
highlightCurrentLine();
5855
}
5956

60-
//![constructor]
61-
62-
//![extraAreaWidth]
63-
6457
int CodeEditor::lineNumberAreaWidth()
6558
{
6659
int digits = 1;
@@ -75,19 +68,11 @@ int CodeEditor::lineNumberAreaWidth()
7568
return space;
7669
}
7770

78-
//![extraAreaWidth]
79-
80-
//![slotUpdateExtraAreaWidth]
81-
8271
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
8372
{
8473
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
8574
}
8675

87-
//![slotUpdateExtraAreaWidth]
88-
89-
//![slotUpdateRequest]
90-
9176
void CodeEditor::updateLineNumberArea(const QRect& rect, int dy)
9277
{
9378
if (dy)
@@ -99,10 +84,6 @@ void CodeEditor::updateLineNumberArea(const QRect& rect, int dy)
9984
updateLineNumberAreaWidth(0);
10085
}
10186

102-
//![slotUpdateRequest]
103-
104-
//![resizeEvent]
105-
10687
void CodeEditor::resizeEvent(QResizeEvent* e)
10788
{
10889
QPlainTextEdit::resizeEvent(e);
@@ -111,9 +92,20 @@ void CodeEditor::resizeEvent(QResizeEvent* e)
11192
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
11293
}
11394

114-
//![resizeEvent]
115-
116-
//![cursorPositionChanged]
95+
void CodeEditor::keyPressEvent(QKeyEvent* e)
96+
{
97+
switch (e->key()) {
98+
case Qt::Key_Tab:
99+
QPlainTextEdit::insertPlainText(" ");
100+
break;
101+
//TODO Indentation
102+
// case Qt::Key_Enter:
103+
// case Qt::Key_Return:
104+
// break;
105+
default:
106+
QPlainTextEdit::keyPressEvent(e);
107+
}
108+
}
117109

118110
void CodeEditor::highlightCurrentLine()
119111
{
@@ -134,25 +126,16 @@ void CodeEditor::highlightCurrentLine()
134126
setExtraSelections(extraSelections);
135127
}
136128

137-
//![cursorPositionChanged]
138-
139-
//![extraAreaPaintEvent_0]
140-
141129
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
142130
{
143131
QPainter painter(lineNumberArea);
144132
painter.fillRect(event->rect(), Qt::lightGray);
145133

146-
//![extraAreaPaintEvent_0]
147-
148-
//![extraAreaPaintEvent_1]
149134
QTextBlock block = firstVisibleBlock();
150135
int blockNumber = block.blockNumber();
151136
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
152137
int bottom = top + (int)blockBoundingRect(block).height();
153-
//![extraAreaPaintEvent_1]
154138

155-
//![extraAreaPaintEvent_2]
156139
while (block.isValid() && top <= event->rect().bottom()) {
157140
if (block.isVisible() && bottom >= event->rect().top()) {
158141
QString number = QString::number(blockNumber + 1);
@@ -167,4 +150,3 @@ void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
167150
++blockNumber;
168151
}
169152
}
170-
//![extraAreaPaintEvent_2]

codeeditor.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,11 @@ QT_END_NAMESPACE
5353

5454
class LineNumberArea;
5555

56-
//![codeeditordefinition]
57-
5856
class CodeEditor : public QPlainTextEdit {
5957
Q_OBJECT
6058

6159
public:
6260
CodeEditor(QWidget* parent = 0);
63-
6461
void lineNumberAreaPaintEvent(QPaintEvent* event);
6562
int lineNumberAreaWidth();
6663

@@ -74,19 +71,16 @@ private slots:
7471

7572
private:
7673
QWidget* lineNumberArea;
74+
void keyPressEvent(QKeyEvent* e);
7775
};
7876

79-
//![codeeditordefinition]
80-
//![extraarea]
81-
8277
class LineNumberArea : public QWidget {
8378
public:
8479
LineNumberArea(CodeEditor* editor)
8580
: QWidget(editor)
8681
{
8782
codeEditor = editor;
8883
}
89-
9084
QSize sizeHint() const
9185
{
9286
return QSize(codeEditor->lineNumberAreaWidth(), 0);
@@ -102,6 +96,4 @@ class LineNumberArea : public QWidget {
10296
CodeEditor* codeEditor;
10397
};
10498

105-
//![extraarea]
106-
10799
#endif

el.png

2.08 KB
Loading

main.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#include <Python.h>
21
#include "mainview.h"
32
#include <QApplication>
43

54
static MainView* mainView;
5+
static Snippets* snip;
66

7+
//--------------------------------------------------------------------
8+
// call back functions
79
static PyObject* emb_get_input(PyObject* self, PyObject* args)
810
{
911
if (!PyArg_ParseTuple(args, ":numargs"))
@@ -12,6 +14,14 @@ static PyObject* emb_get_input(PyObject* self, PyObject* args)
1214
return Py_BuildValue("s", mainView->GetInput().toStdString().c_str());
1315
}
1416

17+
static PyObject* emb_get_apppath(PyObject* self, PyObject* args)
18+
{
19+
if (!PyArg_ParseTuple(args, ":numargs"))
20+
return NULL;
21+
22+
return Py_BuildValue("s", QCoreApplication::applicationDirPath().toStdString().c_str());
23+
}
24+
1525
static PyObject* emb_set_output(PyObject* self, PyObject* args)
1626
{
1727
char* data;
@@ -35,6 +45,8 @@ static PyObject* emb_write_output(PyObject* self, PyObject* args)
3545
static PyMethodDef EmbMethods[] = {
3646
{ "get_input", emb_get_input, METH_VARARGS,
3747
"Get input textbox's content as as string" },
48+
{ "get_apppath", emb_get_apppath, METH_VARARGS,
49+
"Get application path" },
3850
{ "set_output", emb_set_output, METH_VARARGS,
3951
"Set output textbox's content" },
4052
{ "write_output", emb_write_output, METH_VARARGS,
@@ -43,21 +55,27 @@ static PyMethodDef EmbMethods[] = {
4355
{ NULL, NULL, 0, NULL }
4456
};
4557

58+
//--------------------------------------------------------------------
4659
int main(int argc, char* argv[])
4760
{
4861
QApplication app(argc, argv);
4962

5063
Py_SetProgramName(argv[0]);
5164
Py_Initialize();
52-
PySys_SetArgv(argc, argv);
53-
Py_InitModule("emb", EmbMethods);
5465

66+
PySys_SetArgv(argc, argv); //TODO Change this dynamically
67+
68+
Py_InitModule("emb", EmbMethods);
69+
snip = new Snippets();
5570
mainView = new MainView();
71+
mainView->SetSnippets(snip);
5672
mainView->show();
5773

5874
int result = app.exec();
59-
6075
Py_Finalize();
6176

77+
delete snip;
78+
delete mainView;
79+
6280
return result;
6381
}

0 commit comments

Comments
 (0)