Skip to content

Commit

Permalink
Work Area: Fix Work Area - Search in results - Clear highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
BLKSerene committed Jan 5, 2025
1 parent a6454df commit 1650efb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Work Area: Fix Wordlist Generator - Filter results - Number of syllables
- Work Area: Fix Wordlist Generator - Syllabification
- Work Area: Fix Work Area - Filter results - File to filter
- Work Area: Fix Work Area - Search in results - Clear highlights

### ❌ Removals
- Measures: Remove effect size - Log-frequency biased MD / Mutual Dependency
Expand Down
49 changes: 24 additions & 25 deletions wordless/wl_results/wl_results_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ def find_next(self):
if self.items_found:
selected_rows = []

for table in self.tables:
table.disable_updates()

for table in self.tables:
if table.get_selected_rows():
selected_rows = [id(table), table.get_selected_rows()]
Expand Down Expand Up @@ -231,19 +228,13 @@ def find_next(self):
self.tables[0].scrollTo(table.model().index(self.items_found[0][1], 0))
self.tables[0].selectRow(self.items_found[0][1])

for table in self.tables:
table.enable_updates()

@wl_misc.log_time
def find_prev(self):
self.find_all()

if self.items_found:
selected_rows = []

for table in self.tables:
table.disable_updates()

for table in self.tables:
if table.get_selected_rows():
selected_rows = [id(table), table.get_selected_rows()]
Expand Down Expand Up @@ -276,9 +267,6 @@ def find_prev(self):
self.tables[-1].scrollTo(table.model().index(self.items_found[-1][1], 0))
self.tables[-1].selectRow(self.items_found[-1][1])

for table in self.tables:
table.enable_updates()

@wl_misc.log_time
def find_all(self):
# Search only when there are no search history or search settings have been changed
Expand Down Expand Up @@ -338,27 +326,29 @@ def clr_highlights(self):
for table in self.tables:
table.disable_updates()

for table, row, col in self.items_found:
if table.indexWidget(table.model().index(row, col)):
table.indexWidget(table.model().index(row, col)).setStyleSheet('border: 0')
# Skip if the found item no longer exist (eg. the table has been re-generated)
elif table.model().item(row, col):
table.model().item(row, col).setForeground(QBrush(QColor(table.default_foreground)))
table.model().item(row, col).setBackground(QBrush(QColor(table.default_background)))
# Clear highlights for every cell since indexes of items found would be changed after sorting
for table in self.tables:
for row in range(table.model().rowCount()):
for col in range(table.model().columnCount()):
if table.indexWidget(table.model().index(row, col)):
table.indexWidget(table.model().index(row, col)).setStyleSheet('border: 0')
else:
table.model().item(row, col).setForeground(QBrush(QColor(table.default_foreground)))
table.model().item(row, col).setBackground(QBrush(QColor(table.default_background)))

for table in self.tables:
table.enable_updates()
table.enable_updates(emit_signals = False)

self.clr_history()

self.main.statusBar().showMessage(self.tr('Highlights cleared.'))

self.button_clr_hightlights.setEnabled(False)

def clr_history(self):
self.last_search_settings.clear()
self.items_found.clear()

self.button_clr_hightlights.setEnabled(False)

class Wl_Worker_Results_Search(wl_threading.Wl_Worker):
def run(self):
for table in self.dialog.tables:
Expand Down Expand Up @@ -406,14 +396,23 @@ def run(self):

search_terms |= set(search_terms_file)

for search_term in search_terms:
len_search_term = len(search_term)
lens_search_terms = [len(search_term) for search_term in search_terms]

for (row, col), text in results.items():
matched = False

for (row, col), text in results.items():
for search_term, len_search_term in zip(search_terms, lens_search_terms):
for ngram in wl_nlp_utils.ngrams(text, len_search_term):
if ngram == tuple(search_term):
self.dialog.items_found.append([table, row, col])

matched = True

break

if matched:
break

self.dialog.items_found = sorted(
self.dialog.items_found,
key = lambda item: (id(item[0]), item[1], item[2])
Expand Down
6 changes: 3 additions & 3 deletions wordless/wl_results/wl_results_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def update_gui(self, results):

results.sort(key = lambda item, span = span: item[2].tokens_raw[span - 1], reverse = reverse)

# Clear highlights before sorting the results
self.table.dialog_results_search.clr_highlights()

self.table.disable_updates()

color_settings = self.main.settings_custom['tables']['concordancer']['sorting_settings']['highlight_colors']
Expand Down Expand Up @@ -240,9 +243,6 @@ def update_gui(self, results):
self.table.set_item_num_val(row, 11, no_para_pct)
self.table.model().item(row, 12).setText(file)

# Clear highlights
self.table.dialog_results_search.clr_highlights()

self.table.enable_updates(emit_signals = False)

class Wl_Table_Results_Sort_Conordancer(wl_tables.Wl_Table_Add_Ins_Del_Clr):
Expand Down
6 changes: 3 additions & 3 deletions wordless/wl_widgets/wl_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,10 @@ def enable_updates(self, emit_signals = True):
self.selectionModel().blockSignals(False)
self.show()

self.horizontalHeader().sectionCountChanged.emit(self.num_cols_old, self.model().columnCount())
self.verticalHeader().sectionCountChanged.emit(self.num_rows_old, self.model().rowCount())

if emit_signals:
self.horizontalHeader().sectionCountChanged.emit(self.num_cols_old, self.model().columnCount())
self.verticalHeader().sectionCountChanged.emit(self.num_rows_old, self.model().rowCount())

self.model().itemChanged.emit(QStandardItem())
self.selectionModel().selectionChanged.emit(QItemSelection(), QItemSelection())

Expand Down

0 comments on commit 1650efb

Please sign in to comment.