Skip to content
Snippets Groups Projects
Commit 98dac4a7 authored by Destiny Kuehn's avatar Destiny Kuehn Committed by Maeva Pourpoint
Browse files

Fix issues #52

parent dc7f5af3
No related branches found
No related tags found
1 merge request!21Fix issues #52
#!/usr/bin/env python
# -*- coding: utf-8 -*-*#
'''
"""
Dialog for selecting channels from a station
Lloyd Carothers
IRIS/PASSCAL
'''
"""
import sys
import os
from PySide6.QtWidgets import (QDialog,
QApplication,
QTableWidgetItem,
)
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QTableWidgetItem
from PySide6.QtUiTools import loadUiType
from .obspyImproved import utc_to_str
def load_ui(filename):
'''
"""
Helper function
Load a ui file relative to this source file
'''
"""
path = os.path.join(os.path.dirname(__file__), filename)
try:
ret = loadUiType(path)
......@@ -33,6 +32,7 @@ def load_ui(filename):
class ChannelSelectDialog(*load_ui('ChannelSelectDialog.ui')):
def __init__(self, station, parent=None):
self.station = station
self.chan_map = {}
super().__init__(parent)
self.setupUi()
......@@ -43,13 +43,26 @@ class ChannelSelectDialog(*load_ui('ChannelSelectDialog.ui')):
self.selected_channels.append(self.chan_map[row])
super().accept()
def sort_table(self, column):
"""
Sort Channel Select Dialog table based on column
header selected by user.
"""
row_map = {0: 'location_code', 1: 'code', 2: 'sample_rate',
3: 'start_date', 4: 'end_date'}
order = self.tableWidget.horizontalHeader().sortIndicatorOrder()
descending = False if order == Qt.AscendingOrder else True
self.chan_map = {ind: v for ind, (_, v) in enumerate(sorted(self.chan_map.items(),
key=lambda item: getattr(item[1], row_map[column]),
reverse=descending))}
def setupUi(self):
super().setupUi(self)
self.setWindowTitle('Select channels')
self.label.setText('Station: {}'.format(self.station.code))
self.tableWidget.setRowCount(len(self.station))
self.tableWidget.horizontalHeader().sectionClicked.connect(self.sort_table)
# Add channels
self.chan_map = {}
for row, chan in enumerate(self.station):
for col, value in enumerate(
('{:>2s}'.format(chan.location_code),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment