wx_object(3)
π wx_object(3) π
Erlang Module Definition bestie, and today we're decoding wx_object, the generic wx object behaviour. buckle up, it's giving β¨architectureβ¨ and it's lowkey iconic.
πΈ NAME πΈ
wx_object β the generic wx object behaviour. yeah that's it, that's the whole name, she's simple and she knows it π
π¦ DESCRIPTION π¦
okay so THIS is a behaviour module, and what it does is let you "sub class" wx objects. how does it work? it works like a regular gen_server module β like, exactly that energy β and it creates a server per object. one object, one server, no sharing, main character energy π«Ά
β οΈ NOTE: Currently no form of inheritance is implemented. bestie. do not go looking for inheritance. she's not there. π
So your user module should export:
init(Args)β should return{wxWindow, State} | {wxWindow, State, Timeout} | ignore | {stop, Reason}
Asynchronous window event handling, bestie:
handle_event(#wx{}, State)β should return{noreply, State} | {noreply, State, Timeout} | {stop, Reason, State}
Your user module can export these callback functions too:
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. no cap. not a vibe check you want to fail.
The user module can also export:
handle_info(Info, State)β whereInfois a message, e.g.{'EXIT', P, R},{nodedown, N}, ... and it 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. like, straight up ghosted π
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, and fr fr it is always called when the server terminates or when wx_object() in the driver is deleted. and 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()
β¨ DATA TYPES β¨
the big one. here's event(), and she is LONG, and every single variant is here because I do not skip, I do not summarise, I do not gatekeep π
event() ::
wxActivateEvent:wxActivate() |
wxAuiManagerEvent:wxAuiManager() |
wxAuiNotebookEvent:wxAuiNotebook() |
wxBookCtrlEvent:wxBookCtrl() |
wxCalendarEvent:wxCalendar() |
wxChildFocusEvent:wxChildFocus() |
wxClipboardTextEvent:wxClipboardText() |
wxCloseEvent:wxClose() |
wxColourPickerEvent:wxColourPicker() |
wxCommandEvent:wxCommand() |
wxContextMenuEvent:wxContextMenu() |
wxDateEvent:wxDate() |
wxDisplayChangedEvent:wxDisplayChanged() |
wxDropFilesEvent:wxDropFiles() |
wxEraseEvent:wxErase() |
wxFileDirPickerEvent:wxFileDirPicker() |
wxFocusEvent:wxFocus() |
wxFontPickerEvent:wxFontPicker() |
wxGridEvent:wxGrid() |
wxHelpEvent:wxHelp() |
wxHtmlLinkEvent:wxHtmlLink() |
wxIconizeEvent:wxIconize() |
wxIdleEvent:wxIdle() |
wxInitDialogEvent:wxInitDialog() |
wxJoystickEvent:wxJoystick() |
wxKeyEvent:wxKey() |
wxListEvent:wxList() |
wxMaximizeEvent:wxMaximize() |
wxMenuEvent:wxMenu() |
wxMouseCaptureChangedEvent:wxMouseCaptureChanged() |
wxMouseCaptureLostEvent:wxMouseCaptureLost() |
wxMouseEvent:wxMouse() |
wxMoveEvent:wxMove() |
wxNavigationKeyEvent:wxNavigationKey() |
wxPaintEvent:wxPaint() |
wxPaletteChangedEvent:wxPaletteChanged() |
wxQueryNewPaletteEvent:wxQueryNewPalette() |
wxSashEvent:wxSash() |
wxScrollEvent:wxScroll() |
wxScrollWinEvent:wxScrollWin() |
wxSetCursorEvent:wxSetCursor() |
wxShowEvent:wxShow() |
wxSizeEvent:wxSize() |
wxSpinEvent:wxSpin() |
wxSplitterEvent:wxSplitter() |
wxStyledTextEvent:wxStyledText() |
wxSysColourChangedEvent:wxSysColourChanged() |
wxTaskBarIconEvent:wxTaskBarIcon() |
wxTreeEvent:wxTree() |
wxUpdateUIEvent:wxUpdateUI() |
wxWebViewEvent:wxWebView() |
wxWindowCreateEvent:wxWindowCreate() |
wxWindowDestroyEvent:wxWindowDestroy().
request_id() :: term().
server_ref() :: Obj :: wx:wx_object() | atom() | pid().
π FUNCTIONS π
call
call(Obj, Request) -> term()β whenObj :: wx:wx_object() | atom() | pid(),Request :: term(). Make a call to awx_objectserver. the call waits until it gets a result. invokeshandle_call(Request, From, State)in the server π«Άcall(Obj, Request, Timeout) -> term()β whenObj :: wx:wx_object() | atom() | pid(),Request :: term(),Timeout :: integer(). Make a call to awx_objectserver with a timeout. invokeshandle_call(Request, From, State)in the server. so like, this one has a time limit bestie, it's not gonna wait forever β¨
cast
cast(Obj, Request) -> okβ whenObj :: wx:wx_object() | atom() | pid(),Request :: term(). Make a cast to awx_objectserver. invokeshandle_cast(Request, State)in the server. she returnsokand moves on, no waiting, that's the whole point π
check_response
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 π
get_pid
get_pid(Obj) -> pid()β whenObj :: wx:wx_object() | atom() | pid(). get the pid of the object handle π
reply
reply({pid(), Tag :: term()}, Reply :: term()) -> pid()β get the pid of the object handle. (yeah, the docs literally say the exact same sentence asget_pidright above. i'm just the messenger bestie, i am not fixing it, that's what it says π)
send_request
send_request(Obj, Request :: term()) -> request_id()β whenObj :: wx:wx_object() | atom() | pid(). make a send_request to a generic server, and return aRequestIdwhich can/should be used withwait_response/[1|2]. invokeshandle_call(Request, From, State)in the server. π¦
set_pid
set_pid(Obj, Pid :: pid()) -> wx:wx_object()β whenObj :: wx:wx_object() | atom() | pid(). sets the controlling process of the object handle π₯
start
start(Name, Mod, Args, Options) -> wxWindow:wxWindow() | {error, term()}β whenName :: {local, atom()},Mod :: atom(),Args :: term(),Flag :: trace | log | {logfile, string()} | statistics | debug,Options :: [{timeout, timeout()} | {debug, [Flag]}]. starts a genericwx_objectserver and invokesMod:init(Args)in the new process β¨
start_link
start_link(Mod, Args, Options) -> wxWindow:wxWindow() | {error, term()}β whenMod :: atom(),Args :: term(),Flag :: trace | log | {logfile, string()} | statistics | debug,Options :: [{timeout, timeout()} | {debug, [Flag]}]. starts a genericwx_objectserver and invokesMod:init(Args)in the new process π«Άstart_link(Name, Mod, Args, Options) -> wxWindow:wxWindow() | {error, term()}β whenName :: {local, atom()},Mod :: atom(),Args :: term(),Flag :: trace | log | {logfile, string()} | statistics | debug,Options :: [{timeout, timeout()} | {debug, [Flag]}]. starts a genericwx_objectserver and invokesMod:init(Args)in the new process π
stop
stop(Obj) -> okβ whenObj :: wx:wx_object() | atom() | pid(). stops a genericwx_objectserver with reason'normal'. invokesterminate(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β whenObj :: wx:wx_object() | atom() | pid(),Reason :: term(),Timeout :: timeout(). stops a genericwx_objectserver with the givenReason. invokesterminate(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. so yeah, hold onto your socks π§¦
wait_response
wait_response(RequestId :: request_id()) -> {reply, Reply :: term()} | {error, {term(), server_ref()}}β wait infinitely for a reply from a generic server. she has all the time in the world β¨wait_response(Key :: request_id(), Timeout :: timeout()) -> {reply, Reply :: term()} | timeout | {error, {term(), server_ref()}}β wait'timeout'for a reply from a generic server β° (and yeah,timeoutcan be an actual returned value, it's right there in the return type π)
π CALLBACKS π
this section exists, it's in the source, and it has literally nothing in it. it's giving mystery, it's giving silence, it's giving the callback docs live up in the DESCRIPTION instead. anyway, here it is, in order, because I keep everything π«Ά
that's the whole page bestie!! no notes, ate, periodt π
Ericsson AB Β· wx 2.6 Β· wx_object(3) β that's the little footer at the bottom of the page, considered mentioned, mwah π
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms