Back

Copy2Clipboard ankiplugin upgrade request

#1
I've been using cb4960's copy2clipboard anki plugin together with EBwin, which automatically reads the clipboard, for a month now and it's amazing Big Grin What a timesaver! Thanks a lot.

Unfortunately it doesn't work with Anki 2 (which is obvious with all the changes made)

I feel bad for asking... but any chance someone could find the time to upgrade it to work with Anki 2? Until that time I definitely stick to old anki Big Grin
Reply
#2
Glad your finding the plugin of some use. I'm going to be very busy for the next week or two, but after that I can port it to Anki 2 for you. (I would have already done it but I prefer Anki 1.2.8).

It would probably take <10 minutes to port for someone who is already familiar with Anki 2 plugin creation. Here is the existing Copy2Clipboard code if anybody wants to port it sooner:

Code:
# -*- coding: utf-8 -*-
#  Copyright (C) 2012 Christopher Brochtrup
#
#  This file is part of Copy2Clipboard
#
#  Copy2Clipboard 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.
#
#  Copy2Clipboard 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 Copy2Clipboard.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
# Description:
#
# Copy2Clipboard will automatically copy a single card field to the clipboard
# when either the card's question side is shown or when the card's answer side
# is shown (or both, if desired).
#
# Default behavior:
#
#   * When the card's question is shown:
#       Nothing will be copied to the clipboard.
#
#   * When the card's answer is shown:
#       The card's "Expression" field will be copied to the clipboard (if one exists).
#
# To change the default behavior simply edit the questionField or answerField
# variables in the User Options section of this file.
#
###############################################################################
# Version: 1.0
# Contact: cb4960@gmail.com
###############################################################################

#### Includes ####

import os, codecs
import ankiqt
from anki.hooks import wrap
from PyQt4 import QtGui

#### User Options ####

# The name of the field to copy to the clipboard when the question side of the
# card is shown. Case sensitive. If you don't want to copy, set to a blank string.
questionField = ""

# The name of the field to copy to the clipboard when the answer side of the
# card is shown. Case sensitive. If you don't want to copy, set to a blank string.
answerField = "Expression"


#### Debugging ####

DEBUG = False
LOG_FILE = os.path.join(ankiqt.mw.config.configPath, "plugins", "Copy2Clipboard.log")
CLEAR_LOG_AT_STARTUP = True


#### Functions ####

def clearLog():
    if DEBUG:
        file = codecs.open(LOG_FILE, "w", "utf-8-sig")
        file.write("")
        file.close()


def writeLog(text):
    if DEBUG:
        file = codecs.open(LOG_FILE, "a", "utf-8-sig")
        file.write(text + "\n")
        file.close()


def copyTextToClipboard(text):
    clipboard = QtGui.QApplication.clipboard()
    clipboard.setText(text)


def copyField(state):
    if state == "showQuestion":
        writeLog("copyField: showQuestion")
        if questionField != "":
            for field in ankiqt.mw.currentCard.fact.fields:
                if field.getName() == questionField:
                    writeLog(field.getName() + ": " + field.value)
                    copyTextToClipboard(field.value)
                    break;
    elif state == "showAnswer":
        writeLog("copyField: showAnswer")
        if answerField != "":
            for field in ankiqt.mw.currentCard.fact.fields:
                if field.getName() == answerField:
                    writeLog(field.getName() + ": " + field.value)
                    copyTextToClipboard(field.value)
                    break;


#### Main ####

if CLEAR_LOG_AT_STARTUP:
    clearLog()
writeLog("-----------------------------------------------------------")

writeLog("Main.START")
ankiqt.mw.moveToState = wrap(ankiqt.mw.moveToState, copyField)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Reply
#3
Finally got around to porting the plugin to Anki 2.

https://ankiweb.net/shared/info/3683838311
Reply
May 16 - 30 : Pretty Big Deal: Save 31% on all Premium Subscriptions! - Sign up here
JapanesePod101
#4
Thanks a lot!
Reply
#5
Would it be possible to have this add-on re-uploaded? It gives an invalid id error when I click the link here. Maybe someone still has it and could post a link to it? I'd appreciate it, thanks!

Edit - Turns out I had an old Anki installation on a hard drive I haven't used in a while that had the add-on file. I've gone ahead and uploaded it to dropbox for anyone interested. Maybe cb will re-upload it to the shared add-on page but until then you can get it here:

https://www.dropbox.com/s/w6iz8umrzhu97a...rd.py?dl=1
Edited: 2016-01-18, 4:55 am
Reply