示例#1
0
 def get_layout_spec(self):
     layout = "us"
     layouts = ["us"]
     variant = ""
     variants = []
     options = ""
     try:
         from AppKit import NSTextInputContext, NSTextView       #@UnresolvedImport
         text_input_context = NSTextInputContext.alloc()
         view = NSTextView.new()
         text_input_context.initWithClient_(view)
         current_keyboard = text_input_context.selectedKeyboardInputSource()
         code = APPLE_LAYOUTS.get(current_keyboard.split(".")[-1])
         log("get_layout_spec() current_keyboard=%s, code=%s", current_keyboard, code)
         all_keyboards = text_input_context.keyboardInputSources()
         log("get_layout_spec() other keyboards=%s", all_keyboards)
         if code:
             layout = code
         if all_keyboards:
             layouts = []
             for k in all_keyboards:
                 code = APPLE_LAYOUTS.get(k.split(".")[-1])
                 if code:
                     layouts.append(code)
             if not layouts:
                 layouts.append("us")
         else:
             if code not in layouts:
                 layouts.insert(0, code)
         log("get_layout_spec() view=%s, input_context=%s, layout=%s, layouts=%s", view, text_input_context, layout, layouts)
     except Exception as e:
         log("get_layout_spec()", exc_info=True)
         log.error("Error querying keyboard layout:")
         log.error(" %s", e)
     return layout, layouts, variant, variants, options
示例#2
0
    def watch(ime):
        txtObj = NSTextInputContext.alloc().initWithClient_(NSTextView.new())

        obs = Observer.new().initWithValue_(txtObj)
        obs.ime = ime

        Foundation.NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
            obs, 'bundle:', NSTextInputContextKeyboardSelectionDidChangeNotification, None)
        AppHelper.runConsoleEventLoop()
示例#3
0
 def __init__(self) -> None:
     self.text_input_context = NSTextInputContext.alloc().initWithClient_(NSTextView.new())
     self.last_ime = ImSwitcher.english_ime
     manager = multiprocessing.Manager()
     self.cur_ime = manager.Value(ctypes.c_wchar_p, ImSwitcher.english_ime)
     multiprocessing.Process(target=Observer.watch,
                             args=(self.cur_ime,)).start()
     try:
         # 隐藏macos dock栏小火箭
         info = NSBundle.mainBundle().infoDictionary()
         info["LSBackgroundOnly"] = "1"
     except ImportError:
         print("隐藏macos dock栏小火箭,需要pip3 install -U PyObjC")
示例#4
0
 def __init__(self, vim):
     self.vim = vim
     self.text_input_context = NSTextInputContext.alloc().initWithClient_(
         NSTextView.new())