[Gambas-user] Adding keyboard shortcuts to listbox_keyrelease event

Doriano Blengino doriano.blengino at ...1909...
Thu Oct 9 21:21:48 CEST 2008


M0E Lnx ha scritto:
> Modified it and this time it does work
>
> PUBLIC SUB lbTmZone_KeyPress()
>
>   DIM i AS Integer
>
>
>   IF Key.text > "z" OR Key.text < " " THEN RETURN  ' not searchable
>
>     i = lbTmZone.Index
>       DO
>         INC i
>           IF i >= lbTmZone.Count THEN i = 0 'back to top
>           IF i = lbTmZone.Index THEN RETURN  ' no other match found
>           IF lbTmZone[i].text LIKE Key.Text & "*" THEN
>           lbTmZone.Index = i
>           RETURN
>           END IF
>         LOOP
>   
There are two differences from the previous code; one is the "END IF" I 
forgot to write; the other is the use of lbTmZone instead of "LAST". If 
using LAST does not work, then it is a bug in gambas. I think that LAST 
should be always used, when possible.

Anyway, happy that you succeded - cheers,
Doriano

> Thanks
>
>
> On Thu, Oct 9, 2008 at 7:57 AM, M0E Lnx <m0e.lnx at ...626...> wrote:
>   
>> I can see in my head how this *should* work... but I tried it in my
>> project and it doesn't
>>
>>
>> On Thu, Oct 9, 2008 at 1:17 AM, Doriano Blengino
>> <doriano.blengino at ...1909...> wrote:
>>     
>>> M0E Lnx ha scritto:
>>>       
>>>> is there a way to code it in my key_release event?
>>>>
>>>> On Tue, Oct 7, 2008 at 4:53 PM, Benoit Minisini
>>>> <gambas at ...1...> wrote:
>>>>
>>>>         
>>>>> On mardi 07 octobre 2008, M0E Lnx wrote:
>>>>>
>>>>>           
>>>>>> I have a really long list in a lisbox. I'd like to make it so when I
>>>>>> press "s" on the keyboard, it jumps to the first item whose text
>>>>>> starts with an "s" or any other letter for that matter.
>>>>>>
>>>>>> Can someone suggest a way to do this?
>>>>>>
>>>>>>
>>>>>>             
>>>>> Yes, Qt does that by default, but not GTK+. Again, I need to implement that
>>>>> feature in the gb.gtk component.
>>>>>
>>>>>
>>>>>           
>>> I don't know if the KeyRelease event is the right one to use (it seems
>>> strange to me: why wait for a key release to do something? Normally
>>> things happen as soon as a key is pressed...), but surely KeyPress can work.
>>>
>>> In the KeyPress event of the listbox, start to search for the next item
>>> beginning with the letter, with wrap; then move the index.
>>> In pseudocode:
>>>
>>>    sub xxx_keypress()
>>>      dim scan as integer
>>>
>>>      if key.text > "z" or key.text < " " then return      ' this key is
>>> not "searchable"
>>>
>>>      scan = last.index
>>>      do
>>>        inc scan
>>>        if scan >= last.count then scan=0  ' wrap to the top again
>>>        if scan=last.index then return     ' went where we started off:
>>> didn't find another item
>>>        if last[scan].text like key.text & "*" then
>>>          ' found another
>>>          last.index = scan
>>>          return
>>>      loop
>>>    end sub
>>>
>>> I did not test this snippet but the general idea should work. May be
>>> some adjustment is needed...
>>> May be this is slow...
>>>
>>> Regards,
>>> Doriano
>>>
>>>
>>> -------------------------------------------------------------------------
>>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
>>> Build the coolest Linux based applications with Moblin SDK & win great prizes
>>> Grand prize is a trip for two to an Open Source event anywhere in the world
>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>>> _______________________________________________
>>> Gambas-user mailing list
>>> Gambas-user at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>>       
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>   





More information about the User mailing list