Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TGMS made easy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sylvain Kern
TGMS made easy
Commits
f64fc928
Commit
f64fc928
authored
2 years ago
by
Sylvain Kern
Browse files
Options
Downloads
Patches
Plain Diff
line numbering kinda works
parent
522e8900
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#26104
failed
2 years ago
Stage: package
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tgms_made_easy.py
+99
-69
99 additions, 69 deletions
tgms_made_easy.py
with
99 additions
and
69 deletions
tgms_made_easy.py
+
99
−
69
View file @
f64fc928
...
...
@@ -159,9 +159,10 @@ class import_dialog(QtWidgets.QDialog):
# textfile preview area
self
.
textBoxLayout
=
QtWidgets
.
QHBoxLayout
()
self
.
textWidget
=
QtWidgets
.
QTextBrowser
()
self
.
lineNumberWidget
=
LineNumberWidget
(
self
.
textWidget
)
self
.
textWidget
.
setFontFamily
(
"
Consolas
"
)
# self.textWidget = LineNumberWidget()
# self.lineNumberWidget = LineNumberWidget(self.textWidget)
# self.textWidget.setFontFamily("Consolas")
self
.
textWidget
=
TextPreviewWidget
()
# table preview area
self
.
tableWidget
=
QtWidgets
.
QTableView
()
...
...
@@ -177,7 +178,7 @@ class import_dialog(QtWidgets.QDialog):
textlayout
=
QtWidgets
.
QVBoxLayout
()
textBoxLayout
=
QtWidgets
.
QHBoxLayout
()
textBoxWidget
=
QtWidgets
.
QWidget
()
textBoxLayout
.
addWidget
(
self
.
lineNumberWidget
)
#
textBoxLayout.addWidget(self.lineNumberWidget)
textBoxWidget
.
setLayout
(
textBoxLayout
)
textBoxLayout
.
addWidget
(
self
.
textWidget
)
textBoxLayout
.
addLayout
(
textlayout
)
...
...
@@ -289,7 +290,7 @@ class import_dialog(QtWidgets.QDialog):
self
.
filelabel
.
setText
(
self
.
filename
)
def
get_contents
(
self
,
filename
):
BLOCKSIZE
=
1048576
# or some other, desired size in bytes
#
BLOCKSIZE = 1048576 # or some other, desired size in bytes
# newfilename = ''.join(filename.split(".")[:-1])+'_utf8.'+filename.split(".")[-1]
with
codecs
.
open
(
filename
,
"
rb
"
,
errors
=
"
ignore
"
)
as
sourceFile
:
contents
=
sourceFile
.
read
()
...
...
@@ -903,73 +904,102 @@ class TGMSplot(pg.GraphicsLayoutWidget):
self
.
legend
.
clear
()
class
LineNumberWidget
(
QtWidgets
.
QTextBrowser
):
class
LineNumberArea
(
QtWidgets
.
QWidget
):
def
__init__
(
self
,
editor
):
super
().
__init__
(
editor
)
self
.
editor
=
editor
def
__init__
(
self
,
widget
):
def
sizeHint
(
self
):
return
QtCore
.
QSize
(
self
.
editor
.
lineNumberAreaWidth
(),
0
)
def
paintEvent
(
self
,
event
):
print
(
'
LineNumberArea.paintEvent
'
)
self
.
editor
.
lineNumberAreaPaintEvent
(
event
)
class
TextPreviewWidget
(
QtWidgets
.
QPlainTextEdit
):
def
__init__
(
self
):
super
().
__init__
()
self
.
__initUi
(
widget
)
def
__initUi
(
self
,
widget
):
self
.
__lineCount
=
widget
.
document
().
lineCount
()
self
.
__size
=
int
(
widget
.
font
().
pointSizeF
())
self
.
__styleInit
()
self
.
setVerticalScrollBarPolicy
(
QtCore
.
Qt
.
ScrollBarPolicy
.
ScrollBarAlwaysOff
)
# self.setTextInteractionFlags(QtWidgets.QGraphicsTextItem. .NoTextInteraction)
self
.
verticalScrollBar
().
setEnabled
(
False
)
widget
.
verticalScrollBar
().
valueChanged
.
connect
(
self
.
__changeLineWidgetScrollAsTargetedWidgetScrollChanged
)
self
.
__initLineCount
()
def
__changeLineWidgetScrollAsTargetedWidgetScrollChanged
(
self
,
v
):
self
.
verticalScrollBar
().
setValue
(
v
)
def
__initLineCount
(
self
):
for
n
in
range
(
1
,
self
.
__lineCount
+
1
):
self
.
append
(
str
(
n
))
def
changeLineCount
(
self
,
n
):
max_one
=
max
(
self
.
__lineCount
,
n
)
diff
=
n
-
self
.
__lineCount
if
max_one
==
self
.
__lineCount
:
first_v
=
self
.
verticalScrollBar
().
value
()
for
i
in
range
(
self
.
__lineCount
,
self
.
__lineCount
+
diff
,
-
1
):
self
.
moveCursor
(
QtGui
.
QTextCursor
.
End
,
QtGui
.
QTextCursor
.
MoveAnchor
)
self
.
moveCursor
(
QtGui
.
QTextCursor
.
StartOfLine
,
QtGui
.
QTextCursor
.
MoveAnchor
)
self
.
moveCursor
(
QtGui
.
QTextCursor
.
End
,
QtGui
.
QTextCursor
.
KeepAnchor
)
self
.
textCursor
().
removeSelectedText
()
self
.
textCursor
().
deletePreviousChar
()
last_v
=
self
.
verticalScrollBar
().
value
()
if
abs
(
first_v
-
last_v
)
!=
2
:
self
.
verticalScrollBar
().
setValue
(
first_v
)
else
:
for
i
in
range
(
self
.
__lineCount
,
self
.
__lineCount
+
diff
,
1
):
self
.
append
(
str
(
i
+
1
))
self
.
__lineCount
=
n
def
setValue
(
self
,
v
):
self
.
verticalScrollBar
().
setValue
(
v
)
def
setFontSize
(
self
,
s
:
float
):
self
.
__size
=
int
(
s
)
self
.
__styleInit
()
def
__styleInit
(
self
):
self
.
__style
=
f
'''
QTextBrowser
{{
background: transparent;
border: none;
color: #AAA;
font:
{
self
.
__size
}
pt;
}}
'''
self
.
setStyleSheet
(
self
.
__style
)
self
.
setFixedWidth
(
self
.
__size
*
5
)
self
.
lineNumberArea
=
LineNumberArea
(
self
)
self
.
blockCountChanged
.
connect
(
self
.
updateLineNumberAreaWidth
)
self
.
updateRequest
.
connect
(
self
.
updateLineNumberArea
)
self
.
cursorPositionChanged
.
connect
(
self
.
highlightCurrentLine
)
self
.
updateLineNumberAreaWidth
(
0
)
self
.
setReadOnly
(
True
)
self
.
setFont
(
QtGui
.
QFont
(
"
Consolas
"
))
def
lineNumberAreaWidth
(
self
):
"""
This method has been slightly modified (use of log and uses actual
font rather than standart.)
"""
n_lines
=
self
.
blockCount
()
digits
=
np
.
ceil
(
np
.
log10
(
n_lines
))
+
1
return
int
(
digits
*
QtGui
.
QFontMetrics
(
self
.
font
()).
averageCharWidth
()
+
3
)
def
updateLineNumberAreaWidth
(
self
,
_
):
# print('CodeEditor.updateLineNumberAreaWidth: margin = {}'.format(self.lineNumberAreaWidth()))
self
.
setViewportMargins
(
self
.
lineNumberAreaWidth
(),
0
,
0
,
0
)
def
updateLineNumberArea
(
self
,
rect
,
dy
):
# print('CodeEditor.updateLineNumberArea: rect = {}, dy = {}'.format(rect, dy))
if
dy
:
self
.
lineNumberArea
.
scroll
(
0
,
dy
)
else
:
self
.
lineNumberArea
.
update
(
0
,
rect
.
y
(),
self
.
lineNumberArea
.
width
(),
rect
.
height
())
# print('CodeEditor.updateLineNumberArea: rect.contains(self.viewport().rect()) = {}'.format(rect.contains(self.viewport().rect())))
if
rect
.
contains
(
self
.
viewport
().
rect
()):
self
.
updateLineNumberAreaWidth
(
0
)
def
resizeEvent
(
self
,
event
):
super
().
resizeEvent
(
event
)
cr
=
self
.
contentsRect
();
self
.
lineNumberArea
.
setGeometry
(
QtCore
.
QRect
(
cr
.
left
(),
cr
.
top
(),
self
.
lineNumberAreaWidth
(),
cr
.
height
()))
def
lineNumberAreaPaintEvent
(
self
,
event
):
# print('CodeEditor.lineNumberAreaPaintEvent')
painter
=
QtGui
.
QPainter
(
self
.
lineNumberArea
)
# painter.fillRect(event.rect(), QtCore.Qt.GlobalColor.lightGray)
block
=
self
.
firstVisibleBlock
()
blockNumber
=
block
.
blockNumber
()
top
=
self
.
blockBoundingGeometry
(
block
).
translated
(
self
.
contentOffset
()).
top
()
bottom
=
top
+
self
.
blockBoundingRect
(
block
).
height
()
# Just to make sure I use the right font
height
=
QtGui
.
QFontMetrics
(
self
.
font
()).
height
()
while
block
.
isValid
()
and
(
top
<=
event
.
rect
().
bottom
()):
if
block
.
isVisible
()
and
(
bottom
>=
event
.
rect
().
top
()):
number
=
str
(
blockNumber
+
1
)
# painter.setPen(QtCore.Qt.GlobalColor.black)
painter
.
drawText
(
0
,
int
(
top
),
self
.
lineNumberArea
.
width
(),
height
,
QtCore
.
Qt
.
AlignmentFlag
.
AlignRight
,
number
)
block
=
block
.
next
()
top
=
bottom
bottom
=
top
+
self
.
blockBoundingRect
(
block
).
height
()
blockNumber
+=
1
def
highlightCurrentLine
(
self
):
extraSelections
=
[]
selection
=
QtWidgets
.
QTextEdit
.
ExtraSelection
()
QtWidgets
.
QPushButton
.
palette
lineColor
=
QtWidgets
.
QPushButton
().
palette
().
color
(
QtGui
.
QPalette
.
ColorRole
.
Button
).
lighter
(
160
)
selection
.
format
.
setBackground
(
lineColor
)
selection
.
format
.
setProperty
(
QtGui
.
QTextFormat
.
Property
.
FullWidthSelection
,
True
)
selection
.
cursor
=
self
.
textCursor
()
selection
.
cursor
.
clearSelection
()
extraSelections
.
append
(
selection
)
self
.
setExtraSelections
(
extraSelections
)
class
Experimental_parameters
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment