Example #1
0
def init_JxPlugin():
        """Initialises the Anki GUI to present an option to invoke the plugin."""
        from PyQt4 import QtGui, QtCore

	# put JxWindow at the left of the main window
	widg ={}
	n = mw.mainWin.hboxlayout.count()
        for a in reversed(range(0,n)):
		widg[a+1]=mw.mainWin.hboxlayout.takeAt(a).widget()
		mw.mainWin.hboxlayout.removeWidget(widg[a+1])
        widg[0]=JxWindow	

	for a in range(0,n+1):
		mw.mainWin.hboxlayout.addWidget(widg[a])
	
	# creates menu entry
	mw.mainWin.actionJxMenu = QtGui.QAction('JxMenu', mw)
	mw.mainWin.actionJxMenu.setStatusTip('Stats, Tools ans Settings for Japanese')
        mw.mainWin.actionJxMenu.setEnabled(not not mw.deck)
	mw.connect(mw.mainWin.actionJxMenu, QtCore.SIGNAL('triggered()'), onJxMenu)

	# creates graph entry
	mw.mainWin.actionJxGraphs = QtGui.QAction('JxGraphs', mw)
	mw.mainWin.actionJxGraphs.setStatusTip('Graphs for Japanese')
	mw.mainWin.actionJxGraphs.setEnabled(not not mw.deck)
	mw.connect(mw.mainWin.actionJxGraphs, QtCore.SIGNAL('triggered()'), onJxGraphs)

	
	# adds the plugin icons in the Anki Toolbar
	
	mw.mainWin.toolBar.addAction(mw.mainWin.actionJxMenu)
	mw.mainWin.toolBar.addAction(mw.mainWin.actionJxGraphs)
	
	# to enable or disable Jstats whenever a deck is opened/closed
	mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("JxMenu","JxGraphs",)
	
	# Adding features through hooks !
	mw.addHook('drawAnswer', append_JxPlugin) # additional info in answer cards
	mw.addHook('deckClosed', JxWindow.hide) # hides the main Jxplugin window when the current deck is closed	
	
	# this is needed for people who open Anki by double clicking on an Anki deck (it bypasses newLoadDeck)
	if (mw.deck):
		from database import build_JxDeck
		build_JxDeck()
Example #2
0
                    os.rename(os.path.join(mediaDir, relpath),
                              os.path.join(mediaDir, newrel))
                    renamedFiles += 1
    # rename fields
    modifiedFacts = {}
    updateFields = []
    for (id, fid, val) in deck.s.all("select id, factId, value from fields"):
        oldval = val
        for (full, fname, repl) in mediaRefs(val):
            tmp = re.sub(fromStr, toStr, fname)
            if tmp != fname:
                val = re.sub(re.escape(full), repl % tmp, val)
        if oldval != val:
            updateFields.append({'id': id, 'val': val})
            modifiedFacts[fid] = 1
    if modifiedFacts:
        _modifyFields(deck, updateFields, modifiedFacts, True)
    ui.utils.showInfo("%d files renamed.\n%d facts modified." %
                      (renamedFiles, len(modifiedFacts)))


def init():
    q = QAction(mw)
    q.setText("Bulk Rename")
    mw.mainWin.menuAdvanced.addSeparator()
    mw.mainWin.menuAdvanced.addAction(q)
    mw.connect(q, SIGNAL("triggered()"), bulkrename)


mw.addHook("init", init)
  print "Deck modification complete"
  mw.deck.s.flush()
  mw.deck.setModified()

############################################################
#  Does the actual update of a card with the lesson number #
############################################################
def update_card(card):
  candidate_lesson_nos = []
  for tag in parseTags(card.allTags()):
    if tag.startswith(LESSON_TAG_PREFIX):
      suffix = tag.lstrip(LESSON_TAG_PREFIX)
      
      try:
        candidate_lesson_nos.append(int(suffix))
      except ValueError:
        continue
  
  if len(candidate_lesson_nos) != 1:
    print "Too many or too few lesson numbers, skipping"
    return
  
  card.fact[LESSON_FIELD_NAME] = unicode(candidate_lesson_nos[0])


