Friday, June 5, 2009

Ubuntu built-in color picker


While using Ubuntu, do You like designing Your own graphics and websites? Yes, playing with color and shapes! And did You ever find trouble when You need to choose certain color —either in CSS or RGB, which can only be found in a certain object; say, from Your desktop or panels?

Cheer up, my friend. Ubuntu will (always) help You.

"..then HOW?".

Well, using "color picker" of course. And, even better, unless You've uninstalled the phyton, there's no need to install any supplementary software: Ubuntu contains it.

At default, the color picker is not accessible from any GUI method. But, thanks to Fingel who has uploaded the script at gnomesupport.org, We can make it!

First, open Your favorite text editor, and write char-per-char exactly as below:


#!/usr/bin/python
import gtk, sys
def tohex(c):
#Convert to hex string
#little hack to fix bug
s = ['#',hex(int(c[0]*256))[2:].zfill(2),hex(int(c[1]*256))[2:].zfill(2),hex(int(c[2]*256))[2:].zfill(2)]
for item in enumerate(s):
if item[1]=='100':
s[item[0]]='ff'
print s
return ''.join(s)
csd = gtk.ColorSelectionDialog('Cool Color Picker')
cs = csd.colorsel
cs.set_has_opacity_control(True)
cs.set_current_alpha(65536)
if csd.run()!=gtk.RESPONSE_OK:
print 'No color selected.'
sys.exit()
c = cs.get_current_color()
print "Color Values:"
print 'red:',c.red
print 'green:',c.green
print 'blue:',c.blue
print 'alpha:',cs.get_current_alpha()
print "Hex Codes:"
print tohex((c.red/65536.0, c.green/65536.0, c.blue/65536.0))


(Alright, You CAN copy-paste..). Save the script, then make it executable:

sudo chmod +x /path/to/script

At this condition, You may try to run the script from terminal.

/path/to/script

Cool,, isn't it?

Now, You can make it more useful. Right-click at Your panel, choose "Add to panel...". At the 'Add to panel' window double-click "Custom Application Launcher". Type your favorite color picker name, then browse to the script location. Click "OK" when Your done.

Now You have a 'Cool Color Picker' just one-click from Your panel!

That's it!



reference:
http://gnomesupport.org/forums/viewtopic.php?t=5077

No comments:

Post a Comment