Jump to content

Change Language & abort loop if new GUI msg


gMgmc
 Share

Recommended Posts

Hi Guys!

I've got two questions:

1. I developed a script in German and i'm trying to translate it, I thought this should be possible with an "INI" file. Could someone explain how to do that?

2. A piece of my script looks like this:

Func _Main ()


    GUISetState()

    While 1
        $msg = GUIGetMsg()

        Select
        Case $msg = $GUI_EVENT_CLOSE
                _End ()

            Case $msg = $exititem
                _End ()

            Case $msg = $aboutitem
                MsgBox(64, "About", " .............")

            Case $msg = $pauseitem
                _Pause ()

            Case $msg = $Button1
                _Eingabe ()

            Case $msg = $exititem
                ExitLoop

            Case $msg = $startitem
                _Start ()

            Case $msg = $langitem
                _Lang ()

        EndSelect
    WEnd

EndFunc

Func _Pause ()
        Sleep(100)
        _Main ()
EndFunc

Func _Start ()
    While $schleife=1
        If _IsPressed(73) Then
            _Pause ()
        Else
            Send($var)
        EndIf
    WEnd
EndFunc

Now the problem is:

While Func _Start () is running, my GUI doesn't react anymore if for example I click on "About". How do I resolve this problem?

Hope my English isn't that bad :S xD

Edited by gMgmc
Link to comment
Share on other sites

Is there a loop in _Start()?

Just noticed I could scroll down through the code :|

That's your problem, _Start() isn't ending so _Main() isn't continuing.

SO, take out the first and last line of _Start() (While and WEnd), and make some code that will enable a variable when the button is clicked, and in your loop, if the variable=True, then it will call _Start()

Hope that makes sense, I can't really give example code right now.

Edited by Minikori

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

Is there a loop in _Start()?

yes

I know _Start() isn't ending but I want _Main() to continue is that actually possible?

So _Start() should run but if I click a button on the GUI it should react anyway....

SO, take out the first and last line of _Start() (While and WEnd), and make some code that will enable a variable when the button is clicked, and in your loop, if the variable=True, then it will call _Start()

Hope that makes sense, I can't really give example code right now.

Hmmm... it sounds pretty confusing an example code would be very useful :D I'm not in hurry I can wait... :huggles:

Edited by gMgmc
Link to comment
Share on other sites

  • Moderators

gMgmc,

Welcome to the AutoIt forum. :D

Answer to your first question - do something like this:

#include <GUIConstantsEx.au3>

$sLanguage = IniRead("language.ini", "Current", "Language", "English")

$sOne = IniRead("language.ini", $sLanguage, "One", "One")
$sTwo = IniRead("language.ini", $sLanguage, "Two", "Two")
$sThree = IniRead("language.ini", $sLanguage, "Three", "Three")

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel($sOne, 10, 10, 100, 20)
$hLabel_2 = GUICtrlCreateLabel($sTwo, 10, 50, 100, 20)
$hLabel_3 = GUICtrlCreateLabel($sThree, 10, 90, 100, 20)

$hCombo = GUICtrlCreateCombo("", 10, 150, 200, 20)
GUICtrlSetData(-1, "English|Deutch|Francais", "English")

