0

I'm trying to create a program with Gtk2Hs and Haskell and I wonder whether it is possible to make different widgets communicate with one another.

I have a text entry, which is used to write commands, a drawing area, which draws something when the text entry is validated. These two widgets works together fine.

However, I would like to add an "optional" treeview in a different window, which would be updated when all commands in the text entry have been executed (this can take a long time).

As the treeview is "optional" and created only afterwards, I can't define callbacks to its update in the text entry definition (like the drawing area).

I would to create a signal (event?) to be emitted when all the operations are done and caught by the treeview to update its data.

My questions are :

  • Is there a way to do that with Gtk2Hs and Glib?
  • Is there a module that could be used to make it (portable to Linux/Windows, if possible)?
  • Is there a correct way to make a widget interract/communicate with others?

I'm using GHC 7.4.1 and Gtk2Hs 0.12.3

jub0bs
  • 60,866
  • 25
  • 183
  • 186
JeanJouX
  • 2,555
  • 1
  • 25
  • 37
  • There should be nothing special about a widget created after the program's main window is shown compared to one created before it is shown. Just add to or modify the text entry's handlers once the new widget is available. – Daniel Wagner Jan 22 '15 at 02:21

1 Answers1

0

I find a solution to my problem :

  1. In the main program I create an IORef of a list of actions to perform :

    actionsIO <- newIORef [action_to_do_1,action_to_do_2]
    
  2. I create my custom combined widget for text entry

    ent <- textEntry window canvas state modele parser info actionsIO
    

    Inside, I execute the list of actions that way :

    actions <- readIORef actionsIO
    sequence_ actions
    
  3. I create my treeview

    arwin <- arrayWin modele window canvas state info actionsIO
    

    Inside, I modify/delete/add actions to the list like this :

    let newactions = [new_action_to_do_1,new_action_to_do_2]
    writeIORef actionsIO newactions
    

    These new actions are performed every time a command is validated with the special entry widget.

There is probably a "cleaner" method to do that, but this one work well and solved my problem completely.

JeanJouX
  • 2,555
  • 1
  • 25
  • 37