JeanJouX
JeanJouX

Reputation: 2721

Gtk2Hs : Widget interaction

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 :

I'm using GHC 7.4.1 and Gtk2Hs 0.12.3

Upvotes: 0

Views: 80

Answers (1)

JeanJouX
JeanJouX

Reputation: 2721

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.

Upvotes: 0

Related Questions