← Back to team overview

sikuli-driver team mailing list archive

[Bug 1195259] Re: [1.0.1] Intermittent Problem with Paste Function in SIkuli

 

Sure,
Here you go, it still has a few bugs in it (it pastes the comma for the comma separated values, but it works fine for me)

from java.awt import Robot
from java.awt import Toolkit
from java.awt.event import KeyEvent

from java.awt.datatransfer import Clipboard
from java.awt.datatransfer import ClipboardOwner
from java.awt.datatransfer import DataFlavor
from java.awt.datatransfer import StringSelection
from java.awt.datatransfer import Transferable

class mClipboard(ClipboardOwner):
    _clipboard = []
    _robot = []
    def __init__(self):
        toolkit = Toolkit.getDefaultToolkit()
        self._clipboard = toolkit.getSystemClipboard()
        self._robot = Robot()
        
    def regainOwnership(self,tr):
        contents = self.get()
        self._clipboard.setContents(tr, self)
        
    def set(self, ct):
        strsel = StringSelection(ct)
        try:            
            self._clipboard.setContents(strsel, self)
        except java.lang.IllegalStateException:
            wait (5)
            print "IllegalStateException"
            self.regainOwnership(strsel)
            
    def get(self):
        t = self._clipboard.getContents(self)
        try:
            if t.isDataFlavorSupported(DataFlavor.stringFlavor):
                return t.getTransferData(DataFlavor.stringFlavor)
        except:
            print "Unexpected error in get():"
            print sys.exc_info()[0]
        return null
            
    def doPaste(self,ct):
        self.set(ct)
        self._robot.delay(50)
        self._robot.keyPress(KeyEvent.VK_CONTROL)
        self._robot.keyPress(KeyEvent.VK_V)
        self._robot.keyRelease(KeyEvent.VK_V)
        self._robot.keyRelease(KeyEvent.VK_CONTROL)
        
    def keyPress(self,key):
        self._robot.keyPress(key)
        self._robot.keyRelease(key)

    def delay(self,sec):
        self._robot.delay(sec)

Usage is:

        mclipboard.doPaste("" + VariableName + "")
        mclipboard.keyPress(KeyEvent.VK_COMMA)

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1195259

Title:
  [1.0.1] Intermittent Problem with Paste Function in SIkuli

Status in Sikuli:
  In Progress

Bug description:
  Hello,
   If I run a script that loads data from  a CSV, assigns text from the rows to variables and pastes the variables into certain cells of an application that I am automating , I experience an intermittent error, where the application forgets to paste the data:
  it however over the field and pastes nothing into it.
  I tried it in two ways.
   Manually howering, clicking and pasting it all separately.
  I also tried to do Region.paste.

  Both work, however in certain points the application does not paste
  anything into the cell.

  I have sufficient time outs set up, which indicates to me that it might not be related to a time out.
  Also I have set up the IDE to print the data in the variables to console to make sure that python is assigning the data correctly and it seems that python is fine. 

  Therefore I think there might be some issue with the paste function
  when using it to paste multiple chunks of data, from different
  variables over a long period of time.

  Sometimes it also mixes up data which it is pasting and pastes a value
  of a previously called variable over the value of a currently called
  variable.

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1195259/+subscriptions


References