Skip to content

Commit

Permalink
Merge pull request #50 from Yutsuten/anki21
Browse files Browse the repository at this point in the history
Remove Anki 2.0 support
  • Loading branch information
Yutsuten authored Apr 25, 2020
2 parents 9a669f3 + 6410003 commit 96e457c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 39 deletions.
18 changes: 4 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
all: prepare build cleanup
all: prepare build

prepare:
rm -rf dist/* tmp/*
rm -rf dist/*
find lifedrain -name __pycache__ -type d -exec rm -r {} +
mkdir -p dist tmp
mkdir -p dist

build: build20 build21

build20:
echo -n "import lifedrain" > tmp/lifedrain_loader.py
cp -r lifedrain tmp/lifedrain
(cd tmp && zip -r ../dist/lifedrain20.zip * -x "*.pyc")

build21:
build:
(cd lifedrain && zip -r ../dist/lifedrain21.zip * -x "*.pyc")

cleanup:
rm -rf tmp/*
9 changes: 0 additions & 9 deletions lifedrain/lifedrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ def __init__(self, make_timer, mw, qt):
self.deck_settings_ui = self._settings.deck_settings_ui
self.custom_deck_settings_ui = self._settings.custom_deck_settings_ui

# Configure separator strip - Seems that it is not needed on Anki 2.1
css = 'QMainWindow::separator { width: 0px; height: 0px; }'
mw.setStyleSheet(css)
try:
import Night_Mode # pylint: disable=import-error
Night_Mode.nm_css_menu += css
except Exception: # nosec # pylint: disable=broad-except
pass

def preferences_load(self, pref):
"""Loads Life Drain global settings into the Global Settings dialog.
Expand Down
18 changes: 5 additions & 13 deletions lifedrain/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from anki.collection import _Collection
from anki.hooks import addHook, wrap
from anki.sched import Scheduler
from aqt import appVersion, forms, mw, qt
from aqt import forms, mw, qt
from aqt.deckconf import DeckConf
from aqt.dyndeckconf import DeckConf as FiltDeckConf
from aqt.editcurrent import EditCurrent
Expand Down Expand Up @@ -61,8 +61,7 @@ def setup_user_interface(lifedrain):
# Filtered Deck Settings
forms.dyndconf.Ui_Dialog.setupUi = wrap(
forms.dyndconf.Ui_Dialog.setupUi,
lambda *args: lifedrain.custom_deck_settings_ui(
args[0], appVersion.startswith('2.1')))
lambda *args: lifedrain.custom_deck_settings_ui(args[0]))
FiltDeckConf.loadConf = wrap(
FiltDeckConf.loadConf,
lambda *args: lifedrain.deck_settings_load(args[0]))
Expand All @@ -77,16 +76,9 @@ def setup_shortcuts(lifedrain):
Args:
lifedrain: A Lifedrain instance.
"""
if appVersion.startswith('2.0'):
Reviewer._keyHandler = wrap( # pylint: disable=protected-access
Reviewer._keyHandler, # pylint: disable=protected-access
lambda self, evt, _old: lifedrain.toggle_drain()
if evt.text() == 'p' else _old(self, evt),
'around')
elif appVersion.startswith('2.1'):
toggle_drain_shortcut = tuple(['p', lifedrain.toggle_drain])
addHook('reviewStateShortcuts',
lambda shortcuts: shortcuts.append(toggle_drain_shortcut))
toggle_drain_shortcut = tuple(['p', lifedrain.toggle_drain])
addHook('reviewStateShortcuts',
lambda shortcuts: shortcuts.append(toggle_drain_shortcut))


def setup_hooks(lifedrain):
Expand Down
5 changes: 2 additions & 3 deletions lifedrain/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def deck_settings_ui(self, form):
self._fill_remaining_space()
form.tabWidget.addTab(form.lifedrain_widget, 'Life Drain')

def custom_deck_settings_ui(self, form, is_anki21):
def custom_deck_settings_ui(self, form):
"""Adds Life Drain settings to Filtered Deck Settings dialog.
Args:
Expand All @@ -94,8 +94,7 @@ def custom_deck_settings_ui(self, form, is_anki21):
self._create_check_box('enableDamageInput', 'Enable damage')
self._create_spin_box('damageInput', 'Damage', [-1000, 1000])
self._create_spin_box('currentValueInput', 'Current life', [0, 10000])
index = 3 if is_anki21 else 2
form.verticalLayout.insertWidget(index, form.lifedrain_widget)
form.verticalLayout.insertWidget(3, form.lifedrain_widget)

def preferences_load(self, pref):
"""Loads Life Drain global settings into the form.
Expand Down

0 comments on commit 96e457c

Please sign in to comment.