Skip to content

Commit

Permalink
Merge pull request #1052 from ajdapretnar/word-list-copy
Browse files Browse the repository at this point in the history
Word List: Add option to copy a list
  • Loading branch information
VesnaT authored Apr 2, 2024
2 parents 6aad2ad + 0eea91c commit f73d42f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
16 changes: 15 additions & 1 deletion orangecontrib/text/widgets/owwordlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ def _setup_library_box(self):
action.triggered.connect(self.__on_remove_word_list)
actions_widget.addAction(action)

action = QAction("C", self)
action.setToolTip("Copy word list from library")
action.triggered.connect(self.__on_copy_word_list)
actions_widget.addAction(action)

action = QAction("Update", self)
action.setToolTip("Save changes in the editor to library")
action.setShortcut(QKeySequence(QKeySequence.Save))
Expand Down Expand Up @@ -278,7 +283,7 @@ def __on_library_selection_changed(self, selected: QItemSelection, *_):
def __on_add_word_list(self):
taken = [l.name for l in self.library_model]
name = WordList.generate_word_list_name(taken)
word_list = WordList(name, self.words_model[:])
word_list = WordList(name, [])
self.library_model.append(word_list)
self._set_selected_word_list(len(self.library_model) - 1)

Expand All @@ -289,6 +294,15 @@ def __on_remove_word_list(self):
self._set_selected_word_list(max(index - 1, 0))
self._apply_update_rule()

def __on_copy_word_list(self):
index = self._get_selected_word_list_index()
if index is not None:
taken = [l.name for l in self.library_model]
name = WordList.generate_word_list_name(taken)
word_list = WordList(name, self.words_model[:])
self.library_model.append(word_list)
self._set_selected_word_list(len(self.library_model) - 1)

def __on_update_word_list(self):
self._set_word_list_modified(mod_type=self.LIBRARY)

Expand Down
13 changes: 12 additions & 1 deletion orangecontrib/text/widgets/tests/test_owwordlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_library_add(self):
sel_words = self.widget._get_selected_words_indices()
self.assertEqual(sel_wlist, 2)
self.assertListEqual(sel_words, [])
self.assertListEqual(self.widget.words_model[:], self._word_list_1)
self.assertListEqual(self.widget.words_model[:], [])

self.widget._set_selected_word_list(1)
self.assertListEqual(self.widget.words_model[:], self._word_list_2)
Expand All @@ -179,6 +179,17 @@ def test_library_remove(self):
self.assertIsNone(sel_wlist, 0)
self.assertListEqual(sel_words, [])

def test_library_copy(self):
self.assertEqual(self.widget.library_model.rowCount(), 2)
self.widget._OWWordList__on_copy_word_list()
self.assertEqual(self.widget.library_model.rowCount(), 3)
self.assertEqual(self.widget.words_model.rowCount(), 3)
settings = self.widget.settingsHandler.pack_data(self.widget)
self.assertEqual(settings["word_list_library"][0]["words"],
settings["word_list_library"][2]["words"])
self.assertNotEqual(settings["word_list_library"][1]["words"],
settings["word_list_library"][2]["words"])

def test_library_update(self):
self.assertEqual(self.widget._get_selected_word_list_index(), 0)
model = self.widget.words_model
Expand Down

0 comments on commit f73d42f

Please sign in to comment.