Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Keywords: Fix selection and use idClicked instead of buttonClicked #965

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions orangecontrib/text/widgets/owkeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _setup_gui(self):
button.setChecked(method == self.sel_method)
grid.addWidget(button, method, 0)
self.__sel_method_buttons.addButton(button, method)
self.__sel_method_buttons.buttonClicked.connect(self._set_selection_method)
self.__sel_method_buttons.idClicked.connect(self._set_selection_method)

spin = gui.spin(
box, self, "n_selected", 1, 999, addToLayout=False,
Expand Down Expand Up @@ -389,9 +389,9 @@ def update_scores(self):
self.start(run, self.corpus, self.words, self.__cached_keywords,
self.selected_scoring_methods, kwargs, self.agg_method)

def _set_selection_method(self):
self.sel_method = self.__sel_method_buttons.checkedId()
self.__sel_method_buttons.button(self.sel_method).setChecked(True)
def _set_selection_method(self, method: int):
self.sel_method = method
self.__sel_method_buttons.button(method).setChecked(True)
self._select_rows()

def _select_rows(self):
Expand Down
46 changes: 45 additions & 1 deletion orangecontrib/text/widgets/tests/test_owkeywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import Mock, patch

import numpy as np
from AnyQt.QtCore import QItemSelectionModel
from AnyQt.QtWidgets import QCheckBox

from Orange.data import Table
Expand All @@ -13,7 +14,7 @@
rake_keywords
from orangecontrib.text.preprocess import *
from orangecontrib.text.widgets.owkeywords import OWKeywords, run, \
AggregationMethods, ScoringMethods
AggregationMethods, ScoringMethods, SelectionMethods
from orangecontrib.text.widgets.utils.words import create_words_table


Expand Down Expand Up @@ -230,6 +231,49 @@ def test_send_report(self):
self.send_signal(self.widget.Inputs.corpus, None)
self.widget.send_report()

def test_selection_none(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
radio_buttons = self.widget._OWKeywords__sel_method_buttons
radio_buttons.button(SelectionMethods.NONE).click()

output = self.get_output(self.widget.Outputs.words)
self.assertIsNone(output)

def tests_selection_all(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
radio_buttons = self.widget._OWKeywords__sel_method_buttons
radio_buttons.button(SelectionMethods.ALL).click()

output = self.get_output(self.widget.Outputs.words)
self.assertEqual(42, len(output))

def test_selection_manual(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
self.wait_until_finished()
radio_buttons = self.widget._OWKeywords__sel_method_buttons
radio_buttons.button(SelectionMethods.MANUAL).click()

mode = QItemSelectionModel.Rows | QItemSelectionModel.Select
self.widget.view.clearSelection()
model = self.widget.view.model()
self.widget.view.selectionModel().select(model.index(2, 0), mode)
self.widget.view.selectionModel().select(model.index(3, 0), mode)

output = self.get_output(self.widget.Outputs.words)
self.assertEqual(2, len(output))

def test_selection_n_best(self):
self.send_signal(self.widget.Inputs.corpus, self.corpus)
radio_buttons = self.widget._OWKeywords__sel_method_buttons
radio_buttons.button(SelectionMethods.N_BEST).click()

output = self.get_output(self.widget.Outputs.words)
self.assertEqual(3, len(output))

self.widget.controls.n_selected.setValue(5)
output = self.get_output(self.widget.Outputs.words)
self.assertEqual(5, len(output))


if __name__ == "__main__":
unittest.main()