Skip to content
Open
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
24 changes: 12 additions & 12 deletions CustomQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from aqt.utils import showInfo

#Import all of the Qt GUI library
from aqt.qt import *
from aqt.qt import QPalette, QBrush, QColor, QComboBox, QStyledItemDelegate, QEvent, QFontMetrics, QStandardItem, Qt # Qt classes from Anki's qt wrapper


#Taken from: https://gis.stackexchange.com/questions/350148/qcombobox-multiple-selection-pyqt5
Expand All @@ -28,8 +28,8 @@ def __init__(self, *args, **kwargs):
self.setEditable(True)
self.lineEdit().setReadOnly(True)
# Make the lineedit the same color as QPushButton
palette = qApp.palette()
palette.setBrush(QPalette.Base, palette.button())
palette = mw.palette()
palette.setBrush(QPalette.ColorRole.Base, palette.button())
self.lineEdit().setPalette(palette)

# Use custom delegate
Expand All @@ -53,7 +53,7 @@ def resizeEvent(self, event):
def eventFilter(self, object, event):

if object == self.lineEdit():
if event.type() == QEvent.MouseButtonRelease:
if event.type() == QEvent.Type.MouseButtonRelease:
if self.closeOnLineEditClick:
self.hidePopup()
else:
Expand All @@ -62,14 +62,14 @@ def eventFilter(self, object, event):
return False

if object == self.view().viewport():
if event.type() == QEvent.MouseButtonRelease:
if event.type() == QEvent.Type.MouseButtonRelease:
index = self.view().indexAt(event.pos())
item = self.model().item(index.row())

if item.checkState() == Qt.Checked:
item.setCheckState(Qt.Unchecked)
if item.checkState() == Qt.CheckState.Checked:
item.setCheckState(Qt.CheckState.Unchecked)
else:
item.setCheckState(Qt.Checked)
item.setCheckState(Qt.CheckState.Checked)
return True
return False

Expand All @@ -93,13 +93,13 @@ def timerEvent(self, event):
def updateText(self):
texts = []
for i in range(self.model().rowCount()):
if self.model().item(i).checkState() == Qt.Checked:
if self.model().item(i).checkState() == Qt.CheckState.Checked:
texts.append(self.model().item(i).text())
text = ", ".join(texts)

# Compute elided text (with "...")
metrics = QFontMetrics(self.lineEdit().font())
elidedText = metrics.elidedText(text, Qt.ElideRight, self.lineEdit().width())
elidedText = metrics.elidedText(text, Qt.TextElideMode.ElideRight, self.lineEdit().width())
self.lineEdit().setText(elidedText)

def addItem(self, text, data=None):
Expand All @@ -109,8 +109,8 @@ def addItem(self, text, data=None):
item.setData(text)
else:
item.setData(data)
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
item.setData(Qt.Unchecked, Qt.CheckStateRole)
item.setFlags(Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable)
item.setData(Qt.CheckState.Unchecked, Qt.ItemDataRole.CheckStateRole)
self.model().appendRow(item)

def addItems(self, texts, datalist=None):
Expand Down
6 changes: 3 additions & 3 deletions FieldTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def __init__(self, group, *args, **kwargs):
self.addFieldRow()

#Resize the columns
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.Fixed)
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.Stretch)
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
self.horizontalHeader().resizeSection(2, 65)

#Method trigger to update the field in the Comparer object and also adds a new row if the index = row count - 1
Expand Down
6 changes: 3 additions & 3 deletions GroupWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, Comparer, parent, *args, **kwargs):
#Create and add widgets to this layout group window
self.groupNum = self.groupIndex + 1
self.title = QLabel(f"<b>Group {self.groupNum} (G{self.groupNum})</b>", parent)
self.title.setAlignment(Qt.AlignCenter)
self.title.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.addWidget(self.title)

