Man, you have *got* to get into the habit of creating a minimal working example. =)
The minimal framework I could put around your code to make it run is included below. It does not have the problem you describe. Does the code below show the bad behavior you describe when you try it? If not, could you please try to cook up the smallest piece of code that *does* reproduce your problem? ~d import Control.Monad.IO.Class import Graphics.UI.Gtk main = do initGUI w <- windowNew b <- buttonNewWithLabel "foo" on b buttonPressEvent (tryEvent (do button <- eventButton theTime <- eventTime case button of RightButton -> liftIO (mouseButtonPressed theTime) _ -> stopEvent)) containerAdd w b widgetShowAll w mainGUI mouseButtonPressed :: TimeStamp -> IO () mouseButtonPressed theTime = do menu <- menuNew print "mouseButtonPressed called" print ("time", theTime) menuItem <- menuItemNewWithLabel "New transaction (ctrl-n)" on menuItem menuItemActivated (putStrLn "activated, lol") menuShellAppend menu menuItem menuItem <- menuItemNewWithLabel "Duplicate selected transaction (ctrl-d)" menuShellAppend menu menuItem widgetShowAll menu print "about to call menuPopup" menuPopup menu (Just (RightButton, theTime)) On 2014-02-18 20:17, Donald Allen wrote: > I am trying to pop up a menu when the right button is pressed with the > cursor in a particular treeview. I set up the event handler as follows: > > -- Handle buttonPressEvent within the view > on view buttonPressEvent (tryEvent (do button <- eventButton > theTime <- eventTime > case button of > RightButton -> liftIO (mouseButtonPressed theTime accountRegister > globals) > _ -> stopEvent)) > > and > > mouseButtonPressed :: TimeStamp -> AccountRegister -> Globals -> IO () > mouseButtonPressed theTime accountRegister globals > = do menu <- menuNew > print "mouseButtonPressed called" > print ("time", theTime) > menuItem <- menuItemNewWithLabel "New transaction (ctrl-n)" > on menuItem menuItemActivated (newTransaction accountRegister globals) > menuShellAppend menu menuItem > menuItem <- menuItemNewWithLabel "Duplicate selected transaction > (ctrl-d)" > menuShellAppend menu menuItem > widgetShowAll menu > print "about to call menuPopup" > menuPopup menu (Just (RightButton, theTime)) > > The first time I press the right button, the menu appears for perhaps > 10 seconds and then disappears. During that time, I can click 'New > transaction' and the right thing happens. The second time I press the > right button, the menu appears very briefly, less than a second and > then disappears. Subsequent right clicks behave the same. In other > words, useless. > > The debugging prints in mouseButtonPressed all appear in response to > the right clicks. The event time advances, as you would expect. > > I'm at a complete loss as to what might be causing this and can't > continue with my project if this is not solved. Any suggestions would > be appreciated. > > ------------------------------------------------------------------------------ > Managing the Performance of Cloud-Based Applications > Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. > Read the Whitepaper. > http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk > [1] > > _______________________________________________ > Gtk2hs-devel mailing list > Gtk2hs-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel [2] Links: ------ [1] http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk [2] https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk _______________________________________________ Gtk2hs-devel mailing list Gtk2hs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel