Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SOHViewer
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
3
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
90e2c066
Commit
90e2c066
authored
3 months ago
by
Kien Le
Browse files
Options
Downloads
Patches
Plain Diff
Add a read all data column to channel table editor
parent
5e7d8001
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sohstationviewer/view/db_config/channel_dialog.py
+62
-11
62 additions, 11 deletions
sohstationviewer/view/db_config/channel_dialog.py
with
62 additions
and
11 deletions
sohstationviewer/view/db_config/channel_dialog.py
+
62
−
11
View file @
90e2c066
...
...
@@ -3,12 +3,43 @@ channel_dialog.py
GUI to add/edit/remove channels
"""
from
typing
import
List
,
Union
from
PySide6.QtWidgets
import
QMessageBox
from
PIL.ImageOps
import
contain
from
PySide6.QtCore
import
Qt
from
PySide6.QtWidgets
import
(
QMessageBox
,
QCheckBox
,
QWidget
,
QBoxLayout
,
QHBoxLayout
,
)
from
sohstationviewer.view.db_config.db_config_dialog
import
UiDBInfoDialog
from
sohstationviewer.database.process_db
import
execute_db
class
CenteredCheckbox
(
QWidget
):
"""
A checkbox that is centered horizontally and vertically.
Implementation-wise, this puts a QCheckBox into a layout and centers it in
there. Method calls are then passed on to the internal QCheckBox for
processing.
"""
def
__init__
(
self
,
parent
=
None
):
super
(
CenteredCheckbox
,
self
).
__init__
(
parent
)
layout
=
QHBoxLayout
()
self
.
setLayout
(
layout
)
self
.
checkbox
=
QCheckBox
()
layout
.
addWidget
(
self
.
checkbox
)
layout
.
setContentsMargins
(
0
,
0
,
0
,
0
)
layout
.
setAlignment
(
Qt
.
AlignmentFlag
.
AlignCenter
)
def
isChecked
(
self
)
->
bool
:
return
self
.
checkbox
.
isChecked
()
def
setChecked
(
self
,
checked
:
bool
):
self
.
checkbox
.
setChecked
(
checked
)
class
ChannelDialog
(
UiDBInfoDialog
):
def
__init__
(
self
,
parent
):
"""
...
...
@@ -21,21 +52,36 @@ class ChannelDialog(UiDBInfoDialog):
self
.
param_choices
=
[]
super
().
__init__
(
parent
,
[
'
No.
'
,
'
Channel
'
,
'
Label
'
,
'
Param
'
,
'
ConvertFactor
'
,
'
Unit
'
,
'
FixPoint
'
],
'
channel
'
,
'
channels
'
,
resize_content_columns
=
[
0
,
4
,
5
,
6
],
'
ConvertFactor
'
,
'
Unit
'
,
'
FixPoint
'
,
'
All data
'
],
'
channel
'
,
'
channels
'
,
resize_content_columns
=
[
0
,
4
,
5
,
6
,
7
],
need_data_type_choice
=
True
,
required_columns
=
{
2
:
'
Param
'
},
check_fk
=
False
)
self
.
delete_sql_supplement
=
f
"
AND dataType=
'
{
self
.
data_type
}
'"
self
.
setWindowTitle
(
"
Edit/Add/Delete Channels
"
)
self
.
insert_sql_template
=
(
f
"
INSERT INTO Channels VALUES
"
f
"
(?, ?, ?,
''
, ?, ?, ?,
"
f
"
(?, ?, ?,
''
, ?, ?, ?,
?,
"
f
"'
{
self
.
data_type
}
'
)
"
)
self
.
update_sql_template
=
(
f
"
UPDATE Channels SET channel=?,
"
f
"
label=?, param=?, convertFactor=?,
"
f
"
unit=?, fixPoint=?
"
f
"
unit=?, fixPoint=?
, readAllPoints=?
"
f
"
WHERE channel=
'
%s
'
"
f
"
AND dataType=
'
{
self
.
data_type
}
'"
)
def
add_checkbox_widget
(
self
,
row_idx
:
int
,
col_idx
:
int
):
"""
Add a checkbox to a cell of the data table.
:param row_idx: the row to insert the checkbox into
:param col_idx: the column to insert the checkbox into
:return the created checkbox widget
"""
checked
=
(
self
.
database_rows
[
row_idx
][
col_idx
-
1
]
if
row_idx
<
len
(
self
.
database_rows
)
else
False
)
checkbox
=
CenteredCheckbox
(
self
.
data_table_widget
)
checkbox
.
setChecked
(
checked
)
self
.
data_table_widget
.
setCellWidget
(
row_idx
,
col_idx
,
checkbox
)
return
checkbox
def
update_data_table_widget_items
(
self
):
"""
Create list of parameters to used in widget for selecting parameters
...
...
@@ -49,6 +95,7 @@ class ChannelDialog(UiDBInfoDialog):
"""
Clear the content of the first row of the editor.
"""
self
.
data_table_widget
.
cellWidget
(
0
,
4
).
setText
(
'
1
'
)
self
.
data_table_widget
.
cellWidget
(
0
,
6
).
setValue
(
0
)
self
.
data_table_widget
.
cellWidget
(
0
,
7
).
setChecked
(
False
)
def
set_row_content
(
self
,
row_idx
:
int
,
row_content
:
List
[
Union
[
str
,
int
]]):
...
...
@@ -69,6 +116,7 @@ class ChannelDialog(UiDBInfoDialog):
str
(
row_content
[
3
]))
self
.
data_table_widget
.
cellWidget
(
row_idx
,
5
).
setText
(
row_content
[
4
])
self
.
data_table_widget
.
cellWidget
(
row_idx
,
6
).
setValue
(
row_content
[
5
])
self
.
data_table_widget
.
cellWidget
(
row_idx
,
7
).
set_checked
(
row_content
[
6
])
def
set_row_widgets
(
self
,
row_idx
,
fk
=
False
):
"""
...
...
@@ -85,6 +133,7 @@ class ChannelDialog(UiDBInfoDialog):
self
.
add_widget
(
row_idx
,
4
,
field_name
=
'
convertFactor
'
)
self
.
add_widget
(
row_idx
,
5
)
# unit
self
.
add_widget
(
row_idx
,
6
,
range_values
=
[
0
,
5
])
# fixPoint
self
.
add_checkbox_widget
(
row_idx
,
7
)
self
.
add_delete_button_to_row
(
row_idx
,
fk
)
self
.
add_reset_button_to_row
(
row_idx
)
...
...
@@ -154,21 +203,22 @@ class ChannelDialog(UiDBInfoDialog):
Get list of data to fill self.data_table_widgets
'
content
"""
sql
=
(
f
"
SELECT channel,
"
f
"
IFNULL(label,
''
) AS label,
"
f
"
SELECT channel,
"
f
"
IFNULL(label,
''
) AS label,
"
f
"
IFNULL(param,
''
) AS param,
"
f
"
convertFactor,
"
f
"
IFNULL(unit,
''
) AS unit,
"
f
"
IFNULL(fixPoint, 0) AS fixPoint
"
f
"
IFNULL(fixPoint, 0) AS fixPoint,
"
f
"
readAllPoints
"
f
"
FROM Channels
"
f
"
WHERE dataType=
'
{
self
.
data_type
}
'"
)
backup_rows
=
execute_db
(
sql
,
db_path
=
'
backup_db_path
'
)
self
.
backup_database_rows
=
[
[
d
[
0
],
d
[
1
],
d
[
2
],
float
(
d
[
3
]),
d
[
4
],
int
(
d
[
5
])]
[
d
[
0
],
d
[
1
],
d
[
2
],
float
(
d
[
3
]),
d
[
4
],
int
(
d
[
5
])
,
int
(
d
[
6
])
]
for
d
in
backup_rows
]
channel_rows
=
execute_db
(
sql
)
return
[[
d
[
0
],
d
[
1
],
d
[
2
],
float
(
d
[
3
]),
d
[
4
],
int
(
d
[
5
])]
return
[[
d
[
0
],
d
[
1
],
d
[
2
],
float
(
d
[
3
]),
d
[
4
],
int
(
d
[
5
])
,
int
(
d
[
6
])
]
for
d
in
channel_rows
]
def
get_row_inputs
(
self
,
row_idx
):
...
...
@@ -183,7 +233,8 @@ class ChannelDialog(UiDBInfoDialog):
self
.
data_table_widget
.
cellWidget
(
row_idx
,
3
).
currentText
(),
float
(
self
.
data_table_widget
.
cellWidget
(
row_idx
,
4
).
text
()),
self
.
data_table_widget
.
cellWidget
(
row_idx
,
5
).
text
(),
self
.
data_table_widget
.
cellWidget
(
row_idx
,
6
).
value
()
self
.
data_table_widget
.
cellWidget
(
row_idx
,
6
).
value
(),
int
(
self
.
data_table_widget
.
cellWidget
(
row_idx
,
7
).
isChecked
()),
]
def
remove_row
(
self
,
remove_row_idx
):
...
...
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