In the ''filetext'' routine below I''m passing an FStreelistItem and attempting to display the item.data on top of the TreeList. Any idea why using dlg.execute vs. dlg.show would place the TextField at a radically different screen position? dlg.show does as I would expect, placing the field at the top of the main window. dlg.execute places the field over the tree where I but the x coordinate is way to the left. I have no idea where dlg.execute is picking up the y coordinate. Also: How can I determine the width of the FXVerticalFrame the FXTreeList is being displayed in? How can I pickup the screen position of a FXTreeListItem? I tried to use FXEvent.win_y in the trees event code to get the coordinate of the event (close enough) but get a runtime error: ''undefined method `win_y'' for Fox::FXEvent:Class (NoMethodError)'' Lastly in this code I try to set the FXTextField target to be it''s parent dialog window and send a FXDialogBox::ID_CANCEL when it is ckicked to close the dialog. Why doesn''t this work? ############### def filetext(item,y) x=getApp()::mainWindow.x y=getApp()::mainWindow.y w=getApp()::mainWindow.width #w=@group1.maxChildWidth() h=22 MsgOut([x,y,w,h]) #dlg = FXDialogBox.new(getApp(),"File Info",DECOR_BORDER,x,y,w,h,2,2,2,2,0,0) dlg = FXDialogBox.new(@group1,"File Info",DECOR_BORDER,x,y,w,h,2,2,2,2,0,0) #initialize(p, ncols, tgt=nil, sel=0, opts=TEXTFIELD_READONLY, x=0, y=0, w=0, h=0, pl=DEFAULT_PAD, pr=DEFAULT_PAD, pt=DEFAULT_PAD, pb=DEFAULT_PAD) # :yields: theTextField textbox=FXTextField.new(dlg, 200, dlg,FXDialogBox::ID_CANCEL, TEXTFIELD_READONLY,2,2,w-4,h-4,0,0,0,0) #(,10,10,w,h,DEFAULT_PAD,DEFAULT_PAD,DEFAULT_PAD,DEFAULT_PAD) textbox.text=item.data.to_s dlg.create #dlg.execute dlg.show end ################ # The FXTreeList definition ################ def filelist $tree= FXTreeList.new(@group1, 0, nil, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_TOP|LAYOUT_RIGHT|TREELIST_SHOWS_LIN ES| TREELIST_SHOWS_BOXES|TREELIST_ROOT_BOXES|TREELIST_EXTENDEDSELECT) $tree.connect(SEL_CLICKED ) do |sender, selector, ptr| y=FXEvent.win_y y=50+getApp().mainWindow.y MsgOut(["Y="+y.to_s]) if ptr.numChildren == 0 itemselect(sender, selector, ptr,y) end
On Mar 20, 2005, at 8:58 PM, Harold Worby wrote:> Any idea why using dlg.execute vs. dlg.show would place the TextField > at a > radically different screen position? > dlg.show does as I would expect, placing the field at the top of the > main > window. > dlg.execute places the field over the tree where I but the x > coordinate is > way to the left. > I have no idea where dlg.execute is picking up the y coordinate.The FXDialogBox#execute method takes an optional argument that allows you to specify the placement of the dialog box on the screen: http://www.fxruby.org/doc/api/classes/Fox/FXDialogBox.html As shown in the documentation, the default value for that placement argument is PLACEMENT_CURSOR, which means "place this dialog box under the current cursor position", which is usually a pretty good place to put it. In your case, I think you''re saying that you want to fix the initial x & y coordinates of the dialog box, so you might instead choose to use the PLACEMENT_DEFAULT option: dlg.execute(PLACEMENT_DEFAULT) Now, the show() method that you''re also trying is inherited from the FXWindow class: http://www.fxruby.org/doc/api/classes/Fox/FXWindow.html and it takes no arguments, and its behavior is like PLACEMENT_DEFAULT. For completeness, there''s also a different version of show (defined in FXTopWindow) that does take one argument for the ''placement''.> Also: > How can I determine the width of the FXVerticalFrame the FXTreeList is > being > displayed in?Unless I''m misunderstanding the question, just call its width method: theWidth = someVerticalFrame.width> How can I pickup the screen position of a FXTreeListItem?Well, I don''t think we have a way to do that, exactly. There''s a getItemAt method, which will return a reference to the tree item at some (x, y) position (if any), e.g. theItemAtXY = treeList.getItemAt(x, y) but I don''t know of any easy way to get the (x, y) position of an item.> I tried to use FXEvent.win_y in the trees event code to get the > coordinate > of the event (close enough) but get a runtime error: > ''undefined method `win_y'' for Fox::FXEvent:Class (NoMethodError)''FXEvent#win_y is an instance method, not a class method. That is, you need to have an FXEvent object lying around and call its win_y() method to get the y-coordinate.> Lastly in this code I try to set the FXTextField target to be it''s > parent > dialog window and send a FXDialogBox::ID_CANCEL when it is ckicked to > close > the dialog. Why doesn''t this work?I don''t think I understand this at all. You''re creating a dialog box that contains a text field (which is used to allow the user to enter and edit a line of text), but you want the dialog box to close as soon as the user clicks inside that text field?
-----Original Message----- From: Lyle Johnson [mailto:lyle@knology.net] Sent: Monday, March 21, 2005 8:18 AM To: Harold Worby Cc: fxruby-users@rubyforge.org Subject: Re: [fxruby-users] dialog.execute vs dialog.show <Snip>>> I tried to use FXEvent.win_y in the trees event code to get the >> coordinate >> of the event (close enough) but get a runtime error: >> ''undefined method `win_y'' for Fox::FXEvent:Class (NoMethodError)''>FXEvent#win_y is an instance method, not a class method. That is, you >need to have an FXEvent object lying around and call its win_y() method>to get the y-coordinate.How would one create FXEvent object that references a widgets events? I mean in: tree= FXTreeList.new(@group1, 0, nil, 0,...) tree.connect(SEL_CLICKED ) do |sender, selector, ptr| y=myFXEvent.win_y itemselect(sender, selector, ptr,y) end How would you declare the myFXEvent object. As part is the application, the widget, or in the event routine? <Snip>>> Lastly in this code I try to set the FXTextField target to be it''s >> parent >> dialog window and send a FXDialogBox::ID_CANCEL when it is ckicked to>> close >> the dialog. Why doesn''t this work?>I don''t think I understand this at all. You''re creating a dialog box >that contains a text field (which is used to allow the user to enter >and edit a line of text), but you want the dialog box to close as soon >as the user clicks inside that text field?The idea is when the user to clicks on a leaf item a read only text box appears over the top of it displaying more detailed information about the item. Then when the user clicks again the text box goes away. I.E. dlg FXDialogBox.new(@group1,"FileInfo",DECOR_BORDER,x,y,w,h,2,2,2,2,0,0) textbox=FXTextField.new(dlg, 200, dlg,FXDialogBox::ID_CANCEL,TEXTFIELD_READONLY,2,2,w-4,h-4,0,0,0,0) textbox.text=item.data.to_s ... P.S. I now have updated to v1.5. Thanks for the help.
On Mar 21, 2005, at 10:04 AM, Harold Worby wrote:> How would one create FXEvent object that references a widgets events? I > mean in: > > tree= FXTreeList.new(@group1, 0, nil, 0,...) > tree.connect(SEL_CLICKED ) do |sender, selector, ptr| > y=myFXEvent.win_y > itemselect(sender, selector, ptr,y) > end > > How would you declare the myFXEvent object. As part is the application, > the widget, or in the event routine?You don''t actually create an FXEvent object yourself; FOX creates one and passes it into some message handler routines as the event data. Now in general, you can find out what kind of message data is passed in as the message data for a message handler block by looking at the API documentation for the class that sends the message. In this case, it''s an FXTreeList who sends the message (a SEL_CLICKED message), so you look at the docs for FXTreeList: http://www.fxruby.org/doc/api/classes/Fox/FXTreeList.html and in the list of events near the top of that page, you will see that the message data for SEL_CLICKED is a reference to the FXTreeItem that was "clicked". So something like this should do the trick: tree.connect(SEL_CLICKED) do | sender, sel, clickedItem | ... end Now this doesn''t tell you anything about the (x, y) position that was clicked, but let''s read on...> The idea is when the user to clicks on a leaf item a read only text box > appears over the top of it displaying more detailed information about > the item. Then when the user clicks again the text box goes away. > I.E. > dlg > FXDialogBox.new(@group1,"FileInfo",DECOR_BORDER,x,y,w,h,2,2,2,2,0,0) > textbox=FXTextField.new(dlg, 200, > dlg,FXDialogBox::ID_CANCEL,TEXTFIELD_READONLY,2,2,w-4,h-4,0,0,0,0) > textbox.text=item.data.to_sOK, so for starters I would recommend calling dlg.execute without any arguments: dlg.execute or explicitly specifying the placement, if you like: dlg.execute(PLACEMENT_CURSOR) so that the dialog box will appear on top of the tree item that the user just clicked. In that case, you don''t actually need to know the (x, y) coordinates. Also, if it''s a read-only field anyways, I might consider using an FXLabel instead of an FXTextField, since an FXTextField suggests to the user that this is a field they can edit and change. Finally, I think I''d add a "Close" button -- even a small one -- to the dialog box to allow the user to dismiss it. And if that''s the case, that you''re basically looking for a dialog box with an OK button and some text label, you might instead consider the FXMessageBox class, a subclass of FXDialogBox that is intended exactly for that purpose.> P.S. > I now have updated to v1.5.I hate to ask (because I think I know the answer), but you''ve updated *what* to version 1.5? ;)> Thanks for the help.No problem!