-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a622b41
Showing
5 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
{ "keys": ["ctrl+shift+c"], "command": "color_pick" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# sublime-colorpicker | ||
|
||
Color picker plugin for Sublime Text 2 (Linux) using pygtk color selection dialog. | ||
|
||
![Example](http://i.minus.com/ihwLvn8m29GxZ.png "Example") | ||
|
||
Source for the original colorpicker plugin for OSX can be found at https://github.com/jnordberg/sublime-colorpick/ | ||
|
||
## installation | ||
|
||
cd ~/.config/sublime-text-2/Packages | ||
git clone git://github.com/weslly/sublime-colorpicker.git ColorPicker | ||
|
||
It's important that you check out the repo as ColorPicker as the plugin will look for the color picker script in `<sublime packages dir>/ColorPicker/colorchooser.py` | ||
|
||
## usage | ||
|
||
`ctrl+shift+c` to insert or change a selected color |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
import pygtk | ||
pygtk.require('2.0') | ||
import gtk | ||
import sys | ||
|
||
color_sel = gtk.ColorSelectionDialog("Sublime Color Picker") | ||
|
||
if len(sys.argv) > 1: | ||
if gtk.gdk.Color(sys.argv[1]): | ||
color_sel.colorsel.set_current_color(gtk.gdk.Color(sys.argv[1])) | ||
|
||
if color_sel.run() == gtk.RESPONSE_OK: | ||
color = color_sel.colorsel.get_current_color() | ||
#Convert to 8bit channels | ||
red = color.red / 256 | ||
green = color.green / 256 | ||
blue = color.blue / 256 | ||
#Convert to hexa strings | ||
red = str(hex(red))[2:] | ||
green = str(hex(green))[2:] | ||
blue = str(hex(blue))[2:] | ||
#Format | ||
if len(red) == 1: | ||
red = "0%s" % red | ||
if len(green) == 1: | ||
green = "0%s" % green | ||
if len(blue) == 1: | ||
blue = "0%s" % blue | ||
|
||
finalcolor = red+green+blue | ||
print finalcolor.upper() | ||
|
||
color_sel.destroy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import sublime | ||
import sublime_plugin | ||
from os import path | ||
import subprocess | ||
|
||
def is_valid_hex_color(s): | ||
if len(s) not in (3, 6): | ||
return False | ||
try: | ||
return 0 <= int(s, 16) <= 0xffffff | ||
except ValueError: | ||
return False | ||
|
||
class ColorPickCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
view = self.view | ||
sel = view.sel() | ||
start_color = None | ||
|
||
# get the currently selected color - if any | ||
if len(sel) > 0: | ||
selected = view.substr(view.word(sel[0])).strip() | ||
if selected.startswith('#'): selected = selected[1:] | ||
if is_valid_hex_color(selected): | ||
start_color = "#"+selected | ||
|
||
# get new color from picker | ||
args = [path.join(sublime.packages_path(), 'ColorPicker', 'colorchooser.py')] | ||
if start_color: | ||
args.append(start_color) | ||
|
||
proc = subprocess.Popen(args, stdout=subprocess.PIPE) | ||
color = proc.communicate()[0].strip() | ||
|
||
if color: | ||
# replace all regions with color | ||
for region in sel: | ||
word = view.word(region) | ||
# if the selected word is a valid color, replace it | ||
if is_valid_hex_color(view.substr(word)): | ||
# include '#' if present | ||
if view.substr(word.a - 1) == '#': | ||
word = sublime.Region(word.a - 1, word.b) | ||
# replace | ||
self.view.replace(edit, word, '#' + color) | ||
# otherwise just replace the selected region | ||
else: | ||
self.view.replace(edit, region, '#' + color) |