Jump to content

GUI is -VERY- slow


Zest
 Share

Recommended Posts

Hello,

I'm working on a script to start different servers for Pro/Engineer with different configs (to use at work).

I have made a GUI with as many tabs as servers (max. 5) and 10 radio buttons per tab for configs.

All settings are defined in an .ini file.

Somehow the updating of the GUI is extremely slow, especially when switching between tabs. E.g. it can take 20 seconds or longer for the GUI to update the labels for the radio buttons. I have no clue what causes this, but I think it must be somewhere in the "CREATE GUI" section.

Any help is appreciated!

Here is the (stripped) code:

#include <GUIConstants.au3>
#Include <GuiTab.au3>

;READ VALUES FROM .INI
; Declare Array 1 larger than number of configs for convenience
; $NumOfServers = real number of servers + 1 !!!
Dim $NumOfServers = 6
Dim $server_file[$NumOfServers]
Dim $server_label[$NumOfServers]
Dim $server_pathvar[$NumOfServers]
Dim $tab[$NumOfServers]
; $NumOfCfgs = real number of configs + 1 !!!
Dim $NumOfCfgs = 11
Dim $config_path[$NumOfServers][$NumOfCfgs]
Dim $config_label[$NumOfServers][$NumOfCfgs]
Dim $config_pathvar[$NumOfServers][$NumOfCfgs]
Dim $Radio[$NumOfServers][$NumOfCfgs]
Dim $State_Radio[$NumOfServers][$NumOfCfgs]

; check if server settings start with system variable and set script variable accordingly
For $server_count = 1 to $NumOfServers-1 step 1
    $server_file[$server_count] = IniRead("config_select.ini", "locations", "server_" & $server_count & "_file", "NotFound")
;MsgBox(0,$server_count,$server_file[$server_count])
    If StringLeft( $server_file[$server_count], 1) = "%" Then
        Dim $len = ""
        $len = StringLen( $server_file[$server_count])
        For $i = 2 to $len-2 step 1
            $string_cut = StringLeft( $server_file[$server_count], $i)
            If StringRight($string_cut,1) = "%" Then
            ExitLoop
            EndIf
        Next
        $server_pathvar[$server_count] = StringLeft( $server_file[$server_count], $i-1)
        $server_pathvar[$server_count] = StringRight($server_pathvar[$server_count], $i-2)
        $server_pathvar[$server_count] = EnvGet($server_pathvar[$server_count])
        If $server_pathvar[$server_count] = "" Then
            MsgBox(4112, "Variable Error", "The .ini setting for 'server_" & $server_count & "_file' contains a nonexistent variable")
            Exit
        EndIf
        $server_file[$server_count] = StringRight( $server_file[$server_count], $len-$i-1)
    Else
        $server_pathvar[$server_count] = ""
    EndIf
;Msgbox(0,"VARS", $server_pathvar[$server_count] & $server_file[$server_count])
Next

; check if config settings start with system variable and set script variable accordingly
For $server_count = 1 to $NumOfServers-1 step 1
    For $cfg_count = 1 to $NumOfCfgs-1 step 1
        $config_path[$server_count][$cfg_count] = IniRead("config_select.ini", "locations", "config" & $server_count & "_" & $cfg_count & "_path", "NotFound")
;MsgBox(0,$server_count & "." & $cfg_count ,$config_path[$server_count][$cfg_count])
        If StringLeft( $config_path[$server_count][$cfg_count], 1) = "%" Then
            Dim $len = ""
            $len = StringLen( $config_path[$server_count][$cfg_count])
            For $i = 2 to $len-2 step 1
                $string_cut = StringLeft( $config_path[$server_count][$cfg_count], $i)
                If StringRight($string_cut,1) = "%" Then
                ExitLoop
                EndIf
            Next
            $config_pathvar[$server_count][$cfg_count] = StringLeft( $config_path[$server_count][$cfg_count], $i-1)
            $config_pathvar[$server_count][$cfg_count] = StringRight($config_pathvar[$server_count][$cfg_count], $i-2)
            $config_pathvar[$server_count][$cfg_count] = EnvGet($config_pathvar[$server_count][$cfg_count])
            If $config_pathvar[$server_count][$cfg_count] = "" Then
                MsgBox(4112, "Variable Error", "The .ini setting for 'config" & $server_count & "_" & $cfg_count & "_file' contains a nonexistent variable")
                Exit
            EndIf
            $config_path[$server_count][$cfg_count] = StringRight( $config_path[$server_count][$cfg_count], $len-$i)