if __name__ == "__main__":
  print "Don't run me.  I'm a plugin!"

else:
  mw.addHook('init', init_hook)
  print 'Tag to lesson number plugin loaded'
Example #4
0
        pass


def tagCurrentCard(tag):
    mw.deck.setUndoStart(_("Suspend"))
    mw.currentCard.fact.tags = addTags(tag, mw.currentCard.fact.tags)
    mw.currentCard.fact.setModified()
    for card in mw.currentCard.fact.cards:
        mw.deck.updatePriority(card)
    mw.deck.setModified()
    mw.lastScheduledTime = None
    mw.reset()
    mw.deck.setUndoEnd(_("Suspend"))


def replaceMenu():
    # create the new menu
    createTagsMenu()

    # insert it into the "current" menu
    mw.mainWin.menuEdit.insertMenu(mw.mainWin.actionSuspendCard, mw.tagsMenu)
    mw.mainWin.menuEdit.removeAction(mw.mainWin.actionSuspendCard)

    # the app should do the same things to the menu as it would to the old button
    mw.mainWin.actionSuspendCard = mw.tagsMenu

    mw.connect(mw.tagsMenu, SIGNAL("aboutToShow()"), updateMenu)


mw.addHook("init", replaceMenu)
Example #5
0
    def onSaveResults( self ):
        destPath = QFileDialog.getSaveFileName( caption='Save results to?', directory=util.dbPath + 'results.db' )
        if not destPath: return
        self.db.save( str(destPath) )
        infoMsg( 'Success', 'Save db' )

    def updateDisplay( self ):
        bs = self.blacklist.text().split(',')
        ws = self.whitelist.text().split(',') if self.whitelist.text() else []
        for m in self.db.db.keys():
            if m.pos in bs:
                self.db.db.pop( m )
            elif ws and m.pos not in ws:
                self.db.db.pop( m )
        if self.col4Mode.isChecked():
            self.morphDisplay.setText( self.db.showMs() )
        else:
            self.morphDisplay.setText( u'\n'.join( [ m.base for m in self.db.db ] ) )
        self.analysisDisplay.setText( self.db.analyze2str() )

def onMorphMan():
    mw.mainWin.mm = MorphMan( mw )
    mw.mainWin.mm.show()

def init():
    mw.mainWin.morphMan = QAction( 'MorphMan', mw )
    mw.connect( mw.mainWin.morphMan, SIGNAL('triggered()'), onMorphMan )
    mw.mainWin.toolBar.addAction( mw.mainWin.morphMan )

mw.addHook( 'init', init )
Example #6
0
    
def latexExport():
    filename = saveDialog(masks['latex'], mw.deck.name())
    if len(filename)!=0:
        writeFile(filename, deck2LaTeX(mw.deck))

def MWExport():
    filename = saveDialog(masks['wiki'], mw.deck.name())
    if len(filename)!=0:
        writeFile(filename, deck2MediaWiki(mw.deck))
    
def addMenu():
    a = QAction(mw)
    a.setText("PDF Export")
    mw.mainWin.menuTools.addAction(a)
    mw.connect(a, SIGNAL("triggered()"), pdfExport)

    a = QAction(mw)
    a.setText("LaTeX Export")
    mw.mainWin.menuTools.addAction(a)
    mw.connect(a, SIGNAL("triggered()"), latexExport)

    a = QAction(mw)
    a.setText("MediaWiki Export")
    mw.mainWin.menuTools.addAction(a)
    mw.connect(a, SIGNAL("triggered()"), MWExport)
    
    
tmpdir = tempfile.mkdtemp(prefix="anki")
mw.addHook("init", addMenu)
def get_jlpt4_kanjis():
    return "一七万三上下中九二五人今休会何先入八六円出分前北十千午半南友口古右名四国土外多大天女子学安小少山川左年店後手新日時書月木本来東校母毎気水火父生男白百目社空立耳聞花行西見言話語読買足車週道金長間雨電食飲駅高魚".decode(
        "utf-8"
    )


