Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87742 > unrolled thread
| Started by | "Timothy W. Grove" <tim_grove@sil.org> |
|---|---|
| First post | 2015-03-19 17:20 +0000 |
| Last post | 2015-03-19 17:20 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: win32api.LoadKeyboardLayout; any solutions for OSX? "Timothy W. Grove" <tim_grove@sil.org> - 2015-03-19 17:20 +0000
| From | "Timothy W. Grove" <tim_grove@sil.org> |
|---|---|
| Date | 2015-03-19 17:20 +0000 |
| Subject | Re: win32api.LoadKeyboardLayout; any solutions for OSX? |
| Message-ID | <mailman.25.1426786092.10327.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
A personal reply to my question sent me to the following link:
http://stackoverflow.com/questions/23729704/change-osx-keyboard-layoutinput-source-programmatically-via-terminal-or-appl.
I seem to have found a solution that worked using PyObjC.
I'm currently using Python 3.3 installed via macports, and I installed
the appropriate ports for my setup (py33-pyobjc, py33-pyobjc-cocoa).
For my import statement:
from AppKit import NSTextInputContext
To find the current keyboard being used:
ic = NSTextInputContext.new()
current_keyboard = ic.selectedKeyboardInputSource()
To list the currently available keyboards:
keyboards = ic.keyboardInputSources()
To change the current keyboard (to 'Arabic', for example):
ic.setValue_forKey_('com.apple.keylayout.Arabic',
'selectedKeyboardInputSource')
Now, that is the good news! This all worked great in my source code, but
as an app bundle (created with cx_Freeze 4.3.2) it wouldn't run at all.
I'll include the full error trace at the end of this email, but the
problems seem to start with the import of AppKit and end with
objc/_lazyimport.py.
I'm not sure if this points to a 'bug' in objc or something else which
I've left out of my setup routine, but if anyone has any ideas, I would
be interested to hear from you.
Best regards,
Timothy Grove
On 05/03/2015 14:51, Timothy W. Grove wrote:
> I was looking for a way to change keyboard layouts from within a
> Python 3 / PyQt4 application. Win32api.LoadKeyboardLayout has come to
> my rescue on Windows, but is anyone aware of a cross-platform or OSX
> specific solution for Apple Mac? Thanks for any suggestions.
>
> Best regards,
> Tim
Traceback (most recent call last):
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/cx_Freeze/initscripts/Console3.py",
line 27, in <module>
exec(code, m.__dict__)
File "soosl.py", line 6, in <module>
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1532, in _find_and_load_unlocked
loader.load_module(name)
File
"/Users/timothygrove/Documents/workspace/SooSL/mainwindow.py", line
19, in <module>
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1532, in _find_and_load_unlocked
loader.load_module(name)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/AppKit/__init__.py",
line 9, in <module>
import Foundation
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1532, in _find_and_load_unlocked
loader.load_module(name)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Foundation/__init__.py",
line 9, in <module>
import CoreFoundation
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1565, in _find_and_load
return _find_and_load_unlocked(name, import_)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",
line 1532, in _find_and_load_unlocked
loader.load_module(name)
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/CoreFoundation/__init__.py",
line 20, in <module>
}, ())
File
"/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/objc/_lazyimport.py",
line 82, in __init__
if nm.startswith(pfx):
AttributeError: 'NoneType' object has no attribute 'startswith'
logout
[Process completed]
Back to top | Article view | comp.lang.python
csiph-web