raghuram534 / autokey

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

clipboard.get_selection sometimes fails #40

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.  Assign a hotkey to a script using clipboard.get_selection.
2.  Save, and close the configuration window.
3.  Try using the script on selected text.
This problem typically does not occur when AutoKey is first started, but
later it happens consistently.

What is the expected output? What do you see instead?
The script should successfully get the selected text, but it gives an error
instead.

What version of the product are you using? On what operating system?
AutoKey 0.70.2 on Ubuntu Hardy.

Please provide any additional information below.
The strange thing is that having the AutoKey configuration window open
guarantees that the error will not happen, and the script will work just
fine.  The error is not entirely predictable when the window is closed, but
never happens when it is open.  If I have the problem and then open the
configuration window and try the hotkey again, the script will work fine,
and if I close it, the error behavior will immediately return.  If I keep
the configuration window open all day, the error never happens.

I think I have experienced this issue all along, but with the frequent
improvements to AutoKey's hotkey handling I had hoped it was just a glitch
that would get worked out in the course of things.

Here is the log from executing "Selection Test" from the "Sample Scripts"
folder.

DEBUG - iomediator - <alt> pressed
DEBUG - iomediator - <ctrl> pressed
DEBUG - service - Key: u't', modifiers: ['<alt>', '<ctrl>']
INFO - service - Matched hotkey phrase/script with prompt=False
DEBUG - service - Script runner executing: Script('Selection Test')
DEBUG - iomediator - <ctrl> released
DEBUG - iomediator - <alt> released
ERROR - service - Script error
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/autokey/service.py", line 378, in
execute
    exec script.code in self.scope
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/autokey/scripting.py", line 679,
in get_selection
    return self.text.decode("utf-8")
AttributeError: 'NoneType' object has no attribute 'decode'

If this is just due to Hardy having an older Xorg, then I can just leave
the configuration window open until I upgrade.

Original issue reported on code.google.com by dv8box-...@yahoo.com on 19 Apr 2010 at 12:47

GoogleCodeExporter commented 8 years ago
This error occurs when there is no text received from the X selection. There is
nothing that can be done about it, probably would be good to have a nicer error 
from
AutoKey though.

Original comment by cdekter on 19 Apr 2010 at 2:21

GoogleCodeExporter commented 8 years ago
Any idea why it would only happen when the AutoKey configuration window is not 
open?

Original comment by dv8box-...@yahoo.com on 19 Apr 2010 at 3:29

GoogleCodeExporter commented 8 years ago
No idea... there's a small test you could try though:

In the method __execAsync() at line 713 of 
/usr/share/pyshared/autokey/scripting.py,
replace the entire method body with the following code:
        self.sem = threading.Semaphore(0)
        gtk.gdk.threads_enter()
        callback(*args)
        gtk.gdk.threads_leave()
        self.sem.acquire()

See if that improves the reliability...

Original comment by cdekter on 19 Apr 2010 at 3:37

GoogleCodeExporter commented 8 years ago
I think that may have fixed it.  I used it last night and this morning, and it 
has
not failed at all.  Thanks.

Original comment by dv8box-...@yahoo.com on 19 Apr 2010 at 12:44

GoogleCodeExporter commented 8 years ago
Fix released in v0.70.3

Original comment by cdekter on 22 Apr 2010 at 6:16