Home Download Buy Blog Forum Support

Color Picker for Windows

Re: Color Picker for Windows

Postby decagrog on Mon Mar 04, 2013 3:38 pm

There is a way to call a third part color picker?
I found this plugin pretty userful but the standard windows color picker is awful an pretty useless! :cry:
Some basic functionality that I miss are input an hex code and see the color or target something on the screen and pick the color...for example a good picker program that I use is Pixeur, it would be perfect be able to override the default windows picker and open that one.
decagrog
 
Posts: 2
Joined: Mon Mar 04, 2013 3:28 pm

Re: Color Picker for Windows

Postby facelessuser on Mon Mar 04, 2013 5:35 pm

Yes it is very possible. I have done a test to show it is possible. In this example I have simply used a local python on my machine with WxPython installed, and grabbed the 3rd party python color picker dialog from http://xoomer.virgilio.it/infinity77/AG ... ialog.html called CubeColourDialog. I created a simple program that provides the CubeColourDialog Gui based off a demo they had posted:

color_test.png
color_test.png (171.76 KiB) Viewed 1641 times


import wx
import wx.lib.agw.cubecolourdialog as CCD
import json

# Our normal wxApp-derived class, as usual
app = wx.App(0)

colourData = wx.ColourData()
dlg = CCD.CubeColourDialog(None, colourData)

if dlg.ShowModal() == wx.ID_OK:

# If the user selected OK, then the dialog's wx.ColourData will
# contain valid information. Fetch the data ...
colourData = dlg.GetColourData()
h, s, v, a = dlg.GetHSVAColour()

# ... then do something with it. The actual colour data will be
# returned as a three-tuple (r, g, b) in this particular case.
colour = colourData.GetColour()
r, g, b, alpha = colour.Red(), colour.Green(), colour.Blue(), colour.Alpha()
colors = {
"rgba": (r, g, b, alpha),
"hsva": (h, s, v, a)
}
print json.dumps(colors)
else:
print "{}"

# Once the dialog is destroyed, Mr. wx.ColourData is no longer your
# friend. Don't use it again!
dlg.Destroy()

app.MainLoop()




I compiled it as an EXE with pyinstaller http://www.pyinstaller.org/ and then accessed the executable via a sublime plugin and output the result in the debug panel.

import sublime
import sublime_plugin
import subprocess as sp
import os.path as path
import json


def check_output(command):
process = sp.Popen(command, shell=True, stdout=sp.PIPE, stderr=sp.STDOUT, universal_newlines=True)
output = process.communicate()
retcode = process.poll()
if retcode:
raise(sp.CalledProcessError(retcode, command, output=output[0]))
return output[0]


class ColorTestCommand(sublime_plugin.TextCommand):
def run(self, edit):
print("ColorTest: Custom Color Dialog Feasibility Demo")
cmd = path.join(sublime.packages_path(), "ColorTest", "clr_pick.exe")
colors = json.loads(check_output(cmd))
if "rgba" in colors and "hsva" in colors:
print("ColorTest (rgba): r=%d, g=%d, b=%d, a=%d" % tuple(colors["rgba"]))
print("ColorTest (hsva): h=%d, s=%d, v=%d, a=%d" % tuple(colors["hsva"]))
else:
print("No color selected!")



Results:
Code: Select all
>>> sublime.active_window().active_view().run_command("color_test")
ColorTest: Custom Color Dialog Feasibility Demo
ColorTest (rgba): r=67, g=188, b=117, a=255
ColorTest (hsva): h=145, s=163, v=188, a=255


It would be better if I threaded this and the dialog is a little buggy, but this shows you can create your own custom dialogs etc. and access them from sublime. You don't have to create the executable in python like I did, but this just shows you can create your own custom gui to do stuff. I think this is an untapped approach that developers could really do some neat stuff with.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Re: Color Picker for Windows

Postby decagrog on Wed Mar 06, 2013 10:45 am

thanks for the explanation facelessuser, i've managed to set my favourite picker in the plugin :)
decagrog
 
Posts: 2
Joined: Mon Mar 04, 2013 3:28 pm

Re: Color Picker for Windows

Postby facelessuser on Wed Mar 06, 2013 3:57 pm

Glad I could help.
facelessuser
 
Posts: 1576
Joined: Tue Apr 05, 2011 7:38 pm

Previous

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 7 guests