<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Thanks again. Macports didn't have the latest pyobjc, but pip
    updated my installation to the fixed version. Problem solved.<br>
    <br>
    Tim<br>
    <br>
    <div class="moz-cite-prefix">On 20/03/2015 00:18, michael h wrote:<br>
    </div>
    <blockquote
cite="mid:CAD0nt=H-uaO-oLs8OY0k=oW+qNSYX++DJx10gNiKG4ZPd+8Hog@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>Did you see this:</div>
        <div><br>
        </div>
        <a moz-do-not-send="true"
href="https://bitbucket.org/ronaldoussoren/pyobjc/issue/95/attributeerror-in-some-cases-when-checking">https://bitbucket.org/ronaldoussoren/pyobjc/issue/95/attributeerror-in-some-cases-when-checking</a><br>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Thu, Mar 19, 2015 at 12:20 PM,
          Timothy W. Grove <span dir="ltr"><<a
              moz-do-not-send="true" href="mailto:tim_grove@sil.org"
              target="_blank">tim_grove@sil.org</a>></span> wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000"> A personal reply to
              my question sent me to the following link: <a
                moz-do-not-send="true"
href="http://stackoverflow.com/questions/23729704/change-osx-keyboard-layoutinput-source-programmatically-via-terminal-or-appl"
                target="_blank">http://stackoverflow.com/questions/23729704/change-osx-keyboard-layoutinput-source-programmatically-via-terminal-or-appl</a>.
              I seem to have found a solution that worked using PyObjC.<br>
              <br>
              I'm currently using Python 3.3 installed via macports, and
              I installed the appropriate ports for my setup
              (py33-pyobjc, py33-pyobjc-cocoa).<br>
              <br>
              For my import statement:<br>
              <blockquote>from AppKit import NSTextInputContext<br>
                <br>
              </blockquote>
              To find the current keyboard being used:<br>
              <blockquote>ic = NSTextInputContext.new()<br>
                current_keyboard = ic.selectedKeyboardInputSource()<br>
                <br>
              </blockquote>
              To list the currently available keyboards:<br>
              <blockquote>keyboards = ic.keyboardInputSources()<br>
                <br>
              </blockquote>
              To change the current keyboard (to 'Arabic', for example):<br>
              <blockquote>ic.setValue_forKey_('com.apple.keylayout.Arabic',

                'selectedKeyboardInputSource')<br>
              </blockquote>
              <br>
              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. <br>
              <br>
              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.<br>
              <br>
              Best regards,<br>
              Timothy Grove<span class=""><br>
                <small><small> <br>
                    <br>
                  </small></small><br>
                <div>On 05/03/2015 14:51, Timothy W. Grove wrote:<br>
                </div>
                <blockquote type="cite">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. <br>
                  <br>
                  Best regards, <br>
                  Tim <br>
                </blockquote>
                <br>
              </span>
              <blockquote>
                <p><small><small>Traceback (most recent call last):</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/cx_Freeze/initscripts/Console3.py",


                      line 27, in <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>    exec(code, m.__dict__)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File "soosl.py", line 6, in
                      <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1565, in _find_and_load</small></small></p>
                <small><small> </small></small>
                <p><small><small>    return
                      _find_and_load_unlocked(name, import_)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1532, in _find_and_load_unlocked</small></small></p>
                <small><small> </small></small>
                <p><small><small>    loader.load_module(name)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/Users/timothygrove/Documents/workspace/SooSL/mainwindow.py",
                      line 19, in <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1565, in _find_and_load</small></small></p>
                <small><small> </small></small>
                <p><small><small>    return
                      _find_and_load_unlocked(name, import_)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1532, in _find_and_load_unlocked</small></small></p>
                <small><small> </small></small>
                <p><small><small>    loader.load_module(name)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/AppKit/__init__.py",


                      line 9, in <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>    import Foundation</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1565, in _find_and_load</small></small></p>
                <small><small> </small></small>
                <p><small><small>    return
                      _find_and_load_unlocked(name, import_)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1532, in _find_and_load_unlocked</small></small></p>
                <small><small> </small></small>
                <p><small><small>    loader.load_module(name)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/Foundation/__init__.py",


                      line 9, in <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>    import CoreFoundation</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1565, in _find_and_load</small></small></p>
                <small><small> </small></small>
                <p><small><small>    return
                      _find_and_load_unlocked(name, import_)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py",


                      line 1532, in _find_and_load_unlocked</small></small></p>
                <small><small> </small></small>
                <p><small><small>    loader.load_module(name)</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/CoreFoundation/__init__.py",


                      line 20, in <module></small></small></p>
                <small><small> </small></small>
                <p><small><small>    }, ())</small></small></p>
                <small><small> </small></small>
                <p><small><small>  File
                      "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/objc/_lazyimport.py",


                      line 82, in __init__</small></small></p>
                <small><small> </small></small>
                <p><small><small>    if nm.startswith(pfx):</small></small></p>
                <small><small> </small></small>
                <p><small><small>AttributeError: 'NoneType' object has
                      no attribute 'startswith'</small></small></p>
                <small><small> </small></small>
                <p><small><small>logout</small></small></p>
                <small><small> </small></small>
                <p><small><small><br>
                    </small></small></p>
                <small><small> </small></small>
                <p><small><small>[Process completed]</small></small></p>
              </blockquote>
              <br>
            </div>
            <br>
            _______________________________________________<br>
            PyQt mailing list    <a moz-do-not-send="true"
              href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
            <a moz-do-not-send="true"
              href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt"
              target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>