Jump to content

Recommended Posts

Posted (edited)

I am trying to create dynamic editor for my lua file. I found that best way to do this is 3d array. Array dimensions are following: 1) line 2)control 3) tab

Lines are made of controls which are based on criterias in timing.lua functions.

I have 1 tab for every function in timing.lua.

Meaning of lines and tabs are explained on screenshot:

Posted Image

My objective:

Write code that would work so that when I click on remove it would tell me number of line where remove button I clicked is located and tab on which it lays.

Problem:

I dont know how to edit ConsoleWrite("Line: "&$OtherControls[0][0][0]&" Tab: ") (on line 91) if I want to make it print line nr and tab nr.

It would be great if someone would be so nice and help me figure out how that line should be.

Script.au3

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$list = False
If FileExists(@ScriptDir & "\timeedit.eng.lng") Then
    $list = StringSplit(FileRead(@ScriptDir & "\timeedit.eng.lng"), @CRLF, 1)
EndIf

$sFileData = FileRead(@ScriptDir & "\timing.lua")
Dim $buttons[1]
$buttons[0] = "-9999"
Dim $OtherControls[1][1][1]
;~ $sFileData = FileRead(@ScriptDir & "\ra.lua")
;~ GetTiming("Monday")
;~ Exit

$y = 50

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Timing", 628, 453, 192, 124)
If $list[0] > 1 Then WinSetTitle($Form1, "", $list[10])
$Tab1 = GUICtrlCreateTab(0, 0, 625, 417)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("Mon")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[1])
_execute(GetTiming("Monday"))
$TabSheet2 = GUICtrlCreateTabItem("Tue")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[2])
$y = 50
_execute(GetTiming("Tuesday"))
$TabSheet3 = GUICtrlCreateTabItem("Wed")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[3])
$y = 50
_execute(GetTiming("Wednesday"))
$TabSheet4 = GUICtrlCreateTabItem("Thu")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[4])
$y = 50
_execute(GetTiming("Thursday"))
$TabSheet5 = GUICtrlCreateTabItem("Fri")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[5])
$y = 50
_execute(GetTiming("Friday"))
$TabSheet6 = GUICtrlCreateTabItem("Sat")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[6])
$y = 50
_execute(GetTiming("Saturday"))
$TabSheet7 = GUICtrlCreateTabItem("Sun")
If $list[0] > 1 Then GUICtrlSetData(-1, $list[7])
$y = 50
_execute(GetTiming("Sunday"))
GUICtrlCreateTabItem("")
$Save = GUICtrlCreateButton("Save", 8, 424, 75, 25, $WS_GROUP)
If $list[0] > 1 Then GUICtrlSetData(-1, $list[8])
$Reload = GUICtrlCreateButton("Reload", 88, 424, 75, 25, $WS_GROUP)
If $list[0] > 1 Then GUICtrlSetData(-1, $list[9])
$new = GUICtrlCreateButton($list[16], 548, 424, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
;~ _ArrayDisplay($OtherControls)
;~ _ArrayDisplay($buttons)
;~ _MultiDimArrayDisplay($OtherControls, "My multipliable dimensional array displayer")

;~ _execute(GetTiming("Monday"))
Func _execute($sStr)
;~  MsgBox(0,0,$sStr)
    Local $handle
    $a = StringSplit($sStr, @CRLF, 1)
    For $i = 1 To $a[0]
        $handle = Execute($a[$i])
        If StringInStr($a[$i], "GUICtrlCreateButton") Then
            ReDim $buttons[UBound($buttons) + 1]
            ReDim $OtherControls[UBound($OtherControls,1) + 1][1][UBound($OtherControls,3)]
            $buttons[UBound($buttons) - 1] = $handle
        ElseIf StringInStr($a[$i], "GUICtrlCreateCombo") or StringInStr($a[$i], "GUICtrlCreateInput") Then
            ReDim $OtherControls[UBound($OtherControls)][UBound($OtherControls,2)+1][UBound($OtherControls,3)]
            $OtherControls[UBound($OtherControls) - 1][UBound($OtherControls,2)-1][UBound($OtherControls,3)-1] = $handle
            ConsoleWrite("$OtherControls["&UBound($OtherControls) - 1&"]["&UBound($OtherControls,2)-1&"]["&UBound($OtherControls,3)-1&"] = "&$handle&@CRLF)
        EndIf
    Next
    ReDim $OtherControls[UBound($OtherControls)][UBound($OtherControls,2)][UBound($OtherControls,3)+1]
EndFunc   ;==>_execute

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    for $i= 0  To UBound($buttons) -1
        If $nMsg = $buttons[$i] Then
;~          ConsoleWrite("Line: "&$OtherControls[0][0][0]&" Tab: ")
        EndIf
    Next
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Save
    EndSwitch
WEnd

Func GetTiming($sDay)
    $split = StringSplit($sFileData, @CRLF, 1)
    For $i = 1 To $split[0]
        $start = StringInStr($split[$i], "function " & $sDay)
        If $start Then
            ExitLoop
        EndIf
    Next
    ConsoleWrite("i = " & $i & @CRLF)
    For $n = $i To $split[0]
        $start = StringInStr($split[$n], "Allowed =")
        If $start Then
            ExitLoop
        EndIf
    Next
    ConsoleWrite("n = " & $n & @CRLF)
    For $a = $n To $split[0]
        $paramstart = StringInStr($split[$a], "(")
        If $paramstart Then
            ExitLoop
        EndIf
    Next
    ConsoleWrite("a = " & $a & @CRLF)
    For $b = $a To $split[0]
        $paramend = StringInStr($split[$b], ")")
        If $paramend Then
            ExitLoop
        EndIf
    Next
    ConsoleWrite("b = " & $b & @CRLF)

    $fullstr = ""
    For $c = $a To $b
        $fullstr &= Interpretate(_RemoveSpace($split[$c]))
    Next
    Return $fullstr
EndFunc   ;==>GetTiming

Func Interpretate($sStr)
    If StringLeft($sStr, 2) = "--" Then
        Return ""
    EndIf
    If StringLen($sStr) < 2 Then
        Return ""
    EndIf
;~  ConsoleWrite("interpretate: "&$sStr&@CRLF)
    $words = StringSplit($sStr, " ")
    $global = ""
    If $words[0] >= 3 Then
        For $i = 1 To $words[0]
            If StringInStr($words[$i], "<") Or StringInStr($words[$i], ">") Or StringInStr($words[$i], "=") Then
                $data = ''
                $data &= 'GUICtrlCreateCombo("", ' & 10 + ($i - 1) * 120 & ', ' & $y & ',75)' & @CRLF
                $data &= 'GUICtrlSetData(-1, ' & luaReplace('"<|>|==|<=|>=|~="') & ',"' & luaReplace($words[$i]) & '")' & @CRLF
                $data &= 'GUICtrlSetColor(-1,0xff0000)' & @CRLF
            EndIf

            If StringInStr($words[$i], "and") Or StringInStr($words[$i], "or") Then
                $data = ''
                $data &= 'GUICtrlCreateCombo("",' & 10 + ($i - 1) * 120 & ',' & $y & ',75)' & @CRLF
                $data &= 'GUICtrlSetData(-1, ' & luaReplace('"and|or"') & ',"' & luaReplace($words[$i]) & '")' & @CRLF
                $data &= 'GUICtrlSetColor(-1,0x0000ff)' & @CRLF
            EndIf

            If StringInStr($words[$i], "minute") Or StringInStr($words[$i], "hour") Then
                $data = ''
                $data &= 'GUICtrlCreateCombo("", ' & 10 + ($i - 1) * 120 & ',' & $y & ',75)' & @CRLF
                $data &= 'GUICtrlSetData(-1, ' & luaReplace('"hour|minute"') & ',"' & luaReplace($words[$i]) & '")' & @CRLF
                $data &= 'GUICtrlSetColor(-1,0xcc00cc)' & @CRLF
            EndIf

            If StringIsDigit($words[$i]) Then
                $data = ''
                $data &= 'GUICtrlCreateInput("' & luaReplace($words[$i]) & '",' & 10 + ($i - 1) * 120 & ',' & $y & ',75,25)' & @CRLF
            EndIf

            $global &= $data
;~          ConsoleWrite($words[$i]&@CRLF)
        Next
    EndIf
    $global &= 'GUICtrlCreateButton("'&$list[15]&'",' & 10 + ($i - 1) * 120 & ',' & $y & ',75,25)' & @CRLF
    $y += 45
    Return $global
EndFunc   ;==>Interpretate

Func luaReplace($sStr)
    $sStr = StringReplace($sStr, "hour", $list[11])
    $sStr = StringReplace($sStr, "minute", $list[12])
    $sStr = StringReplace($sStr, "and", $list[13])
    $sStr = StringReplace($sStr, "or", $list[14])
    Return $sStr
EndFunc   ;==>luaReplace

; #FUNCTION# ;===============================================================================
;
; Name...........: _RemoveSpace
; Description ...: Removes spaces and tabs at beginning of string
; Syntax.........: _RemoveSpace($sString)
; Parameters ....:  $sString    - Input string
; Return values .: $sString with out spaces and tabs at the beginning of string
; Author ........: E1M1
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; No
;
; ;==========================================================================================
Func _RemoveSpace($sString)
    While 1
        If StringLeft($sString, 1) = " " Or StringLeft($sString, 1) = @TAB Then
            $sString = StringTrimLeft($sString, 1)
        Else
            Return $sString
        EndIf
    WEnd
EndFunc   ;==>_RemoveSpace

;~ $lang_id=et
;~  $monday='Esmaspäev'
;~  $tuesday='Tesipäev'
;~  $wednesday='Kolmapäev'
;~  $thursday='Neljapäev'
;~  $friday='Reede'
;~  $saturday='Laupäev'
;~  $sunday='Pühapäev'
;~ $save='Salvesta'
;~ $load_again='Lae uuesti'
;~ $times='Ajad'
;~ * 'load_again' as

timeedit.eng.lng

Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Save
Reload
Times
hour
minute
and
or
remove
Add

timing.lua

now = os.date("*t"); local hour,minute,weekday = now.hour,now.minute,now.wday;
variable = 1234
function IsAllowed()
    local Fixed = true
    local Allowed = false

    if Fixed == false then
        if weekday == 1 then Allowed = Sunday()
        elseif weekday == 2 then Allowed =  Monday()
        elseif weekday == 3 then Allowed =  Tuesday()
        elseif weekday == 4 then Allowed = Wednesday()
        elseif weekday == 5 then Allowed = Thursday()
        elseif weekday == 6 then Allowed = Friday()
        elseif weekday == 7 then Allowed = Saturday()
        end
    else
        Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    end

    return Allowed
end

function Monday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Tuesday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Wednesday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Thursday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Friday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Saturday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end

function Sunday()
    Allowed =
        (
            hour >= 16
                and minute >= 0
                and minute < 59
            or hour >= 18
        )
    return Allowed
end
Edited by E1M1

edited

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
  • Recently Browsing   0 members

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