Что нового

таймер отображаемый в ToolTip

nu3dell

Осваивающий
Сообщения
139
Репутация
24
в этой теме http://autoit-script.ru/index.php/topic,3083.0.html пользователь "SECTOR" привев очень хороший пример таймера
Код:
_Sleep(15) ; Таймер на 15 секунд
MsgBox(0,"Пауза...","Время вышло :)")

Func _Sleep($iSec,$iX=10,$iY=10)

    Local $hTimer = TimerInit(), $iTimer = 0

    Do
        $iTimer = Round(TimerDiff($hTimer)/1000,0)
        ToolTip("Прошло "&$iTimer&" из "&$iSec&" секунд...",$iX,$iY,"Пауза...")
        Sleep(250)
    Until $iTimer >= $iSec

    ToolTip("")

EndFunc

Нужно добавить туда не только секунды но и часы и минуты, в таком формате 00:00:00

соответствен GUI в таком формате
Код:
$Gui=GUICreate('timer', 285, 81 ,Default,Default)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('00',25,57,20,16)	
$m =GUICtrlCreateInput('00',48,57,20,16)
$s =GUICtrlCreateInput('00',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
 

VladUs

Скриптер
Сообщения
621
Репутация
181
nu3dell [?]
Нужно добавить туда не только секунды но и часы и минуты, в таком формате 00:00:00
Посмотрите пример из справки к функции _TicksToTime() для библиотеки Date.au3. Мне кажется, что это, то что Вам нужно.
 
Автор
nu3dell

nu3dell

Осваивающий
Сообщения
139
Репутация
24
VladUs Я это все смотрел, я сначала пользуюсь поиском, а потом если что пишу в теме.
Мне нужно не то, это как секундомер, а мне нужен таймер
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
"Топорный" метод :smile::
Код:
$Gui=GUICreate('timer', 285, 81 ,Default,Default)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('00',25,57,20,16)
$m =GUICtrlCreateInput('01',48,57,20,16)
$s =GUICtrlCreateInput('03',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
GUISetState()

While 1
	Switch GUIGetMsg()
		Case -3
			Exit
		Case $reb
			_Sleep(GUICtrlRead($h) & ':' & GUICtrlRead($m) & ':' & GUICtrlRead($s))
			MsgBox(0,"Пауза...","Время вышло :)")
	EndSwitch
WEnd

Func _Sleep($iSec, $iX=10, $iY=10)
	$Split = StringSplit($iSec, ':')

    Do
		$Split[3] = $Split[3] - 1
		If $Split[3] < 0 Then
			If Not $Split[2] <= 0 Then
				$Split[2] = $Split[2] - 1
				$Split[3] = 59
			Else
				$Split[3] = 0
			EndIf
		EndIf

		If $Split[2] <= 0 Then
			If Not $Split[1] <= -1 Then
				$Split[1] = $Split[1] - 1
				$Split[2] = 59
			Else
				$Split[2] = 0
			EndIf
		EndIf

		If $Split[1] = -1 Then $Split[1] = '00'
		If $Split[1] = 0 Then $Split[1] = '00'
		If $Split[1] = 1 Then $Split[1] = '01'
		If $Split[1] = 2 Then $Split[1] = '02'
		If $Split[1] = 3 Then $Split[1] = '03'
		If $Split[1] = 4 Then $Split[1] = '04'
		If $Split[1] = 5 Then $Split[1] = '05'
		If $Split[1] = 6 Then $Split[1] = '06'
		If $Split[1] = 7 Then $Split[1] = '07'
		If $Split[1] = 8 Then $Split[1] = '08'
		If $Split[1] = 9 Then $Split[1] = '09'

		If $Split[2] = 0 Then $Split[2] = '00'
		If $Split[2] = 1 Then $Split[2] = '01'
		If $Split[2] = 2 Then $Split[2] = '02'
		If $Split[2] = 3 Then $Split[2] = '03'
		If $Split[2] = 4 Then $Split[2] = '04'
		If $Split[2] = 5 Then $Split[2] = '05'
		If $Split[2] = 6 Then $Split[2] = '06'
		If $Split[2] = 7 Then $Split[2] = '07'
		If $Split[2] = 8 Then $Split[2] = '08'
		If $Split[2] = 9 Then $Split[2] = '09'

		If $Split[3] = 0 Then $Split[3] = '00'
		If $Split[3] = 1 Then $Split[3] = '01'
		If $Split[3] = 2 Then $Split[3] = '02'
		If $Split[3] = 3 Then $Split[3] = '03'
		If $Split[3] = 4 Then $Split[3] = '04'
		If $Split[3] = 5 Then $Split[3] = '05'
		If $Split[3] = 6 Then $Split[3] = '06'
		If $Split[3] = 7 Then $Split[3] = '07'
		If $Split[3] = 8 Then $Split[3] = '08'
		If $Split[3] = 9 Then $Split[3] = '09'

		$iTime = $Split[1] & ':' & $Split[2] & ':' & $Split[3]
        ToolTip($iTime, $iX, $iY, "Осталось")
        Sleep(1000)
    Until $Split[1] <=0 And $Split[2] <= 0 And $Split[3] <= 1

    ToolTip("")
EndFunc
 
Автор
nu3dell

nu3dell

Осваивающий
Сообщения
139
Репутация
24
Zaramot
При много благодарен, + ушел
 

VladUs

Скриптер
Сообщения
621
Репутация
181
nu3dell [?]
мне нужен таймер
Тогда могу предложить такой вариант:

Код:
#Include <Date.au3>
Global $asDatePart,  $iTimePart
$Gui=GUICreate('timer', 285, 81 ,Default,Default)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('00',25,57,20,16)
$m =GUICtrlCreateInput('01',48,57,20,16)
$s =GUICtrlCreateInput('03',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
GUISetState()

While 1
  $msg = GUIGetMsg()
SELECT
   Case $msg = -3 
      Exit
   Case $msg = $reb
      $ht =GUICtrlRead($h)
      $mt  =GUICtrlRead($m)
      $st =GUICtrlRead($s)
      $New =  _DateAdd("s",-1, "1970/01/01 " & $ht & ":" & $mt & ":" & $st)
      AdlibRegister("_TimeMinus",1000)
EndSelect

WEnd 

Func _TimeMinus()
 _DateTimeSplit($New,  $asDatePart,  $iTimePart)
$New =  _DateAdd("s",-1, $New)
ToolTip($iTimePart[1] & " час : " & $iTimePart[2] & " мин : " & $iTimePart[3] & " сек",0,0 , "Осталось")
IF $iTimePart[3] = 0 And $iTimePart[2] = 0 And $iTimePart[1] = 0  Then 
   MsgBox(0,"Пауза...","Время вышло :")
   AdlibUnRegister("_TimeMinus")
   ToolTip("")
EndIf
EndFunc
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
nu3dell,
Можно и так попробовать:
Код:
#include <GUIConstantsEx.au3>
#include <Date.au3>
#include <StaticConstants.au3>

Dim $aCombo[4][3] = [[3],[3600, 'часы'],[60, 'минуты'],[1, 'секунды']], $sData, $fExit = True, _
		$iHour, $iMins, $iSecs, $iW = 10 + $aCombo[0][0] * 55, $iTimeOut, $iStart, $fColor

For $i = 0 To 59
	$sData &= StringFormat('%02d|', $i)
Next

$hGui = GUICreate('Timer', $iW, 130)
For $i = 1 To $aCombo[0][0]
	GUICtrlCreateLabel($aCombo[$i][1], 10 + ($i - 1) * 55, 10, 45, 15, $SS_CENTER)
	$aCombo[$i][2] = GUICtrlCreateCombo('', 10 + ($i - 1) * 55, 30, 45, 20)
	GUICtrlSetData(-1, $sData, '00')
Next
$nLabel = GUICtrlCreateLabel('задайте таймаут', ($iW - 100) / 2, 65, 100, 15, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$nButton = GUICtrlCreateButton('GO', ($iW - 100) / 2, 90, 100, 30)
GUISetState()
$sData = ''
While 1
	Switch GUIGetMsg()
		Case $GUI_EVENT_CLOSE
			If $fExit Then
				Exit
			EndIf
		Case $nButton
			$iTimeOut = 0
			For $i = 1 To $aCombo[0][0]
				$iTimeOut += Number(GUICtrlRead($aCombo[$i][2])) * $aCombo[$i][0] * 1000
			Next
			If Not $iTimeOut Then ContinueLoop
			GUICtrlSetState($nButton, $GUI_DISABLE)
			$iStart = TimerInit()
			AdlibRegister('_Timer', 500)
			$fExit = False
	EndSwitch
WEnd

Func _Timer()
	Local $s_Time, $i_Timer = $iTimeOut - Int(TimerDiff($iStart))
	_TicksToTime($i_Timer, $iHour, $iMins, $iSecs)
	$s_Time = StringFormat("%02i:%02i:%02i", $iHour, $iMins, $iSecs)
	GUICtrlSetData($nLabel, $s_Time)
	If $i_Timer < 60000 And Not $fColor Then
		GUICtrlSetColor($nLabel, 0xFF0000)
		$fColor = True
	EndIf
	If $i_Timer <= 0 Then
		Beep(300, 100)
		AdlibUnRegister('_Timer')
		GUICtrlSetColor($nLabel, Default)
		GUICtrlSetData($nLabel, 'Время вышло')
		GUICtrlSetState($nButton, $GUI_ENABLE)
		$fColor = False
		$fExit = True
	EndIf
EndFunc   ;==>_Timer
 
Автор
nu3dell

nu3dell

Осваивающий
Сообщения
139
Репутация
24
Zaramot блин только вчера заметил, если выстосвлять на, 01:00:00 то через секунду будет в tooltip не 00:59:59, а 01:00:59, вот такая проблема. VladUs не подходит
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Оптимизировал код...
Вот, держи:
Код:
#include <Date.au3>

$Gui=GUICreate('Таймер', 285, 81)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('01',25,57,20,16)
$m =GUICtrlCreateInput('00',48,57,20,16)
$s =GUICtrlCreateInput('00',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $reb
            _Sleep(GUICtrlRead($h) & ':' & GUICtrlRead($m) & ':' & GUICtrlRead($s))
            MsgBox(0,"Пауза...","Время вышло :)")
    EndSwitch
WEnd

Func _Sleep($iTime)
    Local $iH, $iM, $iS

    $Split = StringSplit($iTime, ':')

    $Ticks = _TimeToTicks($Split[1], $Split[2], $Split[3])

    Do
        $Ticks = $Ticks - 2
        $Time = _TicksToTime($Ticks, $iH, $iM, $iS)
        $Format = StringFormat("%02i:%02i:%02i", $iH, $iM, $iS)
        ToolTip($Format, MouseGetPos(0) + 20, MouseGetPos(1) + 20, 'Осталось')
    Until $Ticks < 0

    ToolTip('')
EndFunc
 
Автор
nu3dell

nu3dell

Осваивающий
Сообщения
139
Репутация
24
за мышкой это лишнее, и у вас 1сек.=0.5 сек, то есть очень быстро не такая скорость у секунд
 
Автор
nu3dell

nu3dell

Осваивающий
Сообщения
139
Репутация
24
Zaramot что простите исправили? все осталось также tooltip летает за мышкой

Update: а все спасибо я дурачек ума не хватило
Код:
ToolTip($Format,0,0,'Осталось')

Только мне не нравиться слишком мерцает, вот этот был хорошо
Код:
$Gui=GUICreate('timer', 285, 81 ,Default,Default)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('00',25,57,20,16)
$m =GUICtrlCreateInput('01',48,57,20,16)
$s =GUICtrlCreateInput('03',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $reb
            _Sleep(GUICtrlRead($h) & ':' & GUICtrlRead($m) & ':' & GUICtrlRead($s))
            MsgBox(0,"Пауза...","Время вышло :)")
    EndSwitch
WEnd

Func _Sleep($iSec, $iX=10, $iY=10)
    $Split = StringSplit($iSec, ':')

    Do
        $Split[3] = $Split[3] - 1
        If $Split[3] < 0 Then
            If Not $Split[2] <= 0 Then
                $Split[2] = $Split[2] - 1
                $Split[3] = 59
            Else
                $Split[3] = 0
            EndIf
        EndIf

        If $Split[2] <= 0 Then
            If Not $Split[1] <= -1 Then
                $Split[1] = $Split[1] - 1
                $Split[2] = 59
            Else
                $Split[2] = 0
            EndIf
        EndIf

        If $Split[1] = -1 Then $Split[1] = '00'
        If $Split[1] = 0 Then $Split[1] = '00'
        If $Split[1] = 1 Then $Split[1] = '01'
        If $Split[1] = 2 Then $Split[1] = '02'
        If $Split[1] = 3 Then $Split[1] = '03'
        If $Split[1] = 4 Then $Split[1] = '04'
        If $Split[1] = 5 Then $Split[1] = '05'
        If $Split[1] = 6 Then $Split[1] = '06'
        If $Split[1] = 7 Then $Split[1] = '07'
        If $Split[1] = 8 Then $Split[1] = '08'
        If $Split[1] = 9 Then $Split[1] = '09'

        If $Split[2] = 0 Then $Split[2] = '00'
        If $Split[2] = 1 Then $Split[2] = '01'
        If $Split[2] = 2 Then $Split[2] = '02'
        If $Split[2] = 3 Then $Split[2] = '03'
        If $Split[2] = 4 Then $Split[2] = '04'
        If $Split[2] = 5 Then $Split[2] = '05'
        If $Split[2] = 6 Then $Split[2] = '06'
        If $Split[2] = 7 Then $Split[2] = '07'
        If $Split[2] = 8 Then $Split[2] = '08'
        If $Split[2] = 9 Then $Split[2] = '09'

        If $Split[3] = 0 Then $Split[3] = '00'
        If $Split[3] = 1 Then $Split[3] = '01'
        If $Split[3] = 2 Then $Split[3] = '02'
        If $Split[3] = 3 Then $Split[3] = '03'
        If $Split[3] = 4 Then $Split[3] = '04'
        If $Split[3] = 5 Then $Split[3] = '05'
        If $Split[3] = 6 Then $Split[3] = '06'
        If $Split[3] = 7 Then $Split[3] = '07'
        If $Split[3] = 8 Then $Split[3] = '08'
        If $Split[3] = 9 Then $Split[3] = '09'

        $iTime = $Split[1] & ':' & $Split[2] & ':' & $Split[3]
        ToolTip($iTime, $iX, $iY, "Осталось")
        Sleep(1000)
    Until $Split[1] <=0 And $Split[2] <= 0 And $Split[3] <= 1

    ToolTip("")
EndFunc

нельзя никак изменить?

Update: все ровно очень быстро, можете 1 ваш вариант, отредактировать? он и не мерцает и адекватный

Update: если так поставить то нормально
Код:
$Ticks = $Ticks - 0.7
но все равно не красиво получается мерцает
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
А так ?:
Код:
#include <Date.au3>

$Gui=GUICreate('Таймер', 285, 81)
$reb = GUICtrlCreateButton('Старт', 10, 10, 85,24)
$h =GUICtrlCreateInput('01',25,57,20,16)
$m =GUICtrlCreateInput('00',48,57,20,16)
$s =GUICtrlCreateInput('00',72,57,20,16)
GUICtrlCreateLabel(':',45,59,2,12)
GUICtrlCreateLabel(':',68,59,2,12)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $reb
            _Sleep(GUICtrlRead($h) & ':' & GUICtrlRead($m) & ':' & GUICtrlRead($s))
            MsgBox(0,"Пауза...","Время вышло :)")
    EndSwitch
WEnd

Func _Sleep($iTime, $iX=0, $iY=0)
    Local $iH, $iM, $iS

    $Split = StringSplit($iTime, ':')

    $Ticks = _TimeToTicks($Split[1], $Split[2], $Split[3])

    Do
        $Ticks = $Ticks - 1000
        $Time = _TicksToTime($Ticks, $iH, $iM, $iS)
        $Format = StringFormat("%02i:%02i:%02i", $iH, $iM, $iS)
        ToolTip($Format, $iX, $iY, 'Осталось')
		Sleep(1000)
    Until $Ticks < 0

    ToolTip('')
EndFunc


Вроде бы без мерцании и секунды идут как надо.
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Все проблемы были изо того что, я думал что вам надо чтобы ToolTip "бегал" за мышкой. Но раз уж вам это не надо, то вы упростили мне задачу :smile:
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Обновил функцию _Sleep()

Изменения:
- Добавлена возможность
1) Изменять заголовок.
2) Устанавливать иконку.
3) Устанавливать опции отображения ToolTip.

Код:
#include <Date.au3>

_Sleep('00:00:05', 100, 100, 'Осталось', 2, 3)

#cs ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 AutoIt Version:  	3.3.6.1
 Author:			Zaramot
 Parameters:  		$iTime - Sleep time in format HH:MM:SS
					$iX - X coord of tootlip
					$iY - Y coord of tootlip
					$iTitle - Title of tooltip
					$iIcon - Icon for display in tooltip
						0 - No icon (Default)
						1 - Information icon
						2 - Exclamaion icon
						3 - Error icon
					$iOptions - Sets different options for how the tooltip will be displayed
						1 = Display as Balloon Tip Requires IE5+
						2 = Center the tip at the x,y coordinates instead of using them for the upper left corner.
						4 = Force the tooltip to always be visible confining it to monitor borders if necessary. If multiple monitors are used, then the tooltip will "snap-to" the nearest monitor.
 Syntacsis: 		_Sleep($iTime, $iX=0, $iY=0, $iTitle='', $iIcon=0, $iOptions=0)
 Exemple:	 		_Sleep('00:00:10', 100, 100, 'Осталось', 2, 3)

#ce ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Func _Sleep($iTime, $iX=0, $iY=0, $iTitle='', $iIcon=0, $iOptions=0)
    Local $iH, $iM, $iS

    $Split = StringSplit($iTime, ':')

    $Ticks = _TimeToTicks($Split[1], $Split[2], $Split[3])

    Do
        $Ticks = $Ticks - 1000
        $Time = _TicksToTime($Ticks, $iH, $iM, $iS)
        $Format = StringFormat("%02i:%02i:%02i", $iH, $iM, $iS)
        ToolTip($Format, $iX, $iY, $iTitle, $iIcon, $iOptions)
        Sleep(1000)
    Until $Ticks < 1000

    ToolTip('')
EndFunc


PS Может кому понадобится :smile:
 
Верх