Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • software_public/passoft/sohstationviewer
1 result
Show changes
Commits on Source (10)
Showing
with 354 additions and 405 deletions
...@@ -17,7 +17,7 @@ requirements: ...@@ -17,7 +17,7 @@ requirements:
- python >=3.9 - python >=3.9
- numpy>=1.23.0 - numpy>=1.23.0
- obspy >=1.3.0 - obspy >=1.3.0
- PySide2 - PySide6>=6.5.2
- matplotlib>=3.5.0 - matplotlib>=3.5.0
test: test:
......
...@@ -34,7 +34,7 @@ setup( ...@@ -34,7 +34,7 @@ setup(
install_requires=[ install_requires=[
'numpy>=1.23.0', 'numpy>=1.23.0',
'obspy>=1.3.0', 'obspy>=1.3.0',
'PySide2', 'PySide6>=6.5.2',
'matplotlib>=3.5.0', 'matplotlib>=3.5.0',
], ],
setup_requires=[], setup_requires=[],
......
import configparser import configparser
from pathlib import Path from pathlib import Path
from PySide2 import QtCore from PySide6 import QtCore
from sohstationviewer.conf import constants from sohstationviewer.conf import constants
from sohstationviewer.conf.constants import CONFIG_PATH from sohstationviewer.conf.constants import CONFIG_PATH
......
...@@ -9,9 +9,9 @@ import re ...@@ -9,9 +9,9 @@ import re
from pathlib import Path from pathlib import Path
from typing import List, Optional, Dict, Tuple, Union, BinaryIO from typing import List, Optional, Dict, Tuple, Union, BinaryIO
from PySide2.QtCore import QEventLoop, Qt from PySide6.QtCore import QEventLoop, Qt
from PySide2.QtGui import QCursor from PySide6.QtGui import QCursor
from PySide2.QtWidgets import QTextBrowser, QApplication from PySide6.QtWidgets import QTextBrowser, QApplication
from obspy.io import reftek from obspy.io import reftek
from obspy import UTCDateTime from obspy import UTCDateTime
......
...@@ -9,8 +9,8 @@ from datetime import datetime ...@@ -9,8 +9,8 @@ from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Tuple, List, Union, Dict from typing import Tuple, List, Union, Dict
from PySide2 import QtCore from PySide6 import QtCore
from PySide2.QtWidgets import QTextBrowser from PySide6.QtWidgets import QTextBrowser
from obspy import UTCDateTime from obspy import UTCDateTime
......
...@@ -2,20 +2,22 @@ ...@@ -2,20 +2,22 @@
basic executing database functions basic executing database functions
""" """
import sqlite3 import sqlite3
from typing import Sequence, Union
from sohstationviewer.conf.dbSettings import dbConf from sohstationviewer.conf.dbSettings import dbConf
def execute_db(sql): def execute_db(sql: str, parameters: Union[dict, Sequence] = ()):
""" """
Execute or fetch data from DB Execute or fetch data from DB
:param sql: str - request string to execute or fetch data from database :param sql: str - request string to execute or fetch data from database
:param parameters: the parameters used for executing parameterized queries
:return rows: [(str/int,] - result of querying DB :return rows: [(str/int,] - result of querying DB
""" """
conn = sqlite3.connect(dbConf['dbpath']) conn = sqlite3.connect(dbConf['dbpath'])
cur = conn.cursor() cur = conn.cursor()
try: try:
cur.execute(sql) cur.execute(sql, parameters)
except sqlite3.OperationalError as e: except sqlite3.OperationalError as e:
print("sqlite3.OperationalError:%s\n\tSQL: %s" % (str(e), sql)) print("sqlite3.OperationalError:%s\n\tSQL: %s" % (str(e), sql))
rows = cur.fetchall() rows = cur.fetchall()
......
#!/usr/bin/env python3 #!/usr/bin/env python3
import platform
import os import os
import sys import sys
import traceback import traceback
from pathlib import Path from pathlib import Path
from PySide2 import QtWidgets from PySide6 import QtWidgets
from PySide2.QtGui import QGuiApplication from PySide6.QtWidgets import QMessageBox
from PySide2.QtWidgets import QMessageBox
from sohstationviewer.view.main_window import MainWindow from sohstationviewer.view.main_window import MainWindow
from sohstationviewer.conf.config_processor import ( from sohstationviewer.conf.config_processor import (
...@@ -15,16 +13,6 @@ from sohstationviewer.conf.config_processor import ( ...@@ -15,16 +13,6 @@ from sohstationviewer.conf.config_processor import (
BadConfigError, BadConfigError,
) )
# Enable Layer-backing for MacOs version >= 11
# Only needed if using the pyside2 library with version>=5.15.
# Layer-backing is always enabled in pyside6.
os_name, version, *_ = platform.platform().split('-')
# if os_name == 'macOS' and version >= '11':
# mac OSX 11.6 appear to be 10.16 when read with python and still required this
# environment variable
if os_name == 'macOS':
os.environ['QT_MAC_WANTS_LAYER'] = '1'
def fix_relative_paths() -> None: def fix_relative_paths() -> None:
""" """
...@@ -74,12 +62,12 @@ def check_if_user_want_to_reset_config() -> bool: ...@@ -74,12 +62,12 @@ def check_if_user_want_to_reset_config() -> bool:
bad_config_dialog.setDetailedText(traceback.format_exc()) bad_config_dialog.setDetailedText(traceback.format_exc())
bad_config_dialog.setInformativeText('Do you want to reset the config ' bad_config_dialog.setInformativeText('Do you want to reset the config '
'file?') 'file?')
bad_config_dialog.setStandardButtons(QMessageBox.Ok | bad_config_dialog.setStandardButtons(QMessageBox.StandardButton.Ok |
QMessageBox.Close) QMessageBox.StandardButton.Close)
bad_config_dialog.setDefaultButton(QMessageBox.Ok) bad_config_dialog.setDefaultButton(QMessageBox.StandardButton.Ok)
bad_config_dialog.setIcon(QMessageBox.Critical) bad_config_dialog.setIcon(QMessageBox.Icon.Critical)
reset_choice = bad_config_dialog.exec_() reset_choice = bad_config_dialog.exec()
return reset_choice == QMessageBox.Ok return reset_choice == QMessageBox.StandardButton.Ok
def main(): def main():
...@@ -104,7 +92,7 @@ def main(): ...@@ -104,7 +92,7 @@ def main():
QMessageBox.critical(None, 'Cannot reset config', QMessageBox.critical(None, 'Cannot reset config',
'Config file cannot be reset. Please ensure ' 'Config file cannot be reset. Please ensure '
'that it is not opened in another program.', 'that it is not opened in another program.',
QMessageBox.Close) QMessageBox.StandardButton.Close)
sys.exit(1) sys.exit(1)
elif do_reset is not None: elif do_reset is not None:
sys.exit(1) sys.exit(1)
...@@ -112,7 +100,7 @@ def main(): ...@@ -112,7 +100,7 @@ def main():
resize_windows(wnd) resize_windows(wnd)
wnd.show() wnd.show()
sys.exit(app.exec_()) sys.exit(app.exec())
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -5,7 +5,8 @@ import traceback ...@@ -5,7 +5,8 @@ import traceback
from pathlib import Path from pathlib import Path
from typing import Union, List, Optional from typing import Union, List, Optional
from PySide2 import QtCore, QtWidgets from PySide6.QtCore import Qt
from PySide6 import QtCore, QtWidgets
from sohstationviewer.conf import constants from sohstationviewer.conf import constants
from sohstationviewer.controller.util import display_tracking_info from sohstationviewer.controller.util import display_tracking_info
...@@ -84,7 +85,7 @@ class DataLoaderWorker(QtCore.QObject): ...@@ -84,7 +85,7 @@ class DataLoaderWorker(QtCore.QObject):
# its unpause slot to the loader's unpause signal # its unpause slot to the loader's unpause signal
data_object = object_type.get_empty_instance() data_object = object_type.get_empty_instance()
self.button_chosen.connect(data_object.receive_pause_response, self.button_chosen.connect(data_object.receive_pause_response,
type=QtCore.Qt.DirectConnection) type=Qt.ConnectionType.DirectConnection)
data_object.__init__( data_object.__init__(
self.data_type, self.tracking_box, self.data_type, self.tracking_box,
self.is_multiplex, self.list_of_dir, self.is_multiplex, self.list_of_dir,
......
...@@ -6,8 +6,8 @@ import traceback ...@@ -6,8 +6,8 @@ import traceback
from obspy import UTCDateTime from obspy import UTCDateTime
from PySide2 import QtCore from PySide6 import QtCore
from PySide2 import QtWidgets from PySide6 import QtWidgets
from sohstationviewer.controller.util import \ from sohstationviewer.controller.util import \
display_tracking_info, get_valid_file_count, validate_file, validate_dir display_tracking_info, get_valid_file_count, validate_file, validate_dir
......
from PySide2 import QtWidgets from PySide6 import QtWidgets
from sohstationviewer.view.ui.calendar_ui_qtdesigner import Ui_CalendarDialog from sohstationviewer.view.ui.calendar_ui_qtdesigner import Ui_CalendarDialog
......
from PySide2 import QtCore, QtGui, QtWidgets from PySide6 import QtCore, QtGui, QtWidgets
class CalendarWidget(QtWidgets.QCalendarWidget): class CalendarWidget(QtWidgets.QCalendarWidget):
...@@ -43,7 +43,8 @@ class CalendarWidget(QtWidgets.QCalendarWidget): ...@@ -43,7 +43,8 @@ class CalendarWidget(QtWidgets.QCalendarWidget):
self.toggle_day_of_year.setCheckable(True) self.toggle_day_of_year.setCheckable(True)
palette = self.toggle_day_of_year.palette() palette = self.toggle_day_of_year.palette()
palette.setColor(QtGui.QPalette.WindowText, QtGui.QColor('white')) palette.setColor(QtGui.QPalette.ColorRole.WindowText,
QtGui.QColor('white'))
self.toggle_day_of_year.setPalette(palette) self.toggle_day_of_year.setPalette(palette)
self.toggle_day_of_year.show() self.toggle_day_of_year.show()
......
from typing import Dict, List, Union from typing import Dict, List, Union
from pathlib import Path from pathlib import Path
from PySide2 import QtWidgets, QtCore from PySide6 import QtWidgets, QtCore
from PySide2.QtWidgets import QDialogButtonBox, QDialog, QPlainTextEdit, \ from PySide6.QtWidgets import QDialogButtonBox, QDialog, QPlainTextEdit, \
QMainWindow QMainWindow
from sohstationviewer.database.process_db import ( from sohstationviewer.database.process_db import (
...@@ -35,7 +35,10 @@ class InputDialog(QDialog): ...@@ -35,7 +35,10 @@ class InputDialog(QDialog):
self.text_box.setPlainText(text) self.text_box.setPlainText(text)
button_box = QDialogButtonBox( button_box = QDialogButtonBox(
QDialogButtonBox.Ok | QDialogButtonBox.Cancel, self) QDialogButtonBox.StandardButton.Ok |
QDialogButtonBox.StandardButton.Cancel,
self
)
layout = QtWidgets.QFormLayout(self) layout = QtWidgets.QFormLayout(self)
layout.addRow(self.text_box) layout.addRow(self.text_box)
...@@ -230,8 +233,12 @@ class ChannelPreferDialog(OneWindowAtATimeDialog): ...@@ -230,8 +233,12 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
'Edit', 'Clear'] 'Edit', 'Clear']
self.soh_list_table_widget.setHorizontalHeaderLabels(col_headers) self.soh_list_table_widget.setHorizontalHeaderLabels(col_headers)
header = self.soh_list_table_widget.horizontalHeader() header = self.soh_list_table_widget.horizontalHeader()
header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents) header.setSectionResizeMode(
header.setSectionResizeMode(3, QtWidgets.QHeaderView.Stretch) QtWidgets.QHeaderView.ResizeMode.ResizeToContents
)
header.setSectionResizeMode(
3, QtWidgets.QHeaderView.ResizeMode.Stretch
)
self.soh_list_table_widget.setRowCount(TOTAL_ROW) self.soh_list_table_widget.setRowCount(TOTAL_ROW)
self.avail_data_types = self.get_data_types() self.avail_data_types = self.get_data_types()
...@@ -380,8 +387,9 @@ class ChannelPreferDialog(OneWindowAtATimeDialog): ...@@ -380,8 +387,9 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
f"#{row_idx + 1}?") f"#{row_idx + 1}?")
result = QtWidgets.QMessageBox.question( result = QtWidgets.QMessageBox.question(
self, "Confirmation", msg, self, "Confirmation", msg,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) QtWidgets.QMessageBox.StandardButton.Yes |
if result == QtWidgets.QMessageBox.No: QtWidgets.QMessageBox.StandardButton.No)
if result == QtWidgets.QMessageBox.StandardButton.No:
return return
self.changed = True self.changed = True
if soh_list_name_item.text() != '': if soh_list_name_item.text() != '':
...@@ -454,8 +462,10 @@ class ChannelPreferDialog(OneWindowAtATimeDialog): ...@@ -454,8 +462,10 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
"Do you want to add channels from DB?") "Do you want to add channels from DB?")
result = QtWidgets.QMessageBox.question( result = QtWidgets.QMessageBox.question(
self, "Add Channels from DB for RT130", msg, self, "Add Channels from DB for RT130", msg,
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) QtWidgets.QMessageBox.StandardButton.Ok |
if result == QtWidgets.QMessageBox.Ok: QtWidgets.QMessageBox.StandardButton.Cancel
)
if result == QtWidgets.QMessageBox.StandardButton.Ok:
self.add_db_channels() self.add_db_channels()
else: else:
self.scan_chan_btn.setEnabled(True) self.scan_chan_btn.setEnabled(True)
...@@ -546,8 +556,9 @@ class ChannelPreferDialog(OneWindowAtATimeDialog): ...@@ -546,8 +556,9 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
"database.") "database.")
result = QtWidgets.QMessageBox.question( result = QtWidgets.QMessageBox.question(
self, "Confirmation", msg, self, "Confirmation", msg,
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) QtWidgets.QMessageBox.StandardButton.Ok |
if result == QtWidgets.QMessageBox.Cancel: QtWidgets.QMessageBox.StandardButton.Cancel)
if result == QtWidgets.QMessageBox.StandardButton.Cancel:
return False return False
sql_list = [] sql_list = []
for row_idx in range(TOTAL_ROW): for row_idx in range(TOTAL_ROW):
......
from typing import List from typing import List
from PySide2 import QtWidgets from PySide6 import QtWidgets
def create_multi_buttons_dialog( def create_multi_buttons_dialog(
...@@ -28,12 +28,15 @@ def create_multi_buttons_dialog( ...@@ -28,12 +28,15 @@ def create_multi_buttons_dialog(
# reasons. # reasons.
label = str(label).replace("'", '').replace('"', '') label = str(label).replace("'", '').replace('"', '')
buttons.append( buttons.append(
msg_box.addButton(label, QtWidgets.QMessageBox.ActionRole) msg_box.addButton(label,
QtWidgets.QMessageBox.ButtonRole.ActionRole)
) )
if has_abort: if has_abort:
abort_button = msg_box.addButton(QtWidgets.QMessageBox.Abort) abort_button = msg_box.addButton(
QtWidgets.QMessageBox.StandardButton.Abort
)
msg_box.exec_() msg_box.exec()
try: try:
if msg_box.clickedButton() == abort_button: if msg_box.clickedButton() == abort_button:
return -1 return -1
......
from PySide2.QtCore import Qt, QDate from PySide6.QtCore import Qt, QDate
from PySide2.QtGui import ( from PySide6.QtGui import (
QKeyEvent, QWheelEvent, QContextMenuEvent QKeyEvent, QWheelEvent, QContextMenuEvent, QAction,
) )
from PySide2.QtWidgets import ( from PySide6.QtWidgets import (
QDateEdit, QLineEdit, QMenu, QAction, QDateEdit, QLineEdit, QMenu
) )
......
...@@ -3,8 +3,8 @@ import platform ...@@ -3,8 +3,8 @@ import platform
import os import os
from typing import Optional, Dict from typing import Optional, Dict
from PySide2 import QtWidgets, QtGui from PySide6 import QtWidgets, QtGui
from PySide2.QtWidgets import QWidget, QDialog from PySide6.QtWidgets import QWidget, QDialog
from sohstationviewer.database.process_db import execute_db from sohstationviewer.database.process_db import execute_db
from sohstationviewer.database.extract_data import ( from sohstationviewer.database.extract_data import (
...@@ -23,7 +23,8 @@ def add_separation_line(layout): ...@@ -23,7 +23,8 @@ def add_separation_line(layout):
:param layout: QLayout - the layout that contains the line :param layout: QLayout - the layout that contains the line
""" """
label = QtWidgets.QLabel() label = QtWidgets.QLabel()
label.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Sunken) label.setFrameStyle(QtWidgets.QFrame.Shape.HLine |
QtWidgets.QFrame.Shadow.Sunken)
label.setLineWidth(1) label.setLineWidth(1)
layout.addWidget(label) layout.addWidget(label)
...@@ -73,7 +74,7 @@ class AddEditSingleChannelDialog(QDialog): ...@@ -73,7 +74,7 @@ class AddEditSingleChannelDialog(QDialog):
"to convert from count to actual value" "to convert from count to actual value"
) )
validator = QtGui.QDoubleValidator(0.0, 5.0, 6) validator = QtGui.QDoubleValidator(0.0, 5.0, 6)
validator.setNotation(QtGui.QDoubleValidator.StandardNotation) validator.setNotation(QtGui.QDoubleValidator.Notation.StandardNotation)
self.conversion_lnedit.setValidator(validator) self.conversion_lnedit.setValidator(validator)
self.conversion_lnedit.setText('1') self.conversion_lnedit.setText('1')
...@@ -216,8 +217,10 @@ class AddEditSingleChannelDialog(QDialog): ...@@ -216,8 +217,10 @@ class AddEditSingleChannelDialog(QDialog):
f"'{self.chan_id}'?") f"'{self.chan_id}'?")
result = QtWidgets.QMessageBox.question( result = QtWidgets.QMessageBox.question(
self, "Confirmation", msg, self, "Confirmation", msg,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) QtWidgets.QMessageBox.StandardButton.Yes |
if result == QtWidgets.QMessageBox.No: QtWidgets.QMessageBox.StandardButton.No
)
if result == QtWidgets.QMessageBox.StandardButton.No:
self.param_changed_by_signal = True self.param_changed_by_signal = True
self.param_cbobox.setCurrentText(self.param) self.param_cbobox.setCurrentText(self.param)
return return
...@@ -274,11 +277,12 @@ class AddEditSingleChannelDialog(QDialog): ...@@ -274,11 +277,12 @@ class AddEditSingleChannelDialog(QDialog):
"Are you sure you want to continue?") "Are you sure you want to continue?")
result = QtWidgets.QMessageBox.question( result = QtWidgets.QMessageBox.question(
self, "Confirmation", msg, self, "Confirmation", msg,
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) QtWidgets.QMessageBox.StandardButton.Yes |
if result == QtWidgets.QMessageBox.No: QtWidgets.QMessageBox.StandardButton.No)
if result == QtWidgets.QMessageBox.StandardButton.No:
return return
win = EditSingleParamDialog(self, self.param_cbobox.currentText()) win = EditSingleParamDialog(self, self.param_cbobox.currentText())
win.exec_() win.exec()
def update_para_info(self, param): def update_para_info(self, param):
""" """
...@@ -347,5 +351,5 @@ if __name__ == '__main__': ...@@ -347,5 +351,5 @@ if __name__ == '__main__':
# test TriColorLInes. Ex: param. Ex: param:Error/warning # test TriColorLInes. Ex: param. Ex: param:Error/warning
# test = AddEditSingleChannelDialog(None, 'Error/Warning', 'RT130') # test = AddEditSingleChannelDialog(None, 'Error/Warning', 'RT130')
test.exec_() test.exec()
sys.exit(app.exec_()) sys.exit(app.exec())
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
channel_dialog.py channel_dialog.py
GUI to add/edit/remove channels GUI to add/edit/remove channels
""" """
from PySide2.QtWidgets import QMessageBox from PySide6.QtWidgets import QMessageBox
from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog
from sohstationviewer.database.process_db import execute_db from sohstationviewer.database.process_db import execute_db
...@@ -22,10 +22,18 @@ class ChannelDialog(UiDBInfoDialog): ...@@ -22,10 +22,18 @@ class ChannelDialog(UiDBInfoDialog):
parent, ['No.', 'Channel', 'Label', 'Param', parent, ['No.', 'Channel', 'Label', 'Param',
'ConvertFactor', 'Unit', 'FixPoint'], 'ConvertFactor', 'Unit', 'FixPoint'],
'channel', 'channels', resize_content_columns=[0, 4, 5, 6], 'channel', 'channels', resize_content_columns=[0, 4, 5, 6],
need_data_type_choice=True, required_columns={3: 'Param'}, need_data_type_choice=True, required_columns={2: 'Param'},
check_fk=False) check_fk=False)
self.delete_sql_supplement = f" AND dataType='{self.data_type}'" self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
self.setWindowTitle("Edit/Add/Delete Channels") self.setWindowTitle("Edit/Add/Delete Channels")
self.insert_sql_template = (f"INSERT INTO Channels VALUES"
f"(?, ?, ?, '', ?, ?, ?, "
f"'{self.data_type}')")
self.update_sql_template = (f"UPDATE Channels SET channel=?, "
f"label=?, param=?, convertFactor=?, "
f"unit=?, fixPoint=? "
f"WHERE channel='%s' "
f"AND dataType='{self.data_type}'")
def update_data_table_widget_items(self): def update_data_table_widget_items(self):
""" """
...@@ -57,16 +65,35 @@ class ChannelDialog(UiDBInfoDialog): ...@@ -57,16 +65,35 @@ class ChannelDialog(UiDBInfoDialog):
row to be deleted row to be deleted
""" """
self.add_widget(None, row_idx, 0) # No. self.add_widget(None, row_idx, 0) # No.
self.add_widget(self.data_list, row_idx, 1, foreign_key=fk) # chanID self.add_widget(self.database_rows, row_idx, 1,
self.add_widget(self.data_list, row_idx, 2) # label foreign_key=fk) # chanID
self.add_widget(self.data_list, row_idx, 3, choices=self.param_choices) self.add_widget(self.database_rows, row_idx, 2) # label
self.add_widget(self.data_list, row_idx, 4, self.add_widget(self.database_rows, row_idx, 3,
choices=self.param_choices)
self.add_widget(self.database_rows, row_idx, 4,
field_name='convertFactor') field_name='convertFactor')
self.add_widget(self.data_list, row_idx, 5) # unit self.add_widget(self.database_rows, row_idx, 5) # unit
self.add_widget(self.data_list, row_idx, 6, self.add_widget(self.database_rows, row_idx, 6,
range_values=[0, 5]) # fixPoint range_values=[0, 5]) # fixPoint
self.add_delete_button_to_row(row_idx, fk) self.add_delete_button_to_row(row_idx, fk)
def get_data_type_from_selector(self):
"""
Update the dialog with the new data type. Also update some other
attributes of the dialog affected by the data type.
:return:
"""
old_data_type = self.data_type
self.data_type = self.data_type_combo_box.currentText()
self.update_data_table_widget_items()
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
self.insert_sql_template = self.insert_sql_template.replace(
old_data_type, self.data_type
)
self.update_sql_template = self.update_sql_template.replace(
old_data_type, self.data_type
)
def data_type_changed(self): def data_type_changed(self):
""" """
Method called when the data type of the data table is changed. Method called when the data type of the data table is changed.
...@@ -85,9 +112,7 @@ class ChannelDialog(UiDBInfoDialog): ...@@ -85,9 +112,7 @@ class ChannelDialog(UiDBInfoDialog):
return return
if not self.has_changes(): if not self.has_changes():
self.data_type = self.data_type_combo_box.currentText() self.get_data_type_from_selector()
self.update_data_table_widget_items()
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
return return
unsaved_changes_prompt = ( unsaved_changes_prompt = (
...@@ -95,17 +120,18 @@ class ChannelDialog(UiDBInfoDialog): ...@@ -95,17 +120,18 @@ class ChannelDialog(UiDBInfoDialog):
'Are you sure you want to change the data type? ' 'Are you sure you want to change the data type? '
'Any changes you made will not be saved?' 'Any changes you made will not be saved?'
) )
options = QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel options = (QMessageBox.StandardButton.Save |
QMessageBox.StandardButton.Discard |
QMessageBox.StandardButton.Cancel)
user_choice = QMessageBox.warning(self, 'Unsaved Changes', user_choice = QMessageBox.warning(self, 'Unsaved Changes',
unsaved_changes_prompt, options) unsaved_changes_prompt, options)
if user_choice != QMessageBox.Cancel: if user_choice != QMessageBox.StandardButton.Cancel:
if user_choice == QMessageBox.Save: if user_choice == QMessageBox.StandardButton.Save:
self.save_changes(need_confirmation=False) self.save_changes(need_confirmation=False)
elif user_choice == QMessageBox.Discard: elif user_choice == QMessageBox.StandardButton.Discard:
self.undo_all_deletes() self.untrack_changes()
self.data_type = self.data_type_combo_box.currentText() pass
self.update_data_table_widget_items() self.get_data_type_from_selector()
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
else: else:
# Cover both the case where the cancel button is pressed and the # Cover both the case where the cancel button is pressed and the
# case where the exit button is pressed. # case where the exit button is pressed.
...@@ -153,26 +179,3 @@ class ChannelDialog(UiDBInfoDialog): ...@@ -153,26 +179,3 @@ class ChannelDialog(UiDBInfoDialog):
for i in range(remove_row_idx, self.data_table_widget.rowCount()): for i in range(remove_row_idx, self.data_table_widget.rowCount()):
cell_widget = self.data_table_widget.cellWidget(i, 0) cell_widget = self.data_table_widget.cellWidget(i, 0)
cell_widget.setText(str(i)) cell_widget.setText(str(i))
def update_data(self, row, widget_idx, list_idx):
"""
Prepare insert, update queries and additional condition for common
delete query then update data of a row from
self.data_table_widgets' content.
:param row: list - data of a row
:param widget_idx: index of row in self.data_table_widgets
:param list_idx: index of row in self.data_list
"""
insert_sql = (f"INSERT INTO Channels VALUES"
f"('{row[0]}', '{row[1]}', '{row[2]}',"
f" {row[3]}, '{row[4]}', {row[5]}, '{self.data_type}')")
update_sql = (f"UPDATE Channels SET channel='{row[0]}', "
f"label='{row[1]}', param='{row[2]}', "
f"convertFactor={row[3]}, unit='{row[4]}', "
f"fixPoint={row[5]} "
f"WHERE channel='%s'"
f" AND dataType='{self.data_type}'")
del_sql_add = f" AND dataType='{self.data_type}'"
return super().update_data(
row, widget_idx, list_idx, insert_sql, update_sql, del_sql_add)
...@@ -13,6 +13,9 @@ class DataTypeDialog(UiDBInfoDialog): ...@@ -13,6 +13,9 @@ class DataTypeDialog(UiDBInfoDialog):
super().__init__(parent, ['No.', 'DataType'], 'dataType', 'dataTypes', super().__init__(parent, ['No.', 'DataType'], 'dataType', 'dataTypes',
resize_content_columns=[0]) resize_content_columns=[0])
self.setWindowTitle("Edit/Add/Delete DataTypes") self.setWindowTitle("Edit/Add/Delete DataTypes")
self.insert_sql_template = "INSERT INTO DataTypes VALUES(?)"
self.update_sql_template = ("UPDATE DataTypes SET dataType=? "
"WHERE dataType='%s'")
def set_row_widgets(self, row_idx, fk=False): def set_row_widgets(self, row_idx, fk=False):
""" """
...@@ -23,7 +26,7 @@ class DataTypeDialog(UiDBInfoDialog): ...@@ -23,7 +26,7 @@ class DataTypeDialog(UiDBInfoDialog):
row to be deleted row to be deleted
""" """
self.add_widget(None, row_idx, 0) # No. self.add_widget(None, row_idx, 0) # No.
self.add_widget(self.data_list, row_idx, 1, foreign_key=fk) self.add_widget(self.database_rows, row_idx, 1, foreign_key=fk)
self.add_delete_button_to_row(row_idx, fk) self.add_delete_button_to_row(row_idx, fk)
def get_data_list(self): def get_data_list(self):
...@@ -41,19 +44,3 @@ class DataTypeDialog(UiDBInfoDialog): ...@@ -41,19 +44,3 @@ class DataTypeDialog(UiDBInfoDialog):
:param row_idx: index of row :param row_idx: index of row
""" """
return [self.data_table_widget.cellWidget(row_idx, 1).text().strip()] return [self.data_table_widget.cellWidget(row_idx, 1).text().strip()]
def update_data(self, row, widget_idx, list_idx):
"""
Prepare insert, update queries then update data of a row from
self.data_table_widgets' content.
:param row: list - data of a row
:param widget_idx: index of row in self.data_table_widgets
:param list_idx: index of row in self.data_list
"""
insert_sql = f"INSERT INTO DataTypes VALUES('{row[0]}')"
update_sql = (f"UPDATE DataTypes SET dataType='{row[0]}' "
f"WHERE dataType='%s'")
return super().update_data(
row, widget_idx, list_idx, insert_sql, update_sql)
...@@ -3,8 +3,8 @@ import platform ...@@ -3,8 +3,8 @@ import platform
import os import os
from typing import Optional, Dict from typing import Optional, Dict
from PySide2 import QtWidgets from PySide6 import QtWidgets
from PySide2.QtWidgets import QWidget, QDialog, QLineEdit from PySide6.QtWidgets import QWidget, QDialog, QLineEdit
from sohstationviewer.view.util.plot_func_names import plot_functions from sohstationviewer.view.util.plot_func_names import plot_functions
...@@ -165,5 +165,5 @@ if __name__ == '__main__': ...@@ -165,5 +165,5 @@ if __name__ == '__main__':
# test TriColorLInes. Ex: param. Ex: param:Error/warning # test TriColorLInes. Ex: param. Ex: param:Error/warning
# test = EditSingleParamDialog(None, 'Error/Warning', 'RT130') # test = EditSingleParamDialog(None, 'Error/Warning', 'RT130')
test.exec_() test.exec()
sys.exit(app.exec_()) sys.exit(app.exec())
...@@ -3,11 +3,9 @@ param_dialog.py ...@@ -3,11 +3,9 @@ param_dialog.py
GUI to add/dit/remove params GUI to add/dit/remove params
NOTE: Cannot remove or change params that are already used for channels. NOTE: Cannot remove or change params that are already used for channels.
""" """
from typing import List from PySide6 import QtWidgets, QtCore
from PySide6.QtCore import Qt
from PySide2 import QtWidgets, QtCore from PySide6.QtWidgets import QComboBox, QWidget
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QComboBox, QWidget
from sohstationviewer.conf.constants import ColorMode, ALL_COLOR_MODES from sohstationviewer.conf.constants import ColorMode, ALL_COLOR_MODES
from sohstationviewer.view.util.plot_func_names import plot_functions from sohstationviewer.view.util.plot_func_names import plot_functions
...@@ -36,6 +34,16 @@ class ParamDialog(UiDBInfoDialog): ...@@ -36,6 +34,16 @@ class ParamDialog(UiDBInfoDialog):
['No.', 'Param', 'Plot Type', 'ValueColors', 'Height '], ['No.', 'Param', 'Plot Type', 'ValueColors', 'Height '],
'param', 'parameters', 'param', 'parameters',
resize_content_columns=[0, 3]) resize_content_columns=[0, 3])
value_colors_column = 'valueColors' + self.color_mode
self.insert_sql_template = (f"INSERT INTO Parameters "
f"(param, plotType, {value_colors_column},"
f" height) VALUES (?, ?, ?, ?)")
self.update_sql_template = (f"UPDATE Parameters SET param=?, "
f"plotType=?, {value_colors_column}=?, "
f"height=? "
f"WHERE param='%s'")
self.setWindowTitle("Edit/Add/Delete Parameters") self.setWindowTitle("Edit/Add/Delete Parameters")
self.add_color_selector(color_mode) self.add_color_selector(color_mode)
...@@ -65,10 +73,10 @@ class ParamDialog(UiDBInfoDialog): ...@@ -65,10 +73,10 @@ class ParamDialog(UiDBInfoDialog):
:param fk: bool: True if there is a foreign constrain that prevents the :param fk: bool: True if there is a foreign constrain that prevents the
row to be deleted row to be deleted
""" """
self.add_widget(None, row_idx, 0) # No. self.add_widget(None, row_idx, 0) # No.
self.add_widget(self.data_list, row_idx, 1, foreign_key=fk) self.add_widget(self.database_rows, row_idx, 1, foreign_key=fk)
plot_type = self.add_widget( plot_type = self.add_widget(
self.data_list, row_idx, 2, self.database_rows, row_idx, 2,
choices=[''] + sorted(plot_functions.keys())) choices=[''] + sorted(plot_functions.keys()))
place_holder_text = "" place_holder_text = ""
if plot_type in self.require_valuecolors_plottypes: if plot_type in self.require_valuecolors_plottypes:
...@@ -81,9 +89,9 @@ class ParamDialog(UiDBInfoDialog): ...@@ -81,9 +89,9 @@ class ParamDialog(UiDBInfoDialog):
place_holder_text = "Ex: 1:R|0:Y" place_holder_text = "Ex: 1:R|0:Y"
elif plot_type == "dotForTime": elif plot_type == "dotForTime":
place_holder_text = "Ex: G" place_holder_text = "Ex: G"
self.add_widget(self.data_list, row_idx, 3, self.add_widget(self.database_rows, row_idx, 3,
place_holder_text=place_holder_text) place_holder_text=place_holder_text)
self.add_widget(self.data_list, row_idx, 4, range_values=[0, 10]) self.add_widget(self.database_rows, row_idx, 4, range_values=[0, 10])
self.add_delete_button_to_row(row_idx, fk) self.add_delete_button_to_row(row_idx, fk)
def get_data_list(self): def get_data_list(self):
...@@ -149,31 +157,6 @@ class ParamDialog(UiDBInfoDialog): ...@@ -149,31 +157,6 @@ class ParamDialog(UiDBInfoDialog):
int(self.data_table_widget.cellWidget(row_idx, 4).value()) int(self.data_table_widget.cellWidget(row_idx, 4).value())
] ]
def update_data(self, row: List, widget_idx: int, list_idx: int) -> int:
"""
Prepare insert, update queries then update data of a row from
self.data_table_widgets' content.
:param row: list - data of a row
:param widget_idx: index of row in self.data_table_widgets
:param list_idx: index of row in self.data_list
"""
# The valueColors for each color mode is stored in a separate column.
# Seeing as we only need one of these columns for a color mode, we only
# pull the needed valueColors column from the database.
value_colors_column = 'valueColors' + self.color_mode
insert_sql = (f"INSERT INTO Parameters "
f"(param, plotType, {value_colors_column}, height) "
f"VALUES"
f"('{row[0]}', '{row[1]}', '{row[2]}', {row[3]})")
update_sql = (f"UPDATE Parameters SET param='{row[0]}', "
f"plotType='{row[1]}', {value_colors_column}='{row[2]}',"
f"height={row[3]} "
f"WHERE param='%s'")
return super().update_data(
row, widget_idx, list_idx, insert_sql, update_sql)
@QtCore.Slot() @QtCore.Slot()
def on_color_mode_changed(self, new_color_mode: ColorMode): def on_color_mode_changed(self, new_color_mode: ColorMode):
""" """
...@@ -181,7 +164,16 @@ class ParamDialog(UiDBInfoDialog): ...@@ -181,7 +164,16 @@ class ParamDialog(UiDBInfoDialog):
:param new_color_mode: the new color mode :param new_color_mode: the new color mode
""" """
old_value_colors_column = 'valueColors' + self.color_mode
self.color_mode = new_color_mode self.color_mode = new_color_mode
new_value_colors_column = 'valueColors' + self.color_mode
self.insert_sql_template = self.insert_sql_template.replace(
old_value_colors_column,
new_value_colors_column)
self.update_sql_template = self.update_sql_template.replace(
old_value_colors_column,
new_value_colors_column)
# Remove all rows in the table while keeping the widths of the columns # Remove all rows in the table while keeping the widths of the columns
# intact # intact
self.data_table_widget.setRowCount(0) self.data_table_widget.setRowCount(0)
......