$hButton = GUICtrlCreateButton("Set", 10, 180, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sLanguage = GUICtrlRead($hCombo)
            IniWrite("language.ini", "Current", "Language", $sLanguage)
            $sOne = IniRead("language.ini", $sLanguage, "One", "One")
            GUICtrlSetData($hLabel_1, $sOne)
            $sTwo = IniRead("language.ini", $sLanguage, "Two", "Two")
            GUICtrlSetData($hLabel_2, $sTwo)
            $sThree = IniRead("language.ini", $sLanguage, "Three", "Three")
            GUICtrlSetData($hLabel_3, $sThree)
    EndSwitch

WEnd

and use something like this as the ini file:

[Current]
Language=English
[English]
One=One
Two=Two
Three=Three
[Deutch]
One=Ein
Two=Zwei
Three=Drei
[Francais]
One=Un
Two=Deux
Three=Trois

As to the second question - _About runs a MessageBox and everything else in the script will pause until you close it. So the short answer to you question is: "You cannot!"

By the way, your code is pretty messed up. You are restarting the _Main function via _Start and _Pause before you end either. This is known as recursion and will lead into BIG trouble. You need to get back to _Main using Return or having the functions end naturally, not calling it again.

Perhaps if yyou posted your whole code we coudl look and see how we might get over this. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

gMgmc,

Welcome to the AutoIt forum. :D

Answer to your first question - do something like this:

#include <GUIConstantsEx.au3>

$sLanguage = IniRead("language.ini", "Current", "Language", "English")

$sOne = IniRead("language.ini", $sLanguage, "One", "One")
$sTwo = IniRead("language.ini", $sLanguage, "Two", "Two")
$sThree = IniRead("language.ini", $sLanguage, "Three", "Three")

$hGUI = GUICreate("Test", 500, 500)

$hLabel_1 = GUICtrlCreateLabel($sOne, 10, 10, 100, 20)
$hLabel_2 = GUICtrlCreateLabel($sTwo, 10, 50, 100, 20)
$hLabel_3 = GUICtrlCreateLabel($sThree, 10, 90, 100, 20)

$hCombo = GUICtrlCreateCombo("", 10, 150, 200, 20)
GUICtrlSetData(-1, "English|Deutch|Francais", "English")

$hButton = GUICtrlCreateButton("Set", 10, 180, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $sLanguage = GUICtrlRead($hCombo)
            IniWrite("language.ini", "Current", "Language", $sLanguage)
            $sOne = IniRead("language.ini", $sLanguage, "One", "One")
            GUICtrlSetData($hLabel_1, $sOne)
            $sTwo = IniRead("language.ini", $sLanguage, "Two", "Two")
            GUICtrlSetData($hLabel_2, $sTwo)
            $sThree = IniRead("language.ini", $sLanguage, "Three", "Three")
            GUICtrlSetData($hLabel_3, $sThree)
    EndSwitch

WEnd

and use something like this as the ini file:

[Current]
Language=English
[English]
One=One
Two=Two
Three=Three
[Deutch]
One=Ein
Two=Zwei
Three=Drei
[Francais]
One=Un
Two=Deux
Three=Trois

As to the second question - _About runs a MessageBox and everything else in the script will pause until you close it. So the short answer to you question is: "You cannot!"

By the way, your code is pretty messed up. You are restarting the _Main function via _Start and _Pause before you end either. This is known as recursion and will lead into BIG trouble. You need to get back to _Main using Return or having the functions end naturally, not calling it again.

Perhaps if yyou posted your whole code we coudl look and see how we might get over this. :huggles:

M23

Hi!

Thank you for the informations!

I'll post the whole code:

#RequireAdmin
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <Misc.au3>
Local $filemenu, $fileitem, $recentfilesmenu, $separator1, $startitem, $pauseitem
Local $exititem, $langitem, $helpmenu, $aboutitem, $update, $optmenu
Local $msg, $file
$Font = "Comic Sans MS"
$Form1 = GUICreate("Press Bot Beta    ...by gta99", 284, 136, 712, 335)
$Button1 = GUICtrlCreateButton("Eingabe ändern", 8, 8, 145, 33, $WS_GROUP)
$filemenu = GUICtrlCreateMenu("Datei")
$startitem = GUICtrlCreateMenuItem("Skript starten         (F2)", $filemenu)
$pauseitem = GUICtrlCreateMenuItem("Skript pausieren    (F4)", $filemenu)
$exititem = GUICtrlCreateMenuItem("Beenden", $filemenu)
$helpmenu = GUICtrlCreateMenu("Hilfe")
$aboutitem = GUICtrlCreateMenuItem("Über", $helpmenu)
$optmenu = GUICtrlCreateMenu("Optionen")
$langitem = GUICtrlCreateMenuItem("Sprache ändern", $optmenu)
GUISetFont(12, 400, 0, $Font)
$Label1 = GUICtrlCreateLabel("F2 = Start"&@CRLF&"F4 = Pause", 8, 48, 148, 57)
GUISetBkColor(0x00CC33)
GUISetState(@SW_SHOW)
$schleife = "1"
$var = "{SPACE}"
IniWrite("lang.ini", "English", "ChangeValue", "Change value")
IniWrite("lang.ini", "English", "File", "File")
IniWrite("lang.ini", "German", "ChangeValue", "Eingabe ändern")
IniWrite("lang.ini", "German", "File", "Datei")

HotKeySet("{F2}", "_Start")
HotKeySet("{F4}", "_Pause")
HotKeySet("{ESC}", "_End")


Opt('MustDeclareVars', 1)

_Main ()

Func _Main ()


    GUISetState()

    While 1
        $msg = GUIGetMsg()

        Select
        Case $msg = $GUI_EVENT_CLOSE
                _End ()

            Case $msg = $exititem
                _End ()

            Case $msg = $aboutitem
                MsgBox(64, "Über", " Dieser Bot wurde von ->EMAIL<- entwickelt.")

            Case $msg = $pauseitem
                _Pause ()

            Case $msg = $Button1
                _Eingabe ()

            Case $msg = $exititem
                ExitLoop

            Case $msg = $startitem
                _Start ()

            Case $msg = $langitem
                _Lang ()

        EndSelect
    WEnd

EndFunc

Func _Pause ()
        Sleep(100)
        _Main ()
EndFunc

Func _Start ()
        If _IsPressed(73) Then
            _Pause ()
        Else
            Send($var)
        EndIf
EndFunc

Func _Lang ()

EndFunc

Func _Eingabe ()
    $var = InputBox("Frage", "Was soll gedrückt werden?", """Beispiel: {SPACE} oder N""")
EndFunc

Func _End ()
    Exit
EndFunc

As you can see I already tried to do something with the languages... :D

If you want to, I will translate the code I wrote in German but I think it's possible to understand the code like this :

Edited by gMgmc
Link to comment
Share on other sites

  • Moderators

gMgmc,

A bit tidied up and with a few helpful (I hope :D ) comments:

;#RequireAdmin
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <Misc.au3>

;Opt('MustDeclareVars', 1) ; If you want to declare all variables then put this at the top and declare them all!!!

; These are Global variables by default - why have you set them to Local?
Local $filemenu, $fileitem, $recentfilesmenu, $separator1, $startitem, $pauseitem
Local $exititem, $langitem, $helpmenu, $aboutitem, $update, $optmenu
Local $msg, $file

; And these are not declaered at all!!
$Font = "Comic Sans MS"

$Form1 = GUICreate("Press Bot Beta    ...by gta99", 284, 136, 712, 335)
$Button1 = GUICtrlCreateButton("Eingabe ändern", 8, 8, 145, 33, $WS_GROUP)
$filemenu = GUICtrlCreateMenu("Datei")
$startitem = GUICtrlCreateMenuItem("Skript starten" & @TAB & "(F2)", $filemenu)
$pauseitem = GUICtrlCreateMenuItem("Skript pausieren" & @TAB & "(F4)", $filemenu)
$exititem = GUICtrlCreateMenuItem("Beenden", $filemenu)
$helpmenu = GUICtrlCreateMenu("Hilfe")
$aboutitem = GUICtrlCreateMenuItem("Über", $helpmenu)
$optmenu = GUICtrlCreateMenu("Optionen")
$langitem = GUICtrlCreateMenuItem("Sprache ändern", $optmenu)
GUISetFont(12, 400, 0, $Font)
$Label1 = GUICtrlCreateLabel("F2 = Start" & @CRLF & "F4 = Pause", 8, 48, 148, 57)
GUISetBkColor(0x00CC33)
GUISetState(@SW_SHOW)

$schleife = "1"
$var = "{SPACE}"

HotKeySet("{F2}", "_Start")
HotKeySet("{F4}", "_Pause")
HotKeySet("{ESC}", "_End")

$fPaused = False

_Main()

Func _Main()
    
    ;GUISetState()  ; What is this doing here????

    While 1
        Switch GUIGetMsg() ; If you use Switch....

            Case $GUI_EVENT_CLOSE, $exititem ; then you can do this - multiple arguments!!!!
                _End()

            Case $aboutitem
                MsgBox(64, "Über", " Dieser Bot wurde von ->EMAIL<- entwickelt.")

            Case $pauseitem
                _Pause()

            Case $Button1
                _Eingabe()

            Case $startitem
                _Start()

            Case $langitem
                _Lang()

        EndSwitch
    WEnd

EndFunc   ;==>_Main

Func _Pause()

    ; Toggle "paused" state
    $fPaused = Not $fPaused
    ; Adjust menu item text
    If $fPaused Then
        GUICtrlSetData($pauseitem, "Skript restarten" & @TAB & "(F4)") ; Apologies if this is not good German!!!!!!
    Else
        GUICtrlSetData($pauseitem, "Skript pausieren" & @TAB & "(F4)")
    EndIf
    ; Idle loop if paused
    While $fPaused
        ; Check if [X] clicked
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    WEnd

EndFunc   ;==>_Pause

Func _Start()
    Send($var)
EndFunc   ;==>_Start

Func _Lang()

EndFunc   ;==>_Lang

Func _Eingabe()
    $var = InputBox("Frage", "Was soll gedrückt werden?", """Beispiel: {SPACE} oder N""")
EndFunc   ;==>_Eingabe

Func _End()
    Exit
EndFunc   ;==>_End

However, as I now see your script is a bot, that is as far as I go. Have fun with the rest of it. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

gMgmc,

A bit tidied up and with a few helpful (I hope :D ) comments:

;#RequireAdmin
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <Misc.au3>

;Opt('MustDeclareVars', 1) ; If you want to declare all variables then put this at the top and declare them all!!!

; These are Global variables by default - why have you set them to Local?
Local $filemenu, $fileitem, $recentfilesmenu, $separator1, $startitem, $pauseitem
Local $exititem, $langitem, $helpmenu, $aboutitem, $update, $optmenu
Local $msg, $file

; And these are not declaered at all!!
$Font = "Comic Sans MS"

$Form1 = GUICreate("Press Bot Beta    ...by gta99", 284, 136, 712, 335)
$Button1 = GUICtrlCreateButton("Eingabe ändern", 8, 8, 145, 33, $WS_GROUP)
$filemenu = GUICtrlCreateMenu("Datei")
$startitem = GUICtrlCreateMenuItem("Skript starten" & @TAB & "(F2)", $filemenu)
$pauseitem = GUICtrlCreateMenuItem("Skript pausieren" & @TAB & "(F4)", $filemenu)
$exititem = GUICtrlCreateMenuItem("Beenden", $filemenu)
$helpmenu = GUICtrlCreateMenu("Hilfe")
$aboutitem = GUICtrlCreateMenuItem("Über", $helpmenu)
$optmenu = GUICtrlCreateMenu("Optionen")
$langitem = GUICtrlCreateMenuItem("Sprache ändern", $optmenu)
GUISetFont(12, 400, 0, $Font)
$Label1 = GUICtrlCreateLabel("F2 = Start" & @CRLF & "F4 = Pause", 8, 48, 148, 57)
GUISetBkColor(0x00CC33)
GUISetState(@SW_SHOW)

$schleife = "1"
$var = "{SPACE}"

HotKeySet("{F2}", "_Start")
HotKeySet("{F4}", "_Pause")
HotKeySet("{ESC}", "_End")

$fPaused = False

_Main()

Func _Main()
    
    ;GUISetState()  ; What is this doing here????

    While 1
        Switch GUIGetMsg() ; If you use Switch....

            Case $GUI_EVENT_CLOSE, $exititem ; then you can do this - multiple arguments!!!!
                _End()

            Case $aboutitem
                MsgBox(64, "Über", " Dieser Bot wurde von ->EMAIL<- entwickelt.")

            Case $pauseitem
                _Pause()

            Case $Button1
                _Eingabe()

            Case $startitem
                _Start()

            Case $langitem
                _Lang()

        EndSwitch
    WEnd

EndFunc   ;==>_Main

Func _Pause()

    ; Toggle "paused" state
    $fPaused = Not $fPaused
    ; Adjust menu item text
    If $fPaused Then
        GUICtrlSetData($pauseitem, "Skript restarten" & @TAB & "(F4)") ; Apologies if this is not good German!!!!!!
    Else
        GUICtrlSetData($pauseitem, "Skript pausieren" & @TAB & "(F4)")
    EndIf
    ; Idle loop if paused
    While $fPaused
        ; Check if [X] clicked
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    WEnd

EndFunc   ;==>_Pause

Func _Start()
    Send($var)
EndFunc   ;==>_Start

Func _Lang()

EndFunc   ;==>_Lang

Func _Eingabe()
    $var = InputBox("Frage", "Was soll gedrückt werden?", """Beispiel: {SPACE} oder N""")
EndFunc   ;==>_Eingabe

Func _End()
    Exit
EndFunc   ;==>_End

However, as I now see your script is a bot, that is as far as I go. Have fun with the rest of it. :huggles:

M23

Hi M23!

Well, these are some code snippets, my bot is made with them, that's why the global variables are local, I just took it from the AutoIt example :D

and I'm not a very good AutoIt scripter I learn from the examples and my bot is the result xD

I tried to use the code you wrote but it still doesn't react if I click on a button of the GUI while start is running....

Hope that someone finally can help me, but thanks anyway for your job :

Edit: Just forget about let the GUI react while running the script thing I don't care about it anymore I just wanna try to let the language thing work...

Edited by gMgmc
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...