Sign in to follow this  
Followers 0
Dieuz

Need help to make this run WAY faster

7 posts in this topic

#1 ·  Posted (edited)

I made a little code that let the user decide wich images he want. The problem in my script is that the image selection is WAY too slow. When the user click on the little arrow, it take alot of time before changing to the next image. I want to make my script run way faster/smoother. If the script I made is crappy than I will need to use another method to select my images.

Have a look at the Attached File to see what really happen.

#include <GuiConstants.au3>

GuiCreate("Choices", 188, 200,-1, -1, BitOR($WS_SYSMENU, $WS_CAPTION))

$Text_c = GuiCtrlCreateLabel("Choices", 70, 42, 150, 20)
$ChoicePic1 = GuiCtrlCreatePic(@ScriptDir & "\Images.bmp", 33, 67, 35, 35)
$ChoicePic2 = GuiCtrlCreatePic(@ScriptDir & "\Images.bmp", 78, 67, 35, 35)
$ChoicePic3 = GuiCtrlCreatePic(@ScriptDir & "\Images.bmp", 123, 67, 35, 35)


$Arrow_right1 = GuiCtrlCreateButton("", 51, 105, 15, 14, $BS_BITMAP)
$Arrow_left1 = GuiCtrlCreateButton("", 35, 105, 15, 14, $BS_BITMAP)
GUICtrlSetImage($Arrow_right1, @ScriptDir & "\Images\arrow_droite.bmp")
GUICtrlSetImage($Arrow_left1, @ScriptDir & "\Images\arrow_gauche.bmp")

$Arrow_right2 = GuiCtrlCreateButton("", 96, 105, 15, 14, $BS_BITMAP)
$Arrow_left2 = GuiCtrlCreateButton("", 80, 105, 15, 14, $BS_BITMAP)
GUICtrlSetImage($Arrow_right2, @ScriptDir & "\Images\arrow_droite.bmp")
GUICtrlSetImage($Arrow_left2, @ScriptDir & "\Images\arrow_gauche.bmp")

$Arrow_right3 = GuiCtrlCreateButton("", 141, 105, 15, 14, $BS_BITMAP)
$Arrow_left3 = GuiCtrlCreateButton("", 125, 105, 15, 14, $BS_BITMAP)
GUICtrlSetImage($Arrow_right3, @ScriptDir & "\Images\arrow_droite.bmp")
GUICtrlSetImage($Arrow_left3, @ScriptDir & "\Images\arrow_gauche.bmp")

