Search the Community
Showing results for tags 'Chooser'.
-
Even if I know about the existence of the _GUICtrlMonthCal* functions, here is a simple home made "Visual date chooser" function. It is in a raw draft format and can likely be emprooved, but I think that, all in all, this "skeleton" is not so bad. Maybe it can be of use... ; Calendar mini #include <date.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GUIEdit.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Local $aResult = _Peek_A_Date() MsgBox(0, 'Result', (@error) ? 'No date selected' : _DateTimeFormat($aResult[0] & "/" & $aResult[1] & "/" & $aResult[2], 1), 3) ; ---------------------------------------------------------------------------------- ; a simple 'visual' date peeker function ; parameters are optional ; YYYY and MM for initial desired calendar ; last parameter: if true (default) first weekday is moonday ; if false first weekday is sunday ; returns: on success a 3 elements array as [0]Year yyyy; [1]Monthh mm; [2]Day dd ; on error set @error and returns 0 ; ----------------------------------------------------------------------------------- Func _Peek_A_Date($iYear = @YEAR, $iMonth = @MON, $bISO = True) Local $hCalendar = GUICreate('', 210, 160, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW), $iDay = @MDAY Local $IdDate = GUICtrlCreateLabel('', 25, 4, 160, 20, $SS_CENTER, $GUI_WS_EX_PARENTDRAG), $idWeekDays = GUICtrlCreateLabel('', 2, 28, 206, 20) Local $idDays = GUICtrlCreateEdit('', 2, 50, 206, 108, BitOR($ES_READONLY, $ES_MULTILINE), 0), $hDays = GUICtrlGetHandle(-1) Local $iColor = 0x00ffd700, $Dummy = GUICtrlSetBkColor(-1, $iColor) + GUICtrlSetCursor(-1, 0) Local $Dummy = GUICtrlSetFont($idWeekDays, 12, -1, -1, 'courier new') + GUICtrlSetFont($idDays, 12, -1, -1, 'courier new') + GUICtrlSetFont($IdDate, 10, 700) ; 'courier new') Local $idPrevMonth = GUICtrlCreateButton('<', 2, 2, 18, 18), $idNextMonth = GUICtrlCreateButton('>', 190, 2, 18, 18) Local $sDaysOfWeek = '', $aDate[3] = [$iYear, $iMonth, $iDay], $aBounds, $aCharPos, $sLine, $s $iYear = 0 For $i = 1 To 7 $sDaysOfWeek &= StringLeft(_DateDayOfWeek($i, $DMW_LOCALE_SHORTNAME), 2) & " " Next $sDaysOfWeek = ($bISO) ? StringMid($sDaysOfWeek, 4) & StringLeft($sDaysOfWeek, 2) : StringLeft($sDaysOfWeek, 20) GUICtrlSetData($idWeekDays, $sDaysOfWeek) Local $sDays = ' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31' GUISetBkColor($iColor) GUISetState(@SW_SHOW) Local $aBounds[2] = [($bISO) ?(_DateToDayOfWeekISO($aDate[0], $aDate[1], 1)) :(_DateToDayOfWeek($aDate[0], $aDate[1], 1)), _DateDaysInMonth($aDate[0], $aDate[1])] While WinActive($hCalendar) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_PRIMARYDOWN $aDate[2] = $s If _DateIsValid($aDate[0] & "/" & $aDate[1] & '/' & $aDate[2]) Then ToolTip('') GUIDelete($hCalendar) Return SetError(0, 0, $aDate) EndIf Case $GUI_EVENT_MOUSEMOVE ; https://www.autoitscript.com/forum/topic/157899-get-text-word-under-the-mouse-pointer/?do=findComment&comment=1145318 ; (portions of code by Malkey) $aCharPos = _GUICtrlEdit_CharFromPos($hDays, _WinAPI_GetMousePosX(True, $hDays), _WinAPI_GetMousePosY(True, $hDays)) $sLine = _GUICtrlEdit_GetLine($hDays, $aCharPos[1]) $aCharPos[0] -= _GUICtrlEdit_LineIndex($hDays, $aCharPos[1]) $s = (StringMid($sLine, $aCharPos[0] + 1, 1) == " ") ? "" : StringRegExpReplace($sLine, "(?s)^.{0," & $aCharPos[0] & "}(?: |^)([^ ]*).*$", "\1") ToolTip(($s = "") ? "" : _DateTimeFormat($aDate[0] & "/" & $aDate[1] & "/" & $s, 2)) Case $idPrevMonth $aDate = StringSplit(_DateAdd('M', -1, $aDate[0] & "/" & $aDate[1] & '/1'), '/', 2) Case $idNextMonth $aDate = StringSplit(_DateAdd('M', +1, $aDate[0] & "/" & $aDate[1] & '/1'), '/', 2) EndSwitch If $iYear <> $aDate[0] Or $iMonth <> $aDate[1] Then $iYear = $aDate[0] $iMonth = $aDate[1] $aBounds[0] = ($bISO) ?(_DateToDayOfWeekISO($aDate[0], $aDate[1], 1)) :(_DateToDayOfWeek($aDate[0], $aDate[1], 1)) $aBounds[1] = _DateDaysInMonth($aDate[0], $aDate[1]) GUICtrlSetData($idDays, StringLeft(StringLeft(StringFormat('%' & 18 & 's', ""), 3 * ($aBounds[0] - 1)) & _ StringTrimRight($sDays, (31 - $aBounds[1]) * 3) & StringFormat('%' & 40 & 's', ""), 126)) GUICtrlSetData($IdDate, _DateToMonth($aDate[1], $DMW_LOCALE_LONGNAME) & " " & $aDate[0]) EndIf ; WEnd GUIDelete($hCalendar) Return SetError(1, 0, 0) EndFunc ;==>_Peek_A_Date
-
Ever had the need to pick a hex value for a color for a GUI or a control? Ever tried to figure out how to get those numbers into your script once you've picked the perfect color? I have come up with an extremely small script, that when compiled and placed in a folder inside the SciTE folder will allow you to quickly select the color you want using the _ChooseColor dialog. It will then paste this color code into your script where you cursor is currently placed. It works with Scite only for now, mainly because it uses ControlSend to paste the value into SciTE's editor window, but can easily be modified to work with any editor by changing the window title and control ID it's sending to. This code will work when compiled and placed into the "Autoit3\Scite\ColorChooser" folder, or wherever you have your installation of SciTE, but has to be in the folder named ColorChooser for the tool code to work, or you'll have to change that yourself. Here's the code for the colorchooser: #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Run_Tidy=y #Tidy_Parameters=/rel #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/so #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Misc.au3> #include <SendMessage.au3> Opt("WinTitleMatchMode", 2) Global $sDefaultColor = 0 Global $iMode = 1 Global Const $WM_COPYDATA = 0x004A If $cmdline[0] > 0 Then $sDefaultColor = $cmdline[1] EndIf If StringLeft($sDefaultColor, 2) <> "0x" Then $iMode = 0 $sDefaultColor = "0x" & $sDefaultColor EndIf $sReturn = _ChooseColor(2, $sDefaultColor, 2) If $sReturn = -1 Then Exit (1) If Not $iMode Then $sReturn = StringMid($sReturn, 3) EndIf _SciTE_InsertText($sReturn) Func _SciTE_InsertText($sString) Return _SciTE_Send_Command(0, WinGetHandle("DirectorExtension"), "insert:" & $sString) EndFunc ;==>_SciTE_InsertText Func _SciTE_Send_Command($hHandle, $hSciTE, $sString) Local $ilParam, $tData If StringStripWS($sString, 8) = "" Then Return SetError(2, 0, 0) ; String is blank. EndIf $sString = ":" & Dec(StringTrimLeft($hHandle, 2)) & ":" & $sString $tData = DllStructCreate("char[" & StringLen($sString) + 1 & "]") ; wchar DllStructSetData($tData, 1, $sString) $ilParam = DllStructCreate("ptr;dword;ptr") ; ulong_ptr;dword;ptr DllStructSetData($ilParam, 1, 1) ; $ilParam, 1, 1 DllStructSetData($ilParam, 2, DllStructGetSize($tData)) DllStructSetData($ilParam, 3, DllStructGetPtr($tData)) _SendMessage($hSciTE, $WM_COPYDATA, $hHandle, DllStructGetPtr($ilParam)) Return Number(Not @error) EndFunc ;==>_SciTE_Send_Command As you can see, there's not a whole lot to it. It just pops open the color chooser dialog, copies the results to the clipboard and then pastes it into SciTE using the ControlSend command. You will also notice, that if you don't choose a color, by hitting cancel in the Color Chooser dialog, it will also exit without pasting anything, so you shouldn't need to worry about pasting something you don't want in your scripts. This code should be added to your SciTEUser.properties file so that you can call it from within SciTE by hitting Ctrl-Alt-C, this can be changed if you already have a hot key set to that combination. # 43 Color Chooser command.name.43.*=Color Chooser command.43.*="$(SciteDefaultHome)\ColorChooser\ColorChooser.exe" $(CurrentSelection) command.shortcut.43.*=Ctrl+Alt+C That's all there is to it, enjoy. EDIT: I have updated the script and the SciTEUser.properties code so that if you have a color code that's currently selected when this is called, it will send that to the _ChooseColor dialog now as the starting color. UPDATED: 31-May-12 I've updated the script so that it now uses the "DirectorExtension" as suggested by guinness instead of copying the data to the clipboard and pasting it into SciTE, which might cause problems with what you have on the clipboard currently. I have also updated it so that if you send the script a color in the format "FFFFFF" without the preceeding "0x", it will return the color code in the same format. This is useful if, for example, you're changing a color in one of SciTE's properties files, which don't start with "0x". I've also changed the command.43.* line, I've moved the quote from the end of the line to the end of the command because I've noticed that a lot of times it causes issues if the color code is inside the quotes.
- 14 replies
-
- Scite extension
- Color
-
(and 2 more)
Tagged with: