Disallow certain characters in a wxTextCtrl

BlitzMax Forums/Brucey's Modules/Disallow certain characters in a wxTextCtrl

plash(Posted 2008) [#1]
Is this feature already built in? can I like supply a string of characters that aren't allowed?

Checked all the tutorials, didn't find anything...


rs22(Posted 2008) [#2]
wxTextValidator looks like it might be useful to you.


Brucey(Posted 2008) [#3]
There's always someone who wants something I haven't finished :-p

The biggest reason for not having implemented the validator stuff properly yet was because I was still unsure how to wrap some of it.
Well, that's not entirely true... but it does implement some callbacks which are always a big pain to code. For example OnChar() is not implemented - which might be useful to some.

However, wxTextValidator may work for you.

Please let me know either way (if it works or not). Thanks :-)


plash(Posted 2008) [#4]
Not working (also tried wxFILTER_EXCLUDE_CHAR_LIST)... Ubuntu 8.04


;(


Brucey(Posted 2008) [#5]
wxTextCtrl can take a validator as the last param :
	Method Create:wxTextCtrl(parent:wxWindow, id:Int, value:String = "", x:Int = -1, y:Int = -1, w:Int = -1, h:Int = -1, style:Int = 0, validator:wxValidator = Null)


which might help?


Brucey(Posted 2008) [#6]
Hmm. I guess we need a simple example to test...


plash(Posted 2008) [#7]
Nope.. didn't work.
and
' BlitzMax code generated with wxCodeGen v1.10 : 18 Aug 2008 16:45:19
' 
' 
' PLEASE DO "NOT" EDIT THIS FILE!


:D (jkjk)


Brucey(Posted 2008) [#8]
Okay... here's a test app - which currently doesn't work.
SuperStrict
 
Framework wx.wxApp
Import wx.wxFrame
Import wx.wxTextCtrl
 
New MyApp.Run()
 
Type MyApp Extends wxApp

	Method OnInit:Int()
	
		Local sim:Simple = Simple(New Simple.Create(Null, wxID_ANY, "Validator Test", -1, -1, 250, 150))
		sim.Show(True)
 
		Return True
	End Method

End Type

Type Simple Extends wxFrame
 
	Field text:wxTextCtrl
	Field login_validator:wxTextValidator

	Method OnInit()
	
		text = New wxTextCtrl.Create(Self, -1)

		login_validator = New wxTextValidator.Create(wxFILTER_EXCLUDE_LIST)
		login_validator.SetExcludes(["a", "b"])
		login_validator.SetWindow(text)
		
		Centre()
 
	End Method
	
End Type



Brucey(Posted 2008) [#9]
Assuming that the excludes list is correct (?) it shouldn't allow "a" or "b" to be typed.

Unless I'm missed the point somewhere?


plash(Posted 2008) [#10]
Assuming that the excludes list is correct (?) it shouldn't allow "a" or "b" to be typed.
That's what I'm trying to do.. yes.


Brucey(Posted 2008) [#11]
Okay... I have a hack (um, I mean fix!)...

Just need to tidy it up a tad...

However, it seems that this :
login_validator.SetWindow(text)

just doesn't work...

so you will need to do :
text.SetValidator(login_validator)


Will let you know when I've broken the repository ;-)


Brucey(Posted 2008) [#12]
Okay... this version works here now :

Beeps (on Mac) when typing "a" or "b"... cool :-p

Notes... I've completely rewritten the wxTextValidator, wxValidator, added wxWindow.SetValidator, and fixed wxTextCtrl and wxSearchCtrl to fit with the changes too.

Rev 505.


plash(Posted 2008) [#13]
Rawr, changing wxWindow makes it recompile basically all wx mods! (still building)

Anywho, now I reckon we can use the same validator for multiple controls? (hence ctrl.SetValidator(), instead of validator.SetWindow())


Brucey(Posted 2008) [#14]
Well, SetWindow() doesn't seem to do anything (here on Mac).

changing wxWindow makes it recompile basically all wx mods!

Yeah... sorry about that ;-)
But hey, if it works... it's a small price to pay!


plash(Posted 2008) [#15]
Weird, I can't use an already existing array, instead I have to pass the values in directly

'Doesn't work
Global glb_filterlist:String[] = ["~~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "{", "}", "|", "~q", ":", "<", ">", "?", "`", "[", "]", "\", ";", "'", ",", "/", "=", " "]
login_validator.SetExcludes(glb_filterlist)

'Works
login_validator.SetExcludes(["~~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "{", "}", "|", "~q", ":", "<", ">", "?", "`", "[", "]", "\", ";", "'", ",", "/", "=", " "])


EDIT: Other then that it works - though, with no ding, or something to notify the user (which leads into my needing for a ballon tip).


Brucey(Posted 2008) [#16]
You are right... same here on Mac... wonder what's going on there then?

EDIT - Actually, it works fine for me here, I just had the Global in the wrong place... (it was never called) :-p


Brucey(Posted 2008) [#17]
it also dings here - but I'm guessing there that it uses whatever is platform default.

What's the default on Linux?


plash(Posted 2008) [#18]
What's the default on Linux?
What do you mean?

I just turned on system beep and system sounds (they were both off) and it still ain't making noise.
However, neither is the terminal when I hold down the backspace key.. as far as I can remember it did beep at you if you did that.

EDIT:
EDIT - Actually, it works fine for me here, I just had the Global in the wrong place... (it was never called) :-p
Oh.. lol same here (works now, when I create it just before I set it).. BUT WAIT, why didn't it yell at me for it not being instanced?


Brucey(Posted 2008) [#19]
Oh, and don't forget the "£" :-)

btw, wouldn't wxFILTER_ALPHANUMERIC be useful?


Brucey(Posted 2008) [#20]
BUT WAIT, why didn't it yell at me for it not being instanced?

you'd need to ask Mr Sibly about that feature I'm afraid ;-)


plash(Posted 2008) [#21]
btw, wouldn't wxFILTER_ALPHANUMERIC be useful?
Yep (EDIT: If I didn't want the user to be able to use a '.' in their account name).

One more itch.. why don't we have to 'Import wx.wxTextValidator' for the example to work?


Brucey(Posted 2008) [#22]
Because wxTextCtrl imports it.

Although, it actually probably should only be importing wxValidator - which wxWindow is already importing...

Good question :-)


plash(Posted 2008) [#23]
btw, wouldn't wxFILTER_ALPHANUMERIC be useful?

Yep (EDIT: If I didn't want the user to be able to use a '.' in their account name).


That's an interesting case, if I set wxFILTER_ALPHANUMERIC, and try to do login_validator.SetIncludes(["."]) it doesn't work.

With wxFILTER_INCLUDE_CHAR_LIST I can't enter in anything.
With wxFILTER_INCLUDE_LIST I can enter everything but alphanumeric's (including '.')

Would it be possible to add in that feature?


Yahfree(Posted 2008) [#24]
little off topic but it has to do with this fix:

I just updated my wxmax version through svn update and recompiling its giving me the error(a little ways down):

Compiling:common.bmx
Compile Error: Can't find interface for module 'wx.wxwindow'
[D:/BlitzMax/mod/wx.mod/wxvalidator.mod/common.bmx;24;1]
Build Error: failed to compile D:/BlitzMax/mod/wx.mod/wxvalidator.mod/common.bmx


any ideas?


plash(Posted 2008) [#25]
I just updated (for the helpprovider code) and the code compiled just fine.. (newer revision?)


Brucey(Posted 2008) [#26]
just updated my wxmax version through svn update and recompiling its giving me the error(a little ways down):

Apologies... I've changed the imports, and it should be okay now - twas an issue with me adding am import in wxWindow, which resulted in a circular import...

I probably should have done a full rebuild - which would have shown the problem - but it takes a while.

Plash won't have had the error as sometimes not all the code affected by a particular change is rebuilt by BlitzMax, and it sees that everything is still okay. - I've come across some nasty crashes in code which I knew should work, only to realize (again!) that I should have done a clean build.


Yahfree(Posted 2008) [#27]
Thanks Brucey! Seems to be compiling no problem now.