Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
14
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
PASSOFT
SOHViewer
Commits
adadf36c
Commit
adadf36c
authored
4 months ago
by
Lan Dam
Browse files
Options
Downloads
Patches
Plain Diff
Display changelog in about dialog
parent
63b3fd28
No related branches found
No related tags found
1 merge request
!326
Display changelog in about dialog
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sohstationviewer/view/about_dialog.py
+77
-5
77 additions, 5 deletions
sohstationviewer/view/about_dialog.py
with
77 additions
and
5 deletions
sohstationviewer/view/about_dialog.py
+
77
−
5
View file @
adadf36c
import
sys
from
typing
import
Union
from
typing
import
Union
,
Dict
import
os
from
pathlib
import
Path
import
re
from
PySide6
import
QtWidgets
,
QtCore
from
PySide6.QtWidgets
import
QApplication
,
QWidget
,
QDialog
,
QLabel
,
QFrame
from
PySide6.QtWidgets
import
QApplication
,
QWidget
,
QDialog
,
QLabel
,
QFrame
,
\
QListWidget
,
QPlainTextEdit
from
sohstationviewer.conf
import
constants
...
...
@@ -18,6 +22,17 @@ def add_separation_line(layout):
layout
.
addWidget
(
label
)
def
remove_empty_lines
(
text
:
str
)
->
str
:
"""
Remove lines with no text from text
:param text: the text with empty lines that need to be removed
:return: text with no empty lines
"""
lines
=
text
.
split
(
'
\n
'
)
no_empty_lines
=
[
line
for
line
in
lines
if
line
.
strip
()]
return
'
\n
'
.
join
(
no_empty_lines
)
class
AboutDialog
(
QDialog
):
"""
Dialog to show information of the software.
...
...
@@ -25,7 +40,7 @@ class AboutDialog(QDialog):
About Dialog is always opened and will be raised up when the about menu
action is triggered.
"""
def
__init__
(
self
,
parent
:
Union
[
QWidget
,
QApplication
]):
def
__init__
(
self
,
parent
:
Union
[
QWidget
,
QApplication
,
None
]):
"""
:param parent: the parent widget
"""
...
...
@@ -41,18 +56,31 @@ class AboutDialog(QDialog):
"
by different types of data loggers.
"
)
self
.
description_label
=
QLabel
(
description
)
self
.
history_label
=
QLabel
(
'
History
'
)
# Dictionary of history by version
self
.
history_dict
:
Dict
[
str
,
str
]
=
self
.
get_history_dict
()
self
.
version_list_widget
=
QListWidget
(
self
)
self
.
version_list_widget
.
addItems
(
reversed
(
self
.
history_dict
.
keys
()))
self
.
changelog_edit
=
QPlainTextEdit
()
self
.
changelog_edit
.
setReadOnly
(
True
)
version
=
f
"
Version
{
constants
.
SOFTWARE_VERSION
}
"
self
.
version_label
=
QLabel
(
version
)
built_time
=
f
"
Built on
{
constants
.
BUILD_TIME
}
"
self
.
built_time_label
=
QLabel
(
built_time
)
copyright
=
u
"
Copyright
\u00A9
2024 EarthScope Consortium
"
self
.
copyright_label
=
QLabel
(
copyright
)
version_year
=
constants
.
SOFTWARE_VERSION
.
split
(
'
.
'
)[
0
]
copy_right
=
(
u
"
Copyright
\u00A9
"
f
"
{
version_year
}
EarthScope Consortium
"
)
self
.
copyright_label
=
QLabel
(
copy_right
)
self
.
ok_button
=
QtWidgets
.
QPushButton
(
'
OK
'
,
self
)
self
.
setup_ui
()
self
.
connect_signals
()
self
.
version_list_widget
.
setCurrentRow
(
0
)
def
setup_ui
(
self
):
self
.
setWindowTitle
(
"
About SOHViewer
"
)
...
...
@@ -63,6 +91,13 @@ class AboutDialog(QDialog):
main_layout
.
addWidget
(
self
.
description_label
)
add_separation_line
(
main_layout
)
main_layout
.
addWidget
(
self
.
history_label
)
history_layout
=
QtWidgets
.
QHBoxLayout
()
main_layout
.
addLayout
(
history_layout
)
self
.
version_list_widget
.
setFixedWidth
(
100
)
history_layout
.
addWidget
(
self
.
version_list_widget
)
history_layout
.
addWidget
(
self
.
changelog_edit
)
main_layout
.
addWidget
(
self
.
version_label
)
main_layout
.
addWidget
(
self
.
built_time_label
)
main_layout
.
addWidget
(
self
.
copyright_label
)
...
...
@@ -73,8 +108,45 @@ class AboutDialog(QDialog):
button_layout
.
addWidget
(
self
.
ok_button
)
def
connect_signals
(
self
)
->
None
:
self
.
version_list_widget
.
currentTextChanged
.
connect
(
self
.
on_version_changed
)
self
.
ok_button
.
clicked
.
connect
(
self
.
close
)
@staticmethod
def
get_history_dict
():
"""
Get dictionary of history by version from file HISTORY.rst
:return: dictionary of history by version
"""
current_file_path
=
os
.
path
.
abspath
(
__file__
)
root
=
Path
(
current_file_path
).
parent
.
parent
.
parent
history_path
=
root
.
joinpath
(
'
HISTORY.rst
'
)
version_re
=
re
.
compile
(
'
^[1-3][0-9]{3}.[1-9].[0-9].[0-9]$
'
)
history_dict
=
{}
lines
=
[]
version
=
None
with
open
(
history_path
)
as
file
:
lines
=
file
.
readlines
()
for
line
in
lines
:
line
=
line
.
strip
()
if
version_re
.
match
(
line
):
version
=
line
history_dict
[
version
]
=
""
elif
version
is
not
None
and
'
------
'
not
in
line
:
history_dict
[
version
]
+=
line
+
'
\n
'
return
history_dict
@QtCore.Slot
()
def
on_version_changed
(
self
,
version
):
"""
When version is changed, place the corresponded changelog in changelog
edit.
:param version: the selected version
"""
changelog
=
remove_empty_lines
(
self
.
history_dict
[
version
])
self
.
changelog_edit
.
setPlainText
(
changelog
)
if
__name__
==
'
__main__
'
:
app
=
QtWidgets
.
QApplication
(
sys
.
argv
)
...
...
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