[fxruby-users] runModalWhileShown

Philippe Lang philippe.lang at attiksystem.ch
Fri Dec 1 18:26:55 EST 2006


Hi,

I have a problem with an application that uses popups in TreeLists: this test code shows a TreeList that you can expand recursively with a right click on the base node. It runs fine, you will see, but afterwards the applications starts behaving strangely: if you use the scroller to look at nodes at the bottom, and go back with the cursor in the TreeList pane, you will see you go back to the first node. This DOES NOT happen when you expand nodes "by hand", without showing the popup menu.

I could find that the problems apparently starts with the line:

self.getApp().runModalWhileShown(menu)

Apparently this call breaks something in the event management.
As far as I know, this is how to code popups in Fox? Am I doing anything wrong?

Thanks to anyone that can help!

Philippe


My config: FXRuby 1.6.3 / Ruby 1.8.4 / Windows XP


-----------------------------------------------------

#!/usr/bin/ruby

require 'fox16'

include Fox

class MyWindow < FXMainWindow
    
  def initialize(app)

    super(app, "Window", nil, nil, DECOR_ALL, 0, 0, 200, 200)
    
    # Menu bar stretched along the top of the main window
    menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
  
    # File menu
    filemenu = FXMenuPane.new(self)
    FXMenuCommand.new(filemenu, "&Quit\tCtl-Q\tQuit the application",
        nil, app, FXApp::ID_QUIT)
    FXMenuTitle.new(menubar, "&File", nil, filemenu)
    
    # Frame
    treelistframe = FXVerticalFrame.new(self,
      FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y,
      0, 0, 0, 0, 0, 0, 0, 0)
    
    # Tree
    tree = FXTreeList.new(treelistframe, nil, 0, 
      LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT|TREELIST_SHOWS_LINES|
      TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|TREELIST_EXTENDEDSELECT)
    
    # Test data
    tb = tree.appendItem(nil, "Base")
    (0..20).each do
      t1 = tree.appendItem(tb, "ok")
      t2 = tree.appendItem(t1, "ok")
    end
    
    # Contextual menu when right-clicking in tree
    tree.connect(SEL_RIGHTBUTTONPRESS) do |sender, selector, data|
      menu = FXMenuPane.new(self)
      FXMenuCommand.new(menu, "expand all").connect(SEL_COMMAND) do |sender, selector, data|
        
        # Expanding all nodes, recursively
        def expandAllTree(tree, item)
          item.each do |e|
            expandAllTree(tree, e)
          end
          tree.expandTree(item)
        end
      
        expandAllTree(tree, tb)
        
      end
      menu.create()
      menu.popup(nil, data.root_x, data.root_y)
      menu.grabKeyboard
      self.getApp().runModalWhileShown(menu)
    end
    
  end

  def create
    super
    show(PLACEMENT_SCREEN)
  end

end

if __FILE__ == $0
  application = FXApp.new("Attik System", "FXRuby Test")
  MyWindow.new(application)
  application.create
  application.run
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3125 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20061202/8f1a3839/attachment.bin 


More information about the fxruby-users mailing list