BCDA-APS / mdaviz

Data visualization for mda
https://bcda-aps.github.io/mdaviz/
Other
3 stars 0 forks source link

BUG updateFolderView triggers onFileSelected unexpectedly #138

Open rodolakis opened 1 month ago

rodolakis commented 1 month ago
    def updateFolderView(self):
        """Clear existing data and set new data for the folder tableview"""
        self.mda_folder_tableview.clearContents()
        self.mda_folder_tableview.displayTable()
        model = self.mda_folder_tableview.tableView.model()
        if model is not None and len(self.mdaFileList()) > 0:
            self.mda_folder_tableview.tableView.setFocus()
            selection_model = self.mda_folder_tableview.tableView.selectionModel()
            self.setSelectionModel(selection_model)
            utils.reconnect(self.selectionModel().currentChanged, self.onFileSelected)

This last line triggers onFileSelected (for what appear to be the first file of the previous selected subfolder?); only happens at the third occurrence of changing subfolder in subfolder menu, then second, then every time? Commenting out this line solve the problem but would create more issues (new selection model no longer connected to the new folder table view).

I tried to disconnect the selection model prior to creating the new one but that does not work:

    def updateFolderView(self):
        """Clear existing data and set new data for the folder tableview"""
        if self.selectionModel() is not None:
            try:
                self.selectionModel().currentChanged.disconnect(self.onFileSelected)
            except (TypeError, RuntimeError):
                pass
        self.mda_folder_tableview.clearContents()
        self.mda_folder_tableview.displayTable()
        model = self.mda_folder_tableview.tableView.model()
        if model is not None and len(self.mdaFileList()) > 0:
            self.mda_folder_tableview.tableView.setFocus()
            selection_model = self.mda_folder_tableview.tableView.selectionModel()
            self.setSelectionModel(selection_model)
            self.selectionModel().currentChanged.connect(self.onFileSelected)

To be investigated. @prjemian I think That can be v1.1, not a big deal (does not make the app crash.

rodolakis commented 3 weeks ago

See notes from notebook (page 6/1)