Page 1 sur 1

gestion avancee des stringgadget

Publié : dim. 12/nov./2006 17:57
par sined
hi,

je voudrais pouvoir controler la saisie à l'interieur d'un stringgadget,
i.e : controler la longueur, le masque de saisie (par exemple : refuser un chiffre en 3eme position)...

pour cela, j'ai besoin de :

1/ savoir si un evement "touche appuyée" a été généré sur mon stringgadget
2/ récupérer la touche et sa position dans la chaine

le tout si possible en conservant la portabilité du langage. (je dois pouvoir utiliser le code sous linux)

merci d'aance pour vos nombreuses réponses

A+

Publié : dim. 12/nov./2006 18:41
par Dr. Dri
si tu veux un truc portable va falloir attendre une maj avec les évennements du clavier (un jour peut etre...)

Dri

Publié : dim. 12/nov./2006 18:49
par sined
si il existe une solution via WinAPI et une via la glibc, je suis aussi preneur...


Merci pour ta réponse DR Dri

SINED

Publié : dim. 12/nov./2006 19:00
par Dr. Dri
Pour windows tu as ces macros :
http://purebasic.hmt-forum.com/viewtopi ... on+clavier

Dri

Publié : lun. 13/nov./2006 0:54
par sined
Merci pour ton aide, j'ai jetté un oeil sur ces macros.

Ca me permet en effet de récupérer le caractère saisi, mais je ne connais pas son rang dans la chaine. Ce n'est pas forcement à la suite du dernier caractère, si l'utilisateur déplace le curseur souris en plein milieu de la chaine, je dois etre capable de l'insérer à sa bonne place...



A+
SID

Publié : lun. 13/nov./2006 3:17
par Backup
ça te vas pas ça ? 8O



; Codé par Dobro
; en purebasic 4.00
;- Window Constants
;
Enumeration
     #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
     #String_0
     #Text_0
EndEnumeration


Procedure Open_Window_0()
     If OpenWindow ( #Window_0 , 216, 0, 600, 300, "New window ( 0 )" , #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
         If CreateGadgetList ( WindowID ( #Window_0 ))
             StringGadget ( #String_0 , 50, 30, 150, 20, "" , #PB_String_Numeric )
             TextGadget ( #Text_0 , 50, 60, 140, 20, "Limité a 6 caracteres chiffre" )
            
         EndIf
     EndIf
EndProcedure

Open_Window_0()

Repeat ; Start of the event loop
    
    Event = WaitWindowEvent () ; This line waits until an event is received from Windows
    
     WindowID = EventWindow () ; The Window where the event is generated, can be used in the gadget procedures
    
     GadgetID = EventGadget () ; Is it a gadget event?
    
     EventType = EventType () ; The event type
    
     ;You can place code here, and use the result as parameters for the procedures
    
     If Event = #PB_Event_Gadget
        
         If GadgetID = #String_0
            text$= GetGadgetText ( #String_0 )
             If Len ( text$)>6
                text$= Left (text$,6)
                 StringGadget ( #String_0 , 50, 30, 150, 20, "" , #PB_String_ReadOnly|#PB_String_Numeric )
                 StringGadget ( #String_0 , 50, 30, 150, 20, "" , #PB_String_Numeric )
                 SetGadgetText ( #String_0 , text$)
             EndIf
            
         EndIf
        
     EndIf
    
Until Event = #PB_Event_CloseWindow ; End of the event loop

End
;

Publié : lun. 13/nov./2006 11:10
par sined
Salut Dobro,


Merci pour ton petit code. Il permet effectivement de gérer le nombre maximum de caractères à saisir, mais ne permet pas de filtrer les caractères de facon individuelle. i.e : je ne peux pas imposer un masque de saisie de la forme : <+/-><1-9><0-9><0-9><0-9><.><0-9><0-9>
ou encore plus spécifique : <A|b|c><0-9><X|Y><&|#>


you see what i mean ?


Bye
SID

Publié : lun. 13/nov./2006 13:46
par gnozal

Publié : mar. 14/nov./2006 4:28
par Backup
sinon tu as ce code :D

Code : Tout sélectionner

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=3279&highlight=
; Author: Sylvia
; Date: 29. December 2003


;********************************** 
;* 2003 Dec.29 "Sylvia" GermanForum 
;********************************** 

Procedure.s StringUsing(Format$,Wert) 
    ; Liefert einen formatierten Zahlenstring zurück 
    ; 
    ; Format$ = Erste 2 Zeichen= ">$" = Wert wird Hexadezimal konvertiert 
    ;           Erste 2 Zeichen= ">%" = Wert wird Binär       konvertiert 
    ;            
    ;           0  Ziffer/Vorzeichen oder zwingend 0 
    ;           #  Ziffer/Vorzeichen oder Blank 
    ; 
    ;           andere Zeichen werden 1:1 ausgegeben 
    ; 
    ; Result$ = formatierter Zahlenstring 
    
    Protected Result$,a,Wert$ 
    
    Result$="" 
    
    If Len(Format$)=0: Goto StringUsingEnd: EndIf 
    
    ; Wert in Hex/Binär/Dezimal-String umwandeln 
    Select Left(Format$,2) 
        Case ">$": Wert$=Hex(Wert): Format$=Right(Format$,Len(Format$)-2) 
        Case ">%": Wert$=Bin(Wert): Format$=Right(Format$,Len(Format$)-2) 
            
        Default:   Wert$=Str(Wert) 
    EndSelect 
    
    ; Result$ von hinten auffüllen 
    For a=Len(Format$) To 1 Step -1 
        Select Mid(Format$,a,1) 
            Case "0" 
                If Len(Wert$) 
                    Result$=Right(Wert$,1)+Result$ 
                    Wert$=Left(Wert$,Len(Wert$)-1) 
                Else 
                    Result$="0"+Result$ 
                EndIf 
                
            Case "#" 
                If Len(Wert$) 
                    Result$=Right(Wert$,1)+Result$ 
                    Wert$=Left(Wert$,Len(Wert$)-1) 
                Else 
                    Result$=" "+Result$ 
                EndIf 
                
            Default 
                Result$=Mid(Format$,a,1)+Result$ 
                
        EndSelect 
        
    Next a 
    
    StringUsingEnd: 
    ProcedureReturn Result$ 
    
EndProcedure 


; Beispiele 
a$=">% %########  ########": Zahl= 123456789:      Debug StringUsing(a$,Zahl) 
a$=">%%0000 0000 0000 0000": Zahl= 123456789:      Debug StringUsing(a$,Zahl) 
Debug "" 
a$=">$ 00 00 00 00":         Zahl= 123456789:      Debug StringUsing(a$,Zahl) 
a$=">$ 0000 0000":           Zahl= 123456789:      Debug StringUsing(a$,Zahl) 
Debug "" 
a$="###0.000 kByte":         Zahl= 123456789/1024: Debug StringUsing(a$,Zahl) 

; ExecutableFormat=Windows
; FirstLine=1
; EOF

ou bien celui ci de Jacobus , Si je me souviens bien

Code : Tout sélectionner

Procedure.s FormatNumber(format.s,Number.f, Unit.s)
        Ret.s = ""
        EntF.l = FindString(format,".",1)-1
        DecF.l = Len(format)-EntF-1
        EntN.l = Len(Str(Number))
        CarF.s = Left(format,1)
        
        If CarF = "#"
                CarF = " "
        EndIf
        
        If EntF => EntN
                Ret = Space(EntF-EntN)+StrF(Number,DecF)
                Ret = ReplaceString(Ret," ",CarF)
        Else
                Ret = Space(EntF)+"."+Space(DecF)
                Ret = ReplaceString(Ret," ","x")
        EndIf
        
        Ret + Unit
        
        ProcedureReturn Ret
        
EndProcedure

; Exemples
exemple.s = FormatNumber("0######.##",2355.236," cm")+Chr(13)
exemple + FormatNumber("0###.##",231155.236," dl")+Chr(13)
exemple + FormatNumber(" #######.###",-255.18," m²")+Chr(13)
exemple + FormatNumber("######.##",857.596," Km")+Chr(13)
exemple + FormatNumber("_######.##",2355.236,"")

MessageRequester("Exemples de formats possibles", exemple)

Publié : mer. 15/nov./2006 15:36
par sined
Merci à Gnozal et à toi aussi Dobro, je devrais pouvoir me débrouiller à faire quelque chose de tout ca, au moins pour la version windows, je vais essayer d'avoir des infos sur l'API GTK pour adapter la solution à Linux.


Merci encore à vous 2


SID