On May 17, 2008, at 6:54 AM, David Toll wrote:> I tried to submit the following message to the "fxruby-users" > message board (I clicked the link to send it as an email to fxruby-users at rubyforge.org > , but the message did not appear). I conclude I do not know how to > submit questions to this message board.You need to be subscribed to the mailing list before you can send questions to it. Are you subscribed? If not, fill out the subscription form here: http://rubyforge.org/mailman/listinfo/fxruby-users Note that you need to send messages from the same address that you''re subscribed under. So if you''re subscribed as "tolld at gmail.com" (for example), you wouldn''t be able to send messages from "tolld at optonline.net ").> In a table column with a header, when I use "fitColumnsToContents", > if the header is wider than any of the cells in the column then the > header is truncated. It would appear that the contents of the > header are ignored when determining the column width from the column > contents.I took a quick look at the FOX source code and it looks like you''re right. Only the cells in the body of the table are considered.> A work-around is to pad the column data with spaces. However, is > there a better way of doing this?This seems to work; see what you think: class FXTable def fitColumnsToContents(col, nc) col.upto(col+nc-1) do |c| cw = getMinColumnWidth(c) hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c)) setColumnWidth(c, [cw, hw].max) end end end Note that this is similar to the original implementation of fitColumnsToContents() from FOX; but it also checks the width of the column header items to see if they''re wider.> I have another question: > > Many FXRuby objects have a "height" parameter. However, it seems to > be ignored in at least some cases. For example, if you create an > FXText object without "LAYOUT_FILL" or "LAYOUT_FILL_Y" then the text > window is something like 3 lines high. If I add a height parameter, > the object height does not change.True. For those cases you''d need to specify the LAYOUT_FIX_HEIGHT layout width to get it to enforce your specified height value.> A corollary to this is - what are the units for "height" (pixels, > lines, inches, ....)? - I have not found this in the API > documentation.Width and height are always in pixels.> I have a table with column headers. I changed the header font from > the default (Tahoma at about 8 or 9 point) to Tahoma Bold at 10 > points. The font changes OK; however, the height of the header is > not changed to allow more space for the font - in my case, > descenders (such as the bottom of a "y") are chopped off. > > How do I get round this? My reading of the documentation is that it > should automatically increase the size of the header to fit the > contents unless you tell it the height is fixed (which is not the > case here).When the table constructs its header, it''s passing in the LAYOUT_FIX_HEIGHT option. So it''s not you that''s telling it to use a fixed height, but that is in fact what it''s doing. To work around this, just reset the layout hints for that widget: table.columnHeader.layoutHints = 0> Many thanks for you help. I suspect many of my problems are because > I am a novice at FXRuby.No, they''re good questions and things that aren''t obvious from the documentation. I always learn something when I have to dig in and figure out these problems. ;) Hope this helps, Lyle --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby
Jason Martin
2008-May-19 09:55 UTC
[fxruby-users] Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTED
Hi All, I am new to the list, and FXRuby, this being my first post. I have hit a little snag, I am futzing around with a texteditor and everything works fine, but I would like to add in a snippet like functionality, but I seem to be at a loss for how to do it. How I imagine it would be done is. I have created a Dispatcher class, this class handles most messages in the program, adding a new tab/editor, displaying x or why. What I would like to do is have my Dispatcher class intercept messages to and from the FXText, and then perform some actions on the FXText. If someone presses the TAB key, I would want to intercept that, grab the text before the cursor, see if a snippet has been defined, if so, add the text in, otherwise, send the TAB key to the FXText like normal and let it do it''s thing. Some code: #dispatcher.rb class Dispatcher def initialize(owner,sender,sel,event) puts "Dispatcher Called with: #{owner}, #{sender}, #{sel}, #{event}" end end #content_pane.rb ... def add_buffer(name) FXHorizontalFrame.new(@tab_book, FRAME_THICK|FRAME_RAISED|LAYOUT_FILL_X|LAYOUT_FILL_Y) do |frame| @buffers << FXText.new(frame,:opts => TEXT_WORDWRAP|LAYOUT_FILL) @current_buffer = @buffers.last @current_buffer.setFocus end end ... Essentially, what I imagine is this: #content_pane.rb def add_buffer(name) ... #pseudo Code @buffers.last.connect(message) do |sender,sel,event| Dispatcher.new(self,sender,sel,event) end #end pseudo code ... end #dispatcher.rb ... #pseudo code def handle_text_widget_message(sender,sel,event) if event.code == code_i_want then #do something here else send_message_to(sender,sel,event) end end #end pseudocode ... I may be completely off my rocker and doing things retarded, as I am mainly a webprogrammer, and very new to GUI programming and how it works, so if there is a better, or more standard way of doing it, please point it out to me, or reference documents that might help, anything will be greatly appreciated. While writing this, I realize that I can use SEL_KEYRELEASE and get the info I want, however, I would like to get it before insertion,a nd not have to handle determining key behavior for the widget, like backspace, and insert etc. Many thanks in advance, Jason
Lyle Johnson
2008-May-19 18:34 UTC
[fxruby-users] Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTED
On Mon, May 19, 2008 at 4:55 AM, Jason Martin <jason at jolierouge.net> wrote:> I may be completely off my rocker and doing things retarded, as I am mainly > a webprogrammer, and very new to GUI programming and how it works, so if > there is a better, or more standard way of doing it, please point it out to > me, or reference documents that might help, anything will be greatly > appreciated. While writing this, I realize that I can use SEL_KEYRELEASE and > get the info I want, however, I would like to get it before insertion,a nd > not have to handle determining key behavior for the widget, like backspace, > and insert etc.Well, if you catch the SEL_KEYPRESS message (instead of SEL_KEYRELEASE) you can interecept the Tab key press before any text gets inserted, right? And if you determine that there is some "snippet" text before the current cursor position, you would (I guess) insert the expanded text and then return true to indicate that your message handler handled the event and FXText''s regular SEL_KEYPRESS handler doesn''t need to do anything else with it. If you instead determine that there is no "snippet" text to try to expand, you''d want to return false from the message handler so that the default SEL_KEYPRESS processing kicks in. Hope this helps, Lyle> > Many thanks in advance, > Jason > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >
Lyle: I have tried your suggested replacement for fitColumnsToContents. While it is better than the "standard" version, it does not completely cure my problem. It does not get a large enough value for the width of the heading text, and so far I have not determined why. I found that if I increase this size estimate by 1/3 then the display looks about right. That is, the line that determines "hw" is now: hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c))*4/3 However, this is a somewhat arbitrary solution to the problem, I am hoping someone knows why the call to font.getTextWidth does not return an adequate value. The font I am using for the cell headers is: @tahoma10Bold = FXFont.new(app, "Tahoma", 10, FXFont::Bold) The font for the table contents is: @courierNew10 = FXFont.new(app, "Courier New", 10) # 10 point, fixed width Thanks Dave ____________________________________________________________ David C. Toll, Research Staff Member, Secure Systems and Smart Cards IBM T. J. Watson Research Center, 19 Skyline Drive, Hawthorne NY 10532 Phone: 914-784-7019 (t/l 863) Fax: 914-784-6205 (t/l 863) email: toll at us.ibm.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20080519/4d18dca0/attachment.html>
Jason Martin
2008-May-19 19:24 UTC
[fxruby-users] Intercepting and reviewing FXText messages, especially KEY_PRESS|SEL_INSERTED
Lyle Johnson wrote:> > Well, if you catch the SEL_KEYPRESS message (instead of > SEL_KEYRELEASE) you can interecept the Tab key press before any text > gets inserted, right? And if you determine that there is some > "snippet" text before the current cursor position, you would (I guess) > insert the expanded text and then return true to indicate that your > message handler handled the event and FXText''s regular SEL_KEYPRESS > handler doesn''t need to do anything else with it. If you instead > determine that there is no "snippet" text to try to expand, you''d want > to return false from the message handler so that the default > SEL_KEYPRESS processing kicks in. > > Hope this helps, > > Lyle >Hi Lyle, Thanks, that was the piece of info I was looking for, I am sure it''s written somewhere, but I missed it. I didn''t know that returning false would cause the keypress/message to be sent on. I guess I thought it kinda died there on the operating table... /jason -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20080519/a7cb03b3/attachment.html>
On May 19, 2008, at 1:56 PM, David Toll wrote:> I have tried your suggested replacement for fitColumnsToContents. > While it is better than the "standard" version, it does not > completely cure my problem. It does not get a large enough value > for the width of the heading text, and so far I have not determined > why. I found that if I increase this size estimate by 1/3 then the > display looks about right. That is, the line that determines "hw" > is now: > > hw = > columnHeader.font.getTextWidth(columnHeader.getItemText(c))*4/3 > > However, this is a somewhat arbitrary solution to the problem, I am > hoping someone knows why the call to font.getTextWidth does not > return an adequate value.I see part of the problem, now that I look at it again. We''re not taking into account the cell margin values. So if you change the calculation of "hw" to this: hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c)) + marginLeft + marginRight You get a bit closer to the correct width. But for the particular big font that I''m trying it''s still a little short. I don''t know if this indicates a bug in FXFont::getTextWidth(), or if there''s still some factor that I''m overlooking. Hope this helps, Lyle --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20080519/f9d94ae4/attachment.html>
On May 19, 2008, at 8:34 PM, Lyle Johnson wrote:> I see part of the problem, now that I look at it again. We''re not > taking into account the cell margin values. So if you change the > calculation of "hw" to this: > > hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c)) + > marginLeft + marginRight > > You get a bit closer to the correct width. But for the particular > big font that I''m trying it''s still a little short. I don''t know if > this indicates a bug in FXFont::getTextWidth(), or if there''s still > some factor that I''m overlooking.Wait, I''ve got it now. The spacing''s different because it''s a header item and not a table item. Here''s the correct formula: hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c)) + 2*columnHeader.borderWidth + columnHeader.padLeft + columnHeader.padRight That looks right here, for the font that I''m testing with. Let me know what you think! -- Lyle --- "FXRuby: Create Lean and Mean GUIs with Ruby" Now available from the Pragmatic Bookshelf! http://www.pragprog.com/titles/fxruby
On May 19, 2008, at 9:43 PM, Lyle Johnson wrote: Wait, I''ve got it now. The spacing''s different because it''s a header item and not a table item. Here''s the correct formula: hw = columnHeader.font.getTextWidth(columnHeader.getItemText(c)) + 2*columnHeader.borderWidth + columnHeader.padLeft + columnHeader.padRight That looks right here, for the font that I''m testing with. Let me know what you think! That does indeed work as I would expect. Thank you. Does this mean there is a bug in the "standard" version of fitColumnstoContents - i.e. should the standard version be changed to this new version? Dave ____________________________________________________________ David C. Toll, Research Staff Member, Secure Embedded Systems IBM T. J. Watson Research Center, 19 Skyline Drive, Hawthorne NY 10532 Phone: 914-784-7019 (t/l 863) Fax: 914-784-6205 (t/l 863) email: toll at us.ibm.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20080520/2f69ca90/attachment-0001.html>
On Tue, May 20, 2008 at 9:05 AM, David Toll <toll at us.ibm.com> wrote:> That does indeed work as I would expect. Thank you. > > Does this mean there is a bug in the "standard" version of > fitColumnstoContents - i.e. should the standard version be changed to this > new version?I would consider it a bug, but I don''t know if Jeroen (FOX''s developer) would.