|
Post by axelmoe on Aug 28, 2015 7:19:58 GMT 1
Hi all, i am new in BECON. At first thank you for this fantastic programming and Development environment.
hier my first questions:
I wich to limit the input length in HUG entry. Whats the best way? I want to allow only numeric entries in a Hug entry. Whats the best way?
many thanks for your support.
Regards from Germany
Axel
|
|
|
Post by vovchik on Aug 28, 2015 11:14:26 GMT 1
Dear Axel, Have a look at this: GTKAfter creating the widget, you can set the property, eg: SETPROPERTY(entry_widget, "width-chars", 10) SETPROPERTY(entry_widget,"text-length", 10) And you can use GRAB$ in a CALLBACK function for the widget to check the input until you get what you need from the user. With kind regards, vovchik
|
|
|
Post by alexfish on Aug 29, 2015 14:54:09 GMT 1
Hi Axel
have expanded Vovchik's SETPROPERTY
A couple of option are in the subs
INCLUDE hug.bac
SUB set_numb()
nm# = VAL(GRAB$(entry_widget2)) new_numb$= STR$(nm#)
TEXT(entry_widget2, new_numb$)
END SUB
SUB new_numb()
nm# = VAL(GRAB$(entry_widget))
IF nm# > 0 THEN
new_numb$= STR$(nm#) TEXT(entry_widget, new_numb$)
ELSE
TEXT(entry_widget,"Number Req") END IF
END SUB
LET win = WINDOW("entry", 300, 200)
LET entry_widget = ENTRY("", 100,25) ATTACH(win,entry_widget,10,10)
SETPROPERTY(entry_widget, "width-chars", 10)
CALLBACK(entry_widget,new_numb)
LET entry_widget2 = ENTRY("", 100,25) ATTACH(win,entry_widget2,10,40)
SETPROPERTY(entry_widget2, "width-chars", 10) REM set the entry to the right SETPROPERTY(entry_widget2, "xalign", 1.0)
CALLBACK(entry_widget2,set_numb)
DISPLAY
BR Alex
|
|
|
Post by axelmoe on Aug 31, 2015 7:22:04 GMT 1
Hi all,
many thanks for your extensive answers.
rgds
Axel
|
|
|
Post by axelmoe on Sept 2, 2015 10:58:52 GMT 1
Hi all,
this settings ++ SETPROPERTY(entry_widget, "width-chars", 10) SETPROPERTY(entry_widget,"text-length", 10) ++
have shown no effect in my tests.
The check for numerc entrys work but I want to permit directly at the keystroke only digits.
Can someone help me?
Thanks + regrads
Axel
|
|
|
Post by vovchik on Sept 2, 2015 11:44:50 GMT 1
Dear Axel,
Here is a tiny python script that does that. Easy to port to BaCon, but I am in a rush right now:
#!/usr/bin/env python import gtk import pygtk
class xEntry(gtk.Entry): def __init__(self, allowedchars): gtk.Entry.__init__(self) self.allowedchars=allowedchars self.connect("changed", self.charcheck, None)
def charcheck(self, widget, string, *args): pos = widget.get_position() char = widget.get_chars(pos, pos + 1) if char not in self.allowedchars: widget.select_region(pos, pos + 1) widget.delete_selection()
class MainWindow(gtk.Window): def __init__(self): print "111" gtk.Window.__init__(self,gtk.WINDOW_TOPLEVEL) self.entry = xEntry("1234567890.") self.box = gtk.VBox() self.box.pack_start(self.entry) self.add(self.box) self.show_all()
def main(): m=MainWindow() gtk.main()
if __name__ == "__main__": main()
With kind regards, vovchik
|
|
|
Post by axelmoe on Sept 2, 2015 18:31:11 GMT 1
hi all,
the parameter for SETPROPERTY is
max_length
axel
|
|
|
Post by axelmoe on Sept 3, 2015 10:50:25 GMT 1
Hi all,
I have found teh HUG function KEY but I don't understand the usage. Can someone provide me an example.
Thanks
Axel
|
|
|
Post by Pjot on Sept 3, 2015 17:24:27 GMT 1
|
|
|
Post by alexfish on Sept 3, 2015 23:11:35 GMT 1
Hi Axel Can look at the key options , here not sure if it will work 100% , this can relate to the IM input options, hence if the key press event distracts the focus away from the widget then possible focus for input may = null .. developer.gnome.org/gtk2/stable/ look at both the gtk2 entry + the entrybuffer .. this points to a no valid read of key event unless specific to the function IE the Entry requires the Enter Key event.. (but can allow an over-ride as explained in the IM on the entry buffer.. one possible option if met with failure . use multiple entry's to the number of digits required , then after each input focus on the next box , or what ever BR Alex EG:: INCLUDE hug.bac
SUB check_input(NUMBER widget) PRINT "changed"
SELECT widget CASE entry_widget PRINT "box1" FOCUS(entry_widget2)
CASE entry_widget2 PRINT "box2"
END SELECT ENDSUB
LET win = WINDOW("entry", 300, 200)
LET entry_widget = ENTRY("", 15,25) SETPROPERTY(entry_widget,"max-length",1) ATTACH(win,entry_widget,15,40) CALLBACK(entry_widget,check_input) LET entry_widget2 = ENTRY("", 15,25) SETPROPERTY(entry_widget2,"max-length",1) ATTACH(win,entry_widget2,30,40) CALLBACK(entry_widget2,check_input) REM focus on first entry box FOCUS(entry_widget) DISPLAY
|
|
|
Post by alexfish on Sept 8, 2015 18:35:57 GMT 1
Hi Axel
Here have taken the hug key event routine + add some mods to it.
There is still work to be done as regards adding code , hence added print + select to help U on the way
BR Alex
INCLUDE hug.bac
FUNCTION get_entry_key(NUMBER hug_widget, void *hug_data1, NUMBER hug_data2) : REM INCLUDE
LOCAL inkey USEC typedef struct { int type; void *entry; signed char send_event; unsigned int time; unsigned int state; unsigned int keyval; } GdkEventKey;
GdkEventKey *keypress; keypress = (GdkEventKey*)hug_data1;
inkey = keypress->keyval;
END USEC REM can sort the bits here PRINT inkey , " : " , inkey FORMAT "%d %s %c \n"
SELECT inkey
CASE 48
PRINT "0"
CASE 49
PRINT "1"
CASE 50
PRINT "2"
CASE 51
PRINT "3"
CASE 52
PRINT "4"
CASE 53
PRINT "5"
CASE 54
PRINT "6"
CASE 55
PRINT "7"
CASE 56
PRINT "8"
CASE 57
PRINT "9" DEFAULT
REM do something here as well
PRINT "Err"
END SELECT
RETURN FALSE
END FUNCTION
LET win = WINDOW("test entry key event",600,400)
LET entry_widget = ENTRY("",200,25)
SETPROPERTY(entry_widget,"max-length",10)
g_signal_connect_data(entry_widget, "key-press-event", get_entry_key, 0, 0, 0)
ATTACH(win,entry_widget,20,20)
FOCUS(entry_widget)
DISPLAY
|
|
|
Post by axelmoe on Sept 9, 2015 6:58:27 GMT 1
Hi All,
many thanks for your grreat examples. My first test's lokked fine. I'll create an example wich is demonstrating the me now variants of input check.
rgds
Axel
|
|
|
Post by vovchik on Sept 9, 2015 15:40:56 GMT 1
Dear Alex and Alex,
What about this?
INCLUDE hug.bac
' ------------------ FUNCTION NUMERIC_FILTER(NUMBER hug_widget) ' ------------------ ' here, '-' for negative and '.' for decimal nums are OK ' but there must be a better way to write the REGEX ' - i.e [[:digit:]], plus '-' and '.' IF REGEX(GRAB$(hug_widget), "[[:alpha:] ~`!@#$%^&*()_+=<>?]") THEN TEXT(hug_widget, "") END IF RETURN FALSE END FUNCTION
' ------------------ FUNCTION PRINT_ENTRY(NUMBER hug_widget) ' ------------------ PRINT GRAB$(entry_widget) RETURN FALSE END FUNCTION
' ------------------ SUB MK_GUI() ' ------------------ win = WINDOW("Filter entry input", 300, 100) entry_widget = ENTRY("", 200, 25) but = BUTTON("OK", 90, 30) ATTACH(win, entry_widget, 20, 20) ATTACH(win, but, 200, 60) SETPROPERTY(entry_widget, "max-length", 10) g_signal_connect_data(entry_widget, "changed", NUMERIC_FILTER, 0, 0, 0) FOCUS(entry_widget) CALLBACK(but, PRINT_ENTRY) END SUB
MK_GUI() DISPLAY
With kind regards, vovchik
|
|
|
Post by axelmoe on Sept 10, 2015 8:36:18 GMT 1
|
|
|
Post by vovchik on Sept 10, 2015 11:33:41 GMT 1
Dear Axel,
I think this is a neater, better way to write the numeric filter (but still needs improvement):
' ------------------ FUNCTION NUMERIC_FILTER(NUMBER hug_widget) ' ------------------ IF ISFALSE(REGEX(GRAB$(hug_widget), "[[:digit:].-]")) THEN TEXT(hug_widget, "") END IF RETURN FALSE END FUNCTION
but I like the idea of masks and templates described in the link you provided. We'll have to think of how to implement something like that, which would be very useful.
With kind regards, vovchik
|
|