Hello, is somebody interested on something like this? There is a little problem with the FXChoiceBox.ask which I just replaced by a p "Warning" and I have some difficulties how to quote a "\" and "(" in a regular expression but everything else seems to work in here. Can somebody help me out here? Is there a database of code snippets, where I would put something like this, or do you guys think, people should write this kind of stuff (extensions of widgets) themselves? See you, Uwe by the way, "*" is a wildcard in here... require ''fox14'' include Fox class ProgressiveSelectTextField < FXTextField include Responder def initialize(parent, new_entries_allowed = true, confirm_new_entries = true, nc = 3, tgt=nil, sel=0, opts=TEXTFIELD_NORMAL, x=0, y=0, w=0, h=0, pl=DEFAULT_PAD, pr=DEFAULT_PAD, pt=DEFAULT_PAD, pb=DEFAULT_PAD) super(parent, nc, tgt=nil, sel=0, opts = LAYOUT_FILL_X) @new_entries_allowed = new_entries_allowed @confirm_new_entries = confirm_new_entries @fields = [] @items = [] @selected = 0 @old_text = "" connect(SEL_CHANGED, method(:on_changed)) connect(SEL_KEYPRESS, method(:on_key)) connect(SEL_FOCUSIN, method(:on_focus_in)) connect(SEL_FOCUSOUT, method(:on_focus_out)) connect(SEL_LEFTBUTTONPRESS, method(:on_clicked)) enable @sp = FXMenuPane.new(self, POPUP_VERTICAL|FRAME_RAISED|FRAME_THICK) @list = FXList.new(@sp, nil, 0, LIST_SINGLESELECT|LAYOUT_FILL_X| LAYOUT_FILL_Y) @list.connect(SEL_DOUBLECLICKED) { |sender, sel, data| self.text = @items[data] self. selectAll @sp.popdown } @list.connect(SEL_KEYPRESS) { |sender, sel, event| self.text = event.to_s @sp.popdown } end def appendItem(text) @fields << text end def append_array(txt) txt.each do |tt| appendItem(tt) end end def set_default_text(def_text = "*") self.text = def_text @old_text = def_text end def on_clicked(sender, sel, event) on_focus_in(sender, sel, event) end def on_focus_in(sender, sel, event) if !@sp.shown?() populateList(self.text) ret = true @selected = 0 else ret = false end ret end def on_focus_out(sender, sel, data) if (@new_entries_allowed && @confirm_new_entries && !@fields.include? (self.text)) f = File.open("icons/bigpenguin.png", "rb") icon = FXPNGIcon.new(getApp(), f.read) p "here there is the need for asking if the user wants to get a new text string in the field (not existent in the Array. Not implemented" #choice = FXChoiceBox.ask(getApp(), opts = 0, caption = "Unbekannter Eintrag", text = "Wirklich neuen Wert anlegen?", icon, ["Ja", "Nein"]) #self.text = "" if choice == 1 end end def on_changed(sender, sel, data) new = !populateList(data) if !@new_entries_allowed && new self.text = @old_text end @old_text = self.text @selected = 0 end def sel if @selected < @list.numItems @list.makeItemVisible(@selected) @list.selectItem(@selected) end end def on_key(sender, sel, event) if populateList(self.text) if ((@selected < ((@list.numItems) - 1)) && event.code == 65364) #arrow down @selected += 1 self.sel elsif ((@selected > 0) && event.code == 65362) #arrow up @selected -= 1 self.sel elsif event.code == 65293 # Enter key self.text = @list.getItem(@selected).text self.cursorPos = self.text.length self.selectAll @sp.popdown end end false end def popup xy = translateCoordinatesTo(getRoot(), x, y) @sp.popup(nil, xy[0], xy[1]+height, self.width, 100) @sp.recalc @sp.create end def populateList(searchString = "") ss = searchString.gsub("(", ".") ss.gsub!(")", ".") p ss re = Regexp.new(ss.gsub("*", "(\\D*|\\d*)")) p re @items = @fields.collect { |val| val if val.match(re).to_s != ""} @items.delete(nil) @list.clearItems if @items.length > 0 @items.each do |it| @list.appendItem(it) end popup sel ret = true else @sp.popdown() ret = false end return ret end end class Welcome < FXMainWindow def initialize() super($theApp, ''ComboBox'', icon=nil, miniIcon=nil, opts=DECOR_ALL, x=0, y=0, width=300, height=300) ta = ProgressiveSelectTextField.new(self) txt = ["able", "apartment", "apple", "Appolinaris", "andruide", "berta", "aparent", "aple", "Apinaris", "anduide", "beta", "Zeta"] ta.append_array(txt) ta.set_default_text(txt[2]) end end if $0 == __FILE__ $theApp = FXApp.new $wn = Welcome.new $wn.show $theApp.create $theApp.run end -- *********************************************************************** Uwe Hartl e-mail: Uwe.Hartl at gmx.net 91522 Ansbach Telephone: (0981) 9724526 Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 Germany ***********************************************************************
Uwe Hartl wrote:> Hello, > > is somebody interested on something like this? There is a little problem with > the FXChoiceBox.ask which I just replaced by a > > p "Warning" > > and I have some difficulties how to quote a "\" and "(" in a regular > expression but everything else seems to work in here. Can somebody help me > out here?"special chars in REs are quoted by prefixing them with a ''\'' eg /\w+\\\w+\([^)]*\)/ would match \jadahjasg\fghjagfkj(jgsdfjksdghjkf) Russell
Quoting Uwe Hartl <uwe.hartl at gmx.net>:> Hello, > > is somebody interested on something like this? There is a little problem with > > the FXChoiceBox.ask which I just replaced by a > > p "Warning" > > and I have some difficulties how to quote a "\" and "(" in a regular > expression but everything else seems to work in here. Can somebody help me > out here? > > Is there a database of code snippets, where I would put something like this, > > or do you guys think, people should write this kind of stuff (extensions of > widgets) themselves? > > See you, > > Uwe > > by the way, "*" is a wildcard in here... >Uwe, This is great! I tried something similar and it doesn''t work nearly as nice as this. What do you need help on? Scott
it''s quite nice. i definitely will have use for that. there are also some little things, that are not so cool about it: * configuration via constructor (yes, fox is all like this, but it makes classes definitly less easy to use ... especially if there are many of them) * inconsequent coding style: appendItem vs append_array. but that is easy to fix ;) i appreciate that you share your code with us. should be done more often on this list. thanks a lot!! -- henon On 2/28/06, Uwe Hartl <uwe.hartl at gmx.net> wrote:> > Hello, > > is somebody interested on something like this? There is a little problem > with > the FXChoiceBox.ask which I just replaced by a > > p "Warning" > > and I have some difficulties how to quote a "\" and "(" in a regular > expression but everything else seems to work in here. Can somebody help me > out here? > > Is there a database of code snippets, where I would put something like > this, > or do you guys think, people should write this kind of stuff (extensions > of > widgets) themselves? > > See you, > > Uwe > > by the way, "*" is a wildcard in here... > > require ''fox14'' > include Fox > > > class ProgressiveSelectTextField < FXTextField > include Responder > > def initialize(parent, new_entries_allowed = true, > confirm_new_entries > true, nc = 3, tgt=nil, sel=0, opts=TEXTFIELD_NORMAL, x=0, y=0, w=0, h=0, > pl=DEFAULT_PAD, pr=DEFAULT_PAD, pt=DEFAULT_PAD, pb=DEFAULT_PAD) > super(parent, nc, tgt=nil, sel=0, opts = LAYOUT_FILL_X) > @new_entries_allowed = new_entries_allowed > @confirm_new_entries = confirm_new_entries > @fields = [] > @items = [] > @selected = 0 > @old_text = "" > connect(SEL_CHANGED, method(:on_changed)) > connect(SEL_KEYPRESS, method(:on_key)) > connect(SEL_FOCUSIN, method(:on_focus_in)) > connect(SEL_FOCUSOUT, method(:on_focus_out)) > connect(SEL_LEFTBUTTONPRESS, method(:on_clicked)) > enable > @sp = FXMenuPane.new(self, > POPUP_VERTICAL|FRAME_RAISED|FRAME_THICK) > @list = FXList.new(@sp, nil, 0, > LIST_SINGLESELECT|LAYOUT_FILL_X| > LAYOUT_FILL_Y) > @list.connect(SEL_DOUBLECLICKED) { |sender, sel, data| > self.text = @items[data] > self. selectAll > @sp.popdown > } > @list.connect(SEL_KEYPRESS) { |sender, sel, event| > self.text = event.to_s > @sp.popdown > } > end > def appendItem(text) > @fields << text > end > def append_array(txt) > txt.each do |tt| > appendItem(tt) > end > end > def set_default_text(def_text = "*") > self.text = def_text > @old_text = def_text > end > def on_clicked(sender, sel, event) > on_focus_in(sender, sel, event) > end > def on_focus_in(sender, sel, event) > if !@sp.shown?() > populateList(self.text) > ret = true > @selected = 0 > else > ret = false > end > ret > end > def on_focus_out(sender, sel, data) > if (@new_entries_allowed && @confirm_new_entries && !@ > fields.include? > (self.text)) > f = File.open("icons/bigpenguin.png", "rb") > icon = FXPNGIcon.new(getApp(), f.read) > p "here there is the need for asking if the user > wants to get a new text > string in the field (not existent in the Array. Not implemented" > #choice = FXChoiceBox.ask(getApp(), opts = 0, > caption = "Unbekannter > Eintrag", text = "Wirklich neuen Wert anlegen?", icon, ["Ja", "Nein"]) > #self.text = "" if choice == 1 > end > end > def on_changed(sender, sel, data) > new = !populateList(data) > if !@new_entries_allowed && new > self.text = @old_text > end > @old_text = self.text > @selected = 0 > end > def sel > if @selected < @list.numItems > @list.makeItemVisible(@selected) > @list.selectItem(@selected) > end > end > def on_key(sender, sel, event) > if populateList(self.text) > if ((@selected < ((@list.numItems) - 1)) && > event.code == 65364) #arrow > down > @selected += 1 > self.sel > elsif ((@selected > 0) && event.code == 65362) > #arrow up > @selected -= 1 > self.sel > elsif event.code == 65293 # Enter key > self.text = @list.getItem(@selected).text > self.cursorPos = self.text.length > self.selectAll > @sp.popdown > end > end > false > end > def popup > xy = translateCoordinatesTo(getRoot(), x, y) > @sp.popup(nil, xy[0], xy[1]+height, self.width, 100) > @sp.recalc > @sp.create > end > def populateList(searchString = "") > ss = searchString.gsub("(", ".") > ss.gsub!(")", ".") > p ss > re = Regexp.new(ss.gsub("*", "(\\D*|\\d*)")) > p re > @items = @fields.collect { |val| val if val.match(re).to_s > != ""} > @items.delete(nil) > @list.clearItems > if @items.length > 0 > @items.each do |it| > @list.appendItem(it) > end > popup > sel > ret = true > else > @sp.popdown() > ret = false > end > return ret > end > end > > > > class Welcome < FXMainWindow > def initialize() > super($theApp, ''ComboBox'', icon=nil, miniIcon=nil, > opts=DECOR_ALL, x=0, y=0, > width=300, height=300) > > ta = ProgressiveSelectTextField.new(self) > txt = ["able", "apartment", "apple", "Appolinaris", > "andruide", "berta", > "aparent", "aple", "Apinaris", "anduide", "beta", "Zeta"] > ta.append_array(txt) > ta.set_default_text(txt[2]) > end > end > > if $0 == __FILE__ > $theApp = FXApp.new > $wn = Welcome.new > $wn.show > $theApp.create > > $theApp.run > end > > -- > *********************************************************************** > Uwe Hartl e-mail: Uwe.Hartl at gmx.net > 91522 Ansbach Telephone: (0981) 9724526 > Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 > Germany > *********************************************************************** > > > _______________________________________________ > fxruby-users mailing list > fxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/fxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20060301/cdb1b1c5/attachment-0001.htm
Ok, I will fix these. I started programming a couple of weeks ago in ruby after a 9 year brake, coming fron C. Sorry, I will improve. A couple of things I would need help with: I tried "fillItems" from the FXList and get a segfault. Thats why I wrote append_array(txt). Can somebody verify this, please? In my case we look at an Gentoo system, I have no idea if this is system specific. I want to have a String: "blabla\(blabla" to make the "(" a normal character for the regex; Here are my Attempts irb(main):089:0* "blabla\(blabla" => "blabla(blabla" irb(main):090:0> "blabla\\(blabla" => "blabla\\(blabla" irb(main):091:0> ''blabla\\(blabla'' => "blabla\\(blabla" Can somebody tell me how I can do this? I either get two backslashes or I get none. What do I miss? Thanks Uwe On Wednesday 01 March 2006 07:34, Meinrad Recheis wrote:> it''s quite nice. i definitely will have use for that. > there are also some little things, that are not so cool about it: > * configuration via constructor (yes, fox is all like this, but it makes > classes definitly less easy to use ... especially if there are many of > them) * inconsequent coding style: appendItem vs append_array. > but that is easy to fix ;) > > i appreciate that you share your code with us. should be done more often on > this list. > thanks a lot!! > -- henon > > On 2/28/06, Uwe Hartl <uwe.hartl at gmx.net> wrote: > > Hello, > > > > is somebody interested on something like this? There is a little problem > > with > > the FXChoiceBox.ask which I just replaced by a > > > > p "Warning" > > > > and I have some difficulties how to quote a "\" and "(" in a regular > > expression but everything else seems to work in here. Can somebody help > > me out here? > > > > Is there a database of code snippets, where I would put something like > > this, > > or do you guys think, people should write this kind of stuff (extensions > > of > > widgets) themselves? > > > > See you, > > > > Uwe > > > > by the way, "*" is a wildcard in here... > > > > require ''fox14'' > > include Fox > > > > > > class ProgressiveSelectTextField < FXTextField > > include Responder > > > > def initialize(parent, new_entries_allowed = true, > > confirm_new_entries > > true, nc = 3, tgt=nil, sel=0, opts=TEXTFIELD_NORMAL, x=0, y=0, w=0, h=0, > > pl=DEFAULT_PAD, pr=DEFAULT_PAD, pt=DEFAULT_PAD, pb=DEFAULT_PAD) > > super(parent, nc, tgt=nil, sel=0, opts = LAYOUT_FILL_X) > > @new_entries_allowed = new_entries_allowed > > @confirm_new_entries = confirm_new_entries > > @fields = [] > > @items = [] > > @selected = 0 > > @old_text = "" > > connect(SEL_CHANGED, method(:on_changed)) > > connect(SEL_KEYPRESS, method(:on_key)) > > connect(SEL_FOCUSIN, method(:on_focus_in)) > > connect(SEL_FOCUSOUT, method(:on_focus_out)) > > connect(SEL_LEFTBUTTONPRESS, method(:on_clicked)) > > enable > > @sp = FXMenuPane.new(self, > > POPUP_VERTICAL|FRAME_RAISED|FRAME_THICK) > > @list = FXList.new(@sp, nil, 0, > > LIST_SINGLESELECT|LAYOUT_FILL_X| > > LAYOUT_FILL_Y) > > @list.connect(SEL_DOUBLECLICKED) { |sender, sel, data| > > self.text = @items[data] > > self. selectAll > > @sp.popdown > > } > > @list.connect(SEL_KEYPRESS) { |sender, sel, event| > > self.text = event.to_s > > @sp.popdown > > } > > end > > def appendItem(text) > > @fields << text > > end > > def append_array(txt) > > txt.each do |tt| > > appendItem(tt) > > end > > end > > def set_default_text(def_text = "*") > > self.text = def_text > > @old_text = def_text > > end > > def on_clicked(sender, sel, event) > > on_focus_in(sender, sel, event) > > end > > def on_focus_in(sender, sel, event) > > if !@sp.shown?() > > populateList(self.text) > > ret = true > > @selected = 0 > > else > > ret = false > > end > > ret > > end > > def on_focus_out(sender, sel, data) > > if (@new_entries_allowed && @confirm_new_entries && !@ > > fields.include? > > (self.text)) > > f = File.open("icons/bigpenguin.png", "rb") > > icon = FXPNGIcon.new(getApp(), f.read) > > p "here there is the need for asking if the user > > wants to get a new text > > string in the field (not existent in the Array. Not implemented" > > #choice = FXChoiceBox.ask(getApp(), opts = 0, > > caption = "Unbekannter > > Eintrag", text = "Wirklich neuen Wert anlegen?", icon, ["Ja", "Nein"]) > > #self.text = "" if choice == 1 > > end > > end > > def on_changed(sender, sel, data) > > new = !populateList(data) > > if !@new_entries_allowed && new > > self.text = @old_text > > end > > @old_text = self.text > > @selected = 0 > > end > > def sel > > if @selected < @list.numItems > > @list.makeItemVisible(@selected) > > @list.selectItem(@selected) > > end > > end > > def on_key(sender, sel, event) > > if populateList(self.text) > > if ((@selected < ((@list.numItems) - 1)) && > > event.code == 65364) #arrow > > down > > @selected += 1 > > self.sel > > elsif ((@selected > 0) && event.code == 65362) > > #arrow up > > @selected -= 1 > > self.sel > > elsif event.code == 65293 # Enter key > > self.text = @list.getItem(@selected).text > > self.cursorPos = self.text.length > > self.selectAll > > @sp.popdown > > end > > end > > false > > end > > def popup > > xy = translateCoordinatesTo(getRoot(), x, y) > > @sp.popup(nil, xy[0], xy[1]+height, self.width, 100) > > @sp.recalc > > @sp.create > > end > > def populateList(searchString = "") > > ss = searchString.gsub("(", ".") > > ss.gsub!(")", ".") > > p ss > > re = Regexp.new(ss.gsub("*", "(\\D*|\\d*)")) > > p re > > @items = @fields.collect { |val| val if > > val.match(re).to_s != ""} > > @items.delete(nil) > > @list.clearItems > > if @items.length > 0 > > @items.each do |it| > > @list.appendItem(it) > > end > > popup > > sel > > ret = true > > else > > @sp.popdown() > > ret = false > > end > > return ret > > end > > end > > > > > > > > class Welcome < FXMainWindow > > def initialize() > > super($theApp, ''ComboBox'', icon=nil, miniIcon=nil, > > opts=DECOR_ALL, x=0, y=0, > > width=300, height=300) > > > > ta = ProgressiveSelectTextField.new(self) > > txt = ["able", "apartment", "apple", "Appolinaris", > > "andruide", "berta", > > "aparent", "aple", "Apinaris", "anduide", "beta", "Zeta"] > > ta.append_array(txt) > > ta.set_default_text(txt[2]) > > end > > end > > > > if $0 == __FILE__ > > $theApp = FXApp.new > > $wn = Welcome.new > > $wn.show > > $theApp.create > > > > $theApp.run > > end > > > > -- > > *********************************************************************** > > Uwe Hartl e-mail: Uwe.Hartl at gmx.net > > 91522 Ansbach Telephone: (0981) 9724526 > > Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 > > Germany > > *********************************************************************** > > > > > > _______________________________________________ > > fxruby-users mailing list > > fxruby-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/fxruby-users-- *********************************************************************** Uwe Hartl e-mail: Uwe.Hartl at gmx.net 91522 Ansbach Telephone: (0981) 9724526 Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 Germany ***********************************************************************
Hi Uwe,> I want to have a String: "blabla\(blabla" to make the "(" a normal > character for the regex;irb(main):003:0> Regexp.compile ''blabla\(blabla'' => /blabla\(blabla/ Ciao Sascha
Uwe Hartl wrote:> I want to have a String: "blabla\(blabla" to make the "(" a normal character > for the regex; >What string are you trying to match? and I also suggest you post the actual code. The complication here is that if you are assigning to a string and then using the string in an RE then there *two* levels of quoting necessary, one for the string and one for the RE with the \ needing to be quoted twice and the ( once. i.e. to get a single \ in the RE you would need \\\\ in the string -- this gets unmanageable really fast so I recommend not using variables in REs unless you really have to. We need to see exactly what you are trying to do to solve this one there are too many ambiguities. Russell
On Wed, 1 Mar 2006 20:25:13 +0100 Uwe Hartl <uwe.hartl at gmx.net> wrote:> Ok, I will fix these. I started programming a couple of weeks ago in > ruby after a 9 year brake, coming fron C. Sorry, I will improve. > > A couple of things I would need help with: > > I tried "fillItems" from the FXList and get a segfault. Thats why I > wrote append_array(txt). Can somebody verify this, please? In my case > we look at an Gentoo system, I have no idea if this is system > specific. > > I want to have a String: "blabla\(blabla" to make the "(" a normal > character for the regex; > > Here are my Attempts > irb(main):089:0* "blabla\(blabla" > => "blabla(blabla" > irb(main):090:0> "blabla\\(blabla" > => "blabla\\(blabla" > irb(main):091:0> ''blabla\\(blabla'' > => "blabla\\(blabla" > > Can somebody tell me how I can do this? I either get two backslashes > or I get none. What do I miss?You''re missing that irb displays stuff (almost) the way Ruby is interpreting it. "\(" would always become "(" because Ruby tries to interpret the backslash as a special char (\n, \r, \t etc.) but fails to find a ''r'', ''n'' or ''t'', so the slash is just ignored. To check this, try typing "blabla\t(blabla", which will give you "blabla\t(blabla". Irb returns "\\(" as "\\(", but this doesn''t mean that there will be two backslashes in the actual string output. If it would print "\" you might expect a special char here (=> misleading). To check your expressions, assign the string to a variable and print its value: jannis at nebelsee ~> irb irb(main):001:0> var = "bla\test" => "bla\test" irb(main):002:0> puts var bla est => nil irb(main):003:0> var = "bla\\test" => "bla\\test" irb(main):004:0> puts var bla\test => nil irb(main):005:0> var = "bla\(test" => "bla(test" irb(main):006:0> puts var bla(test => nil irb(main):007:0> var = "bla\\(test" => "bla\\(test" irb(main):008:0> puts var bla\(test => nil Hope this helps, Jannis -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/fxruby-users/attachments/20060301/acacdf1f/attachment.bin
Thanks Jannis, this was enligthening. Thanks. With the help of you guys and gals soon I will understand what I do. No joke. Uwe> jannis at nebelsee ~> irb > irb(main):001:0> var = "bla\test" > => "bla\test" > irb(main):002:0> puts var > bla est > => nil > irb(main):003:0> var = "bla\\test" > => "bla\\test" > irb(main):004:0> puts var > bla\test > => nil > irb(main):005:0> var = "bla\(test" > => "bla(test" > irb(main):006:0> puts var > bla(test > => nil > irb(main):007:0> var = "bla\\(test" > => "bla\\(test" > irb(main):008:0> puts var > bla\(test > => nil > > Hope this helps, > Jannis-- *********************************************************************** Uwe Hartl e-mail: Uwe.Hartl at gmx.net 91522 Ansbach Telephone: (0981) 9724526 Am M?hlfeld 8 Notfall-Mobil: (0160)90418680 Germany ***********************************************************************