def get_jlpt3_kanjis():
    return "不世主乗事京仕代以低住体作使便借働元兄光写冬切別力勉動区医去台合同味品員問回図地堂場声売夏夕夜太好妹姉始字室家寒屋工市帰広度建引弟弱強待心思急悪意所持教文料方旅族早明映春昼暑暗曜有服朝村林森業楽歌止正歩死民池注洋洗海漢牛物特犬理産用田町画界病発県真着知短研私秋究答紙終習考者肉自色英茶菜薬親計試説貸質赤走起転軽近送通進運遠都重野銀門開院集青音頭題顔風飯館首験鳥黒".decode(
        "utf-8"
    )


def get_jlpt2_kanjis():
    return "腕湾和論録老労路連練恋列歴齢零礼冷例令類涙輪緑領量良療涼両了粒留流略率律陸裏利卵乱落絡頼翌浴欲陽踊要葉溶様容幼預与余予郵遊由勇優輸油約役戻毛面綿鳴迷命娘無夢務眠未満末枚埋磨防貿棒望暴忙忘帽坊亡豊訪法放抱宝報包暮募補捕保返辺編片変壁米閉並平兵粉仏沸払複腹福幅復副封部舞武負膚符浮普怖府布富婦夫付貧秒評表氷標筆必匹鼻美備飛非費被皮疲比批悲彼否番晩販般犯版板反判抜髪畑肌箱麦爆薄泊倍配背杯敗拝馬破波農脳能濃悩燃念熱猫認任乳難軟内鈍曇届突独毒得銅童導逃到筒等当灯湯盗投島塔凍党倒怒努途登渡徒塗殿伝点展鉄適的滴泥程庭底定停痛追賃珍沈直頂超調張庁兆貯著駐虫柱宙仲竹畜築遅置恥値談段暖断団炭探担単谷達濯宅第退袋替帯対打他損尊孫存卒続速測束息則側造贈蔵臓憎増像装草総窓相争燥操掃捜想層双組祖全然善選船線浅泉戦専占絶雪節設折接責績積石昔席税静製精清晴星整政成性姓勢制数吹震針辛身臣神申深寝信伸触職植蒸畳状条情常城賞象紹笑章省照焼消昇招承床将商召勝除助諸署緒初処順純準述術祝宿柔舟拾修州周収授受酒種守取若捨実湿失識式辞示治次寺児似歯資誌詞脂糸枝支指志師史司刺伺残賛算散参皿雑殺札察刷冊昨咲坂財罪材在際細祭済歳採才妻最再座砂査差混根婚困込骨腰告刻号香降鉱郊講荒航肯耕紅硬港構更康幸向厚効公候交誤御互雇湖枯故戸庫固呼個限現減原険軒賢肩権検券健件血結決欠劇迎芸警経景敬恵形型傾係軍群訓君靴掘隅偶具苦禁均勤玉極曲局胸狭況橋挟恐境叫協共競供漁許巨居旧給級球泣求救吸久逆客詰喫議疑技記規季祈機期机希寄基器喜危願岩岸含丸関観簡管看甘環汗換慣感干官完巻刊乾活割額革較角覚確格拡各害貝階絵皆灰械改快解介過貨課菓荷河果科可加価仮化温億黄王欧横押応奥央汚塩煙演延園越液鋭泳永栄営雲羽宇因印育域違衣胃移異易委囲偉依位案圧愛".decode(
        "utf-8"
    )


