Skip to content

Commit

Permalink
Merge pull request #21 from obynio/cleanup
Browse files Browse the repository at this point in the history
Address a couple miscellaneous issues
  • Loading branch information
obynio committed Oct 20, 2022
2 parents 8c04cb9 + 4e09569 commit 1bd295e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 11 deletions.
5 changes: 2 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@

from aqt.utils import tooltip
from aqt.qt import *
from aqt.editor import Editor

from aqt import mw

from anki.hooks import addHook

from . import reading
from . import config
from .config import Config
from .selection import Selection
from .utils import removeFurigana

mecab = reading.MecabController()
config = config.Config()
config = Config()

def setupGuiMenu():
useRubyTags = QAction("Use ruby tags", mw, checkable=True, checked=config.getUseRubyTags())
Expand Down
7 changes: 6 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with Japanese Furigana. If not, see <http://www.gnu.org/licenses/>.

from aqt.addons import AbortAddonImport
from aqt import mw

def saveMe(func):
Expand All @@ -25,7 +26,11 @@ def wrapper(self, *args):
return wrapper

class Config:
data = mw.addonManager.getConfig(__name__)
def __init__(self):
if mw is None:
raise AbortAddonImport("No Anki main window?")

self.data = mw.addonManager.getConfig(__name__)

def getUseRubyTags(self):
return self.data['useRubyTags']
Expand Down
20 changes: 13 additions & 7 deletions reading.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# -*- coding: utf-8 -*-

# This file is based on the Japanese Support add-on's reading.py, which can be
# found at <https://github.com/ankitects/anki-addons>.
# This file is part of Japanese Furigana <https://github.com/obynio/anki-japanese-furigana>.
#
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html
# Japanese Furigana is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Automatic reading generation with mecab.
# Japanese Furigana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Japanese Furigana. If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import re
import subprocess
import platform

from typing import Mapping, Optional, Union
from typing import Any, Mapping, Optional, Union

mecabArgs = ['--node-format=%m[%f[7]] ', '--eos-format=\n',
'--unk-format=%m[] ']
Expand Down Expand Up @@ -57,7 +63,7 @@ def escapeText(text):
except:
si.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
else:
si = None
si: Optional[Any] = None

# Syllabary utilities
UNICODE_HIRAGANA_START = 0x3041
Expand Down
Empty file modified support/mecab.arm
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions test/test_reading.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# -*- coding: utf-8 -*-

# This file is part of Japanese Furigana <https://github.com/obynio/anki-japanese-furigana>.
#
# Japanese Furigana is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Japanese Furigana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Japanese Furigana. If not, see <http://www.gnu.org/licenses/>.

import unittest

import reading
Expand Down
17 changes: 17 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# -*- coding: utf-8 -*-

# This file is part of Japanese Furigana <https://github.com/obynio/anki-japanese-furigana>.
#
# Japanese Furigana is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Japanese Furigana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Japanese Furigana. If not, see <http://www.gnu.org/licenses/>.

import unittest

import utils
Expand Down
15 changes: 15 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# -*- coding: utf-8 -*-

# This file is part of Japanese Furigana <https://github.com/obynio/anki-japanese-furigana>.
#
# Japanese Furigana is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Japanese Furigana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Japanese Furigana. If not, see <http://www.gnu.org/licenses/>.

import re

def removeFurigana(text: str):
Expand Down

0 comments on commit 1bd295e

Please sign in to comment.