Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #87742

Re: win32api.LoadKeyboardLayout; any solutions for OSX?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tim_grove@sil.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'skip:" 60': 0.07; '__init__': 0.09; 'rescue': 0.09; 'suggestions.': 0.09; 'windows,': 0.09; 'python': 0.11; "wouldn't": 0.14; '(created': 0.16; 'grove': 0.16; 'received:192.168.1.4': 0.16; 'skip:" 100': 0.16; 'used:': 0.16; 'all.': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; 'app': 0.19; 'pfxlen:0': 0.19; "skip:' 30": 0.19; 'foundation': 0.20; 'code,': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'keyboard': 0.24; 'skip:i 40': 0.24; 'question': 0.24; "i've": 0.25; 'source': 0.25; 'skip:_ 20': 0.27; 'header:In-Reply-To:1': 0.27; 'installed': 0.27; 'to:2**1': 0.27; 'points': 0.29; 'tim': 0.29; "i'm": 0.30; 'trace': 0.31; 'anyone': 0.31; 'file': 0.32; 'run': 0.32; 'received:209.85.212': 0.32; 'worked': 0.33; '(most': 0.33; 'skip:_ 10': 0.34; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'thanks': 0.36; "i'll": 0.36; 'subject:?': 0.36; 'list': 0.37; 'received:209': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'problems': 0.38; 'apple': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'full': 0.61; 'you.': 0.62; 'hear': 0.63; 'personal': 0.63; 'skip:n 10': 0.64; 'great': 0.65; 'within': 0.65; 'reply': 0.66; '20,': 0.68; 'email,': 0.69; 'link:': 0.72; 'timothy': 0.84; 'subject:skip:w 20': 0.91; 'ports': 0.93
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=M5Uz98NJZ+vKtH0SIiJmvaHpcIgCf5wQm9Njgn47WoY=; b=YAu/t4++6pnU6c9cqj8z/SiIGlUTf39xAkCAc/CumbmYDXM8zclpJRYw7hF+m2MiDp K3z8YxZmfgZwey5+CmGamTlrmnzzHgFqq8LZKZwaGnpFTuWyE8QiTIuljVzT+de5qYPi +YhoqAK264qdGAtI5Hu4RxjNOUXqstScfG60QsxoB5w6n0LXxoGxP/aNBHlWktKuBrJ9 8U9BDYUzh5ILBqsttySwOgj8rfQJ9i27q+JTV0x0THvBdq84akeLvOSyZMnfTn2XrOSN iUPOPCsI9qbO9VBIURhRz8OTXyLByNglnoCIRmTF6GLtEIR15xaoLUjwJJTAEHQrg9Ko QPyg==
X-Gm-Message-State ALoCoQn/bWoZJyELPc27bwgKZtNC8fkyXrdySf/GQ5o6iGTAwkWCBVdNILjhN5lxdf2KqwPP9Ke3
X-Received by 10.180.78.136 with SMTP id b8mr18717278wix.6.1426785630352; Thu, 19 Mar 2015 10:20:30 -0700 (PDT)
Date Thu, 19 Mar 2015 17:20:25 +0000
From "Timothy W. Grove" <tim_grove@sil.org>
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To Python <python-list@python.org>, PyQT mailing list <pyqt@riverbankcomputing.com>
Subject Re: win32api.LoadKeyboardLayout; any solutions for OSX?
References <54F86D7B.60504@sil.org>
In-Reply-To <54F86D7B.60504@sil.org>
Content-Type multipart/alternative; boundary="------------090505070708080402010608"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.19
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.25.1426786092.10327.python-list@python.org> (permalink)
Lines 369
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1426786092 news.xs4all.nl 2892 [2001:888:2000:d::a6]:51681
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:87742

Show key headers only | View raw


[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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: win32api.LoadKeyboardLayout; any solutions for OSX? "Timothy W. Grove" <tim_grove@sil.org> - 2015-03-19 17:20 +0000

csiph-web