jay823001 / autokey

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

clipboard.get_selection() and clipboard.get_clipboard() don't understand non-latin #107

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. select some non-latin UTF-text
for example from this page http://ru.wikipedia.org/
2. use predefined script "Abbreviation from selection"

What is the expected output? What do you see instead?
dialog "New Abbreviation" dont open.
$ autokey-qt -l
[...]
DEBUG - interface - New window mapped, grabbing hotkeys
DEBUG - interface - New window mapped, grabbing hotkeys
DEBUG - iomediator - <ctrl> pressed
DEBUG - service - Raw key: '<f6>', modifiers: ['<ctrl>'], Key: '<f6>'
DEBUG - service - No phrase/script matched hotkey
DEBUG - service - Folder matched hotkey - showing menu
DEBUG - phrase-menu - Sorting phrase menu by usage count
DEBUG - iomediator - <ctrl> released
DEBUG - service - Received mouse click - resetting buffer
DEBUG - service - Script runner executing: Script('Abbreviation from selection')
ERROR - service - Script error
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/autokey/service.py", line 403, in execute
    exec script.code in self.scope
  File "<string>", line 3, in <module>
  File "/usr/lib/python2.6/site-packages/autokey/scripting.py", line 622, in get_selection
    return str(self.text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 5: 
ordinal not in range(128)
[...]

What version of the product are you using? On what operating system?
$ autokey-qt -v
Qt: 4.7.1
KDE Development Platform: 4.6.00 (4.6.0)
AutoKey: 0.71.2
$ uname -a
Linux alex-pc.localdomain 2.6.35-std-def-alt9 #1 SMP Thu Dec 9 08:52:44 UTC 
2010 x86_64 GNU/Linux

Please provide any additional information below.
problem in functions clipboard.get_selection() and clipboard.get_clipboard().
i performed patch to fix this problem. see attach.

Original issue reported on code.google.com by ua2...@gmail.com on 4 Mar 2011 at 11:00

Attachments:

GoogleCodeExporter commented 9 years ago
Good catch... I think though your patch could be simplified somewhat. Instead of

t=str(self.text.toUtf8())
return t.decode("utf-8")

you could probably just

return unicode(self.text)

Original comment by cdekter on 4 Mar 2011 at 12:20

GoogleCodeExporter commented 9 years ago

Original comment by cdekter on 4 Mar 2011 at 12:21

GoogleCodeExporter commented 9 years ago
>you could probably just
>return unicode(self.text)

this work fine ;)

Original comment by ua2...@gmail.com on 4 Mar 2011 at 12:30

GoogleCodeExporter commented 9 years ago
Fixed in v0.71.3

Original comment by cdekter on 31 Mar 2011 at 10:34

GoogleCodeExporter commented 9 years ago
I have a problem that might be related. I am on Ubuntu 10.10 (xfce) and 
installed autokey using the ppa. When starting the program I am prompted with 
the following message box:

Fatal error starting AutoKey.
'ascii' codec can't encode characters in position 27-28: ordinal not in 
range(128)

On the console I see the following output:

Xlib.protocol.request.QueryExtension
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 349, sequence_number = 
15, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 349, sequence_number = 
16, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 349, sequence_number = 
17, major_opcode = 33, minor_opcode = 0
X protocol error:
<class 'Xlib.error.BadAccess'>: code = 10, resource_id = 349, sequence_number = 
18, major_opcode = 33, minor_opcode = 0
Xlib.protocol.request.QueryExtension

I previously had an old version of autokey installed, that I obtained by 
entering "apt-get install autokey" prior to adding your ppa. Afterwards I 
followed the instructions posted somewhere here (uninstalling, adding ppa, 
update, install) to upgrade to the current version.

In the old version I created some phrases containing some German umlauts, if 
this could be a cause.

Before submitting I realised there is some information in the file 
"autokey.log". Here the last few lines:
2012-06-27 17:07:46,483 ERROR - root - Fatal error starting AutoKey: 'ascii' 
codec can't encode characters in position 27-28: ordinal not in range(128)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/autokey/gtkapp.py", line 78, in __init__
    self.initialise(options.configure)
  File "/usr/lib/python2.7/dist-packages/autokey/gtkapp.py", line 138, in initialise
    self.notifier = get_notifier(self)
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/notifier.py", line 40, in get_notifier
    return IndicatorNotifier(app)
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/notifier.py", line 178, in __init__
    self.rebuild_menu()
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/notifier.py", line 227, in rebuild_menu
    self.menu = popupmenu.PopupMenu(self.app.service, folders, items, False)
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/popupmenu.py", line 63, in __init__
    menuItem.set_submenu(PopupMenu(service, folder.folders, folder.items, False))
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/popupmenu.py", line 44, in __init__
    items.sort(key=lambda obj: str(obj))
  File "/usr/lib/python2.7/dist-packages/autokey/gtkui/popupmenu.py", line 44, in <lambda>
    items.sort(key=lambda obj: str(obj))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 27-28: 
ordinal not in range(128)

Best regards,
Peter

PS: I hope I did not hijack this bugreport... If so -- sorry!

Original comment by Peter.Pl...@gmail.com on 27 Jun 2012 at 3:09

GoogleCodeExporter commented 9 years ago
I was curious and deleted the folder "data". Afterwards autokey starts as 
expected. So it must have something to do with one of the phrases I entered in 
the old version...

Original comment by Peter.Pl...@gmail.com on 27 Jun 2012 at 3:14

GoogleCodeExporter commented 9 years ago
So I did not stop...

The culprit was the file ".folder.json" inside the folder "My Phrases". Here is 
the unified diff:

diff -u .folder.json .folder.new.json 
--- .folder.json    2012-06-27 16:46:00.000000000 +0200
+++ .folder.new.json    2012-06-27 17:12:36.000000000 +0200
@@ -1,10 +1,8 @@
 {
-    "usageCount": 8, 
+    "usageCount": 0, 
     "abbreviation": {
         "wordChars": "[\\w]", 
-        "abbreviations": [
-            null
-        ], 
+        "abbreviations": [], 
         "immediate": false, 
         "ignoreCase": false, 
         "backspace": true, 
@@ -25,5 +23,5 @@
         "isRecursive": false
     }, 
     "type": "folder", 
-    "showInTrayMenu": true
+    "showInTrayMenu": false
 }

Cheers!
Thank you for the nice program!

Original comment by Peter.Pl...@gmail.com on 27 Jun 2012 at 3:22