[wxErlang] Work with child window

Home Forums Basic Erlang [wxErlang] Work with child window

This topic contains 2 replies, has 2 voices, and was last updated by  Shared_essence 4 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #67158

    Hello all. I decided to learn wxErlang and almost immediately ran into a problem.
    How to organize the interaction between the windows?
    For example, in the main window – the button when clicked should otkryvatsya new.
    So far good. Complicate the task – a window should be unique. How to achieve this?
    Naive option as you might expect – is not working.
    Showing my code, if with them that something is wrong, please also indicate this.

    -module(test).
    -compile(export_all).
    -include_lib("e:/Erlang OTP 17/erl6.1/lib/wx-1.3/include/wx.hrl").
    
    start() ->
      wx:new(),
      Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Main",[{size,{200, 200}}]),
      setup(Frame),
      wxFrame:show(Frame),
      loop(Frame,false).
    
    setup(Frame) ->
      Panel  = wxPanel:new(Frame),
      MainSizer   = wxBoxSizer:new(?wxVERTICAL),
      PlayButton = wxButton:new(Panel,101,[{label,"New"},{size,wxWindow:getClientSize(Frame)}]),
      wxSizer:add(MainSizer, PlayButton),
      wxPanel:setSizer(Panel, MainSizer),
      wxPanel:connect(Panel, command_button_clicked),
      wxFrame:connect(Frame, close_window).
    
    loop(Frame,Condition) ->
      receive
        #wx{id = 101, event=#wxCommand{type = command_button_clicked} } ->
          case Condition of
            false->spawn(?MODULE,make_window,[wx:get_env()]);
            true->ok
          end,
          loop(Frame,true);
    
        #wx{event=#wxClose{}} ->
          wx:destroy(),
          ok
      end.
    
    make_window(Env)->
      wx:set_env(Env),
      Frame = wxFrame:new(wx:null(), 102, "New",[{size,{450, 450}}]),
      wxFrame:show(Frame),
      loop2(Frame).
    
    loop2(NewWindow)->
      receive
        #wx{event=#wxClose{}} ->
          wxWindow:destroy(NewWindow),
          ok
      end.
    #67350

    zxq9
    Member

    Instead of checking a boolean like your Condition above, I find it more useful to register specific activity windows with names on the local node. This is based on a few assumptions about GUI apps, though:

    • The application is running in its own node (whether or not services it connect to are)
    • The application is not distributed
    • The user is in control of the location the GUI application is running

    If these are true, then registering a child window with its own name makes perfect sense. In this scenario you go from

    case Condition of
        true  -> % ok;
        false -> % make_window(Blah)
    end

    to

    case whereis(child_window) of
        undefined -> make_window(Blah);
        ChildWindow -> ok
    end

    You can get more interesting with regard to window labels (when you need non-unique windows, but with unique keys, as in {TypeOfWindow, ChildId}) by using the global module instead.

    #67352

    thanks,it looks like what I need.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.