Skip to content

Commit bf31d0c

Browse files
committed
initial
0 parents  commit bf31d0c

20 files changed

Lines changed: 1640 additions & 0 deletions

.gitignore

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# Created by https://www.gitignore.io
2+
3+
### C++ ###
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
22+
# Compiled Static libraries
23+
*.lai
24+
*.la
25+
*.a
26+
*.lib
27+
28+
# Executables
29+
*.exe
30+
*.out
31+
*.app
32+
33+
34+
### Qt ###
35+
# C++ objects and libs
36+
37+
*.slo
38+
*.lo
39+
*.o
40+
*.a
41+
*.la
42+
*.lai
43+
*.so
44+
*.dll
45+
*.dylib
46+
47+
# Qt-es
48+
49+
/.qmake.cache
50+
/.qmake.stash
51+
*.pro.user
52+
*.pro.user.*
53+
*.moc
54+
moc_*.cpp
55+
qrc_*.cpp
56+
ui_*.h
57+
Makefile*
58+
*-build-*
59+
60+
# QtCreator
61+
62+
*.autosave
63+
64+
#QtCtreator Qml
65+
*.qmlproject.user
66+
*.qmlproject.user.*
67+
68+
69+
### Windows ###
70+
# Windows image file caches
71+
Thumbs.db
72+
ehthumbs.db
73+
74+
# Folder config file
75+
Desktop.ini
76+
77+
# Recycle Bin used on file shares
78+
$RECYCLE.BIN/
79+
80+
# Windows Installer files
81+
*.cab
82+
*.msi
83+
*.msm
84+
*.msp
85+
86+
# Windows shortcuts
87+
*.lnk
88+
89+
90+
### Linux ###
91+
*~
92+
93+
# KDE directory preferences
94+
.directory
95+
96+
97+
### Python ###
98+
# Byte-compiled / optimized / DLL files
99+
__pycache__/
100+
*.py[cod]
101+
102+
# C extensions
103+
*.so
104+
105+
# Distribution / packaging
106+
.Python
107+
env/
108+
build/
109+
develop-eggs/
110+
dist/
111+
downloads/
112+
eggs/
113+
lib/
114+
lib64/
115+
parts/
116+
sdist/
117+
var/
118+
*.egg-info/
119+
.installed.cfg
120+
*.egg
121+
122+
# PyInstaller
123+
# Usually these files are written by a python script from a template
124+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
125+
*.manifest
126+
*.spec
127+
128+
# Installer logs
129+
pip-log.txt
130+
pip-delete-this-directory.txt
131+
132+
# Unit test / coverage reports
133+
htmlcov/
134+
.tox/
135+
.coverage
136+
.cache
137+
nosetests.xml
138+
coverage.xml
139+
140+
# Translations
141+
*.mo
142+
*.pot
143+
144+
# Django stuff:
145+
*.log
146+
147+
# Sphinx documentation
148+
docs/_build/
149+
150+
# PyBuilder
151+
target/
152+
153+
154+
### OSX ###
155+
.DS_Store
156+
.AppleDouble
157+
.LSOverride
158+
159+
# Icon must end with two \r
160+
Icon
161+
162+
# Thumbnails
163+
._*
164+
165+
# Files that might appear on external disk
166+
.Spotlight-V100
167+
.Trashes
168+
169+
# Directories potentially created on remote AFP share
170+
.AppleDB
171+
.AppleDesktop
172+
Network Trash Folder
173+
Temporary Items
174+
.apdisk
175+

Icons/Clear.png

641 Bytes
Loading

Icons/Open.png

446 Bytes
Loading

Icons/Run.png

2.46 KB
Loading

Icons/Save.png

303 Bytes
Loading

Icons/Snippets.png

452 Bytes
Loading

PyRun.pro

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2014-11-22T18:40:41
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
12+
13+
TARGET = PyRun
14+
TEMPLATE = app
15+
16+
SOURCES += main.cpp\
17+
mainview.cpp \
18+
pythonsyntaxhighlighter.cpp \
19+
codeeditor.cpp
20+
21+
HEADERS += mainview.h \
22+
pythonsyntaxhighlighter.h \
23+
codeeditor.h
24+
25+
FORMS += mainview.ui
26+
27+
28+
win32: LIBS += -L$$PWD/../../TermPack/data/python/libs/ -lpython27
29+
30+
INCLUDEPATH += $$PWD/../../TermPack/data/python/include
31+
DEPENDPATH += $$PWD/../../TermPack/data/python/include
32+
33+
RESOURCES += \
34+
PyRunResources.qrc
35+
36+
RC_FILE = windows_res.rc

PyRunResources.qrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<RCC>
2+
<qresource prefix="/data">
3+
<file>startme.py</file>
4+
<file>e.png</file>
5+
<file>Icons/Clear.png</file>
6+
<file>Icons/Open.png</file>
7+
<file>Icons/Save.png</file>
8+
<file>Icons/Snippets.png</file>
9+
<file>Icons/Run.png</file>
10+
</qresource>
11+
</RCC>

codeeditor.cpp

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4+
** Contact: http://www.qt-project.org/legal
5+
**
6+
** This file is part of the examples of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21+
** of its contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
#include <QtWidgets>
42+
43+
#include "codeeditor.h"
44+
45+
//![constructor]
46+
47+
CodeEditor::CodeEditor(QWidget* parent)
48+
: QPlainTextEdit(parent)
49+
{
50+
lineNumberArea = new LineNumberArea(this);
51+
52+
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
53+
connect(this, SIGNAL(updateRequest(QRect, int)), this, SLOT(updateLineNumberArea(QRect, int)));
54+
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine()));
55+
56+
updateLineNumberAreaWidth(0);
57+
highlightCurrentLine();
58+
}
59+
60+
//![constructor]
61+
62+
//![extraAreaWidth]
63+
64+
int CodeEditor::lineNumberAreaWidth()
65+
{
66+
int digits = 1;
67+
int max = qMax(1, blockCount());
68+
while (max >= 10) {
69+
max /= 10;
70+
++digits;
71+
}
72+
73+
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits;
74+
75+
return space;
76+
}
77+
78+
//![extraAreaWidth]
79+
80+
//![slotUpdateExtraAreaWidth]
81+
82+
void CodeEditor::updateLineNumberAreaWidth(int /* newBlockCount */)
83+
{
84+
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
85+
}
86+
87+
//![slotUpdateExtraAreaWidth]
88+
89+
//![slotUpdateRequest]
90+
91+
void CodeEditor::updateLineNumberArea(const QRect& rect, int dy)
92+
{
93+
if (dy)
94+
lineNumberArea->scroll(0, dy);
95+
else
96+
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
97+
98+
if (rect.contains(viewport()->rect()))
99+
updateLineNumberAreaWidth(0);
100+
}
101+
102+
//![slotUpdateRequest]
103+
104+
//![resizeEvent]
105+
106+
void CodeEditor::resizeEvent(QResizeEvent* e)
107+
{
108+
QPlainTextEdit::resizeEvent(e);
109+
110+
QRect cr = contentsRect();
111+
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
112+
}
113+
114+
//![resizeEvent]
115+
116+
//![cursorPositionChanged]
117+
118+
void CodeEditor::highlightCurrentLine()
119+
{
120+
QList<QTextEdit::ExtraSelection> extraSelections;
121+
122+
if (!isReadOnly()) {
123+
QTextEdit::ExtraSelection selection;
124+
125+
QColor lineColor = QColor(Qt::yellow).lighter(160);
126+
127+
selection.format.setBackground(lineColor);
128+
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
129+
selection.cursor = textCursor();
130+
selection.cursor.clearSelection();
131+
extraSelections.append(selection);
132+
}
133+
134+
setExtraSelections(extraSelections);
135+
}
136+
137+
//![cursorPositionChanged]
138+
139+
//![extraAreaPaintEvent_0]
140+
141+
void CodeEditor::lineNumberAreaPaintEvent(QPaintEvent* event)
142+
{
143+
QPainter painter(lineNumberArea);
144+
painter.fillRect(event->rect(), Qt::lightGray);
145+
146+
//![extraAreaPaintEvent_0]
147+
148+
//![extraAreaPaintEvent_1]
149+
QTextBlock block = firstVisibleBlock();
150+
int blockNumber = block.blockNumber();
151+
int top = (int)blockBoundingGeometry(block).translated(contentOffset()).top();
152+
int bottom = top + (int)blockBoundingRect(block).height();
153+
//![extraAreaPaintEvent_1]
154+
155+
//![extraAreaPaintEvent_2]
156+
while (block.isValid() && top <= event->rect().bottom()) {
157+
if (block.isVisible() && bottom >= event->rect().top()) {
158+
QString number = QString::number(blockNumber + 1);
159+
painter.setPen(Qt::black);
160+
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
161+
Qt::AlignRight, number);
162+
}
163+
164+
block = block.next();
165+
top = bottom;
166+
bottom = top + (int)blockBoundingRect(block).height();
167+
++blockNumber;
168+
}
169+
}
170+
//![extraAreaPaintEvent_2]

0 commit comments

Comments
 (0)