def __init__(self, keymap): state = lib.xkb_state_new(keymap._keymap) if not state: raise XKBError("Couldn't create keyboard state") # Keep the keymap around to ensure it isn't collected too soon self.keymap = keymap self._state = ffi.gc(state, _keepref(lib, lib.xkb_state_unref))
def __init__(self, keymap): state = lib.xkb_state_new(keymap._keymap) if not state: raise XKBError("Couldn't create keyboard state") # Keep the keymap around to ensure it isn't collected too soon self.keymap = keymap def free_state_closure(): saved_lib = lib def free_state(obj): saved_lib.xkb_state_unref(obj) return free_state self._state = ffi.gc(state, free_state_closure())
def __init__(self, context, pointer, load_method): self.load_method = load_method self._context = context # This nasty hack is necessary to keep "lib" around long # enough for us to use it to free the context while python is # shutting down. The obvious way of writing it works fine on # python3; this version is necessary for compatibility with # python2. def free_keymap_closure(): saved_lib = lib def free_keymap(obj): saved_lib.xkb_keymap_unref(obj) return free_keymap self._keymap = ffi.gc(pointer, free_keymap_closure()) self._valid_keycodes = None
def __init__(self, no_default_includes=False, no_environment_names=False): """Create a new context. Keyword arguments: no_default_includes: if set, create this context with an empty include path. no_environment_names: if set, don't take RMLVO names from the environment. """ flags = lib.XKB_CONTEXT_NO_FLAGS if no_default_includes: flags = flags | lib.XKB_CONTEXT_NO_DEFAULT_INCLUDES if no_environment_names: flags = flags | lib.XKB_CONTEXT_NO_ENVIRONMENT_NAMES context = lib.xkb_context_new(flags) if not context: raise XKBError("Couldn't create XKB context") # This nasty hack is necessary to keep "lib" around long # enough for us to use it to free the context while python is # shutting down. The obvious way of writing it works fine on # python3; this version is necessary for compatibility with # python2. def free_context_closure(): saved_lib = lib def free_context(obj): saved_lib.xkb_context_unref(obj) return free_context self._context = ffi.gc(context, free_context_closure()) self._log_fn = None # We keep a reference to the handle to keep it alive self._userdata = ffi.new_handle(self) lib.xkb_context_set_user_data(self._context, self._userdata)
def __init__(self, no_default_includes=False, no_environment_names=False): """Create a new context. Keyword arguments: no_default_includes: if set, create this context with an empty include path. no_environment_names: if set, don't take RMLVO names from the environment. """ flags = lib.XKB_CONTEXT_NO_FLAGS if no_default_includes: flags = flags | lib.XKB_CONTEXT_NO_DEFAULT_INCLUDES if no_environment_names: flags = flags | lib.XKB_CONTEXT_NO_ENVIRONMENT_NAMES context = lib.xkb_context_new(flags) if not context: raise XKBError("Couldn't create XKB context") self._context = ffi.gc(context, _keepref(lib, lib.xkb_context_unref)) self._log_fn = None # We keep a reference to the handle to keep it alive self._userdata = ffi.new_handle(self) lib.xkb_context_set_user_data(self._context, self._userdata)
def __init__(self, context, pointer, load_method): self.load_method = load_method self._context = context self._keymap = ffi.gc(pointer, _keepref(lib, lib.xkb_keymap_unref)) self._valid_keycodes = None