class LineListsWindow(UiLinelistsWindow): def __init__(self, plot_window, parent=None): super(LineListsWindow, self).__init__() # Builds GUI self._main_window = QMainWindow() self.setupUi(self._main_window, str(plot_window)) # Request that line lists be read from wherever are they sources. dispatch.on_request_linelists.emit() self.buildViews(plot_window) # Connect buttons to appropriate signals. # # Note that, for the Draw operation, we have to pass the table views to # the handler, even though it would be better to handle the row selections # all in here for the sake of encapsulation. This is so because this class # is not a QWidget or one of its subclasses, thus it cannot implement a # DispatchHandle signal handler. self.draw_button.clicked.connect(lambda: dispatch.on_plot_linelists. emit(table_views=self._table_views)) self.erase_button.clicked.connect(dispatch.on_erase_linelabels.emit) self.dismiss_button.clicked.connect( dispatch.on_dismiss_linelists_window.emit) def buildViews(self, plot_window): # Table views must be preserved in the instance so they can be # passed to whoever is going to do the actual line list plotting. # The plotting code must know which lines (table rows) are selected # in each line list. self._table_views = [] for linelist in plot_window.linelists: table_model = LineListTableModel(linelist) proxy = SortModel(table_model.getName()) proxy.setSourceModel(table_model) if table_model.rowCount() > 0: table_view = QTableView() table_view.setModel(proxy) # setting this to False will significantly speed up # the loading of very large line lists. However, these # lists are often jumbled in wavelength, and consequently # difficult to read and use. It remains to be seen what # would be the approach users will favor. table_view.setSortingEnabled(True) table_view.setSelectionBehavior(QAbstractItemView.SelectRows) table_view.horizontalHeader().setStretchLastSection(True) table_view.resizeColumnsToContents() comments = linelist.meta['comments'] # this preserves the original sorting state # of the list. Use zero to sort by wavelength # on load. Doesn't seem to affect performance # by much tough. proxy.sort(-1, Qt.AscendingOrder) pane = self._buildLinelistPane(table_view, comments) self.tabWidget.addTab(pane, table_model.getName()) self._table_views.append(table_view) def show(self): self._main_window.show() def hide(self): self._main_window.hide() def _buildLinelistPane(self, table, comments): pane = QWidget() layout = QVBoxLayout() layout.setSizeConstraint(QLayout.SetMaximumSize) info = QTextBrowser() info.setMaximumHeight(100) info.setAutoFillBackground(True) info.setStyleSheet("background-color: rgb(230,230,230);") for comment in comments: info.append(comment) layout.addWidget(info) layout.addWidget(table) pane.setLayout(layout) return pane