$click1 = 0
$click2 = 0
$click3 = 0

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
                Case $msg = $Arrow_right1
                If $click1 = 0 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\1.bmp" )
                    $click1 = 1
                ElseIf $click1 = 1 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\2.bmp")
                    $click1 = 2
                ElseIf $click1 = 2 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\3.bmp")
                    $click1 = 3
                ElseIf $click1 = 3 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\4.bmp")
                    $click1 = 4
                ElseIf $click1 = 4 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\5.bmp")
                    $click1 = 5
                ElseIf $click1 = 5 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\6.bmp")
                    $click1 = 6
                ElseIf $click1 = 6 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\7.bmp")
                    $click1 = 7
                ElseIf $click1 = 7 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\8.bmp")
                    $click1 = 8
                ElseIf $click1 = 8 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\9.bmp")
                    $click1 = 9
                ElseIf $click1 = 9 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images.bmp")
                    $click1 = 0
                EndIf
                
            Case $msg = $Arrow_left1
                If $click1 = 0 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\9.bmp")
                    $click1 = 9
                ElseIf $click1 = 1 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images.bmp")
                    $click1 = 0
                ElseIf $click1 = 2 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\1.bmp")
                    $click1 = 1
                ElseIf $click1 = 3 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\2.bmp")
                    $click1 = 2
                ElseIf $click1 = 4 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\3.bmp")
                    $click1 = 3
                ElseIf $click1 = 5 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\4.bmp")
                    $click1 = 4
                ElseIf $click1 = 6 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\5.bmp")
                    $click1 = 5
                ElseIf $click1 = 7 then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\6.bmp")
                    $click1 = 6
                ElseIf $click1 = 8 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\7.bmp")
                    $click1 = 7
                ElseIf $click1 = 9 Then
                    Guictrlsetimage($ChoicePic1 ,@ScriptDir & "\Images\8.bmp")
                    $click1 = 8
                EndIf
                
                ;Buttons 2
            Case $msg = $Arrow_right2
                If $click2 = 0 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\1.bmp" )
                    $click2 = 1
                ElseIf $click2 = 1 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\2.bmp")
                    $click2 = 2
                ElseIf $click2 = 2 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\3.bmp")
                    $click2 = 3
                ElseIf $click2 = 3 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\4.bmp")
                    $click2 = 4
                ElseIf $click2 = 4 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\5.bmp")
                    $click2 = 5
                ElseIf $click2 = 5 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\6.bmp")
                    $click2 = 6
                ElseIf $click2 = 6 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\7.bmp")
                    $click2 = 7
                ElseIf $click2 = 7 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\8.bmp")
                    $click2 = 8
                ElseIf $click2 = 8 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\9.bmp")
                    $click2 = 9
                ElseIf $click2 = 9 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images.bmp")
                    $click2 = 0
                EndIf
                
            Case $msg = $Arrow_left2
                If $click2 = 0 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\9.bmp")
                    $click2 = 9
                ElseIf $click2 = 1 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images.bmp")
                    $click2 = 0
                ElseIf $click2 = 2 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\1.bmp")
                    $click2 = 1
                ElseIf $click2 = 3 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\2.bmp")
                    $click2 = 2
                ElseIf $click2 = 4 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\3.bmp")
                    $click2 = 3
                ElseIf $click2 = 5 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\4.bmp")
                    $click2 = 4
                ElseIf $click2 = 6 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\5.bmp")
                    $click2 = 5
                ElseIf $click2 = 7 then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\6.bmp")
                    $click2 = 6
                ElseIf $click2 = 8 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\7.bmp")
                    $click2 = 7
                ElseIf $click2 = 9 Then
                    Guictrlsetimage($ChoicePic2 ,@ScriptDir & "\Images\8.bmp")
                    $click2 = 8
                EndIf
                
                ;Buttons 3
            Case $msg = $Arrow_right3
                If $click3 = 0 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\1.bmp" )
                    $click3 = 1
                ElseIf $click3 = 1 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\2.bmp")
                    $click3 = 2
                ElseIf $click3 = 2 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\3.bmp")
                    $click3 = 3
                ElseIf $click3 = 3 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\4.bmp")
                    $click3 = 4
                ElseIf $click3 = 4 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\5.bmp")
                    $click3 = 5
                ElseIf $click3 = 5 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\6.bmp")
                    $click3 = 6
                ElseIf $click3 = 6 then
                    ;explosif
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\7.bmp")
                    $click3 = 7
                ElseIf $click3 = 7 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\8.bmp")
                    $click3 = 8
                ElseIf $click3 = 8 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\9.bmp")
                    $click3 = 9
                ElseIf $click3 = 9 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images.bmp")
                    $click3 = 0
                EndIf
                
            Case $msg = $Arrow_left3
                If $click3 = 0 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\9.bmp")
                    $click3 = 9
                ElseIf $click3 = 1 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images.bmp")
                    $click3 = 0
                ElseIf $click3 = 2 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\1.bmp")
                    $click3 = 1
                ElseIf $click3 = 3 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\2.bmp")
                    $click3 = 2
                ElseIf $click3 = 4 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\3.bmp")
                    $click3 = 3
                ElseIf $click3 = 5 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\4.bmp")
                    $click3 = 4
                ElseIf $click3 = 6 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\5.bmp")
                    $click3 = 5
                ElseIf $click3 = 7 then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\6.bmp")
                    $click3 = 6
                ElseIf $click3 = 8 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\7.bmp")
                    $click3 = 7
                ElseIf $click3 = 9 Then
                    Guictrlsetimage($ChoicePic3 ,@ScriptDir & "\Images\8.bmp")
                    $click3 = 8
                EndIf

    EndSelect
WEnd
Exit

Thanks ! :shocked:

Images_selection.rar

Edited by Dieuz

Share this post


Link to post
Share on other sites



Goes pretty smooth here.

Share this post


Link to post
Share on other sites

If you click fast on the buttons, it take alot of time to load the picture ( I mean, this part is the main part of my script so the user will have to choose pictures alot). I agree with you that if you do it like 3-4 time in a row, it seem smooth, but try to make 100+ clicks, the pictures will seem to load way slower.

Share this post


Link to post
Share on other sites

Not related to your problem, but here's a little tip for you..what about cutting down on your unnecessary long code ?

;...
Case $msg = $Arrow_right1
    $click1 += 1 ; increase 1st
    If $click1 = 10 Then $click1 = 0
    GUICtrlSetImage($ChoicePic1, @ScriptDir & "\Images\" & $click1 & ".bmp")
            
Case $msg = $Arrow_left1
    $click1 -= 1 ; decrease 1st
    If $click1 = -1 Then $click1 = 9
    GUICtrlSetImage($ChoicePic1, @ScriptDir & "\Images\" & $click1 & ".bmp")
;...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

@xcal: I will have a look at it !

Helge, thanks you ! The problem is that in my real script there's images that the name is a noun not a number (ex: Ipod.bmp or Smilies.bmp). I like the way you setup the $click variable but how can it work with GuiCtrlImage when it's nouns not numbers.

I will have to use an array right? to associate a $click with a bmp.

Edited by Dieuz

Share this post


Link to post
Share on other sites

Just get a list of files that match a *.bmp wildcard.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0