Skip to content

Commit

Permalink
Merge pull request #69 from weslly/win_colorpicker
Browse files Browse the repository at this point in the history
Better color picker for windows
  • Loading branch information
weslly committed Mar 8, 2015
2 parents c6bda2a + 0eced2b commit 49cf63c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion ColorPicker.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
// For upper-case output (#ABCDEF), set "color_upper_case" to true
// For lower-case (#abcdef), use false
"color_upper_case": true
"color_upper_case": true,

// Set false to use the default windows colorpicker
"win_use_new_picker": true
}
Binary file added lib/win_colorpicker.exe
Binary file not shown.
23 changes: 18 additions & 5 deletions sublimecp.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class ColorPicker(object):
def pick(self, window, starting_color=None):
start_color = None
start_color_osx = None
win_use_new_picker = False

if starting_color is not None:
svg_color_hex = self.SVGColors.get(starting_color, None)
Expand All @@ -292,25 +293,35 @@ def pick(self, window, starting_color=None):
start_color_osx = starting_color

if sublime.platform() == 'windows':
color = win_pick(window, start_color)
s = sublime.load_settings("ColorPicker.sublime-settings")
win_use_new_picker = s.get('win_use_new_picker', True)
if win_use_new_picker:
args = [os.path.join(sublime.packages_path(), binpath)]
if start_color:
args.append(start_color)
else:
color = win_pick(window, start_color)

elif sublime.platform() == 'osx':
args = [os.path.join(sublime.packages_path(), binpath)]
if start_color_osx:
args.append('-startColor')
args.append(start_color_osx)

else:
args = [os.path.join(sublime.packages_path(), binpath)]
if start_color:
args.append(start_color)

if sublime.platform() != 'windows':
if sublime.platform() != "windows" or win_use_new_picker:
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
color = proc.communicate()[0].strip()

if color:
if sublime.platform() != 'windows' or sublime_version == 2:
if (
sublime.platform() != 'windows' or
win_use_new_picker or
sublime_version == 2
):
color = color.decode('utf-8')

return color
Expand Down Expand Up @@ -379,8 +390,10 @@ def run(self, edit):
libdir = os.path.join('ColorPicker', 'lib')
if sublime.platform() == 'osx':
binpath = os.path.join(libdir, 'osx_colorpicker')
else:
elif sublime.platform() == 'linux':
binpath = os.path.join(libdir, 'linux_colorpicker.py')
else:
binpath = os.path.join(libdir, 'win_colorpicker.exe')


def plugin_loaded():
Expand Down

0 comments on commit 49cf63c

Please sign in to comment.