caldurza / autokey

Automatically exported from code.google.com/p/autokey
GNU General Public License v3.0
0 stars 0 forks source link

clipboard.fill_clipboard() crashes Autokey #212

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a test script using clipboard.fill_clipboard():
        text = "hello"
        clipboard.fill_clipboard(text)
        keyboard.send_keys("<ctrl>+v")
2. Set the hotkey for the script.
3. Save and run the script using the assigned hotkey.

What is the expected output? What do you see instead?
Expect: Put "hello" into the clipboard then paste it on the current cursor 
position.
See: Program crashed. No changes in clipboard content. Clipboard not pasted.

What version of the product are you using? On what operating system?
0.90.4
Ubuntu 12.04

Please provide any additional information below.
2012-07-20 00:16:57,319 DEBUG - iomediator - <ctrl> pressed
2012-07-20 00:16:58,502 DEBUG - service - Raw key: u'q', modifiers: ['<ctrl>'], 
Key: q
2012-07-20 00:16:58,503 DEBUG - service - Window visible title: u'AutoKey', 
Window class: 'autokey-gtk.Autokey-gtk'
2012-07-20 00:16:58,503 INFO - service - Matched hotkey phrase/script with 
prompt=False
2012-07-20 00:16:58,503 DEBUG - service - Ignored locking error in 
handle_keypress
2012-07-20 00:16:58,503 DEBUG - service - Script runner executing: 
Script('test')
2012-07-20 00:16:58,503 ERROR - service - Script error
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/autokey/service.py", line 454, in execute
    exec script.code in scope
  File "<string>", line 2, in <module>
  File "/usr/lib/python2.7/dist-packages/autokey/scripting.py", line 837, in fill_clipboard
    self.clipBoard.set_text(contents.encode("utf-8"))
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
TypeError: set_text() takes exactly 3 arguments (2 given)
2012-07-20 00:16:58,700 DEBUG - iomediator - <ctrl> released

Original issue reported on code.google.com by hedgehog...@yahoo.com on 19 Jul 2012 at 4:20

GoogleCodeExporter commented 8 years ago
I had the same problem. To fix it, I had to change the code so it explicitly 
passes the third argument, which should be a default value but for some reason 
isn't.

in /usr/lib/python2.7/dist-packages/autokey/scripting.py, change the following:

* Change this line in GtkClipboard's __fillSelection():
        self.selection.set_text(string.encode("utf-8"))
  to this:
        self.selection.set_text(string.encode("utf-8"), -1)

* Change this line in GtkClipboard's fill_clipboard():
        self.clipBoard.set_text(contents.encode("utf-8"))
  to this:
        self.clipBoard.set_text(contents.encode("utf-8"), -1)

Original comment by pau...@zolabooks.com on 4 Dec 2012 at 9:18

GoogleCodeExporter commented 8 years ago
Yikes! I just ran this and found many more references to set_text() that should 
probably also have the "-1" argument added to them:
grep -rIF '.set_text(' /usr/lib/python2.7/dist-packages/autokey

Original comment by paul...@gmail.com on 5 Dec 2012 at 9:30

GoogleCodeExporter commented 8 years ago
The above hint to do this:
in /usr/lib/python2.7/dist-packages/autokey/scripting.py, change the following:

* Change this line in GtkClipboard's __fillSelection():
        self.selection.set_text(string.encode("utf-8"))
  to this:
        self.selection.set_text(string.encode("utf-8"), -1)

* Change this line in GtkClipboard's fill_clipboard():
        self.clipBoard.set_text(contents.encode("utf-8"))
  to this:
        self.clipBoard.set_text(contents.encode("utf-8"), -1)

worked for me.  Thank you.

Original comment by ranju.ma...@gmail.com on 19 Jul 2013 at 1:32

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Paul's change worked. Except I also needed to add it to interface.py

/usr/lib/python2.7/dist-packages/autokey/interface.py:                
self.clipBoard.set_text(self.__savedClipboard, -1)
/usr/lib/python2.7/dist-packages/autokey/interface.py:            
self.selection.set_text(string.encode("utf-8"), -1)
/usr/lib/python2.7/dist-packages/autokey/interface.py:            
self.clipBoard.set_text(string.encode("utf-8"), -1)
/usr/lib/python2.7/dist-packages/autokey/scripting.py:        
self.selection.set_text(string.encode("utf-8"), -1)
/usr/lib/python2.7/dist-packages/autokey/scripting.py:        
self.clipBoard.set_text(contents.encode("utf-8"), -1)

Original comment by JRep...@gmail.com on 19 Aug 2014 at 6:05

GoogleCodeExporter commented 8 years ago
This issue occured for me whenever I set "Paste using" in the UI to anything 
clipboard related. Only "Keyboard" option worked, but was unusable in some 
applications (due to auto-formatting issues in that app).
0.90.4, Debian Sid.

Adding the -1 parameter in the mentioned places in interface.py and 
scripting.py fixed this issue for me, thanx for sharing!
Any plans on including the two year old fixes upstream?

Original comment by schaefe...@web.de on 21 Nov 2014 at 12:10