BugFix

SciTE - show hex color value in the script

5 posts in this topic

#1 ·  Posted (edited)

Hi,

I think, you all know this: You look at a script containing color values. You have a rough idea of the colors, but would like to know how it looks like. 
I have created a Lua script that displays the color of the value in SciTE as Calltip. Set the cursor in the Hex-value, press the hotkey. Above the value a Call tip appears. The background color corresponds to the hex value.

Read the function header to obtain installation instructions.

So it looks.  calltip_col.thumb.png.f994c28320ec14bc38

EDIT:
I think it's better to bind the function not only of AutoIt. If it can be called in all files, also the color settings in the * .properties can view. For this purpose remove the file attachment from the call. Use: command.13.*=  instead of: command.13.*.au3=

 

EDIT 20.07.2015:
Now I've made some changes
- You can switch to show colors as RGB or BGR
- added new function: PreviewBackForeColor
To have a preview for back and fore color:
- Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR
  have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)".
  If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true"
- No other color value may be included in this line. If any - the first and second color will used.
- Set the cursor in this line and hit the Hotkey.
- A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value.
- If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color.
  In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0"

Because you've different functions in one script, you need another way to install and call it. Read the instructions inside the script.

First color used as back color, second as fore color.

 preview_colors_1.thumb.jpg.e7e37266b1755

Function called with flag - first color is now the fore color.

 preview_colors_1_reverse.thumb.jpg.17d6f

preview_colors_2.thumb.jpg.6466eca72d2b5

-- TIME_STAMP   2015-07-20 17:41:16   v 0.3


--[[
Save the file.
At first, make an entry in your SciTEStartup.lua

LoadLuaFile("ShowHexColorFromCursor.lua", "C:\\Your Path\\with Backslash\\")

]]




--[[
Select free command-numbers from your SciTEUser.properties.
Customize the following settings with this numbers.


# 13 Show HexColor RGB
command.name.13.*=Show RGB-Color From Cursor
command.13.*=dostring ShowHexColorFromCursor()
command.mode.13.*=subsystem:lua
command.shortcut.13.*=Ctrl+Shift+F11

# 14 Show HexColor BGR
command.name.14.*=Show BGR-Color From Cursor
command.14.*=dostring ShowHexColorFromCursor(true)
command.mode.14.*=subsystem:lua
command.shortcut.14.*=Ctrl+Alt+F11


Set the cursor in the Hex-value, press the hotkey to show the color as RGB or as BGR.
Above the value a Call tip appears. The background color corresponds to the hex value.
A possible alpha component is ignored.

Be recognized AutoIt hex color code "0x12AB34" and also HTML hex color code "#12AB34".
]]

function ShowHexColorFromCursor(_fBGR)
    local iLen = 8
    local function isHexChar(_asc)
        local sChar = string.char(_asc)
        if sChar == '#' then iLen = 7 end
        if sChar:find('[#x0-9a-fA-F]') then return true else return false end
    end
    local cursor = editor.CurrentPos
    local beginPos, endPos = cursor, cursor
    local pattHex2 = '[0-9a-fA-F][0-9a-fA-F]'
    while isHexChar(editor.CharAt[beginPos-1]) do
        beginPos = beginPos - 1
    end
    while isHexChar(editor.CharAt[endPos]) do
        endPos = endPos + 1
    end
    if beginPos ~= endPos then
        if endPos - beginPos > iLen then
            editor:SetSelection(beginPos + iLen, beginPos)
        elseif endPos - beginPos == iLen then
            editor:SetSelection(endPos, beginPos)
        else
            return
        end
        local R,G,B = tostring(editor:GetSelText()):match('('..pattHex2..')('..pattHex2..')('..pattHex2..')$')
        scite.SendEditor(SCI_CALLTIPSHOW, beginPos, (' '):rep(iLen))
        scite.SendEditor(SCI_CALLTIPSETHLT, 0, iLen)
        if _fBGR == true then
            scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', R,G,B)))
        else
            scite.SendEditor(SCI_CALLTIPSETBACK, tonumber(string.format('0x%s%s%s', B,G,R)))
        end
    end
end


--[[
To have a preview for back and fore color:
- Write in one line first the back color, than the fore color (i. e. as comment: "; 0xDEDEDE 0x000080") OR
  have this values inside a function call: "_AnyFunction($param1, $param2, 0xDEDEDE, $param3 0x000080)".
  If the order inside the call is reverse (first hex value is fore color), you can call the function with Flag "_fFore1st=true"
- No other color value may be included in this line. If any - the first and second color will used.
- Set the cursor in this line and hit the Hotkey.
- A Calltip appears with the back color and the text "FORE-COLOR" with color of the fore value.
- If only one color value was find in this line, this value will used as back color or, if Flag is "true", as fore color.
  In this cases the fore color is set to black and with Flag the back color is the default GUI back color "0xF0F0F0"

For use with AutoIt color values only.

To have both calls (w/wo flag) make two commands:

# 11 Preview Back and Fore Color / first color value is back color
command.name.11.*.au3=Preview Back and Fore Color
command.11.*.au3=dostring PreviewBackForeColor()
command.mode.11.*.au3=subsystem:lua,savebefore:no
command.shortcut.11.*.au3=Ctrl+Shift+F12

# 16 Preview Fore and Back Color / first color value is fore color
command.name.16.*.au3=Preview Fore and Back Color
command.16.*.au3=dostring PreviewBackForeColor(true)
command.mode.16.*.au3=subsystem:lua,savebefore:no
command.shortcut.16.*.au3=Ctrl+Alt+F12

]]

function PreviewBackForeColor(_fFore1st)
    local pattHex = '()0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])'
    local iBackCol, iForeCol = 0xF0F0F0, 0x000000
    local cursor = editor.CurrentPos
    local sLine, iColumn = editor:GetCurLine()
    local iLineStartPos = cursor - iColumn
    local tMatch, beginPos = {}, nil
    for s, r, g, b in sLine:gmatch(pattHex) do
        if beginPos == nil then beginPos = s end
        local t = {} t['R']=r t['G']=g t['B']=b
        table.insert(tMatch, t)
    end
    if #tMatch == 0 then
        return
    elseif #tMatch == 1 then
        if _fFore1st == true then
            iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
        else
            iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
        end
    else
        if _fFore1st == true then
            iForeCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
            iBackCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R))
        else
            iForeCol = tonumber(string.format('0x%s%s%s', tMatch[2].B, tMatch[2].G, tMatch[2].R))
            iBackCol = tonumber(string.format('0x%s%s%s', tMatch[1].B, tMatch[1].G, tMatch[1].R))
        end
    end
    scite.SendEditor(SCI_CALLTIPSHOW, iLineStartPos + beginPos, ' FORE-COLOR ')
    scite.SendEditor(SCI_CALLTIPSETHLT, 0, 12)
    scite.SendEditor(SCI_CALLTIPSETBACK, iBackCol)
    scite.SendEditor(SCI_CALLTIPSETFOREHLT, iForeCol)
end

 

ShowHexColorFromCursor[0.3].lua

Edited by BugFix
4 people like this

Best Regards BugFix  

Share this post


Link to post
Share on other sites



Very cool


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Now some changes. See first post.

- Display color as RGB or BGR

- New function to have a preview of back and fore color. Useful to test whether color harmony.


Best Regards BugFix  

Share this post


Link to post
Share on other sites

Very usefull.

Thanks for sharing.
 

