Permalink
Browse files

Fixed dir name AND now start picker with selected color

  • Loading branch information...
1 parent 2ff2d95 commit e4e5d64be4a5b307e2c95c4228e6bd2eeea1a40f @icetbr committed Nov 16, 2011
Showing with 24 additions and 3 deletions.
  1. +22 −3 color_picker.py
  2. +2 −0 getcolor.ps1
View
@@ -2,14 +2,33 @@
import subprocess, os
import _winreg as winreg
+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 ShowColorPickerCommand(sublime_plugin.TextCommand):
def run(self,edit):
- color_picker_dir = sublime.packages_path() + '\\Color Picker'
-
+ view = self.view
+ sel = view.sel()
+ start_color = "#0"
+
+ # 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
+
+ color_picker_dir = sublime.packages_path() + '\\ST2-Color-Picker'
+
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
- process = subprocess.Popen(['powershell.exe', '-NonInteractive', '-noprofile', '-file', color_picker_dir + '\\getcolor.ps1'], shell=False, stdout=subprocess.PIPE, startupinfo=startupinfo)
+ process = subprocess.Popen(['powershell.exe', '-NonInteractive', '-noprofile', '-file', color_picker_dir + '\\getcolor.ps1', start_color], shell=False, stdout=subprocess.PIPE, startupinfo=startupinfo)
process.poll()
output = process.communicate()[0]
View
@@ -1,7 +1,9 @@
+param( $start_color )
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$ColorDialog = New-Object System.Windows.Forms.ColorDialog
+$ColorDialog.Color = $start_color;
$ColorDialog.FullOpen = 1;
$ret = $ColorDialog.ShowDialog()

0 comments on commit e4e5d64

Please sign in to comment.