<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 10, 2014 at 4:22 AM, zxq9 <span dir="ltr"><<a href="mailto:zxq9@zxq9.com" target="_blank">zxq9@zxq9.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Tuesday 09 September 2014 19:28:27 Frans Schneider wrote:<br>
><br>
> I want to incorporate wx in my application and was wondering how the<br>
> wx_object behaviour fits into the OTP application structure. Any design<br>
> patterns for this? All examples or applications using wxErlang I found<br>
> do not follow the OTP prinicples.<br>
<br></span></blockquote><div><br></div><div>The top level window could be an wx_object and incorporated in OTP-application.<br></div><div>But generally a terminate signal will be sent when the underlying object is destroyed,<br></div><div>so wx/wxWidgets handles this and it would only be troublesmoe to start several wx_objects</div><div>from supervisor.</div><div><br></div><div>You typically do not want to restart wx_object from a supervisor if it crashes, it is hard enough </div><div>to write stable wx applications :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
</span>I've been experimenting with wx quite a bit myself lately. I noticed the same<br>
thing looking for open source examples of wx use -- almost no utilization of<br>
wx_object. Then I started reading the code that appears when you run wx:demo/0<br>
more carefully. Scroll up to the header (which is not where the module code<br>
window starts at by default), and you'll notice the windows (note: be careful<br>
what "frame" and "window" mean in wx terminology) in demo all use wx_object.<br>
<br>
Inspired by a combination of that and the Android-esque idea that one activity<br>
equals one frame, I have found wx_object to be a helpful thing. If I can<br>
provide an interface to a single user task in a single window, then wx_object<br>
is my wx-augmented gen_server that represents that activity.<br>
<br>
There is a bit of a semantic stew up above ("frame", "task", "window",<br>
"activity", etc.) but the basic idea is that wherever you have a chunk of user<br>
functionality that is best represented as a process of its own (nearly always<br>
the case), it is easier to integrate that using a wx_object than to write a<br>
home-made wx process that talks to a GUI handling gen_server that then talks<br>
to whatever your logic bits are.<br>
<br>
It is cumbersome, on the other hand, to start gen_serverizing every aspect of<br>
the GUI with wx_objects everywhere. As always, you just have to play around<br>
with this a bit on your own to decide what your "correct" level of granularity<br>
is there. I'm still toying with this and haven't decided, but Android folks<br>
define "activity" and "task" have provided me with reasonable starting points.<br>
<br>
I am *intensely* interested in anyone else's opinion on this. Using Erlang in<br>
this way has vastly simplified my reasoning about GUIs, but it still seems that<br>
there are not many examples of wxErlang GUI applications in the wild so I feel<br>
like I'm blazing my own trail every day.<br>
<br></blockquote><div><br></div><div>I have also used it to create my own widgets, an example: </div><div>  <a href="https://github.com/dgud/wings/blob/dgud/wx-backend/src/ww_color_ctrl.erl">https://github.com/dgud/wings/blob/dgud/wx-backend/src/ww_color_ctrl.erl</a> and ww_color_slider.erl</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
-Craig<br>
<div class=""><div class="h5">_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br></div></div>