---
name: "wx_object"
section: "3erl"
platform: "linux"
package: "erlang-manpages"
version: "1:25.2.3+dfsg-1+deb12u4"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/wx_object"
---

# wx\_object(3erl)

wx\_object - Generic wx object behaviour.

## NAME

wx\_object - wx\_object - Generic wx object behaviour.

## DESCRIPTION

wx\_object - Generic wx object behaviour

This is a behaviour module that can be used for "sub classing" wx objects. It works like a regular gen\_server module and creates a server per object.

NOTE: Currently no form of inheritance is implemented.

The user module should export:

init(Args) should return \
 {wxObject, State} \| {wxObject, State, Timeout} \| ignore \| {stop, Reason}

Asynchronous window event handling: \
 handle\_event(#wx{}, State) should return \
 {noreply, State} \| {noreply, State, Timeout} \| {stop, Reason, State}

The user module can export the following callback functions:

handle\_call(Msg, {From, Tag}, State) should return \
 {reply, Reply, State} \| {reply, Reply, State, Timeout} \| {noreply, State} \| {noreply, State, Timeout} \| {stop, Reason, Reply, State}

handle\_cast(Msg, State) should return \
 {noreply, State} \| {noreply, State, Timeout} \| {stop, Reason, State}

If the above are not exported but called, the wx\_object process will crash. The user module can also export:

Info is message e.g. {'EXIT', P, R}, {nodedown, N}, ... \
 handle\_info(Info, State) should return , ... \
 {noreply, State} \| {noreply, State, Timeout} \| {stop, Reason, State}

If a message is sent to the wx\_object process when handle\_info is not exported, the message will be dropped and ignored.

When stop is returned in one of the functions above with Reason = normal \| shutdown \| Term, terminate(State) is called. It lets the user module clean up, it is always called when server terminates or when wx\_object() in the driver is deleted. If the Parent process terminates the Module:terminate/2 function is called. \
 terminate(Reason, State)

Example:

```
  -module(myDialog).
  -export([new/2, show/1, destroy/1]).  %% API
  -export([init/1, handle_call/3, handle_event/2,
           handle_info/2, code_change/3, terminate/2]).
           new/2, showModal/1, destroy/1]).  %% Callbacks
  %% Client API
  new(Parent, Msg) ->
     wx_object:start(?MODULE, [Parent,Id], []).
  show(Dialog) ->
     wx_object:call(Dialog, show_modal).
  destroy(Dialog) ->
     wx_object:call(Dialog, destroy).
  %% Server Implementation ala gen_server
  init([Parent, Str]) ->
     Dialog = wxDialog:new(Parent, 42, "Testing", []),
     ...
     wxDialog:connect(Dialog, command_button_clicked),
     {Dialog, MyState}.
  handle_call(show, _From, State) ->
     wxDialog:show(State#state.win),
     {reply, ok, State};
  ...
  handle_event(#wx{}, State) ->
     io:format("Users clicked button~n",[]),
     {noreply, State};
  ...
```

## DATA TYPES

- **request\_id() = term():**

  - **server\_ref() = wx:wx\_object() \| atom() \| pid():**

  ## EXPORTS

**start(Name, Mod, Args, Options) -\> wxWindow:wxWindow() \| {error, term()}**\

Types:

Name = {local, atom()}\
 Mod = atom()\
 Args = term()\
 Flag = trace \| log \| {logfile, string()} \| statistics \| debug\
 Options = \[{timeout, timeout()} \| {debug, \[Flag\]}\]\

Starts a generic wx\_object server and invokes Mod:init(Args) in the new process.

**start\_link(Mod, Args, Options) -\> wxWindow:wxWindow() \| {error, term()}**\

Types:

Mod = atom()\
 Args = term()\
 Flag = trace \| log \| {logfile, string()} \| statistics \| debug\
 Options = \[{timeout, timeout()} \| {debug, \[Flag\]}\]\

Starts a generic wx\_object server and invokes Mod:init(Args) in the new process.

**start\_link(Name, Mod, Args, Options) -\> wxWindow:wxWindow() \| {error, term()}**\

Types:

Name = {local, atom()}\
 Mod = atom()\
 Args = term()\
 Flag = trace \| log \| {logfile, string()} \| statistics \| debug\
 Options = \[{timeout, timeout()} \| {debug, \[Flag\]}\]\

Starts a generic wx\_object server and invokes Mod:init(Args) in the new process.

**stop(Obj) -\> ok**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\

Stops a generic wx\_object server with reason 'normal'. Invokes terminate(Reason,State) in the server. The call waits until the process is terminated. If the process does not exist, an exception is raised.

**stop(Obj, Reason, Timeout) -\> ok**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\
 Reason = term()\
 Timeout = timeout()\

Stops a generic wx\_object 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.

**call(Obj, Request) -\> term()**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\
 Request = term()\

Make a call to a wx\_object server. The call waits until it gets a result. Invokes handle\_call(Request, From, State) in the server

**call(Obj, Request, Timeout) -\> term()**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\
 Request = term()\
 Timeout = integer()\

Make a call to a wx\_object server with a timeout. Invokes handle\_call(Request, From, State) in server

**send\_request(Obj, Request::term()) -\> request\_id()**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\

Make an send\_request to a generic server. and return a RequestId which can/should be used with wait\_response/\[1\|2\]. Invokes handle\_call(Request, From, State) in server.

**wait\_response(RequestId::request\_id()) -\> {reply, Reply::term()} \| {error, {term(), server\_ref()}}**\

Wait infinitely for a reply from a generic server.

**wait\_response(Key::request\_id(), Timeout::timeout()) -\> {reply, Reply::term()} \| timeout \| {error, {term(), server\_ref()}}**\

Wait 'timeout' for a reply from a generic server.

**check\_response(Msg::term(), Key::request\_id()) -\> {reply, Reply::term()} \| false \| {error, {term(), server\_ref()}}**\

Check if a received message was a reply to a RequestId

**cast(Obj, Request) -\> ok**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\
 Request = term()\

Make a cast to a wx\_object server. Invokes handle\_cast(Request, State) in the server

**get\_pid(Obj) -\> pid()**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\

Get the pid of the object handle.

**set\_pid(Obj, Pid::pid()) -\> wx:wx\_object()**\

Types:

Obj = wx:wx\_object() \| atom() \| pid()\

Sets the controlling process of the object handle.

**reply(X1::{pid(), Tag::term()}, Reply::term()) -\> pid()**\

Get the pid of the object handle.

## AUTHORS

*\<\>*
