1
yomichan-anki/yomichan.py

95 lines
2.6 KiB
Python
Raw Normal View History

2011-11-19 17:19:17 +00:00
#!/usr/bin/env python2
2011-08-28 18:01:32 +00:00
# -*- coding: utf-8 -*-
2011-10-27 15:22:26 +00:00
# Copyright (C) 2013 Alex Yatskov
2011-08-28 18:01:32 +00:00
#
# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
from PyQt4 import QtGui, QtCore
2013-11-03 02:09:12 +00:00
from yomi_base import japanese
2011-11-20 03:02:33 +00:00
from yomi_base.preference_data import Preferences
from yomi_base.reader import MainWindowReader
import sys
2011-08-28 18:01:32 +00:00
2011-11-19 17:19:17 +00:00
class Yomichan:
2011-08-28 18:01:32 +00:00
def __init__(self):
2012-12-24 01:53:48 +00:00
self.language = japanese.initLanguage()
2011-08-28 18:01:32 +00:00
self.preferences = Preferences()
self.preferences.load()
2011-11-19 17:19:17 +00:00
class YomichanPlugin(Yomichan):
def __init__(self):
Yomichan.__init__(self)
2011-08-28 18:01:32 +00:00
self.toolIconVisible = False
self.window = None
2013-11-08 19:27:15 +00:00
self.anki = anki_bridge.Anki()
2011-08-28 18:01:32 +00:00
self.parent = self.anki.window()
2012-12-25 17:11:51 +00:00
separator = QtGui.QAction(self.parent)
separator.setSeparator(True)
self.anki.addUiAction(separator)
action = QtGui.QAction(QtGui.QIcon(':/img/img/icon_logo_32.png'), '&Yomichan...', self.parent)
2012-12-25 17:11:51 +00:00
action.setIconVisibleInMenu(True)
2013-02-05 03:15:10 +00:00
action.setShortcut('Ctrl+Y')
2012-12-25 17:11:51 +00:00
action.triggered.connect(self.onShowRequest)
self.anki.addUiAction(action)
2011-08-28 18:01:32 +00:00
2011-10-08 16:32:51 +00:00
def onShowRequest(self):
2011-08-28 18:01:32 +00:00
if self.window:
self.window.setVisible(True)
self.window.activateWindow()
else:
self.window = MainWindowReader(
self.parent,
2011-11-19 17:19:17 +00:00
self.preferences,
2012-12-24 01:53:48 +00:00
self.language,
2011-08-28 18:01:32 +00:00
None,
self.anki,
2012-12-23 22:11:48 +00:00
self.onWindowClose
2011-08-28 18:01:32 +00:00
)
self.window.show()
2011-10-08 16:32:51 +00:00
def onWindowClose(self):
2011-08-28 18:01:32 +00:00
self.window = None
2011-11-19 17:19:17 +00:00
class YomichanStandalone(Yomichan):
def __init__(self):
Yomichan.__init__(self)
self.application = QtGui.QApplication(sys.argv)
self.window = MainWindowReader(
None,
self.preferences,
2012-12-25 16:39:21 +00:00
self.language,
2011-11-19 17:19:17 +00:00
filename=sys.argv[1] if len(sys.argv) >= 2 else None
)
2011-11-20 03:02:33 +00:00
2011-11-19 17:19:17 +00:00
self.window.show()
self.application.exec_()
if __name__ == '__main__':
instance = YomichanStandalone()
else:
2013-11-08 19:27:15 +00:00
from yomi_base import anki_bridge
2011-11-19 17:19:17 +00:00
instance = YomichanPlugin()