Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Apr 4, 2024
1 parent c9d563a commit b98330d
Show file tree
Hide file tree
Showing 33 changed files with 398 additions and 388 deletions.
4 changes: 2 additions & 2 deletions bulk_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def bulk_add_readings(nids: Sequence[NoteId], parent: Browser) -> None:
parent=parent,
title="Tasks done",
textFormat="rich",
text=f"Processed {len(nids)} selected notes."
text=f"Processed {len(nids)} selected notes.",
)
).run_in_background()


def setup_browser_menu(browser: Browser):
""" Add menu entry to browser window """
"""Add menu entry to browser window"""
action = QAction(ACTION_NAME, browser)
qconnect(action.triggered, lambda: bulk_add_readings(browser.selectedNotes(), parent=browser))
browser.form.menuEdit.addAction(action)
Expand Down
116 changes: 58 additions & 58 deletions config_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def split_words(config_value: str) -> list[str]:
"""Splits string by comma."""
return re.split(r'[、, ]+', config_value, flags=RE_FLAGS)
return re.split(r"[、, ]+", config_value, flags=RE_FLAGS)


class ConfigViewBase(AddonConfigManager):
Expand All @@ -37,24 +37,24 @@ def write_config(self):


class WordBlockListManager(ConfigViewBase):
_NUMBERS = re.compile(r'[一二三四五六七八九十01234567890123456789]+')
_NUMBERS = re.compile(r"[一二三四五六七八九十01234567890123456789]+")

@property
def _should_skip_numbers(self) -> bool:
return self['skip_numbers'] is True
return self["skip_numbers"] is True

@property
def blocklisted_words(self) -> list[str]:
"""Returns a user-defined list of blocklisted words."""
return split_words(self['blocklisted_words'])
return split_words(self["blocklisted_words"])

def is_blocklisted(self, word: str) -> bool:
"""Returns True if the user specified that the word should not be looked up."""

return (
to_katakana(word) in map(to_katakana, self.blocklisted_words)
or (self._should_skip_numbers and re.fullmatch(self._NUMBERS, word))
)
if to_katakana(word) in map(to_katakana, self.blocklisted_words):
return True
if self._should_skip_numbers and re.fullmatch(self._NUMBERS, word):
return True
return False


@enum.unique
Expand All @@ -67,78 +67,78 @@ class ReadingsDiscardMode(enum.Enum):
class PitchAndFuriganaCommon(WordBlockListManager):
@property
def maximum_results(self) -> int:
return int(self['maximum_results'])
return int(self["maximum_results"])

@property
def reading_separator(self) -> str:
return self['reading_separator']
return self["reading_separator"]

@property
def discard_mode(self) -> ReadingsDiscardMode:
return ReadingsDiscardMode[self['discard_mode']]
return ReadingsDiscardMode[self["discard_mode"]]


@final
class FuriganaConfigView(PitchAndFuriganaCommon):
_view_key = 'furigana'
_view_key = "furigana"

@property
def prefer_literal_pronunciation(self) -> bool:
return self['prefer_literal_pronunciation'] is True
return self["prefer_literal_pronunciation"] is True

@property
def mecab_only(self) -> list[str]:
"""Words that shouldn't be looked up in the accent dictionary."""
return split_words(self['mecab_only'])
return split_words(self["mecab_only"])

def can_lookup_in_db(self, word: str) -> bool:
return self.maximum_results > 1 and word not in self.mecab_only


@final
class PitchConfigView(PitchAndFuriganaCommon):
_view_key = 'pitch_accent'
_view_key = "pitch_accent"

@property
def lookup_shortcut(self) -> str:
return self['lookup_shortcut']
return self["lookup_shortcut"]

@property
def output_hiragana(self) -> bool:
return self['output_hiragana'] is True
return self["output_hiragana"] is True

@property
def kana_lookups(self) -> bool:
return self['kana_lookups'] is True
return self["kana_lookups"] is True

@property
def word_separator(self) -> str:
return self['word_separator']
return self["word_separator"]

@property
def style(self) -> PitchPatternStyle:
return PitchPatternStyle[self['style']]
return PitchPatternStyle[self["style"]]


@final
class ContextMenuConfigView(ConfigViewBase):
_view_key = 'context_menu'
_view_key = "context_menu"

@property
def generate_furigana(self) -> bool:
return self['generate_furigana'] is True
return self["generate_furigana"] is True

@property
def to_katakana(self) -> bool:
return self['to_katakana'] is True
return self["to_katakana"] is True

@property
def to_hiragana(self) -> bool:
return self['to_hiragana'] is True
return self["to_hiragana"] is True

@property
def literal_pronunciation(self) -> bool:
return self['literal_pronunciation'] is True
return self["literal_pronunciation"] is True


class ToolbarButtonConfig(NamedTuple):
Expand All @@ -149,7 +149,7 @@ class ToolbarButtonConfig(NamedTuple):

@final
class ToolbarConfigView(ConfigViewBase):
_view_key = 'toolbar'
_view_key = "toolbar"

def __getitem__(self, item) -> ToolbarButtonConfig:
try:
Expand All @@ -159,113 +159,113 @@ def __getitem__(self, item) -> ToolbarButtonConfig:

