Skip to content

Commit

Permalink
Merge pull request #871 from gem/resize-table
Browse files Browse the repository at this point in the history
Improve the usability of the oq-engine calculations list widget
  • Loading branch information
ptormene authored Oct 4, 2024
2 parents 310fff1 + 60f3e47 commit 820074a
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions svir/dialogs/drive_oq_engine_server_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class DriveOqEngineServerDialog(QDialog, FORM_CLASS):
def __init__(self, iface, viewer_dock, hostname=None):
self.iface = iface
self.viewer_dock = viewer_dock # needed to change the output_type
self.col_widths = [340, 60, 135, 70, 80]
QDialog.__init__(self)
# Set up the user interface from Designer.
self.setupUi(self)
Expand Down Expand Up @@ -190,6 +191,9 @@ def __init__(self, iface, viewer_dock, hostname=None):
self.message_bar = QgsMessageBar(self)
self.layout().insertWidget(0, self.message_bar)

self.calc_list_tbl.horizontalHeader().sectionResized.connect(
self.on_column_resized)

self.engine_version = None
self.num_login_attempts = 0

Expand All @@ -199,6 +203,11 @@ def __init__(self, iface, viewer_dock, hostname=None):
self.is_gui_enabled = False
self.attempt_login()

def on_column_resized(self, index, old_size, new_size):
if index < len(self.col_widths):
# ignoring columns with buttons
self.col_widths[index] = new_size

def on_job_id_chosen(self):
try:
job_id = int(self.retrieve_job_by_id_le.text())
Expand Down Expand Up @@ -347,7 +356,6 @@ def refresh_calc_list(self):
'description', 'id', 'calculation_mode', 'owner', 'status']
col_names = [
'Description', 'Job ID', 'Calculation Mode', 'Owner', 'Status']
col_widths = [340, 60, 135, 70, 80]
if not self.calc_list:
self.calc_list_tbl.blockSignals(True)
if self.calc_list_tbl.rowCount() > 0:
Expand All @@ -359,7 +367,7 @@ def refresh_calc_list(self):
self.calc_list_tbl.setHorizontalHeaderLabels(col_names)
self.calc_list_tbl.horizontalHeader().setStyleSheet(
"font-weight: bold;")
self.set_calc_list_widths(col_widths)
self.set_calc_list_widths(self.col_widths)
self.calc_list_tbl.blockSignals(False)
return False
actions = [
Expand Down Expand Up @@ -432,7 +440,7 @@ def refresh_calc_list(self):
self.calc_list_tbl.setHorizontalHeaderLabels(headers)
self.calc_list_tbl.horizontalHeader().setStyleSheet(
"font-weight: bold;")
self.set_calc_list_widths(col_widths)
self.set_calc_list_widths(self.col_widths)
if self.pointed_calc_id:
self.highlight_and_scroll_to_calc_id(self.pointed_calc_id)
# if a running calculation is selected, the corresponding outputs will
Expand Down Expand Up @@ -759,23 +767,20 @@ def on_same_fs(self, checksum_file_path, ipt_checksum):
else:
return result

@pyqtSlot(int, int, int, int)
def on_calc_list_tbl_currentCellChanged(
self, curr_row, curr_column, prev_row, prev_col):
self.calc_list_tbl.selectRow(curr_row)
# find QTableItem corresponding to that calc_id
@pyqtSlot(int, int)
def on_calc_list_tbl_cellClicked(self, row, column):
calc_id_col_idx = 1
item_calc_id = self.calc_list_tbl.item(curr_row, calc_id_col_idx)
item_calc_id = self.calc_list_tbl.item(row, calc_id_col_idx)
calc_id = int(item_calc_id.text())
if self.pointed_calc_id == calc_id:
# if you click again on the row that was selected, it unselects it
if (self.pointed_calc_id is not None
and self.pointed_calc_id == calc_id):
self.pointed_calc_id = None
self.calc_list_tbl.clearSelection()
else:
self.calc_list_tbl.selectRow(row)
self.pointed_calc_id = calc_id
self.update_output_list(calc_id)
self._set_show_calc_params_btn()
self.update_output_list(calc_id)
self._set_show_calc_params_btn()

def _set_show_calc_params_btn(self):
self.show_calc_params_btn.setEnabled(
Expand Down

0 comments on commit 820074a

Please sign in to comment.