Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Improvements to eliminate deprecated API usages and the logged warnings for them #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions chinese/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def onToggle(self, editor):
config.save()

def updateButton(self, editor):
enabled = str(editor.note.model()['id']) in config['enabledModels']
enabled = str(editor.note.note_type()['id']) in config['enabledModels']

if (enabled and not self.buttonOn) or (not enabled and self.buttonOn):
editor.web.eval('toggleEditorButton(chineseSupport);')
Expand All @@ -68,7 +68,7 @@ def onFocusLost(self, _, note, index):
if not self.buttonOn:
return False

allFields = mw.col.models.fieldNames(note.model())
allFields = mw.col.models.field_names(note.note_type())
field = allFields[index]

if update_fields(note, field, allFields):
Expand All @@ -83,7 +83,7 @@ def onFocusLost(self, _, note, index):
def append_tone_styling(editor):
js = 'var css = document.styleSheets[0];'

for line in editor.note.model()['css'].split('\n'):
for line in editor.note.note_type()['css'].split('\n'):
if line.startswith('.tone'):
js += 'css.insertRule("{}", css.cssRules.length);'.format(
line.rstrip())
Expand Down
20 changes: 10 additions & 10 deletions chinese/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,24 @@ def load_menu():
)

add_menu('Chinese::Bulk Fill')
add_menu_item('Chinese::Bulk Fill', _('Hanzi'), bulk_fill_hanzi)
Copy link
Author

Choose a reason for hiding this comment

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

For these removals of the usage of _(), please note this change in Anki
You will see that the function does nothing, and simply triggers a print to stdout to warn about its deprecation, so the removal should have no effect.

add_menu_item('Chinese::Bulk Fill', 'Hanzi', bulk_fill_hanzi)
add_menu_item(
'Chinese::Bulk Fill', _('Transcription'), bulk_fill_transcript
'Chinese::Bulk Fill', 'Transcription', bulk_fill_transcript
)
add_menu_item('Chinese::Bulk Fill', _('Definitions'), bulk_fill_defs)
add_menu_item('Chinese::Bulk Fill', _('Classifiers'), bulk_fill_classifiers)
add_menu_item('Chinese::Bulk Fill', _('Sound'), bulk_fill_sound)
add_menu_item('Chinese::Bulk Fill', _('Silhouette'), bulk_fill_silhouette)
add_menu_item('Chinese::Bulk Fill', _('Usage'), bulk_fill_usage)
add_menu_item('Chinese::Bulk Fill', _('All'), bulk_fill_all)
add_menu_item('Chinese::Bulk Fill', 'Definitions', bulk_fill_defs)
add_menu_item('Chinese::Bulk Fill', 'Classifiers', bulk_fill_classifiers)
add_menu_item('Chinese::Bulk Fill', 'Sound', bulk_fill_sound)
add_menu_item('Chinese::Bulk Fill', 'Silhouette', bulk_fill_silhouette)
add_menu_item('Chinese::Bulk Fill', 'Usage', bulk_fill_usage)
add_menu_item('Chinese::Bulk Fill', 'All', bulk_fill_all)

add_menu('Chinese::Help')
add_menu_item(
'Chinese::Help',
_('Report a bug or make a feature request'),
'Report a bug or make a feature request',
lambda: openLink(CSR_GITHUB_URL + '/issues'),
)
add_menu_item('Chinese::Help', _('About...'), showAbout)
add_menu_item('Chinese::Help', 'About...', showAbout)


def unload_menu():
Expand Down
4 changes: 2 additions & 2 deletions chinese/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def load():
def add_models():
models.append(('Chinese (Advanced)', advanced.add_model))
models.append(('Chinese (Basic)', basic.add_model))
if not mw.col.models.byName('Chinese (Advanced)'):
if not mw.col.models.by_name('Chinese (Advanced)'):
advanced.add_model(mw.col)
if not mw.col.models.byName('Chinese (Basic)'):
if not mw.col.models.by_name('Chinese (Basic)'):
basic.add_model(mw.col)
2 changes: 1 addition & 1 deletion chinese/templates/chinese_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import re
from anki import hooks
from anki.utils import stripHTML
from anki.utils import strip_html as stripHTML
Copy link
Contributor

@3ter 3ter Nov 6, 2022

Choose a reason for hiding this comment

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

Good work on tackling the deprecations!

I suggest here to use the default provided by the ankitects (strip_html) and change the function calls inside the code accordingly.
It's best not to confuse and another dev might think: Why, there is a deprecation let's fix it... ah, they just kept the old name, figures.

By the way. Could it be that @luoliyan or @joeminicucci need more collaborators to check the PRs and all? I would volunteer having been using this addon for a long time and also am collaborating to other Anki addons (namely https://github.com/zjosua/anki-mc/issues, which is much simpler admittedly 🙂).

from anki.template import TemplateRenderContext
from .ruby import ruby_top, ruby_top_text, ruby_bottom_text, no_sound

Expand Down