@property
def generate_all_button(self) -> ToolbarButtonConfig:
return self['generate_all_button']
return self["generate_all_button"]

@property
def regenerate_all_button(self) -> ToolbarButtonConfig:
return self['regenerate_all_button']
return self["regenerate_all_button"]

@property
def furigana_button(self) -> ToolbarButtonConfig:
return self['furigana_button']
return self["furigana_button"]

@property
def hiragana_button(self) -> ToolbarButtonConfig:
return self['hiragana_button']
return self["hiragana_button"]

@property
def clean_furigana_button(self) -> ToolbarButtonConfig:
return self['clean_furigana_button']
return self["clean_furigana_button"]

@property
def audio_search_button(self) -> ToolbarButtonConfig:
return self['audio_search_button']
return self["audio_search_button"]

@property
def add_definition_button(self) -> ToolbarButtonConfig:
return self['add_definition_button']
return self["add_definition_button"]


@final
class AudioSettingsConfigView(ConfigViewBase):
_view_key = 'audio_settings'
_view_key = "audio_settings"

@property
def dictionary_download_timeout(self) -> int:
return self['dictionary_download_timeout']
return self["dictionary_download_timeout"]

@property
def audio_download_timeout(self) -> int:
return self['audio_download_timeout']
return self["audio_download_timeout"]

@property
def attempts(self) -> int:
return self['attempts']
return self["attempts"]

@property
def maximum_results(self) -> int:
return self['maximum_results']
return self["maximum_results"]

@property
def ignore_inflections(self) -> bool:
return bool(self['ignore_inflections'])
return bool(self["ignore_inflections"])

@property
def stop_if_one_source_has_results(self) -> bool:
return bool(self['stop_if_one_source_has_results'])
return bool(self["stop_if_one_source_has_results"])

@property
def search_dialog_dest_field_name(self) -> str:
return self['search_dialog_dest_field_name']
return self["search_dialog_dest_field_name"]

@search_dialog_dest_field_name.setter
def search_dialog_dest_field_name(self, field_name: str):
self['search_dialog_dest_field_name'] = field_name
self["search_dialog_dest_field_name"] = field_name

@property
def search_dialog_src_field_name(self) -> str:
return self['search_dialog_src_field_name']
return self["search_dialog_src_field_name"]

@search_dialog_src_field_name.setter
def search_dialog_src_field_name(self, field_name: str):
self['search_dialog_src_field_name'] = field_name
self["search_dialog_src_field_name"] = field_name

@property
def tag_separator(self) -> str:
return self['tag_separator']
return self["tag_separator"]


@final
class DefinitionsConfigView(ConfigViewBase):
_view_key = 'definitions'
_view_key = "definitions"

@property
def timeout(self) -> int:
return self['timeout']
return self["timeout"]

@property
def remove_marks(self) -> bool:
return bool(self['remove_marks'])
return bool(self["remove_marks"])

@property
def dict_name(self) -> DictName:
return DictName[self['dict_name']]
return DictName[self["dict_name"]]

@property
def search_type(self) -> SearchType:
return SearchType[self['search_type']]
return SearchType[self["search_type"]]

@property
def source(self) -> str:
return self['source']
return self["source"]

@property
def destination(self) -> str:
return self['destination']
return self["destination"]

@property
def behavior(self) -> AddDefBehavior:
return AddDefBehavior[self['behavior']]
return AddDefBehavior[self["behavior"]]


@final
Expand All @@ -280,11 +280,11 @@ def __init__(self):
self._definitions = DefinitionsConfigView()

def iter_profiles(self) -> Iterable[Profile]:
for profile_dict in self['profiles']:
for profile_dict in self["profiles"]:
# In case new options are added or removed in the future,
# load default settings first, then overwrite them.
yield dataclasses.replace(
default := Profile.get_default(profile_dict['mode']),
default := Profile.get_default(profile_dict["mode"]),
**{key: profile_dict[key] for key in (dataclasses.asdict(default).keys() & profile_dict.keys())},
)

Expand All @@ -298,11 +298,11 @@ def audio_settings(self):

@property
def audio_sources(self):
return self['audio_sources']
return self["audio_sources"]

@property
def cache_lookups(self) -> int:
return int(self['cache_lookups'])
return int(self["cache_lookups"])

@property
def furigana(self) -> FuriganaConfigView:
Expand Down
2 changes: 1 addition & 1 deletion context_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class ContextMenuAction(abc.ABC):
subclasses: list[type['ContextMenuAction']] = []
subclasses: list[type["ContextMenuAction"]] = []
shown_when_not_editing = False

def __init_subclass__(cls, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def add_definition(self, editor: Editor) -> None:

for field_name in (self._config.source, self._config.destination):
if field_name not in editor.note:
return tooltip(f"Note doesn't have field \"{field_name}\".")
return tooltip(f'Note doesn\'t have field "{field_name}".')
if not editor.note[self._config.source]:
return tooltip(f"Source field \"{self._config.source}\" is empty.")
return tooltip(f'Source field "{self._config.source}" is empty.')

progress = create_progress_dialog(editor.parentWindow)

Expand Down
Loading

0 comments on commit b98330d

Please sign in to comment.