View Source WxObject behaviour (wx_ex v0.4.3)

An Elixir wrapper for Erlang’s :wx_object behaviour, along the lines of GenServer etc.

Does not yet support 100% of :wx_object’s API.

Unlike GenServer, WxObject returns a wxWindow reference rather than a pid. If you want to include your top level object in your supervision tree, you will need to return the pid from start_link. For example:

def start_link(_arg) do
  ref = WxObject.start_link(__MODULE__, nil, name: __MODULE__)
  {:ok, WxObject.get_pid(ref)}
end

For an example of using this module, see wx_tutorial.

Summary

Functions

Make a synchronous call to the server and wait for its reply.

Cast a request to the server without waiting for a response.

Get the pid of the object handle.

Stops a WxObject server with the given reason. Invokes terminate(reason, state) in the server. The call waits until the process is terminated. If the call times out, or if the process does not exist, an exception is raised.

Callbacks

Link to this callback

handle_call(request, from, state)

View Source (optional)
@callback handle_call(request :: term(), from :: GenServer.server(), state :: term()) ::
  {:reply, reply, new_state}
  | {:reply, reply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason, reply, new_state}
  | {:stop, reason, new_state}
when reply: term(), new_state: term(), reason: term()
Link to this callback

handle_cast(request, state)

View Source (optional)
@callback handle_cast(request :: term(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()
Link to this callback

handle_event(request, state)

View Source
@callback handle_event(
  request ::
    {:wx, id :: integer(), obj :: :wx.wx_object(), userData :: term(),
     event :: tuple()},
  state :: term()
) ::
  {:noreply, new_state :: term()}
  | {:noreply, new_state :: term(), timeout() | :hibernate}
  | {:stop, reason :: term(), new_state :: term()}
Link to this callback

handle_info(msg, state)

View Source (optional)
@callback handle_info(msg :: :timeout | term(), state :: term()) ::
  {:noreply, new_state}
  | {:noreply, new_state,
     timeout() | :hibernate | {:continue, continue_arg :: term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()
Link to this callback

handle_sync_event(request, ref, state)

View Source (optional)
@callback handle_sync_event(
  request ::
    {:wx, id :: integer(), obj :: :wx.wx_object(), userData :: term(),
     event :: tuple()},
  ref :: {:wx_ref, ref :: term(), type :: term(), state :: term()},
  state :: term()
) :: :ok
@callback init(args :: term()) ::
  {{:wx_ref, ref :: term(), type :: term(), state :: term()},
   [{:state, term()}]}
  | {{:wx_ref, ref :: term(), type :: term(), state :: term()}, state :: term(),
     timeout() | :hibernate}
  | {:stop, reason :: term()}
  | :ignore
Link to this callback

terminate(reason, state)

View Source (optional)
@callback terminate(reason, state :: term()) :: term()
when reason: :normal | :shutdown | {:shutdown, term()} | term()

Functions

Link to this function

call(obj, request, timeout \\ 5000)

View Source
@spec call(:wx.wx_object(), term(), timeout()) :: term()

Make a synchronous call to the server and wait for its reply.

@spec cast(:wx.wx_object(), term()) :: term()

Cast a request to the server without waiting for a response.

@spec get_pid(:wx.wx_object() | atom() | pid()) :: pid()

Get the pid of the object handle.

Link to this function

start_link(module, args)

View Source
Link to this function

start_link(name, module, args)

View Source
Link to this function

start_link(name, module, args, options)

View Source
Link to this function

stop(server, reason \\ :normal, timeout \\ :infinity)

View Source
@spec stop(:wx.wx_object(), term(), timeout()) :: :ok

Stops a WxObject server with the given reason. Invokes terminate(reason, state) in the server. The call waits until the process is terminated. If the call times out, or if the process does not exist, an exception is raised.