Page 2 of 6

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 10:27 am
by tproli
Thanks. One thing your IsHexColor function is missing is that there's also 3-digit hex colors, e.g. #40F (= #4400FF).

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 12:30 pm
by guinness
Easy :)

Code: Select all

ConsoleWrite('Return True: ' & _IsHexColor('FF00FF') & @CRLF)
ConsoleWrite('Return False: ' & _IsHexColor('FF00HH') & @CRLF)
ConsoleWrite('Return True: ' & _IsHexColor('0xFF00FF') & @CRLF)
ConsoleWrite('Return False: ' & _IsHexColor('0xFF00HH') & @CRLF)
ConsoleWrite('Return True: ' & _IsHexColor('#FF0000') & @CRLF)
ConsoleWrite('Return False: ' & _IsHexColor('#FF00J0') & @CRLF)
ConsoleWrite('Return False: ' & _IsHexColor('#FF00') & @CRLF)
ConsoleWrite('Return True: ' & _IsHexColor('#FF0') & @CRLF)

; Accepts the following formats:
; 0xFFFFFF
; FFFFFF
; #FFFFFF
Func _IsHexColor($bColor) ; By guinness, Returns True or False.
	Return StringRegExp($bColor, '\b(0x|#)?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b', 0) = 1
EndFunc   ;==>_IsHexColor

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 12:44 pm
by tproli
Thanks. I'm done with the rgb input too but perhaps I will modify it a bit according to your script.

Here is my hex + rgb regex validation for the user input. Wasn't that easy :)

Code: Select all

If StringRegExp($color, '\b[0-9a-fA-F]{6}\b|^(0*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])[, \s]\s*){2}(0*([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])([,]{1})?)\s*$', 0) = 0 Then
        ShowError()
    EndIf
The rgb part accepts leading zeros too, like "120, 245, 00010".

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 1:05 pm
by guinness
RegExp is fun! :mrgreen:

Edit: I will try to shorten it and post the update tomorrow. I enjoy improving my RegExp knowledge as I'm still new to it as you can see.

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 1:16 pm
by tproli
I added 0x0FFFFFF and 0x00FFFFFF color formats for input by adding

Code: Select all

((0x0|0x00){1})?
to the beginning of the regex (+ doing string replace later).

I think I'm done with this, perhaps I will make a new function to copy rgb values from the color picker. That was enough of AutoIt for a while :)

Btw, I just noticed that your regex requires 0x or # in the beginning of the color string. Some applications put html hex values to the clipboard without the hash mark so I made it optional instead.

Re: Portable Software that hasn't been developed?

Posted: Thu Sep 06, 2012 11:21 pm
by guinness
The hash (#) and 0x are optional as you can see from the example(s) I included with the snippet.

Re: Portable Software that hasn't been developed?

Posted: Fri Sep 07, 2012 12:37 pm
by tproli
Sorry, you're right, must have been blind.

Here is the first release of PasteColor:

Image

Changes:
- added RGB input feature
- added copy color from Windows color picker feature (both in RGB and HTML Hex formats)
- input box reappears if invalid color input was entered
- added "/silent" switch to skip input box (clipboard data is used)
- added readme.txt

http://rolandtoth.hu/files/PasteColor.zip

I enjoyed putting this together. It has more features than I planned on start but I think these features greatly improve usability. Because of the way it works and that r-g-b fields are mostly similar in different applications' color pickers, it works almost everywhere. For example I tried in FreeOffice, Photoshop, Microsoft Word, RJ TextEd, etc. Note that Photoshop has an option to copy color in hex format but you cannot copy RGB for example, but you can with PasteColor.

Re: Portable Software that hasn't been developed?

Posted: Fri Sep 07, 2012 7:29 pm
by I am Baas
Nice work there, tproli (& guinness).

A quick comment concerning the readme file, you may want to add a disclaimer re. liability and maybe add a link to the discussion thread on TPFC.

Re: Portable Software that hasn't been developed?

Posted: Fri Sep 07, 2012 11:37 pm
by tproli
Thanks, readme file is updated (link is the same).

I added a feature that allows copy/paste values from arbitrary number of fields. This comes handy for example when copying CMYK color or anywhere where you need to copy/paste values from more than 3 fields. In this case no color conversion is made so it is mainly for copying plain text (e.g. form data).
Commas are used for separators so it will fail if an input field's value also has a comma. As it is not an issue for me I leave it as it is, perhaps I will revisit if someone requests.

Re: PasteColor

Posted: Sun Sep 09, 2012 1:47 am
by tproli
Mods: thanks for the new topic.

Another update:
  • active input field is remembered: if you start PasteColor and switch to another application, PasteColor will paste color to the original color picker (or application) instead of the currently active window.
  • if original color picker (or application) is closed, PasteColor won't paste anything
  • removed systray icon
With saving original window/control handlers enables PasteColor to work in Adobe Illustrator's panels for example.

http://rolandtoth.hu/files/PasteColor.zip

Re: PasteColor

Posted: Sun Sep 09, 2012 1:57 pm
by tproli
Just switched from Send() to ControlSend() (and ControlGetText and ControlSetText) and its now super fast! :)

Download link updated.

Re: PasteColor

Posted: Sun Sep 09, 2012 3:00 pm
by guinness
I had a quick look today and was going to say Send will get you into a lot of trouble.

Re: PasteColor

Posted: Mon Sep 10, 2012 4:31 am
by tproli
Finally I got rid of sending TAB too and making the application even faster. I was testing and I thought it's not working because I saw the cursor not jumping to the next input control. In fact it did but it was too fast.

There's also a caveat. Now I activate the next control with ControlFocus() and in some applications the IDs are not one after the other, e.g. in Illustrator r-g-b is 11, 15, 17. I decided to leave it as it is: it works fine with Windows color picker, which was the main goal. It occassionally works in other applications, e.g. worked fine in Microsoft Word, RJ TextEd.

Re: PasteColor

Posted: Tue Sep 11, 2012 6:01 am
by tproli
It turned out that it is not working on Windows 7. Apparently it has issues on activating the color picker (and perhaps the control also).

If someone could take a look it would be great - I have no machine with Windows 7, unfortunately. AutoIt source is available in the zip:

http://rolandtoth.hu/files/PasteColor.zip

Re: PasteColor

Posted: Wed Sep 12, 2012 2:04 am
by tproli
Nevermind, I've set up a virtualbox to track the issue. Interesting though that the active window (control ID) recognition works fine in XP but not on Win7.