-
-
Notifications
You must be signed in to change notification settings - Fork 85
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] Concordance: selection settings #249
Conversation
Codecov Report
@@ Coverage Diff @@
## master #249 +/- ##
=======================================
Coverage 85.04% 85.04%
=======================================
Files 34 34
Lines 1825 1825
Branches 333 333
=======================================
Hits 1552 1552
Misses 238 238
Partials 35 35 |
autocommit = Setting(True) | ||
context_width = Setting(5) | ||
word = Setting("") | ||
# TODO Set selection settings. | ||
word = ContextSetting("b", exclude_metas=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is "b" the default? Please set it to an empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the widget is still WIP, I have not done the cleaning yet. Anyway thanks for the comments.
@@ -85,7 +85,7 @@ def flags(self, _): | |||
return Qt.ItemIsEnabled | Qt.ItemIsSelectable | |||
|
|||
def rowCount(self, parent=None, *args, **kwargs): | |||
return 0 if parent.isValid() or self.word_index is None \ | |||
return 0 if parent and parent.isValid() or self.word_index is None \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still fails if I select some documents in Concordance and then remove the data. It is fixed in #232.
@@ -223,11 +227,15 @@ def set_width(self): | |||
QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) | |||
|
|||
def set_corpus(self, data=None): | |||
self.closeContext() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While at it, would it not make sense to remove the empty line? Or is this intentional?
self.corpus = data | ||
if data is not None and not isinstance(data, Corpus): | ||
self.corpus = Corpus.from_table(data.domain, data) | ||
self.model.set_corpus(self.corpus) | ||
self.update_widget() | ||
self.openContext(self.corpus) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
else: | ||
self.send("Selected Documents", None) | ||
|
||
|
||
def get_selection(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably nitpicking, but perhaps we should move the two selection methods to line 229? Just trying to keep with the structure of the rest of the Text widgets. :)
Also, please remove the double empty lines above and keep double empty lines only before if name.
Doh, sorry, I didn't see the tag. 🙈 Silly me. |
So is this done or do we wait for similar fixes as in #241 (list issue)? |
Rebased. |
@nikicc Please check as well and merge. :) |
@@ -235,12 +239,32 @@ def set_width(self): | |||
self.conc_view.selectionModel().select(sel, | |||
QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) | |||
|
|||
def get_selection(self): | |||
sel = self.conc_view.selectionModel().selection() | |||
selection = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just:
selection = sorted(set(cell.row() for cell in sel.indexes()))
@@ -256,7 +280,7 @@ def set_word_from_input(self, topic): | |||
def set_word(self): | |||
self.model.set_word(self.word) | |||
self.update_widget() | |||
self.commit() | |||
self.set_selection() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this? Currently, if I am inputing different words on input the selection persists which is kind on unintuitive?
Rows selection not finished yet. Waiting for |
We should probably do the same for #256 to avoid problems with selection being stored in context settings. |
@jerneju What is the state of this PR? Is it still WIP? Can we expect to merge soon? |
@ajdapretnar: It is still impossible to implement this since we cannot do it without proper context handler. See my comment above. |
Ok, next step. Is anyone working on the context handler? If not, should we assign? It would be great to finish this before the workshop. |
@@ -173,7 +173,7 @@ class Outputs: | |||
autocommit = Setting(True) | |||
context_width = Setting(5) | |||
word = ContextSetting("", exclude_metas=False) | |||
# TODO Set selection settings (DataHashContextHandler) | |||
selection = Setting([0], schema_only=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we automatically select the first item? Shouldn't we leave the selection empty by defult?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... Perhaps you are right. Selecting the first item only makes sense in Corpus Viewer, but not in Concordance. I'm sorry, this is probably my fault as I said to make it the same as CV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let it be empty.
if self.corpus: | ||
self._set_selection(selection) | ||
else: | ||
self._set_selection([0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, why do we set [0]
as selection if there is no corpus?
def handleNewSignals(self): | ||
selection = self.selection | ||
if self.corpus: | ||
self._set_selection(selection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._set_selection(self.selection)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
def _save_selection(self): | ||
sel = self.conc_view.selectionModel().selection() | ||
selection = sorted(set(cell.row() for cell in sel.indexes())) | ||
if selection: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this if?
@jerneju I added some code that clears selections when words on input change and also did some refactoring. Please check, if everything is OK. Perhaps, @ajdapretnar can you also check this one more time? |
self.set_word() | ||
|
||
@Inputs.query_word | ||
def set_word_from_input(self, topic): | ||
self.Warning.multiple_words_on_input.clear() | ||
if self.is_word_on_input: # word changed, clear selection | ||
self.selected_rows = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why if
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it only resets when we change the input word from one topic to another and not also when we reload the scema and topic is passed on input.
I think that without this when reloading, the selection would be reset before handleNewSignals
would have the chance to set it.
@@ -259,17 +255,21 @@ def _set_selection(self, selection): | |||
def set_corpus(self, data=None): | |||
self.closeContext() | |||
self.corpus = data | |||
if data is not None and not isinstance(data, Corpus): | |||
self.corpus = Corpus.from_table(data.domain, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these two lines should not have been removed. Now the test fails.
@jerneju I removed the test that doesn't apply anymore. Should be fine now. |
Issue
Fixes #217.
Description of changes
Includes