btw.
Added here: https://www.autoitscript.com/wiki/SciTE4AutoIt3#Useful_Lua_links_and_scripts


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
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

  • Similar Content

    • Hoth2001
      By Hoth2001
      I installed AutoIt to my computer 3 days ago...and have invested the last 3 days learning how to use it.
      As learned in the tutorials, whenever opening I new file in Scite editor I'd immediatley save the file
      I left the Scite Editor open for the past 3 consecutive days on my laptop
       
      No problem
       
      Today I closed Autoit for the first time, restarted my computer, and opened up the Scite Editor
      Now whenever I try to save a file I am prevented from doing so because I apparently don't have permission!?  
      And whenever I try to run any of the programs I've created over the past 3 days now I keep getting annoying popup notifications before I run them
       
      Problem
       
      To go around the issue, I copied a program originally saved in the AUtoIt folder to another folder (since I was barred from saving it in it's original AutoIt location)
      NOw when I run the code the mouse coordiantes are all off
      and I still get that pesky notification whenever I try to run a program
       
      Big Problem!!!
      Anyone have any clue why I'm going through this BS?
       
      1. I checked my User settings and YES I am the administrator on this cpu
      2. I tried to de-select the "read only" attribute for the AutoIt folder (everytime after doing this successfully the folder immediately and automatically reverts back to "read only")
       
      Any help would be MOST appreciated. I've attached screen shots of the annoying bus I keep getting
       
       


    • algiuxas
      By algiuxas
      Hello everybody!
      I get these weird errors in SciTE console:
      [0801/210405:ERROR:tcp_socket_win.cc(335)] bind() returned an error: Only one usage of each socket address (protocol/network address/port) is normally permitted. (0x2740) [0801/210405:ERROR:devtools_http_handler.cc(229)] Cannot start http server for devtools. Stop devtools. [0801/210405:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process. [0801/210405:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process. My script:
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #NoTrayIcon $title = "Hello" $txt = "..." ; TODO: Make 4 of them ;~ #Region ### START Koda GUI section ### Form= ;~ $1_GUI = GUICreate($title, 370, 120, -1, -1) ;~ GUISetBkColor(0xFFFFFF) ;~ $1_B1 = GUICtrlCreateButton("B1", 136, 80, 107, 25) ;~ GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;~ $1_B2 = GUICtrlCreateButton("B2", 248, 80, 107, 25) ;~ GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") ;~ GUICtrlCreateLabel($txt, 16, 24, 338, 52) ;~ GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") ;~ GUICtrlSetColor(-1, 0x000000) ;~ GUISetState(@SW_SHOW) ;~ #EndRegion ### END Koda GUI section ### #Region ### START Koda GUI section ### Form= $2_GUI = GUICreate($title, 370, 0?"Hi :)":120, -1, -1) GUISetBkColor(0xFFFFFF) $2_B1 = GUICtrlCreateButton("B1", 136, 80, 107, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $2_B2 = GUICtrlCreateButton(0?":D":"B2", 248, 80, 107, 25) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlCreateLabel($txt, 16, 24, 338, 52) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $u32dll = DllOpen("user32.dll") ;~ Opt("GUIOnEventMode", 1) ;~ GUICtrlSetOnEvent(-3, "_Exit") ; TODO: Fix, doesn't work with 2 GUI at the same time ;~ GUICtrlSetOnEvent($B11, "_Exit") ;~ GUICtrlSetOnEvent($B21, "_Exit") ;~ GUICtrlSetOnEvent($B12, "_Exit") ;~ GUICtrlSetOnEvent($B22, "_Exit") ;~ $pos1 = WinGetPos($GUI1) ;~ $pos2 = WinGetPos($GUI1) While 1 ;~ $pos1 = WinGetPos($GUI1) ;~ $pos2 = WinGetPos($GUI1) ;~ $x = $pos1[0] - 370 ;~ $y = $pos1[1] ;~ WinMove($GUI2, "", $x, $y, $pos1[2], $pos1[3], 1) ; Press middle mouse button to close (it's gonna be a non malicious prank for my friend) If _IsPressed(4, $u32dll) Then Exit $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() ;~ Case $1_B1 ;~ _Exit() ;~ Case $1_B2 ;~ _Exit() Case $2_B1 _Exit() Case $2_B2 _Exit() EndSwitch WEnd Func _Exit() ; TODO: ... ;~ GUIDelete($1_GUI) GUIDelete($2_GUI) Exit EndFunc ;==>_Exit How to get rid of these errors?
    • Nareshm
      By Nareshm
      I create message box but i dont know how to add button action when i click it.

      Help for : Add script for Button : Left, Right, Right Finger
      example when i press Left finger button do Case $idNotepad
                      $iPID = WinActivate ( " :PS :: Version - 2.8.0.0  - [eFS Bill]")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:btnReset]", "{esc}")
                              ControlClick ( " :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]")
                              ControlSend(" :DS  - eF:: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "^v")
                              ControlSend(" :DS  - eF :: Version - 2.8.0.0  - [eF Bill]", "", "[NAME:txtrdNo]", "{enter}")
      How to add like above ?
                    
                                                                sorry for my bad english
       
    • Altor
      By Altor
      Hi all:
      In Scite it is possible to expand and collapse  all  the #Region at time  with a shortcut ..?
      Now I use the + key to expand and collapse but I can only use this suggestion for a one # Region
      If I collapse all the regions one by one  in order to have the code more understandable when I re-open the script all the regions are expanded and I need to collapse all again one by one.
      Thank.s to all
      Altor
    • corgano
      By corgano
      Edit: A solution was found! Thanks Jos and others who helped me find this:
      You can have AutoIt run a different "Main" autoit script when you hit F5 instead of the current one, per folder, by doing the following:
      Run SciTE (might need administrator, depending on how autoit was installed) Options -> global properties (alt o g) Uncomment properties.directory.enable=1 (line 270 in my case) create a file SciTEDirectory.properties in the project's main folder Alternatively, if you don't have admin or don't want to edit the global.properties for whatever reason, you can just skip step 1,2,3 and name it SciTE.properties Put in the file you created command.go.$(au3)="$(SciteDefaultHome)\..\AutoIt3.exe" "$(SciteDefaultHome)\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "NAME OF SCRIPT HERE.au3" /UserParams $(1) $(2) $(3) $(4) Save the file. Now anything you run in that folder or subfolder will run the main script when you hit F5 Using SciTEDirectory.properties effects that folder and subfolders, where as SciTE.properties only effects that folder. Apart from that they work the same

      Original question:
      I have a main script, and a bunch of includes / udf's. Almost every single time I edit my includes I hit F5 to run the script, but it runs the include instead. I'm tired of switching back to the main script's tab in SciTE to run it, just to switch back to the include. Is there some kind of #flag or option to set a "main au3 file" so when I hit F5, it will see that and run the main file instead?