def get_jlpt1_kanjis():
    return "乙丁刀又勺士及己丈乏寸凡刃弓斤匁氏井仁丹幻凶刈冗弔斗尺屯孔升厄丙且弁功甲仙句巡矢穴丘玄巧矛汁尼迅奴囚凸凹斥弐吏企邦江吉刑充至芝扱旬旨尽缶仰后伏劣朴壮吐如匠妃朱伐舌羊朽帆妄芋沢佐攻系抗迫我抑択秀尾伴邸沖却災孝戒杉里妥肝妙序即寿励芳克没妊豆狂岐廷妨亜把呈尿忍呉伯扶忌肖迭吟汽坑抄壱但松郎房拠拒枠併析宗典祉免忠沿舎抵茂斉炎阻岳拘卓炉牧奇拍往屈径抽披沼肥拐拓尚征邪殴奉怪佳昆芽苗垂宜盲弦炊枢坪泡肪奔享拙侍叔岬侮抹茎劾泌肢附派施姿宣昭皇紀削為染契郡挑促俊侵括透津是奏威柄柳孤牲帝耐恒冒胞浄肺貞胆悔盾軌荘冠卸垣架砕俗洞亭赴盆疫訂怠哀臭洪狩糾峡厘胎窃恨峠叙逓甚姻幽卑帥逝拷某勅衷逐侯弧朕耗挙宮株核討従振浜素益逮陣秘致射貢浦称納紛託敏郷既華哲症倉索俳剤陥兼脅竜梅桜砲祥秩唆泰剣倫殊朗烈悟恩陛衰准浸虐徐脈俵栽浪紋逸隻鬼姫剛疾班宰娠桑飢郭宴珠唐恭悦粋辱桃扇娯俸峰紡胴挿剖唇匿畔翁殉租桟蚊栓宵酌蚕畝倣倹視票渉推崎盛崩脱患執密措描掲控渋掛排訳訟釈隆唱麻斎貫偽脚彩堀菊唯猛陳偏遇陰啓粘遂培淡剰虚帳惨据勘添斜涯眼瓶彫釣粛庶菌巣廊寂酔惜悼累陶粗蛇眺陵舶窒紳旋紺遍猟偵喝豚赦殻陪悠淑笛渇崇曹尉蛍庸渓堕婆脹痘統策提裁証援訴衆隊就塁遣雄廃創筋葬惑博弾塚項喪街属揮貴焦握診裂裕堅賀揺喚距圏軸絞棋揚雰殖随尋棟搭詐紫欺粧滋煮疎琴棚晶堤傍傘循幾掌渦猶慌款敢扉硫媒暁堪酢愉塀閑詠痢婿硝棺詔惰蛮塑虞幹義督催盟献債源継載幕傷鈴棄跡慎携誉勧滞微誠聖詳雅飾詩嫌滅滑頑蓄誇賄墓寛隔暇飼艇奨滝雷酬愚遭稚践嫁嘆碁漠該痴搬虜鉛跳僧溝睡猿摂飽鼓裸塊腸慈遮慨鉢禅絹傑禍酪賊搾廉煩愁楼褐頒嗣銑箇遵態閣摘維遺模僚障徴需端奪誘銭銃駆稲綱閥隠徳豪旗網酸罰腐僕塾漏彰概慢銘漫墜漂駄獄誓酷墨磁寧穀魂暦碑膜漬酵遷雌漆寡慕漸嫡謁賦監審影撃請緊踏儀避締撤盤養還慮緩徹衝撮誕歓縄範暫趣慰潟敵魅敷潮賠摩輝稼噴撲縁慶潜黙輩稿舗熟霊諾勲潔履憂潤穂賓寮澄弊餓窮幣槽墳閲憤戯嘱鋳窯褒罷賜錘墾衛融憲激壊興獲樹薦隣繁擁鋼縦膨憶諮謀壌緯諭糖懐壇奮穏謡憾凝獣縫憩錯縛衡薫濁錠篤隷嬢儒薪錬爵鮮厳聴償縮購謝懇犠翼繊擦覧謙頻轄鍛礁擬謹醜矯嚇霜謄濫離織臨闘騒礎鎖瞬懲糧覆翻顕鎮穫癒騎藩癖襟繕繭璽繰瀬覇簿鯨鏡髄霧麗羅鶏譜藻韻護響懸籍譲騰欄鐘醸躍露顧艦魔襲驚鑑".decode(
        "utf-8"
    )


if __name__ == "__main__":
    print "Don't run me.  I'm a plugin"

else:
    mw.addHook("init", init_hook)
    print "jlpt AHAS progress plugin loaded"
Example #8
0
	mw.connect(mw.mainWin.actionJxGraphs, QtCore.SIGNAL('triggered()'), onJxGraphs)

	# adds the plugin icons in the Anki Toolbar
	
	mw.mainWin.toolBar.addAction(mw.mainWin.actionJxMenu)
	mw.mainWin.toolBar.addAction(mw.mainWin.actionJxGraphs)
	
	# to enable or disable Jstats whenever a deck is opened/closed
	mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("JxMenu","JxGraphs",)
	
	# Adding features through hooks !
	mw.addHook('drawAnswer', append_JxPlugin) # additional info in answer cards
	mw.addHook('deckClosed', JxWindow.hide) # hides the main Jxplugin window when the current deck is closed	

# adds JxPlugin to the list of plugin to process in Anki 
mw.addHook('init', init_JxPlugin)
mw.registerPlugin("Japanese Extended Support", 666)

# let's overload the loadDeck function as there isn't any hook
oldLoadDeck = mw.loadDeck

def newLoadDeck(deckPath, sync=True, interactive=True, uprecent=True,media=None):
    code = oldLoadDeck(deckPath, sync, interactive, uprecent,media)
    if code and mw.deck:
        from database import build_JxDeck
        build_JxDeck()
    return code

mw.loadDeck = newLoadDeck
# The main JxPlugin Windows # funny, you cannot import stuff after these statements
from controls import JxWindow
Example #9
0
			cipher.seek(0,0)
			fact['GPG'] = unicode(re.sub("\n","<br>",cipher.read()), 'ascii')
			mw.deck.addFact(fact)
		except GPGMEError, e:
			QMessageBox.information(mw, "Error", "Could not encrypt your password.\nError: " + str(e))

	except FactInvalidError, e:
		QMessageBox.information(mw, "Error", "Could not store your password.\nError: " + str(e))


""" Set up all the stuff we need initialising. """
def initPlugin():
	main.AnkiQt.showAnswerButton = wrap(main.AnkiQt.showAnswerButton, afterShowAnswerButton, "after")
	main.AnkiQt.keyPressEvent = wrap(main.AnkiQt.keyPressEvent, aroundKeyPressEvent, "around")
	view.View.drawAnswer = wrap(view.View.drawAnswer, aroundDrawAnswer, "around")
	menu = QAction(mw)
	menu.setText("Add Password")
	mw.connect(menu, SIGNAL("triggered()"), addPassword)
	menu2 = QAction(mw)
	menu2.setText("Set GPG User Name")
	mw.connect(menu2, SIGNAL("triggered()"), setGPGName)
	mw.mainWin.menuTools.addSeparator()
	mw.mainWin.menuTools.addAction(menu)
	mw.mainWin.menuTools.addAction(menu2)
	config.load()
	if not config.loaded:
		setGPGName()

""" Ensure we can be set up. """
mw.addHook("init", initPlugin)
Example #10
0
NoWIfySyncThread = NoWifiSync(mw)


def init_NoWifiSync():
    """Initialises the Anki GUI to present an option to invoke the plugin."""
    from PyQt4 import QtGui, QtCore

    # creates menu entry
    mw.mainWin.actionNDSync = QtGui.QAction('NDSync', mw)
    mw.mainWin.actionNDSync.setStatusTip('Sync with Anki.nds without wifi')
    mw.mainWin.actionNDSync.setEnabled(not not mw.deck)
    mw.connect(mw.mainWin.actionNDSync, QtCore.SIGNAL('triggered()'),
               NoWIfySyncThread.start)

    # adds the plugin icons in the Anki Toolbar

    mw.mainWin.toolBar.addAction(mw.mainWin.actionNDSync)

    # to enable or disable Jstats whenever a deck is opened/closed
    mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("NDSync", )


if __name__ == "__main__":
    print "Don't run me : I'm an Anki plugin."
else:
    # adds NoWifiSync to the list of plugin to process in Anki

    mw.addHook('init', init_NoWifiSync)
    mw.registerPlugin("Button to Sync with Anki.nds without wifi", 668)
