Hallo, I am trying to insert text into an FXTextField. Unfortunately the TextField just shows Garbage. If I print (p garbage) the Garbage it says "\a" Why does it not say "dfdf" and show "dfdf" in the text field? Here is the code I use: @txt = FXTextField.new(hf, 10, nil, 0, opts= LAYOUT_FILL_X) @txt.handle(sender, FXSEL(FXTextField::SEL_COMMAND, FXTextField::ID_INSERT_STRING), "dfdf") I a confused. Please, can someone help? Thank you very much. Uwe -- *********************************************************************** Uwe Hartl e-mail: Uwe.Hartl at gmx.net 91522 Ansbach Telephone: (0981) 9724526 Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 Germany ***********************************************************************
On Tue, 24 Jan 2006 00:06:30 +0100, Uwe Hartl <uwe.hartl at gmx.net> wrote :> I am trying to insert text into an FXTextField. Unfortunately the TextField > just shows Garbage. If I print (p garbage) the Garbage it says "\a" > > Why does it not say "dfdf" and show "dfdf" in the text field? Here is thecode> I use: > > @txt = FXTextField.new(hf, 10, nil, 0, opts= LAYOUT_FILL_X) > @txt.handle(sender, FXSEL(FXTextField::SEL_COMMAND, > FXTextField::ID_INSERT_STRING), "dfdf") > > I a confused. Please, can someone help?Uwe, What do you get when you just set the text directly, i.e. @txt.text = "dfdf" ? Lyle
On Jan 23, 2006, at 5:46 PM, Uwe Hartl wrote:> Than I get "dfdf" in the Textfield and the textfield contents is read > out as > "dfdf", too.And that was the desired result, right?
On Jan 24, 2006, at 9:41 AM, Uwe Hartl wrote:> this is setting the text just right away. The point here is, that I > want the > text to be added at the position of the cursor. If I have "qwerty" in > the > text field and I put the cursor behind the "e" that I calll the method > with > "asdfg" I want the result to be "qweasdfgrty". This is what I thought > the > INSERT would do.Ah, OK. I have added this to the bug list and will try to get it fixed for the next release. I am actually surprised to see that Jeroen doesn''t provide an API to (more directly) insert text into a text field as you can with the multiline FXText widget.
On Tuesday 24 January 2006 12:05 pm, Lyle Johnson wrote:> > On Jan 24, 2006, at 9:41 AM, Uwe Hartl wrote: > > > this is setting the text just right away. The point here is, that I > > want the > > text to be added at the position of the cursor. If I have "qwerty" in > > the > > text field and I put the cursor behind the "e" that I calll the method > > with > > "asdfg" I want the result to be "qweasdfgrty". This is what I thought > > the > > INSERT would do. > > Ah, OK. I have added this to the bug list and will try to get it fixed > for the next release. I am actually surprised to see that Jeroen > doesn''t provide an API to (more directly) insert text into a text field > as you can with the multiline FXText widget.Its not there because text fields usually contain only a little text. Note that manipulation of strings is in FXString. So: field->setText(field->getText().insert(pos,"More text")); Should do the trick. I admit it is slightly more work, but up till now no one has never needed a specific API to do just this in FXTextField.... - Jeroen
On Jan 24, 2006, at 12:31 PM, Uwe Hartl wrote:> Thanks, now I think I go a workaround, will see if I get the cursor > position > somehow out of the TextField. Say, is there somewhere better > documentation > for FXRuby than this webpage: > http://www.fxruby.org/1.2/doc/api/index.html > If I look at a class there, there are only a very few methods listed > which are > understood by the widget. If I do a Widget.public_methods.to_yaml I > get a > zillion of methods and I have to guess from the name what I need and > can only > try the real behavior of it.All of the methods that I consider to be part of the public API (e.g. for FXTextField) are documented in the RDoc documentation that you alluded to. Is it possible that public_methods is also showing you all of the widget''s inherited methods as well (i.e. those defined in base classes)? If so, you''d need to check the base class'' documentation for information for those.> The messages understood by the TextField I had > to Google for the information how this works. On the docs, the left > hand > uppper window with the file names, I don''t know what this is good for, > these > do not tell me any information. On the right hand side, the Functions > window > also does not list all of the functions. What do I do wrong? Wich > documentation do you use?This is just the standard RDoc format, which has been a part of the standard Ruby library for a while now. The "Files" frame in the upper left hand corner lists all of the files that were processed to generate the documentation. The "Methods" frame in the upper right-hand corner lists methods but not attribute accessors; I''m not sure if there''s a way to have RDoc generate those or not.
On Jan 24, 2006, at 2:01 PM, Uwe Hartl wrote:> Yes, I think there are the inherited methods too. Some of them I find > in the > tree, others I don''t. But the explaination that you only document the > ones > you consider to be part of the API, this explains the missing methods.OK.> Do I go correct in the assumption, that in new versions only the > documented API is > going to be compatible? This would forbid using the other methods and > attributes. Therefore I get the feeling that I better switch to FXText > for > the purpose I wanted to use FXTextField. FXText seems to deliver all I > can > think of...If I understand your question then the answer is yes, you should stick to using only the documented APIs for FXRuby. There are some things that you can still only do reliably when using the C++ library, such as the example you ran into (sending an ID_INSERT_STRING message directly to the widget).> I just checked, you are the guy who creates FXRuby! Thanks for the > work.You''re welcome. ;) Jeroen van der Zijp, the creator of FOX, has done most of the hard work, but I''m glad to make his work available to the Ruby community too.> I am glad that you do it. I was trying to do the program I want in > Java first but > I had the feeling to fight against Java. I switched to ruby and I had > the > feeling Ruby fights with me...I like this, that you feel like Ruby is fighting with you and not against you. I need to remember that for the future when I talk to people about Java and Ruby.> I have choosen FX because it seemed to be less resource hungry and and > similar capable as the gtk stuff -- and it comes with > the "One click Installer" on Windows. I would be helpless to install > stuff on > Windows. Nothing is as easy as an "emerge fxruby"... > > Again, thank you for creating FXRuby.
On Jan 24, 2006, at 2:37 PM, Uwe Hartl wrote:> it''s me again. Now I changed the TextField to Text an try this: > > @txt = FXText.new(hf, nil, 0, opts= > LAYOUT_FILL_X|FRAME_SUNKEN|FRAME_THICK) > from the documentation I read > Attributes > visibleRows [RW] Number of visible rows [Integer] > > do I interpret this as a readable and writable attribute of FXText? If > I try: > > @txt.visibleRows = 1 > or > @txt.visibleRows= 1 > then I get > ./Dataviewclasses.rb:51:in `showQuery'': undefined method `visibleRows='' > for :Fox::FXText (NoMethodError)I just tried a quick test with the latest releases of FXRuby (versions 1.2.6 and 1.4.4) and it worked fine. Do you know which version of FXRuby you''re using?
On Jan 24, 2006, at 3:18 PM, Uwe Hartl wrote:> Thats what I have... > > * dev-ruby/fxruby > Latest version available: 1.2.2 > Latest version installed: 1.2.2 > Size of downloaded files: 1,628 kB > Homepage: http://www.fxruby.org/ > Description: Ruby language binding to the FOX GUI toolkit > License: LGPL-2.1That is an extremely old version, released on October 1, 2004. You need to upgrade to one of the latest versions, preferably 1.4.4.
Uwe Hartl wrote:> Hi Lyle, > > I got it. It took me forever: > > @txt.connect(SEL_LEFTBUTTONPRESS) {|sender, sel, item| > helpText.setText("Suche nach einem Datum.") > @txt.onLeftBtnPress(sender, sel, item) > 0 > } > > The "0" does the trick. The event is not consumed and the Textfield still > reacts to the mouse. The funny thing is, I get an error message, when I write > return 0That''s because ruby thinks you are returning from the enclosing method, rather than from the block. You can use "break 0" to exit from the block with a certain value.> I got the idea from here: > > http://www.fox-toolkit.com/messages.html > in the section "Message Handler Return Values" > > Thanks for the help > > Uwe >-- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Hi Lyle, I got it. It took me forever: @txt.connect(SEL_LEFTBUTTONPRESS) {|sender, sel, item| helpText.setText("Suche nach einem Datum.") @txt.onLeftBtnPress(sender, sel, item) 0 } The "0" does the trick. The event is not consumed and the Textfield still reacts to the mouse. The funny thing is, I get an error message, when I write return 0 I got the idea from here: http://www.fox-toolkit.com/messages.html in the section "Message Handler Return Values" Thanks for the help Uwe -- *********************************************************************** Uwe Hartl e-mail: Uwe.Hartl at gmx.net 91522 Ansbach Telephone: (0981) 9724526 Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 Germany ***********************************************************************
Hi Joel, not really, I tried it with break 0 and get: ./Dataviewclasses.rb:66:in `call'': break from proc-closure (LocalJumpError) from /usr/lib/ruby/site_ruby/1.8/fox14/responder2.rb:57:in `onHandleMsg'' Uwe
Uwe Hartl wrote:> Hi Joel, > not really, I tried it with break 0 and get: > ./Dataviewclasses.rb:66:in `call'': break from proc-closure (LocalJumpError) > from /usr/lib/ruby/site_ruby/1.8/fox14/responder2.rb:57:in > `onHandleMsg'' > > UweRight, sorry. When a block has been turned into a proc (closure) you can still use next, however: def foo(&bl) @goo = bl end foo { next 4; raise } p @goo.call # ==> 4 -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Hi Joel, this seems to work, too. Thank you. Now I thought I found the wisdom with the message forwarding, but this is far from complete, I guess. I try now to make the FXText to ignore some keys. There are two FXText showing the same information, therefore I used a FXDataTarget. To make the FXText to ignore the keys and I inherited the FXText. In the subclass I connect to the SEL_KEYPRESS and filter the input. This procedure works great with one FXText, but it does not transfer the Info to the other FXText via the DataTarget. Here ist the test - code: require ''fox14'' include Fox class UHS_FXText < FXText def initialize(p, tgt=nil, sel=0, opts=0, x=0, y=0, w=0, h=0, pl=3, pr=3, pt=2, pb=2) super setValidChars("1234567890 :z") end def setValidChars(validchars) connect(SEL_KEYPRESS) {|sender, sel, item| ret = true if validchars.include?(item.text) ret = false else puts "Key not handled!" end ret } end end class Welcome < FXMainWindow def initialize() super($theApp, ''Welcome to the Manager'', icon=nil, miniIcon=nil, opts=DECOR_ALL, x=0, y=0, width=300, height=300) tgt = FXDataTarget.new("FOX") fr = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y) dt1 = UHS_FXText.new(fr, tgt, FXDataTarget::ID_VALUE, opts= LAYOUT_FILL_X| VSCROLLING_OFF|HSCROLLER_ALWAYS) dt1.visibleRows = 2 dt2 = UHS_FXText.new(fr, tgt, FXDataTarget::ID_VALUE, opts= LAYOUT_FILL_X| VSCROLLING_OFF|HSCROLLER_ALWAYS) dt2.visibleRows = 2 end end if $0 == __FILE__ $theApp = FXApp.new $wn = Welcome.new $wn.show $theApp.create $theApp.run p "finishing up" end May be, you can figure this out... Thanks Uwe