Jump to content

Schedule system


Synapse
 Share

Recommended Posts

Hi everyone...here is a simple Scheduling system that i`ve created for one of my scripts that needed to execute an action on a specific time on several day.

Posted Image

How is it work?

* It`s very simple...it has a table with 7 row (for the days in a week) and 24 cols (for the hours).

* Every square was made by individual Graphics.

* If hovered it gets a darker green and show below the Day: hour

* If clicked it gets red and writes an ini file taging the clicked hour of the chosen day

* If clicked again on the red square it becomes again green and write the ini file again signing it with a 0

* Ar relaunch it remembers the checked squares

* If the square is checked the hover color is a darker reddish

* If the current hour matches the checked square it runs a given action

Comments and ideas are wellcomed :D

PS. The hover.au3 that i used is the one made by MrCreatoR and it can be found here

scheduler.rar

Edited by Synapse
Link to comment
Share on other sites

Hi,

I'm very interrested but you are talking about a scheduler ????

But i cannot do a schedule !

Emiel

Hi...yes the example I posted do not do things on the selected time....that part remain to be done by u or whoever wants to use it...because there are many ways to do it...

This is a simple example that can be called with an Adlib:

Func CheckSchedule()
    $ScValue = IniReadSection ( $IniPath, _DateDayOfWeek( @WDAY ) )
    For $i = 1 To $ScValue[0][0]
        $OraCurenta = @HOUR
        If $OraCurenta > 10 Then $OraCurenta = StringRight ( $OraCurenta, 1 )
        If $ScValue[$i][0] = $OraCurenta&"_00-"&$OraCurenta&"_59" And $ScValue[$i][1] = 1 Then 
        ;Execute something here
            MsgBox(0,"","Ora "&@HOUR)
        EndIf
    Next
EndFunc

Dunno if its working...i`ve made it directly in the forum....it`s only to give u an example of how it can be made

Cheers

Edited by Synapse
Link to comment
Share on other sites

There is one problem. You can NOT use GUIOnEventMode and GuiGetMsg(). They will not work together. Either one or the other. I like it a lot just maybe if you add like an on double click you can add an event/or something. Then when you hover over that square it will display it below

Very good idea...thx for the feedback...

