Sublime Forum

Color picker - color insertion

#5

Yup,

+1 !

It would help with these enormous CSS files i have been working on.

Thanks !

0 Likes

#6

If I could get Tkinter and tkColorChoose to import properly, I think this will do exactly what everyone is after!

[code]import sublime, sublime_plugin
from Tkinter import *
from tkColorChooser import askcolor

class ColorPicker(sublime_plugin.WindowCommand):
def run(self):
getBgColor(self)

def getBgColor(self):
(triple, hexstr) = askColor()
if hexstr:
try:
if self.window.active_view():
self.window.active_view().run_command(“insert_hex”, {“hex” : hexstr})
except ValueError:
pass

class InsertHex(sublime_plugin.TextCommand):
def run(self, edit, hex):
self.view.replace(edit, region, str(hex))[/code]
Running getBgColor() without the Sublime functions produces the color picker, but as soon as it becomes a plugin, the module is no longer imported :frowning:

Edit: Fixed indent issue, but still no Tkinter import :frowning:

0 Likes

#7

The Tkinter modules aren’t included in the version of Python distributed with Sublime Text to save on download size - I assumed no one would want to use it :slight_smile:

0 Likes

#8

If that Tkinter code works as advertised, I’d gladly take a slightly heavier binary. Having a color chooser available would be a huge help in editing CSS in ST2.

0 Likes

#9

Is it possible to provide an additional download that could add Tkinter to the default install (maybe with a sublime-package file)? I personally have no need for a colour picker but would appreciate having Tkinter available for other plugins

0 Likes

#10

Please, please, oh please include Tkinter!

The things we could make from it would be amazing!

I desperately need a colour picker and my plugin would be final with Tkinter installed.

0 Likes

#11

I’d need to fix the colour code insertion since I gave up when I found out Tkinter isn’t included.

But it would take two minutes to fix it :smile:

0 Likes

#12

Any word on this, after purchasing this is probably the one thing that gave me frowny face :frowning:

0 Likes

#13

I emailed Jon about getting Tkinter installed into Sublime (manually) but after half an hour I couldn’t get it to work. Too many dependencies. And I’m not a Python developer by trade :smile:

0 Likes

#14

thanks for the update! cut and paste from a colorpicker it is then :frowning:

0 Likes

#15

I’ve tried again, but I got nowhere :frowning:

0 Likes

#16

[quote=“jbrooksuk”]

I emailed Jon about getting Tkinter installed into Sublime (manually) but after half an hour I couldn’t get it to work. Too many dependencies. And I’m not a Python developer by trade :smile:[/quote]

If you have a standard Python installation on you computer, why not directly calling a colorpicker from it ?
Look at Python2x\Tools\pynche\pyColorChooser.py for an example.
You could make a plugin that call the colorpicker and get the value back using stdout output (print) or clipboard.

Note that any colorpicker software that could copy the result to the clipboard work for this task.

0 Likes

#17

+1ing this. A huge feature for me. I’m using Sublime on linux.

0 Likes

#18

i think a colour pallet would be great

something similar to text mate for the mac, so could have transparent background etc would look great!!

0 Likes

#19

No color picker, but this is semi-related and pretty handy:

0 Likes

#20

I uploaded my plugin to GitHub, so you can install it with the Package Manager plugin by wbond.

Every now and then I still play around with the Tkinter stuff and an actual color picker. Shame it doesn’t always work.

0 Likes

#21

Somebody might want to play with this.

I keep getting this error:

Reloading plugin C:\Users\James.Brooks\AppData\Roaming\Sublime Text 2\Packages\Color Picker\color_picker.py Traceback (most recent call last): File ".\sublime_plugin.py", line 61, in reload_plugin File ".\color_picker.py", line 3, in <module> import Tkinter File ".\Tkinter.py", line 39, in <module> import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter

Directions from Jon:

[code]* Copying _tkinter.pyd (and perhaps the tcl*.dll and tk*.dll) files from C:\Python26\DLLs to C:\Program Files\Sublime Text 2 (making sure you’re copying from the 64 bit version of Python if you’re using the 64 bit version of Sublime Text 2

  • Copying C:\Python26\lib\lib-tk to your package directory, so that it’ll be found when you import the modules.[/code]

Unpack this Zip into your Packages directory. If someone can get this to work you’ll be a leg-end.

0 Likes

#22

I Made a plugin that does pretty much what TextMate did

check out github.com/jnordberg/sublime-colorpick

0 Likes

#23

Looks pretty sweet!
Two things:
I had to change line 17 from:

args = [path.join(sublime.packages_path(), 'ColorPick', 'bin', 'colorpick')]
to

args = [path.join(sublime.packages_path(), 'sublime-colorpick', 'bin', 'colorpick')]
because the default folder name when you check out the repo is the repo name,
and I had to chmod +x the colorpick binary.

0 Likes

#24

Works great. One thing I noticed though: when the color panel is open, Sublime seems to stall until I close the colorpicker (gives me the SBBOD…) Other than that its seems great.

0 Likes