Skip to content

Commit

Permalink
Redo refreshing chentry table
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymo111 committed Aug 16, 2023
1 parent dedee5a commit f9a35eb
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/nexus/GUI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
from threading import Thread

from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QPushButton, QStatusBar, QTableWidget, QTableWidgetItem, QMainWindow, \
QDialog

Expand Down Expand Up @@ -126,14 +127,33 @@ def start_stop(self):
def refresh(self):
"""Controller for refresh button"""
words = self.temp_freqlog.list_words()
self.chentry_table.setSortingEnabled(False)
i = 0
words_set = set(map(lambda w: w.word, words.copy()))
while i < self.chentry_table.rowCount():
if self.chentry_table.item(i, 0).text() not in words_set:
self.chentry_table.removeRow(i)
i -= 1
i += 1
table_set = set(map(lambda w: self.chentry_table.item(w, 0).text(), range(self.chentry_table.rowCount())))
for word in words:
if word.word not in table_set:
self.chentry_table.insertRow(i)
self.chentry_table.setItem(i, 0, QTableWidgetItem(word.word))
item = QTableWidgetItem()
item.setData(Qt.ItemDataRole.DisplayRole, word.frequency)
self.chentry_table.setItem(i, 1, item)
item = QTableWidgetItem()
item.setData(Qt.ItemDataRole.DisplayRole, word.last_used.isoformat(sep=" ", timespec="seconds"))
self.chentry_table.setItem(
i, 2, item)
item = QTableWidgetItem()
item.setData(Qt.ItemDataRole.DisplayRole, str(word.average_speed)[2:-3])
self.chentry_table.setItem(i, 3, item)

self.chentry_table.setRowCount(len(words))
for i, word in enumerate(words):
self.chentry_table.setItem(i, 0, QTableWidgetItem(word.word))
self.chentry_table.setItem(i, 1, QTableWidgetItem(str(word.frequency)))
self.chentry_table.setItem(
i, 2, QTableWidgetItem(str(word.last_used.isoformat(sep=" ", timespec="seconds"))))
self.chentry_table.setItem(i, 3, QTableWidgetItem(str(word.average_speed)[2:-3]))
self.chentry_table.resizeColumnsToContents()
self.chentry_table.setSortingEnabled(True)
self.statusbar.showMessage(f"Loaded {len(words)} freqlogged words")

def show_banlist(self):
Expand Down

1 comment on commit f9a35eb

@Raymo111
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #19 and #20

Please sign in to comment.