If anyone has some good ideas please post them here, they are all wellcome. (If the ideas are in code examples then they`re even beter :D)

Link to comment
Share on other sites

aha i see

you program has to be active .

you don't use the Windows builtin task scheduler..

http://msdn2.microsoft.com/en-us/library/a...601(VS.85).aspx

http://msdn2.microsoft.com/en-us/library/a...389(VS.85).aspx

Nice...i didn`t saw that till now...btw that would be a good idea.....but in my case i need a scheduler that runs in an active script...so what i`ve made ATM it`s ok 4 now....

PS. I`ve updated the first post...with some new improvements on the scheduler...

Cheers all !

Link to comment
Share on other sites

  • 6 years later...

86tk.png

Well I took a shot at updating this code base, as I rather liked the original...and the author hasn't touched it in a while.

Anyways feel free to update what I've done. :)

** Update **

Added code suggestions made by PhoenixXL, which greatly enhanced the redraw experience for Enable / Disabled states of the Swatch Grid.

#include <Array.au3>
#include <GUIConstants.au3>
#include <GUICtrlOnHover.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>

Opt( "GuiOnEventMode" , 1 )

; Colors
$sSwatchOutLine  = '0x000000' ; Black
$sSwatchDisabled = '0xb7b7b7' ; Gray
$aSwatchNormal   = StringSplit( '0xc7b299|0xf7941d|0xfff200|0x00a651|0x0054a6|0x600080|0xB30086|0xcc1015' , '|' )
$aSwatchHover    = StringSplit( '0x998675|0xf26522|0xd8ca03|0x007236|0x003471|0x4D0066|0x990073|0x9e0b0f' , '|' )

$aWeekShort = StringSplit( 'Sun|Mon|Tue|Wen|Thu|Fri|Sat' , '|' )
$aWeekLong  = StringSplit( 'Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday' , '|' )

Global $aSwatches[169][2] = [[168]]
Global $sSavedSettings = @ScriptDir & "\Scheduler.ini"

Global $aSwatchMock[UBound( $aSwatchNormal )][2] = [[UBound( $aSwatchNormal ) - 1]]
Global $aWeekLabel[8] = [7]

If Not FileExists( $sSavedSettings ) Then _CreateIni()

Global $bSettingsScheduler = IniRead( $sSavedSettings , 'Settings' , 'Scheduler' , 'True' ) ; Bool Scheduler Usage

$iSwatchCount  = 1
$iSwatchSize   = 19
$iSwatchArea   = $iSwatchSize - 1
$iSwatchMargin = $iSwatchSize + 4

$iFontSize    = 9
$iLabelHeight = 17
$iLabelOffset = Round(( $iSwatchSize - $iLabelHeight ) / 2 ) + 1

$iGroupTop  = 10
$iGroupLeft = 16

$iGridTop  = $iGroupTop  + 26 - $iSwatchArea
$iGridLeft = $iGroupLeft + 36 - $iSwatchArea

$iGroupHeight = ( 26 - $iSwatchArea ) + ( $iSwatchArea *  7 ) + ( $iSwatchMargin * 2 ) + $iSwatchSize + 6
$iGroupWidth  = ( 36 - $iSwatchArea ) + ( $iSwatchArea * 24 ) + $iSwatchSize + 20

Global Const $Scheduler = GUICreate( "Scheduler" , $iGroupLeft + $iGroupWidth + 16 , $iGroupTop + $iGroupHeight + 16 , -1 , -1 )

    GUISetOnEvent( $GUI_EVENT_CLOSE , "_Quit" )

    GUICtrlCreateGroup(" Scheduler Table " , $iGroupLeft , $iGroupTop , $iGroupWidth , $iGroupHeight )
        GUICtrlSetFont( -1 , $iFontSize )

        ; Rows / Days in Week
        For $iDay = 1 To 7
            $iGridTop += $iSwatchArea
            $aHours = IniReadSection( $sSavedSettings , $aWeekLong[$iDay] )
            $aWeekLabel[$iDay] = GUICtrlCreateLabel( $aWeekShort[$iDay] , $iGroupLeft + 2 , $iGridTop + $iLabelOffset , 30 , $iLabelHeight , $SS_RIGHT )
                GUICtrlSetFont( -1 , $iFontSize , 700 )
            ; Columns / Hours in Day
            For $iHour = 1 To 24
                $aSwatches[$iSwatchCount][0] = GUICtrlCreateGraphic( $iGridLeft + ( $iHour * $iSwatchArea ) , $iGridTop , $iSwatchSize , $iSwatchSize )
                GUICtrlSetOnEvent(   $aSwatches[$iSwatchCount][0] , "_SwatchState" )
                GUICtrlSetColor(     $aSwatches[$iSwatchCount][0] , $sSwatchOutLine )
                GUICtrlSetState(     $aSwatches[$iSwatchCount][0] , $GUI_ONTOP ) ; Needed if on Tab Control
                $aSwatches[$iSwatchCount][1] = $aHours[$iHour][1]
                GUICtrlSetBkColor(   $aSwatches[$iSwatchCount][0] , $aSwatchNormal[$aSwatches[$iSwatchCount][1]] )
                _GUICtrl_OnHoverRegister( $aSwatches[$iSwatchCount][0] , "_SwatchHover" , "_SwatchLeave" )
                $iSwatchCount += 1
            Next
        Next

        $lbl_ShowDayHour = GUICtrlCreateLabel( "" , $iGridLeft + $iSwatchArea , $iGridTop + $iSwatchMargin + $iLabelOffset , 130 , $iLabelHeight )
            GUICtrlSetFont( -1 , $iFontSize )

        $chk_Scheduler = GUICtrlCreateCheckbox( "Enable Scheduler" , $iGridLeft + $iSwatchArea , $iGroupHeight - 14 , 115 , $iLabelHeight )
            GUICtrlSetFont( -1 , $iFontSize )
            GUICtrlSetOnEvent( $chk_Scheduler , "_SchedulerState" )

        $iSwatchCount = 1
        For $kk = 1 To 2
            $iGridTop += $iSwatchMargin
            $iSwatchOffset = 9
            For $ll = 1 To 4
                $aSwatchMock[$iSwatchCount][0] = GUICtrlCreateGraphic( $iGridLeft + ( $iSwatchArea * $iSwatchOffset ) , $iGridTop , $iSwatchSize , $iSwatchSize )
                    GUICtrlSetBkColor( -1 , $aSwatchNormal[$iSwatchCount] )
                    GUICtrlSetColor( -1 , $sSwatchOutLine )
                    GUICtrlSetState( -1 , $GUI_ONTOP ) ; Needed if on Tab Control
                $aSwatchMock[$iSwatchCount][1] = GUICtrlCreateLabel( "State " & $iSwatchCount , $iGridLeft + ( $iSwatchArea * $iSwatchOffset ) + $iSwatchArea + 4 , $iGridTop + $iLabelOffset , 40 , $iLabelHeight )
                    GUICtrlSetFont(  -1 , $iFontSize )

                $iSwatchOffset += 4
                $iSwatchCount  += 1
            Next
        Next

    GUICtrlCreateGroup("", -99, -99, 1, 1)

    ; Update Controls
    If $bSettingsScheduler = 'True' Then GUICtrlSetState( $chk_Scheduler , $GUI_CHECKED )
    _SchedulerState()

GUISetState( @SW_SHOW )

; Call the Function Every Minute
AdlibRegister( '_CheckScheduler' , 60 * 1000 )

While 1
    Sleep( 100 )
WEnd

Func _SchedulerState()

    _SendMessage($Scheduler, $WM_SETREDRAW, False)

    If _getControlBoolValue( $chk_Scheduler ) Then
        For $ii = 1 To $aWeekLabel[0]
            GUICtrlSetState( $aWeekLabel[$ii] , $GUI_ENABLE )
        Next
        For $ii = 1 To $aSwatchMock[0][0]
            GUICtrlSetState(   $aSwatchMock[$ii][1] , $GUI_ENABLE )
            GUICtrlSetBkColor( $aSwatchMock[$ii][0] , $aSwatchNormal[$ii] )
        Next
        For $ii = 1 To $aSwatches[0][0]
            GUICtrlSetState(   $aSwatches[$ii][0] , $GUI_ENABLE )
            GUICtrlSetBkColor( $aSwatches[$ii][0] , $aSwatchNormal[$aSwatches[$ii][1]] )
        Next
    Else
        GUICtrlSetData( $lbl_ShowDayHour , '' )
        For $ii = 1 To $aWeekLabel[0]
            GUICtrlSetState( $aWeekLabel[$ii] , $GUI_DISABLE )
        Next
        For $ii = 1 To $aSwatchMock[0][0]
            GUICtrlSetState(   $aSwatchMock[$ii][1] , $GUI_DISABLE )
            GUICtrlSetBkColor( $aSwatchMock[$ii][0] , $sSwatchDisabled )
        Next
        For $ii = 1 To $aSwatches[0][0]
            GUICtrlSetState(   $aSwatches[$ii][0] , $GUI_DISABLE )
            GUICtrlSetBkColor( $aSwatches[$ii][0] , $sSwatchDisabled )
        Next
    EndIf

    _SendMessage($Scheduler, $WM_SETREDRAW, True)
    _WinAPI_RedrawWindow($Scheduler)

EndFunc

Func _SwatchState()
    Local $iCurrentSwatch = _ArraySearch( $aSwatches , @GUI_CTRLID , 1 , 0 , 0 , 0 , 1 , 0 )
    If $iCurrentSwatch <> -1 Then
        $aDayHour = _ReturnDayHour( $iCurrentSwatch )
        $aSwatches[$iCurrentSwatch][1] = _ToggleBase1ArrayValue( $aSwatches[$iCurrentSwatch][1] , $aSwatchNormal )
        GUICtrlSetBkColor( $aSwatches[$iCurrentSwatch][0] , $aSwatchHover[$aSwatches[$iCurrentSwatch][1]] )
        IniWrite( $sSavedSettings , $aDayHour[0] , $aDayHour[1] & "_00-" & $aDayHour[1] & "_59" , $aSwatches[$iCurrentSwatch][1] )
    EndIf
EndFunc

Func _SwatchHover( $iSwatchID )
    Local $iCurrentSwatch = _ArraySearch( $aSwatches , $iSwatchID , 1 , 0 , 0 , 0 , 1 , 0 )
    If $iCurrentSwatch <> -1 Then
        $aDayHour = _ReturnDayHour( $iCurrentSwatch )
        GUICtrlSetData( $lbl_ShowDayHour , $aDayHour[0] & ", " & $aDayHour[1] & ":00 - " & $aDayHour[1] & ":59" )
        GUICtrlSetBkColor( $aSwatches[$iCurrentSwatch][0] , $aSwatchHover[$aSwatches[$iCurrentSwatch][1]] )
    EndIf
EndFunc

Func _SwatchLeave( $iSwatchID )
    Local $iCurrentSwatch = _ArraySearch( $aSwatches , $iSwatchID , 1 , 0 , 0 , 0 , 1 , 0 )
    If $iCurrentSwatch <> -1 Then
        GUICtrlSetBkColor( $aSwatches[$iCurrentSwatch][0] , $aSwatchNormal[$aSwatches[$iCurrentSwatch][1]] )
    EndIf
EndFunc

Func _ReturnDayHour( $iHour )
    Local $aDayHour[2]
    Switch $iHour
        Case   1 To  24
            $aDayHour[0] = "Sunday"
            $aDayHour[1] = $iHour - 1
        Case  25 To  48
            $aDayHour[0] = "Monday"
            $aDayHour[1] = $iHour - 25
        Case  49 To  72
            $aDayHour[0] = "Tuesday"
            $aDayHour[1] = $iHour - 49
        Case  73 To  96
            $aDayHour[0] = "Wednesday"
            $aDayHour[1] = $iHour - 73
        Case  97 To 120
            $aDayHour[0] = "Thursday"
            $aDayHour[1] = $iHour - 97
        Case 121 To 144
            $aDayHour[0] = "Friday"
            $aDayHour[1] = $iHour - 121
        Case 145 To 168
            $aDayHour[0] = "Saturday"
            $aDayHour[1] = $iHour - 145
        Case Else
            $aDayHour[0] = "Unknown"
            $aDayHour[1] = -1
    EndSwitch

    Return $aDayHour
EndFunc

Func _Quit()
    IniWrite( $sSavedSettings , 'Settings' , 'Scheduler' , _getControlBoolValue( $chk_Scheduler ))
    Exit
EndFunc

Func _CreateIni()
    Local $sNewIni = ''
    $sNewIni &= '[Settings]'     & @CRLF
    $sNewIni &= 'Scheduler=True' & @CRLF
    $sNewIni &= @CRLF
    For $ii = 1 To $aWeekLong[0]
        $sNewIni &= '[' & $aWeekLong[$ii] & ']' & @CRLF
        For $jj = 0 To 23
            $sNewIni &= $jj & '_00-' & $jj & '_59=1' & @CRLF
        Next
        $sNewIni &= @CRLF
    Next
    FileWrite( $sSavedSettings , $sNewIni )
EndFunc

Func _ToggleBase1ArrayValue( $iValue , ByRef $aArray )
    $iValue += 1
    If $iValue >= UBound( $aArray ) Then $iValue = 1
    If $iValue <= 0 Then $iValue = 1
    Return $iValue
EndFunc

Func _CheckScheduler()
    If _getControlBoolValue( $chk_Scheduler ) Then
        While $aSwatches[(( @WDAY - 1 ) * 24 ) + @HOUR + 1][1] > 1
            Local $CurrentValue = $aSwatches[(( @WDAY - 1 ) * 24 ) + @HOUR + 1][1]
            Local $CurrentHour  = @HOUR
            Switch $CurrentValue
                Case 2 To 8
                    MsgBox( 0 , $aWeekLong[@WDAY] , @HOUR & ' is set to ' & $CurrentValue )
            EndSwitch
            While @HOUR = $CurrentHour
                Sleep( 60 * 1000 )
            WEnd
        WEnd
    EndIf
EndFunc

Func _getControlBoolValue( $sControl )
    If GUICtrlRead( $sControl ) = 1 Then
         Return True
    Else
        Return False
    EndIf
EndFunc
Edited by Nologic
Link to comment
Share on other sites

  • 10 months later...

Yes, I know it is an old thread, but thought I would update this post, in case anyone else gets here and wants to try it out.

You have to add the following two includes...

#include <StaticConstants.au3>
#include <WindowsConstants.au3>

You also have to download this UDF (GUICtrlOnHover.au3), and put it in the same location as the includes, or the location of your script, as it is not included otherwise...

'?do=embed' frameborder='0' data-embedContent>>

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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...