Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10 from AlexRiina/anki-2.1.38
Browse files Browse the repository at this point in the history
Updates for Anki 2.1.38
  • Loading branch information
AlexRiina authored Dec 30, 2020
2 parents 225f4d4 + 5088c6c commit 5fe6748
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ test:
mypy src
python -m doctest src/settings.py
black --check .

develop:
ln -s ${PWD}/src ~/.local/share/Anki2/addons21/$$(basename ${PWD})_develop
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ On linux, with my Anki installation, this can be done by

```sh
git clone [email protected]:AlexRiina/anki_cousins.git
ln -s `pwd`/src ~/.local/share/Anki2/addons21/beta_cousins
cd anki_cousins
make develop
```

To avoid overwriting your main settings while working on this plugin, you can
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[flake8]
select = F,E9

[mypy-PyQt5.*]
ignore_missing_imports = True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="anki_cousins",
version="0.3",
version="0.4",
tests_require=["PyQt5-stubs" "anki", "black", "flake8", "isort", "mypy"],
packages=["src"],
)
5 changes: 1 addition & 4 deletions src/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def show_settings_dialog() -> None:
dialog_layout = QVBoxLayout()
dialog.setLayout(dialog_layout)

note_types = list(col.models.models.values())
note_types = col.models.all()

append = QPushButton("Add rule")

Expand Down Expand Up @@ -108,11 +108,9 @@ def setFieldNames(note_field_input: QComboBox, new_text):
for index in range(note_field_input.count()):
note_field_input.removeItem(0)

print("setting field names for", new_text)
for note_type in note_types:
if note_type["name"] == new_text:
for field in note_type["flds"]:
print("adding", field["name"])
note_field_input.addItem(field["name"])

self._my_note_field = QComboBox()
Expand Down Expand Up @@ -173,7 +171,6 @@ def set_values(self, rule: MatchRule) -> None:

if rule.cousin_field:
self._other_note_field.setCurrentText(rule.cousin_field)
print("loaded cousin field", rule.cousin_field)

if rule.comparison:
self._matcher.setCurrentIndex(self._matcher.findData(rule.comparison))
Expand Down
12 changes: 7 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
QUEUE_TYPE_REV,
QUEUE_TYPE_SIBLING_BURIED,
)
from anki.models import NoteType
from anki.notes import Note
from anki.sched import Scheduler
from anki.schedv2 import Scheduler as SchedulerV2
Expand All @@ -25,7 +24,7 @@


def buryCousins(self: SomeScheduler, card: "Card") -> None:
""" bury related cards that aren't marked as siblings
"""bury related cards that aren't marked as siblings
Same as Anki: always delete from current rehearsal and if bury new / bury
review are set in deck options, bury until tomorrow
Expand All @@ -39,8 +38,9 @@ def buryCousins(self: SomeScheduler, card: "Card") -> None:
my_note = card.note()

def field_value(note, field_name) -> str:
note_type = self.col.models.get(note.mid)
field_number = self.col.models.fieldMap(note_type)[field_name][0]
model = self.col.models.get(note.mid)
assert model
field_number = self.col.models.fieldMap(model)[field_name][0]

return note.fields[field_number]

Expand Down Expand Up @@ -188,7 +188,9 @@ def findDupes(

def extract_field(model_id, field_name) -> Iterable[Tuple[int, str]]:
# type works better in future anki
model: NoteType = self.models.get(model_id)
model = self.models.get(model_id)
assert model # type is optional, but None should never come back

note_ids = self.findNotes(" ".join(search_filters + [f'note:{model["name"]}']))

field_ord: int = next(
Expand Down
21 changes: 12 additions & 9 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ def __init__(self, col):
self.col = col

def load(self) -> List[MatchRule]:
return [self._deserialize_rule(row) for row in self.col.conf.get(self.key, [])]
return [
self._deserialize_rule(row) for row in self.col.get_config(self.key, [])
]

def save(self, match_rules: Iterable[MatchRule]):
self.col.conf[self.key] = sorted(
[
list(self._serialize_rule(match_rule).values())
for match_rule in match_rules
]
self.col.set_config(
self.key,
sorted(
[
list(self._serialize_rule(match_rule).values())
for match_rule in match_rules
]
),
)

self.col.setMod()

@staticmethod
def _deserialize_rule(stored: List[Serializeable]) -> MatchRule:
rule_dict = dict(zip(MatchRule._fields, stored))
Expand Down Expand Up @@ -204,7 +207,7 @@ def _contains(a: List[str], b: List[str], threshold: float):


class _cloze_contained_by:
""" terms in cloze deletion a contained anywhere in b
"""terms in cloze deletion a contained anywhere in b
>>> bool(_cloze_contained_by()(['{{c1::hello}}'], ['test hello test'], 1))
True
Expand Down

0 comments on commit 5fe6748

Please sign in to comment.