Skip to content
Snippets Groups Projects
Commit 4bd3991e authored by Maeva Pourpoint's avatar Maeva Pourpoint
Browse files

Loop over columns in Station Select Window

parent a681a793
No related branches found
No related tags found
1 merge request!27Fix to issue 34: Allow user to copy datalogger type, gain and sensor type to other stations
...@@ -5,11 +5,10 @@ Dialog for selecting stations to copy ...@@ -5,11 +5,10 @@ Dialog for selecting stations to copy
Datalogger Type, Sensor Type and Gain Datalogger Type, Sensor Type and Gain
""" """
import sys
import os import os
from PySide6.QtGui import QFont, QFontMetrics, Qt from PySide6.QtGui import QFontMetrics, Qt
from PySide6.QtWidgets import QApplication, QTableWidgetItem, QAbstractItemView from PySide6.QtWidgets import QTableWidgetItem, QAbstractItemView, QHeaderView
from PySide6.QtUiTools import loadUiType from PySide6.QtUiTools import loadUiType
from .obspyImproved import utc_to_str from .obspyImproved import utc_to_str
...@@ -31,7 +30,7 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')): ...@@ -31,7 +30,7 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')):
def __init__(self, stations, action, values, parent=None): def __init__(self, stations, action, values, parent=None):
super().__init__(parent) super().__init__(parent)
self.stations = stations self.stations = stations
self.stat_map = {} self.sta_map = {}
self.action = action self.action = action
self.values = values self.values = values
self.setupUi() self.setupUi()
...@@ -40,7 +39,7 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')): ...@@ -40,7 +39,7 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')):
rows = set(item.row() for item in self.tableWidget.selectedItems()) rows = set(item.row() for item in self.tableWidget.selectedItems())
self.selected_stations = [] self.selected_stations = []
for row in rows: for row in rows:
self.selected_stations.append(self.stat_map[row]) self.selected_stations.append(self.sta_map[row])
super().accept() super().accept()
def sort_table(self, column): def sort_table(self, column):
...@@ -51,15 +50,13 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')): ...@@ -51,15 +50,13 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')):
row_map = {0: 'code', 1: 'start_date', 2: 'end_date'} row_map = {0: 'code', 1: 'start_date', 2: 'end_date'}
order = self.tableWidget.horizontalHeader().sortIndicatorOrder() order = self.tableWidget.horizontalHeader().sortIndicatorOrder()
descending = False if order == Qt.AscendingOrder else True descending = False if order == Qt.AscendingOrder else True
self.stat_map = {ind: v for ind, (_, v) in enumerate(sorted(self.stat_map.items(), self.sta_map = {ind: v for ind, (_, v) in enumerate(sorted(self.sta_map.items(),
key=lambda item: getattr(item[1], row_map[column]), key=lambda item: getattr(item[1], row_map[column]),
reverse=descending))} reverse=descending))}
def setupUi(self): def setupUi(self):
super().setupUi(self) super().setupUi(self)
self.setWindowTitle('Select Stations') self.setWindowTitle('Select Stations')
self.tableWidget.setSelectionMode(QAbstractItemView.ExtendedSelection)
if self.action == 'type & gain': if self.action == 'type & gain':
self.uiGainCB.setChecked(True) self.uiGainCB.setChecked(True)
self.uiGainCB.setText(f"Copy Datalogger Gain: {self.values[0]}") self.uiGainCB.setText(f"Copy Datalogger Gain: {self.values[0]}")
...@@ -74,31 +71,21 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')): ...@@ -74,31 +71,21 @@ class StationSelectDialog(*load_ui('StationSelectDialog.ui')):
self.tableWidget.setRowCount(len(self.stations)) self.tableWidget.setRowCount(len(self.stations))
self.tableWidget.horizontalHeader().sectionClicked.connect(self.sort_table) self.tableWidget.horizontalHeader().sectionClicked.connect(self.sort_table)
# Add stations to table # Add stations to table
for row, stat in enumerate(self.stations): for row, sta in enumerate(self.stations):
self.tableWidget.setItem( for col, value in enumerate(('{:<3s}'.format(sta.code),
row, 0, QTableWidgetItem('{:<3s}'.format(stat.code))) utc_to_str(sta.start_date),
utc_to_str(sta.end_date))):
# full start/time item = QTableWidgetItem()
start_date = utc_to_str(stat.start_date) item.setText(value)
start_item = QTableWidgetItem() # shorten start/end time
start_item.setToolTip(start_date) if col == 1 or col == 2:
# shortened start/time # full time as tooltip
start_date = QFontMetrics(QFont()).elidedText( item.setToolTip(value)
start_date, Qt.ElideRight, 100) # rounded time in table
start_item.setText(start_date) value = QFontMetrics(self.tableWidget.font()).elidedText(value,
self.tableWidget.setItem( Qt.ElideRight,
row, 1, start_item) 100)
item.setText(value)
# full start/time self.tableWidget.setItem(row, col, item)
end_date = utc_to_str(stat.end_date) self.sta_map[row] = sta
end_item = QTableWidgetItem()
end_item.setToolTip(end_date)
# shortened start/time
end_date = QFontMetrics(QFont()).elidedText(
end_date, Qt.ElideRight, 100)
end_item.setText(end_date)
self.tableWidget.setItem(
row, 2, end_item)
self.stat_map[row] = stat
self.tableWidget.resizeColumnsToContents() self.tableWidget.resizeColumnsToContents()
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