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

    • TrashBoat
      By TrashBoat
      I've messed around in scite theme settings and it left this blue bar , how can i get rid of it?
      Image (imgur)
       

    • rudi
      By rudi
      Hello,
      very propably this has been asked before, well, I miss the thread(s) ...
      Is there a command line switch to tell the SciTE setup EXE to install silently ("/S") *AND* to end up with "edit" (instead of "run") as system wide default action for *.au3 files?
       

       
      As it can be done with the config tool:
      https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/SciTEConfigb1.PNG
       
      Regards, Rudi.
    • tremolux66
      By tremolux66
      I use a monospace font for editing AutoIt scripts in SciTE (currently, CourierNew 9pt). Regardless of what font size I set in the configuration, when I start SciTE to resume editing the script text is one size smaller than I specified. When I type Ctrl+<numpad-slash> the text changes to the desired size. The same is true of the output pane, and I have to reset the size for both areas every time I start SciTE.
      IIRC, I've made few other changes to the configuration (e.g., changed the search highlight color and disabled Tidy), so this behavior seems odd. About SciTE says it's version 3.6.0 (Aug. 4, 2015).
      Any idea how to fix this?
    • user4157124
      By user4157124
      As they're opinion-based to some degree; how are AutoIt's best practices decided and do suggestions get considered?
      Some suggestions :
      For...To...Step...Next -loop variable-naming like $iN ($i1, $i2, etc.) : conforms to recommended naming convention, identifies level (albeit inverted to ExitLoop and ContinueLoop's convention) and enables SciTE selection-highlighting (requires minimum of 3 characters). Minimize logic in global scope, separate data & settings from logic, use of vertical space, project organization (folder structure, resource- and include file management). Example (loop variable-naming, minimizing logic in global scope and separation of settings from logic) :
      #include <Array.au3> Global Enum $RANDOM_RETURNFLOAT, _ $RANDOM_RETURNINTEGER Global Enum $EXITCODE_NONE Global Const $g_sChar0 = '-' Global Const $g_sChar1 = '+' Global Const $g_iAmountX = 10 Global Const $g_iAmountY = $g_iAmountX Main() Func Main() Local $aArray[$g_iAmountY][$g_iAmountX] For $i1 = 0 To $g_iAmountY - 1 For $i2 = 0 To $g_iAmountX - 1 $aArray[$i1][$i2] = Random(0, 1, $RANDOM_RETURNINTEGER) ? $g_sChar1 : $g_sChar0 Next Next _ArrayDisplay($aArray) Exit $EXITCODE_NONE EndFunc Example (project organization) :
      + project_folder + bak [backup files] + bin [distributed binaries and dependencies] + inc [non-standard include files] + res [resource files (icons, file+install files, etc.)] + usr [configuration files, databases, etc.] - script.au3 - script.exe Example (use of vertical space) :
      Func _DigitalRoot($iNum) Local $sNum = '' Local $aNum While $iNum > 9 $sNum = String($iNum) $aNum = StringSplit($sNum, '') $iNum = 0 For $i1 = 1 To $aNum[0] $iNum += Int($aNum[$i1]) Next WEnd Return $iNum EndFunc
    • wimhek
      By wimhek
      LS
      Is it possible to open file(s) in scite in read only mode ?
      If so, How ?
       
      Thnx