# -*- coding: utf-8 -*-
# Copyright: Damien Elmes <*****@*****.**>
# License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html

# Add an icon to the toolbar. Adds a separator and 'suspend card' by default.

# version 1: initial release

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from ankiqt import mw

def init():
    mw.mainWin.toolBar.addSeparator()
    mw.mainWin.toolBar.addAction(mw.mainWin.actionSuspendCard)

mw.addHook("init", init)
mw.registerPlugin("Add to Toolbar", 13)
Example #12
0
		self.mw = ankiMain

		self.extPrefs = ExtendAnkiPrefs( _("RLC Bitzer Settings") )
		self.extMain = ExtendAnkiMain( self.extPrefs )
		self.extHelp = ExtendAnkiHelp( self.extPrefs, self.mw )
		self.extToolTips = ExtendToolTips( self.extPrefs, self.mw )
		self.extScheduler = ExtendAnkiScheduling( self.extPrefs, self.mw.config )
		self.personalTrainer = AnkiPersonalTrainer( self.extPrefs, self.mw )

	def pluginLateInit( self ):
		self.extHelp.setScribble( getConfig( mw.config, self.extHelp.PREFS_ENABLE_SCRIBBLE, self.extHelp.DEFAULT_ENABLE_SCRIBBLE ) )
		self.extToolTips.hookQtEvents( self.mw.mainWin.mainText )


###################################

def hookPluginInit():
	r.pluginLateInit()


# Startup has been split into 2 stages ... early stuff that happens as soon as
# plugin is imported ... used for intercepting deck load
#
# Stage 2 happens off the "init" hook ... and is used to do any initialisation
# after the main anki stuff has loaded

# Stage 1
r = RlcBitzer( mw )
# Hook Stage 2
mw.addHook( "init", hookPluginInit )
Example #13
0
    origDrawAnswer = mw.bodyView.drawAnswer
    origCardAnswered = mw.cardAnswered
    origMoveToState = mw.moveToState
    mw.moveToState = moveToStateCES
    mw.cardAnswered = cardAnsweredCES
    mw.bodyView.drawAnswer = drawAnswerCES
    mw.mainWin.toolBar.addSeparator()
    toggle = QAction(mw)
    icon = QIcon()
    icon.addPixmap(QPixmap(getLogoFile('zhexsen_logo.png',logo)),QIcon.Normal,QIcon.Off)
    toggle.setIcon(icon)
    toggle.setIconText('zhex')
    toggle.setCheckable(True)
    toggle.setEnabled(False)
    mw.connect(toggle,SIGNAL("toggled(bool)"),doToggle)
    mw.mainWin.toolBar.addAction(toggle)
    next = QAction(mw)
    icon = QIcon()
    icon.addPixmap(QPixmap(getLogoFile('zhexsen_logo_next.png',nextLogo)),QIcon.Normal,QIcon.Off)
    next.setIcon(icon)
    next.setIconText('zhex:next')
    next.setEnabled(False)
    mw.connect(next,SIGNAL("triggered()"),doNext)
    mw.mainWin.toolBar.addAction(next)

mw.addHook("init", initChineseExampleSentence)




Example #14
0
            new = copyToMedia(mw.deck, recorded)
            os.unlink("tmp.mp3")
            os.unlink("tmp.wav")
            os.unlink("tmp2.wav")
            os.unlink("tmp3.wav")
            fact.fields[ordinal].value = u"[sound:%s]" % new
            fact.setModified(textChanged=True)
            mw.deck.flushMod()
            mw.deck.save()
            editorObj.updateAfterCardChange()
            return True
        elif mb.clickedButton() == bSkip:
            return True
        elif mb.clickedButton() == bStop:
            return False


def setupMenus(parent):
    global bulkRecordAction, editorObj
    editorObj = parent
    bulkRecordAction = QAction(parent)
    bulkRecordAction.setText("Bulk record")
    parent.connect(bulkRecordAction,
                   SIGNAL("triggered()"),
                   lambda parent=parent: bulkRecord(parent))
    parent.dialog.menuActions.addSeparator()
    parent.dialog.menuActions.addAction(bulkRecordAction)


