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