PasteColor

If you are currently developing portable freeware or planning to do so, use this forum to discuss technical implementation, seek out like-minded developers for partnership, or solicit interested users for beta testing.
Message
Author
User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: Portable Software that hasn't been developed?

#16 Post by tproli » Thu Sep 06, 2012 10:27 am

Thanks. One thing your IsHexColor function is missing is that there's also 3-digit hex colors, e.g. #40F (= #4400FF).

User avatar
guinness
Posts: 4118
Joined: Mon Aug 27, 2007 2:00 am
Contact:

Re: Portable Software that hasn't been developed?

#17 Post by guinness » Thu Sep 06, 2012 12:30 pm

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
Added 179 Applications: Portable

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: Portable Software that hasn't been developed?

#18 Post by tproli » Thu Sep 06, 2012 12:44 pm

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".

User avatar
guinness
Posts: 4118
Joined: Mon Aug 27, 2007 2:00 am
Contact:

Re: Portable Software that hasn't been developed?

#19 Post by guinness » Thu Sep 06, 2012 1:05 pm

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.
Added 179 Applications: Portable

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: Portable Software that hasn't been developed?

#20 Post by tproli » Thu Sep 06, 2012 1:16 pm

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.

User avatar
guinness
Posts: 4118
Joined: Mon Aug 27, 2007 2:00 am
Contact:

Re: Portable Software that hasn't been developed?

#21 Post by guinness » Thu Sep 06, 2012 11:21 pm

The hash (#) and 0x are optional as you can see from the example(s) I included with the snippet.
Added 179 Applications: Portable

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: Portable Software that hasn't been developed?

#22 Post by tproli » Fri Sep 07, 2012 12:37 pm

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.

User avatar
I am Baas
Posts: 4148
Joined: Thu Aug 07, 2008 4:51 am

Re: Portable Software that hasn't been developed?

#23 Post by I am Baas » Fri Sep 07, 2012 7:29 pm

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.
Bəəs 2.0

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: Portable Software that hasn't been developed?

#24 Post by tproli » Fri Sep 07, 2012 11:37 pm

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.

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: PasteColor

#25 Post by tproli » Sun Sep 09, 2012 1:47 am

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

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: PasteColor

#26 Post by tproli » Sun Sep 09, 2012 1:57 pm

Just switched from Send() to ControlSend() (and ControlGetText and ControlSetText) and its now super fast! :)

Download link updated.

User avatar
guinness
Posts: 4118
Joined: Mon Aug 27, 2007 2:00 am
Contact:

Re: PasteColor

#27 Post by guinness » Sun Sep 09, 2012 3:00 pm

I had a quick look today and was going to say Send will get you into a lot of trouble.
Added 179 Applications: Portable

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: PasteColor

#28 Post by tproli » Mon Sep 10, 2012 4:31 am

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.

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: PasteColor

#29 Post by tproli » Tue Sep 11, 2012 6:01 am

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

User avatar
tproli
Posts: 1172
Joined: Sat Sep 09, 2006 10:14 am
Location: Hungary
Contact:

Re: PasteColor

#30 Post by tproli » Wed Sep 12, 2012 2:04 am

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.

Post Reply