mw.addHook("editor.setupMenus", setupMenus)
Example #15
0
    epwingLookup(mw.currentCard.fact['Meaning'])

def lookupS():
    mw.initLookup()
    mw.lookup.selection(epwingLookup)

def addCustomDict():
    # remove the standard lookup links
    ml = mw.mainWin.menu_Lookup
    for i in ("expr", "mean", "as", "es", "esk"):
        ml.removeAction(getattr(mw.mainWin,
                                "actionLookup_" + i))
    # add custom links
    q = QAction(mw)
    q.setText("..question")
    q.setShortcut(_("Ctrl+1"))
    ml.addAction(q)
    mw.connect(q, SIGNAL("triggered()"), lookupQ)
    a = QAction(mw)
    a.setText("..answer")
    a.setShortcut(_("Ctrl+2"))
    ml.addAction(a)
    mw.connect(a, SIGNAL("triggered()"), lookupA)
    s = QAction(mw)
    s.setText("..selection")
    s.setShortcut(_("Ctrl+3"))
    ml.addAction(s)
    mw.connect(s, SIGNAL("triggered()"), lookupS)

mw.addHook("init", addCustomDict)
Example #16
0


NoWIfySyncThread = NoWifiSync(mw) 
def init_NoWifiSync():
        """Initialises the Anki GUI to present an option to invoke the plugin."""
        from PyQt4 import QtGui, QtCore
	

	# creates menu entry
	mw.mainWin.actionNDSync = QtGui.QAction('NDSync', mw)
	mw.mainWin.actionNDSync.setStatusTip('Sync with Anki.nds without wifi')
	mw.mainWin.actionNDSync.setEnabled(not not mw.deck)
	mw.connect(mw.mainWin.actionNDSync, QtCore.SIGNAL('triggered()'), NoWIfySyncThread.start)

	# adds the plugin icons in the Anki Toolbar
	
	mw.mainWin.toolBar.addAction(mw.mainWin.actionNDSync)
	
	# to enable or disable Jstats whenever a deck is opened/closed
	mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("NDSync",)	

if __name__ == "__main__":
    print "Don't run me : I'm an Anki plugin."
else:
        # adds NoWifiSync to the list of plugin to process in Anki 

        mw.addHook('init', init_NoWifiSync)
        mw.registerPlugin("Button to Sync with Anki.nds without wifi", 668)
    
Example #17
0
def myTrayActivated(reason):
    if reason != QtGui.QSystemTrayIcon.Context:
        if mw.trayIcon.anki_visible:
            mw.trayIcon.hideAll()
        else:
            mw.trayIcon.showAll()


if __name__ == "__main__":
    print "Don't run me. I'm a plugin."

else:
    mw.registerPlugin("Minimize to Tray", 1)
    if not mw.config['showTrayIcon']:
        ans = ui.utils.askUser(
            "Minimize to tray plugin needs tray icon option "
            "enabled.\nWould you like to enable it?")
        if ans:
            mw.config['showTrayIcon'] = True
            mw.config.save()
            mw.setupTray()

    if mw.config['showTrayIcon']:
        mw.quit = quit
        mw.closeEvent = myCloseEvent
        mw.trayIcon.activated = myTrayActivated
        mw.addHook('init', init_hook)
        print 'Minimize to tray plugin loaded'
    else:
        print 'Failed to load minimize to tray plugin. Tray not enabled.'
Example #18
0
from ankiqt import mw
from operator import attrgetter
import re

def numericSort(a, b):
    vals = []
    for question in (a, b):
        # get int from start of string
        m = re.match("^(\d+). ", question)
        if m:
            vals.append(int(m.group(1)))
        else:
            vals.append(0)
    return cmp(*vals)

def sortDeck():
    # sort based on number
    mw.currentDeck.sort(cmp=numericSort, key=attrgetter("question"))
    # print the new order for confirmation
    for card in mw.currentDeck:
        print card.question
    mw.currentDeck.setModified()

mw.addHook("init", sortDeck)