[erlang-questions] wxErlang question 2

Dan Gudmundsson dangud@REDACTED
Mon Jul 3 10:29:31 CEST 2017


Q1:
Where is connect and arguments descrbed in the event handler,
which most of the classes inherits from:
See wx.hrl  and in http://erlang.org/doc/man/wxEvtHandler.html

Then you will have to read which class sends which events..

Q2: The erlang documentation (or lack there of) does not have the intention
of learning
you how to write gui's with wxWidgets only the differences in the erlang
wrapper.
So you will have to look for that information elsewhere, I have tried to
write examples
and you can also look at the observer code for inspiration.

I have not read the book it is old but may still be good, I'm not a
wxWidgets expert
I just wrote the erlang wrapper.

On Sat, Jul 1, 2017 at 5:19 PM Joe Armstrong <erlang@REDACTED> wrote:

> Hello.
>
> I want to make a very simple graphics example in wxErlang
> I want to make a "window" containing a rectangle
>
> Nothing else - this should *not* use the wx_object behaviour but the
> raw wx interface.
>
> See below


> I want to understand one thing at a time and not use abstractions layered
> on top
> of the raw interfaces
>

The abstraction cheats, wx have special code for helping with the
abstraction, so it's
useful but here is what you want in 40 lines:

-module(joe).

-export([run/0]).

-include_lib("wx/include/wx.hrl").

run() ->
    %% Start wx application
    _ = wx:new(),
    %% Create the OS window (called frame)
    NoParent = wx:null(),         % This is the top level window, we have
no parent
    NoId = ?wxID_ANY,             % We can set an id for every widget,
                                  % we don't need a specific id here
    Frame = wxFrame:new(NoParent, NoId, "Hello Joe"),

    %% Create a widget as background and drawing area belonging to the
frame.
    Panel = wxPanel:new(Frame),
    White = {255,255,255},
    wxWindow:setBackgroundColour(Panel, White),

    %% Create a sizer, the sizer handles widgets placement and size
    Sizer = wxBoxSizer:new(?wxVERTICAL),
    wxSizer:add(Sizer, Panel, [{proportion, 1}, {flag, ?wxEXPAND}]),
    wxFrame:setSizer(Frame, Sizer),

    %% Listen to events
    wxPanel:connect(Panel, paint, [{callback, fun redraw/2}]),
    wxFrame:connect(Frame, close_window, [{skip, true}]),
    %%      {skip, true} will let the event be handled by the default
handler
    %%      which will close the window

    %% Show the frame
    wxFrame:show(Frame),
    loop(),
    ok.

loop() ->
    receive
        #wx{event=#wxClose{}} ->
            ok;
        Msg ->
            io:format("~p:~p: Got ~p~n",[?MODULE, ?FUNCTION_NAME, Msg]),
            loop()
    end.

%% This is called in a spawned process, so don't deadlock by
%% calling the process above while that waits in calls to wx.
redraw(#wx{obj=Panel}, _wxPaintEvent) ->
    %% Create a drawing context on the Panel
    DC = wxPaintDC:new(Panel),
    %% You can draw on the DC (old way) with the functions in wxDC module

    %% Or use a Graphics Contexts to have antialising and nicer graphics
    GC = wxGraphicsContext:create(DC),
    wxGraphicsContext:setBrush(GC, ?wxRED_BRUSH),
    wxGraphicsContext:setFont(GC, ?wxITALIC_FONT, {255,255,255}),
    {W,H} = wxPanel:getSize(Panel),
    wxGraphicsContext:drawRoundedRectangle(GC, 35.0,35.0, W-70.0, H-70.0,
10.0),
    wxGraphicsContext:drawText(GC, "Hello Joe", 60.0, 55.0),

    %% Nothing is drawn until you destroy your drawing contexts
    wxGraphicsObject:destroy(GC),
    wxPaintDC:destroy(DC),
    ok.




> _______________________________________________
> 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/20170703/70109d0e/attachment.htm>


More information about the erlang-questions mailing list