From 97cc2f59a546bc8d5d7117b696863c55c845b530 Mon Sep 17 00:00:00 2001 From: GuyTeichman <48219633+GuyTeichman@users.noreply.github.com> Date: Fri, 6 Sep 2024 19:36:13 +0300 Subject: [PATCH] fixup! transitioned RNAlysis to Qt6 --- rnalysis/gui/gui.py | 64 +++++++++++++++++-------------------- rnalysis/gui/gui_windows.py | 2 +- tests/test_gui.py | 14 ++++---- 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/rnalysis/gui/gui.py b/rnalysis/gui/gui.py index ed506271..714fa6ff 100644 --- a/rnalysis/gui/gui.py +++ b/rnalysis/gui/gui.py @@ -3386,28 +3386,27 @@ def new_table_from_folder_htseqcount(self): def load_multiple_files(self): filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(self, "Choose files") - if filenames: - if len(filenames) > 0: - window = MultiOpenWindow(filenames, self) - accepted = window.exec() - if accepted: - paths, types, names, kwargs = window.result() - tabs_to_close = None - if self.tabs.currentWidget().is_empty(): - tabs_to_close = self.tabs.currentIndex() - - for filename in filenames: - path = paths[filename] - table_type = FILTER_OBJ_TYPES[types[filename]] - name = names[filename] - filter_obj = table_type(path, **kwargs[filename]) - if name == '': - self.new_tab_from_filter_obj(filter_obj, JOB_COUNTER.get_id()) - else: - self.new_tab_from_filter_obj(filter_obj, JOB_COUNTER.get_id(), name) - QtWidgets.QApplication.processEvents() - if tabs_to_close is not None: - self.tabs.removeTab(tabs_to_close) + if len(filenames) > 0: + window = MultiOpenWindow(filenames, self) + accepted = window.exec() + if accepted: + paths, types, names, kwargs = window.result() + tabs_to_close = None + if self.tabs.currentWidget().is_empty(): + tabs_to_close = self.tabs.currentIndex() + + for filename in filenames: + path = paths[filename] + table_type = FILTER_OBJ_TYPES[types[filename]] + name = names[filename] + filter_obj = table_type(path, **kwargs[filename]) + if name == '': + self.new_tab_from_filter_obj(filter_obj, JOB_COUNTER.get_id()) + else: + self.new_tab_from_filter_obj(filter_obj, JOB_COUNTER.get_id(), name) + QtWidgets.QApplication.processEvents() + if tabs_to_close is not None: + self.tabs.removeTab(tabs_to_close) @QtCore.pyqtSlot(filtering.Filter, int, str) @QtCore.pyqtSlot(filtering.Filter, int) @@ -3631,18 +3630,15 @@ def import_pipeline(self): self._import_pipeline_from_str(pipeline_name, content) def import_multiple_gene_sets(self): - dialog = gui_windows.MultiFileSelectionDialog() - accepted = dialog.exec() - if accepted == QtWidgets.QDialog.DialogCode.Accepted: - filenames = dialog.result() - tabs_to_close = None - if len(filenames) > 0 and self.tabs.currentWidget().is_empty(): - tabs_to_close = self.tabs.currentIndex() - for filename in filenames: - gene_set = self._filename_to_gene_set(filename) - self.new_tab_from_gene_set(gene_set, JOB_COUNTER.get_id(), Path(filename).stem) - if tabs_to_close is not None: - self.tabs.removeTab(tabs_to_close) + filenames, _ = QtWidgets.QFileDialog.getOpenFileNames(self, "Choose files") + tabs_to_close = None + if len(filenames) > 0 and self.tabs.currentWidget().is_empty(): + tabs_to_close = self.tabs.currentIndex() + for filename in filenames: + gene_set = self._filename_to_gene_set(filename) + self.new_tab_from_gene_set(gene_set, JOB_COUNTER.get_id(), Path(filename).stem) + if tabs_to_close is not None: + self.tabs.removeTab(tabs_to_close) def import_gene_set(self): filename, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Choose a file", filter= diff --git a/rnalysis/gui/gui_windows.py b/rnalysis/gui/gui_windows.py index 1a953922..666c5fec 100644 --- a/rnalysis/gui/gui_windows.py +++ b/rnalysis/gui/gui_windows.py @@ -419,7 +419,7 @@ def save_settings(self): dbs = [] for i in range(self.appearance_widgets['databases'].count()): item = self.appearance_widgets['databases'].item(i) - if item.checkState(): + if item.checkState() == QtCore.Qt.CheckState.Checked: dbs.append(item.text()) settings.set_gui_settings(font, font_size, theme, dbs, show_tutorial, prompt_report_gen) diff --git a/tests/test_gui.py b/tests/test_gui.py index 15df0631..71a8adec 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -2439,8 +2439,8 @@ def test_MainWindow_multiple_new_tables(main_window, monkeypatch): def mock_exec(self): return True - def mock_multi_selection_result(self): - return filenames + def mock_multi_selection_result(self, _): + return filenames, '' def mock_multi_open_result(self): filename_dict = {fname: fname for fname in filenames} @@ -2451,9 +2451,8 @@ def mock_multi_open_result(self): filenames[2]: {'numerator_name': 'num', 'denominator_name': 'denom'}} return filename_dict, types_dict, names_dict, kwargs_dict - monkeypatch.setattr(gui_windows.MultiFileSelectionDialog, 'exec', mock_exec) monkeypatch.setattr(MultiOpenWindow, 'exec', mock_exec) - monkeypatch.setattr(gui_windows.MultiFileSelectionDialog, 'result', mock_multi_selection_result) + monkeypatch.setattr(QtWidgets.QFileDialog, 'getOpenFileNames', mock_multi_selection_result) monkeypatch.setattr(MultiOpenWindow, 'result', mock_multi_open_result) main_window.new_multiple_action.trigger() @@ -2507,11 +2506,10 @@ def test_MainWindow_import_multiple_gene_sets(main_window_with_tabs, monkeypatch truth_featureset = enrichment.FeatureSet(truth_set, Path(filename).stem) truth.append(truth_featureset) - def mock_get_files(*args, **kwargs): - return filenames + def mock_multi_selection_result(self, _): + return filenames, '' - monkeypatch.setattr(gui_windows.MultiFileSelectionDialog, 'result', mock_get_files) - monkeypatch.setattr(gui_windows.MultiFileSelectionDialog, 'exec', lambda *args, **kwargs: True) + monkeypatch.setattr(QtWidgets.QFileDialog, 'getOpenFileNames', mock_multi_selection_result) main_window_with_tabs.import_multiple_sets_action.trigger() assert main_window_with_tabs.tabs.count() == 5 + len(filenames) assert isinstance(main_window_with_tabs.tabs.currentWidget(), SetTabPage)