;Msgbox(0,"VARS" & $cfg_count, $config_pathvar[$cfg_count] & @CRLF & $config_path[$cfg_count])
        Else
            $config_pathvar[$server_count][$cfg_count] = ""
        EndIf
;Msgbox(0,"VARS" & $cfg_count, $config_pathvar[$cfg_count] & $config_path[$cfg_count])
    Next
Next

;read the server labels from the .ini file
For $server_count = 1 to $NumOfServers-1 step 1
    $server_label[$server_count] = IniRead("config_select.ini", "locations", "server_" & $server_count & "_label", "NotFound")
;Msgbox(0,"LABELS", $server_label[$server_count])
Next

;read the config labels from the .ini file
For $server_count = 1 to $NumOfServers-1 step 1
    For $cfg_count = 1 to $NumOfCfgs-1 step 1
    $config_label[$server_count][$cfg_count] = IniRead("config_select.ini", "locations", "config" & $server_count & "_" & $cfg_count & "_label", "NotFound")
;MsgBox(0,$server_count & "." & $cfg_count, $config_label[$server_count][$cfg_count])
    Next
Next

;set GUI font
$editfont="Courier New"

;CREATE GUI
GUICreate("Config Select for Intralink v0.1",1000,560,-1, -1)
$tab_base=GUICtrlCreateTab (10,10, 980,540)
For $server_count = 1 to $NumOfServers-1 step 1 
    If $server_label[$server_count] <> "Notfound" Then
        $tab[$server_count]=GUICtrlCreateTabitem($server_label[$server_count])
        For $cfg_count = 1 to $NumOfCfgs-1 step 1
            $Radio[$server_count][$cfg_count] = GUICtrlCreateRadio ($config_label[$server_count][$cfg_count], 20, 44 * $cfg_count, 230, 20)
            If  $config_path[$server_count][$cfg_count] = "NotFound" Or $config_label[$server_count][$cfg_count] = "" Then
            GUICtrlSetState ($Radio[$server_count][$cfg_count],$GUI_DISABLE)
            EndIf
        Next
    EndIf
Next

GUICtrlCreateTabitem ("")
GUISetState ()
GUISetFont (9, 400, 0)
$OK = GUICtrlCreateButton ("OK", 20, 490, 50)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancel = GUICtrlCreateButton ("Cancel", 90, 490, 50)

GUICtrlSetState ($Radio[1][1],$GUI_CHECKED)
GUISetFont (9, 400, 0, $editfont)
$myedit=GUICtrlCreateEdit ("", 260,50,710,480,$ES_AUTOVSCROLL+$WS_VSCROLL+$WS_HSCROLL+$ES_WANTRETURN+$ES_READONLY)
GUISetFont (9, 400, 0)
GUISetState (@SW_SHOW)

; RUN THE Config GUI UNTIL THE DIALOG IS CLOSED
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $cancel
            Exit
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
Wend

And this is the file called config_select.ini (also stripped and edited)

; .ini file to define Intralink servers and configs (29.11.2006)
; The max. number of servers is 5, numbered server_<servernumber>_file and server_<servernumber>_path
; The max. number of configs per server is 10,
; numbered config<servernumber>_<confignumber>_path and config<servernumber>_<confignumber>_path
;
; The use of system variables is only allowed at the beginning of a key.
;
[locations]
server_1_file=C:\WINDOWS\system32\notepad.exe 
server_1_label=Notepad
server_2_file=C:\WINDOWS\system32\mspaint.exe
server_2_label=MsPaint
server_3_file=
server_3_label=
server_4_file=
server_4_label=
server_5_file=
server_5_label=
config1_1_path=c:\
config1_1_label=(default)
config1_2_path=c:\
config1_2_label=1.2
config1_3_path=c:\
config1_3_label=1.3
config1_4_path=c:\ 
config1_4_label=1.4
config2_1_path=2.1
config2_1_label=2.1
config2_10_path=2.10
config2_10_label=2.10
config3_1_path=3.1
config3_1_label=3.1
config3_10_path=3.10
config3_10_label=3.10
Edited by Zest
Link to comment
Share on other sites

Hi there

Haven't spent a large amount of time to analyse exactly what your program does, but

with my cursory glance I suspect your speed problem may be the amount of loops within loops you have.

You have FOUR for/next loops, that i could see, within each other in your code

these can be a speed killer.

Try and figure an alternate way to load/interprete your config settings.

Your code in those parts may also have a non fatal bug, which may make the processing take longer than expected.

Sorry i cant be more helpful

Good Luck

HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...