| WideStudio Index |
Table of contents
The sample of the event procedures for WSCvifield
Executing some event procedures by return keyYou can execute the specified procedures in the event procedure. Here, the following sample shows executing the procedure which name is "InputFixed".import mpfc # A sample of WSEV_KEY_HOOK trigger. def cbop(object): # (A)Get the pressed key. key = mpfc.WSGIappKeyboard().getKey(); # (B)If the key is return.. if (key == mpfc.WSK_Return): # Execute the procedure which name is "InputFixed". object.execProcedure("InputFixed"); return mpfc.WSGFfunctionRegister("chop",chop)
This procedure sometimes is used to execute some procedure on the end of key input.
- (A): Get the key code which is pressed from the keyboard.
- (B): if it is return key, do (C).
- (C): Execute the procedure which name is "InputFixed".
Clearing the last input string on starting of next inputHere, you create a procedure which clears the last input string on starting of the next. the procedure clears the string the first key input since the input field instance is focused or clicked by the mouse pointer. The clear process is as follows:
- (1)It sets the clear flag True,if the input field is focused.
- (2)It sets the clear flag True,if the input field is clicked.
- (3)It clears the string if the clear flag is True.
- (4)It initializes the sub-procedures (1),(2),(3).import mpfc # To contain the last focused input field. focus_if = None # (1)A sub-procedure with WSEV_FOCUS_CH def _focus_ch_(object): # (A) Examine whether the instance is focused. global focus_if if (focus_if != None and focus_if.getInstanceName() != object.getInstanceName() and object.getFocus() != mpfc.False ): # (B)It need to clear the string! # Set the clear flag True. object.setVariantData("CLEAR TIMING",1); # (C)store that the last focused one is. focus_if = object; return mpfc.WSGFfunctionRegister("_focus_ch_",_focus_ch_) #(2)A sub-procedure with WSEV_MOUSE_PRESS def _btn_press_(object): # (D) if clicked by the mouse pointer, # it needs to clear the string! # Set the clear flag True. object.setVariantData("CLEAR TIMING",1); object.setProperty("cursorPos",0); # (E)store that the last focused one is. global focus_if focus_if = object; return mpfc.WSGFfunctionRegister("_btn_press_",_btn_press_) # (3)A sub-procedure with WSEV_KEY_PRESS def _key_hook_(object): # See the clear flag to clear the last input string. fl = object.getVariantData("CLEAR TIMING"); if (fl.getLong() == 1): key = mpfc.WSGIappKeyboard().getKey(); # (G) Clear the string,if the key is not cursor key. if (key != mpfc.WSK_Tab and key != mpfc.WSK_Up and key != mpfc.WSK_Down and key != mpfc.WSK_Left and key != mpfc.WSK_Right ): # (H)Clear... object.setProperty("labelString",""); else: return; # (I)Set the clear flag False. object.setVariantData("CLEAR TIMING",0); return mpfc.WSGFfunctionRegister("_key_hook_",_key_hook_) # The main-procedure. # (4)Set the input field instance with WSEV_INITIALIZE trigger. def ifdclr(object): # Setup the sub-procedure(1) with WSEV_FOCUS_CH object.addProcedure("ac1","_focus_ch_",mpfc.WSEV_FOCUS_CH); # Setup the sub-procedure(2) with WSEV_MOUSE_PRESS object.addProcedure("ac2","_btn_press_",mpfc.WSEV_MOUSE_PRESS); # Setup the sub-procedure(3) with WSEV_KEY_PRESS object.addProcedure("ac3","_key_hook_",mpfc.WSEV_KEY_HOOK); mpfc.WSGFfunctionRegister("ifdclr",ifdclr)In the focus_ch event procedure, To examine the instance is focused afresh, It uses the static variable which is stored the last focused instance.
- (A): It checks whether the instance is equal to the last focused one. if it differs and it focused (not lost), it means that the instance is focused afresh.
- (B): It sets the clear flag True.
- (C): It stores the instance to the static variable for the next.
- (D): It sets the clear flag True and move the cursor to the top.
- (E): It stores the instance to the static variable for the next.
- (F): It sees the clear flag to clear the last string.
- (G): It is too sad to clear the string with the cursor key, so it sees what it is.
- (H): It clears the string if it is not.
- (I): It sets the clear flag False.
|Copyright(C) WideStudio Development Team, 1999-2005||Last modified: Jan 05, 2005|