Skip to content

Commit

Permalink
fixup! transitioned RNAlysis to Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyTeichman committed Sep 7, 2024
1 parent 2bfa4ae commit 97cc2f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
64 changes: 30 additions & 34 deletions rnalysis/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion rnalysis/gui/gui_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 6 additions & 8 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 97cc2f5

Please sign in to comment.