1wx_object(3) Erlang Module Definition wx_object(3)
2
3
4
6 wx_object - wx_object - Generic wx object behaviour.
7
9 wx_object - Generic wx object behaviour
10
11 This is a behaviour module that can be used for "sub classing" wx ob‐
12 jects. It works like a regular gen_server module and creates a server
13 per object.
14
15 NOTE: Currently no form of inheritance is implemented.
16
17 The user module should export:
18
19 init(Args) should return
20 {wxObject, State} | {wxObject, State, Timeout} | ignore | {stop, Rea‐
21 son}
22
23 Asynchronous window event handling:
24 handle_event(#wx{}, State) should return
25 {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}
26
27 The user module can export the following callback functions:
28
29 handle_call(Msg, {From, Tag}, State) should return
30 {reply, Reply, State} | {reply, Reply, State, Timeout} | {noreply,
31 State} | {noreply, State, Timeout} | {stop, Reason, Reply, State}
32
33 handle_cast(Msg, State) should return
34 {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}
35
36 If the above are not exported but called, the wx_object process will
37 crash. The user module can also export:
38
39 Info is message e.g. {'EXIT', P, R}, {nodedown, N}, ...
40 handle_info(Info, State) should return , ...
41 {noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}
42
43 If a message is sent to the wx_object process when handle_info is not
44 exported, the message will be dropped and ignored.
45
46 When stop is returned in one of the functions above with Reason = nor‐
47 mal | shutdown | Term, terminate(State) is called. It lets the user
48 module clean up, it is always called when server terminates or when
49 wx_object() in the driver is deleted. If the Parent process terminates
50 the Module:terminate/2 function is called.
51 terminate(Reason, State)
52
53 Example:
54
55 -module(myDialog).
56 -export([new/2, show/1, destroy/1]). %% API
57 -export([init/1, handle_call/3, handle_event/2,
58 handle_info/2, code_change/3, terminate/2]).
59 new/2, showModal/1, destroy/1]). %% Callbacks
60
61 %% Client API
62 new(Parent, Msg) ->
63 wx_object:start(?MODULE, [Parent,Id], []).
64
65 show(Dialog) ->
66 wx_object:call(Dialog, show_modal).
67
68 destroy(Dialog) ->
69 wx_object:call(Dialog, destroy).
70
71 %% Server Implementation ala gen_server
72 init([Parent, Str]) ->
73 Dialog = wxDialog:new(Parent, 42, "Testing", []),
74 ...
75 wxDialog:connect(Dialog, command_button_clicked),
76 {Dialog, MyState}.
77
78 handle_call(show, _From, State) ->
79 wxDialog:show(State#state.win),
80 {reply, ok, State};
81 ...
82 handle_event(#wx{}, State) ->
83 io:format("Users clicked button~n",[]),
84 {noreply, State};
85 ...
86
88 request_id() = term():
89
90
91 server_ref() = wx:wx_object() | atom() | pid():
92
93
95 start(Name, Mod, Args, Options) -> wxWindow:wxWindow() | {error,
96 term()}
97
98 Types:
99
100 Name = {local, atom()}
101 Mod = atom()
102 Args = term()
103 Flag = trace | log | {logfile, string()} | statistics | debug
104 Options = [{timeout, timeout()} | {debug, [Flag]}]
105
106 Starts a generic wx_object server and invokes Mod:init(Args) in
107 the new process.
108
109 start_link(Mod, Args, Options) -> wxWindow:wxWindow() | {error, term()}
110
111 Types:
112
113 Mod = atom()
114 Args = term()
115 Flag = trace | log | {logfile, string()} | statistics | debug
116 Options = [{timeout, timeout()} | {debug, [Flag]}]
117
118 Starts a generic wx_object server and invokes Mod:init(Args) in
119 the new process.
120
121 start_link(Name, Mod, Args, Options) -> wxWindow:wxWindow() | {error,
122 term()}
123
124 Types:
125
126 Name = {local, atom()}
127 Mod = atom()
128 Args = term()
129 Flag = trace | log | {logfile, string()} | statistics | debug
130 Options = [{timeout, timeout()} | {debug, [Flag]}]
131
132 Starts a generic wx_object server and invokes Mod:init(Args) in
133 the new process.
134
135 stop(Obj) -> ok
136
137 Types:
138
139 Obj = wx:wx_object() | atom() | pid()
140
141 Stops a generic wx_object server with reason 'normal'. Invokes
142 terminate(Reason,State) in the server. The call waits until the
143 process is terminated. If the process does not exist, an excep‐
144 tion is raised.
145
146 stop(Obj, Reason, Timeout) -> ok
147
148 Types:
149
150 Obj = wx:wx_object() | atom() | pid()
151 Reason = term()
152 Timeout = timeout()
153
154 Stops a generic wx_object server with the given Reason. Invokes
155 terminate(Reason,State) in the server. The call waits until the
156 process is terminated. If the call times out, or if the process
157 does not exist, an exception is raised.
158
159 call(Obj, Request) -> term()
160
161 Types:
162
163 Obj = wx:wx_object() | atom() | pid()
164 Request = term()
165
166 Make a call to a wx_object server. The call waits until it gets
167 a result. Invokes handle_call(Request, From, State) in the
168 server
169
170 call(Obj, Request, Timeout) -> term()
171
172 Types:
173
174 Obj = wx:wx_object() | atom() | pid()
175 Request = term()
176 Timeout = integer()
177
178 Make a call to a wx_object server with a timeout. Invokes han‐
179 dle_call(Request, From, State) in server
180
181 send_request(Obj, Request::term()) -> request_id()
182
183 Types:
184
185 Obj = wx:wx_object() | atom() | pid()
186
187 Make an send_request to a generic server. and return a RequestId
188 which can/should be used with wait_response/[1|2]. Invokes han‐
189 dle_call(Request, From, State) in server.
190
191 wait_response(RequestId::request_id()) -> {reply, Reply::term()} | {er‐
192 ror, {term(), server_ref()}}
193
194 Wait infinitely for a reply from a generic server.
195
196 wait_response(Key::request_id(), Timeout::timeout()) -> {reply, Re‐
197 ply::term()} | timeout | {error, {term(), server_ref()}}
198
199 Wait 'timeout' for a reply from a generic server.
200
201 check_response(Msg::term(), Key::request_id()) -> {reply, Re‐
202 ply::term()} | false | {error, {term(), server_ref()}}
203
204 Check if a received message was a reply to a RequestId
205
206 cast(Obj, Request) -> ok
207
208 Types:
209
210 Obj = wx:wx_object() | atom() | pid()
211 Request = term()
212
213 Make a cast to a wx_object server. Invokes handle_cast(Request,
214 State) in the server
215
216 get_pid(Obj) -> pid()
217
218 Types:
219
220 Obj = wx:wx_object() | atom() | pid()
221
222 Get the pid of the object handle.
223
224 set_pid(Obj, Pid::pid()) -> wx:wx_object()
225
226 Types:
227
228 Obj = wx:wx_object() | atom() | pid()
229
230 Sets the controlling process of the object handle.
231
232 reply(X1::{pid(), Tag::term()}, Reply::term()) -> pid()
233
234 Get the pid of the object handle.
235
237 <>
238
239
240
241 wx 1.9.3.1 wx_object(3)