#Add widget to select group type and link trigger method
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self, Comparer, parent, *args, **kwargs):
#Add widget with autocompleter to enter a tag for the duplicate action
self.tagBox = QLineEdit(parent)
completer = QCompleter(self.group.fieldInfo['Tags'].keys(), parent)
completer.setCaseSensitivity(Qt.CaseInsensitive)
completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
self.tagBox.setCompleter(completer)
self.tagBox.setPlaceholderText('Enter an existing tag or a new one.')
self.addWidget(self.tagBox)
Expand Down Expand Up @@ -282,4 +282,4 @@ def setEnabledAll(self, boolean):
self.tagBox.setEnabled(boolean)

self.fieldTableLabel.setEnabled(boolean)
self.fieldTable.setEnabledAll(boolean)
self.fieldTable.setEnabledAll(boolean)
2 changes: 1 addition & 1 deletion MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs):
\nBy default, notes in different groups are marked as duplicates when their fields with the same number matches.\
\nYou can disable this and specificy your own conditions for duplicate notes if you enable \'advanced mode\' below.\
\nHover over \'advanced mode\' or \'RegEx capture\' for more explanation.')
self.intro.setAlignment(Qt.AlignCenter)
self.intro.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.layout.addWidget(self.intro)

#Create Comparer object and then using the Comparer, create subwindows.
Expand Down
16 changes: 8 additions & 8 deletions QueueDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from aqt.utils import showInfo

#Import all of the Qt GUI library
from aqt.qt import *
from aqt.qt import QComboBox, QDialog, QHeaderView, QLabel, QLineEdit, QMessageBox, QPushButton, QTableWidget, QTableWidgetItem, QVBoxLayout, Qt

#Import local .py modules
from . import Utils
Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(self, Comparer, parent, *args, **kwargs):
If you want to change the action for all duplicates in a group at once, close this window, select the appropiate action from the dropdown menu
and reopen this window by pressing 'show duplicates'. If you hover over a duplicate note you will be able to see all of its fields.
Some notes are marked as duplicates multiple times and all of the set actions will therefore be performed upon it.''', self)
self.intro.setAlignment(Qt.AlignCenter)
self.intro.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.layout.addWidget(self.intro)

#Add a table widget to display the queue
Expand Down Expand Up @@ -80,9 +80,9 @@ def __init__(self, Comparer, parent, *args, **kwargs):

#Resize the columns
for groupIndex in range(self.Comparer.groupNum):
self.queueTable.horizontalHeader().setSectionResizeMode(0 + groupIndex*3, QHeaderView.Stretch)
self.queueTable.horizontalHeader().setSectionResizeMode(1 + groupIndex*3, QHeaderView.Fixed)
self.queueTable.horizontalHeader().setSectionResizeMode(2 + groupIndex*3, QHeaderView.Fixed)
self.queueTable.horizontalHeader().setSectionResizeMode(0 + groupIndex*3, QHeaderView.ResizeMode.Stretch)
self.queueTable.horizontalHeader().setSectionResizeMode(1 + groupIndex*3, QHeaderView.ResizeMode.Fixed)
self.queueTable.horizontalHeader().setSectionResizeMode(2 + groupIndex*3, QHeaderView.ResizeMode.Fixed)
self.queueTable.horizontalHeader().resizeSection(1 + groupIndex*3, 105)
self.queueTable.horizontalHeader().resizeSection(2 + groupIndex*3, 105)

Expand Down Expand Up @@ -208,15 +208,15 @@ def updateTextBox(self, rowIndex, groupIndex, textBox, action):
#Method to ask for conformation for performing the actions by creating a message box
def askConfirmation(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Question)
msg.setIcon(QMessageBox.Icon.Question)
msg.setText("All actions have been set and are ready to be performed.")
msg.setInformativeText("Are you sure you want to perform the set actions on the notes?")
msg.setWindowTitle("Confirmation")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)
res = msg.exec()

#When the user agrees, close the current window
#and perform the actions
if res == QMessageBox.Ok:
if res == QMessageBox.StandardButton.Ok:
self.accept()
self.Comparer.performActions(self.maxRows)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Note Comparer Anki
An anki addon for 2.1 for comparing notes for duplicates.
An anki addon for > 25.09 for comparing notes for duplicates.

## What to use Note Comparer for?
![Main window](/screenshots/main.jpg)
Expand Down