Sublime Forum

Color Picker Tooltip

#1

I’ve created a proof-of-concept for a color picker tooltip plugin I’ve been thinking about creating. It’s far from perfect and currently only works with CSS files and hex color codes (plan to expand this in the future), but I figured I would post what I have to get feed back from the community.

The plugin will scan the current CSS file that is active and create an index of the hex colors in the file. It will order the color list based on the number of times the color is used in the file and when the tooltip is displayed it will create a clickable list of color swatches relative to the current file. I plan to expand this to include all files in the project as well as allow the user to exclude files/folders from the indexing process.

It’s not part of the package control repo yet so you will need to download and install the plugin manually. You can get it here: https://github.com/huot25/SmartColorPicker

Please feel free to send any feedback or post any issues/suggestions to github.

0 Likes

Colortip
Colortip
#2

Come on, you gotta post some screencaps :smile:.

0 Likes

#3

If we were on Discourse, i would give you a +1 :mrgreen:

0 Likes

#4

Looks like a neat plugin. What I would suggest, is to not include keymaps, but instead include example keymaps. I almost always throw out plugins that force keymaps as they often conflict with other keymaps I use. There is almost no way to tell what keymaps a person uses, so including keymaps usually messes things up for a certain percentage of your users. The very rare case is when some shortcuts are bound with very specific context.

0 Likes

#5

I’'ll be getting a few screen shots at some-point today. The computer I posted that message from didn’t have photoshop to crop the images nicely.

I agree with not mapping the keys. I did it in this case so that it was an easy install and test scenario but I’ll be removing those one I post the package to package control.

0 Likes

#6

Now all we need is a proper color picker.

0 Likes

#7

I see you started to work on something similar with your Colortip plugin. I like how you handled opening the tooltip so I’ve implemented something similar in my plugin. Plus I’ve added a photo.

Once we get background colors on inline elements I plan to improve this quite a bit.

0 Likes

#8

Thanks, I find it way more natural to have the colours appear instantly. I’ve made mine go horizontal too, but it scrolls if too many.

0 Likes

#9

Just updated the plugin so it now scans all contents of the project and generates a list of css colors. Working on allowing the user to add primary and secondary colors to a project which will appear at the top of the color list.

When I work on a web project I often mock up the design in photoshop with a specific color palette in mind. I figured if a developer has that workflow they will want to import those colors and have those displayed prominently in the color picker. The first line in the photo displayed above displays this concept.

Eventually I would like to allow importing of .ase files to make it easier to load a defined color palette.

Once we get access to inline elements taking background colors, I am going to adjust the styling of the tooltip so it is much cleaner.

0 Likes

#10

Instead of having two plugins doing the exactly same thing, why you don’t join forces to make something greater? :wink:

0 Likes

#11

They achieve different things though :smile:

0 Likes

#12

I’ve just added the ability to assign project colors to this plugin, which I have named “Smart Color Picker”. The idea was to allow developers to assign project colors based on a color palette that was established during initial designs. These project colors will display above any indexed colors found through out the project and would not be included in the indexing process. This is not a polished plugin, so you may see some bugs in the current version, but feedback is always welcome.

Evenutally I will try to include the ability to import .ase files which can be downloaded from Adobe Kuler or generated from Adobe products to make this process easier, but this may be a version 1.1 feature.

Download the latest version or report issues at https://github.com/huot25/SmartColorPicker

0 Likes

#13

Just added include/exclude file and folder options to the side bar and active view’s context menu. All files and folders are included by default.

In addition to the include/exclude I have added some validation on the project color input. I will probably add scope limitations to limit when the plugin is activated and that will become the initial release on package control.

Download the lastest build at https://github.com/huot25/SmartColorPicker

0 Likes

#14

Hey, so I gave your plugin a try, and I think there are a couple of issues you should be aware of:

  1. You are reading all of the files in your project as bytes, but then you try to decode them with the default decoder (which I think is ascii). Files may be in UTF-8 and have characters you can’t decode. I would advise providing your regex string as bytes as well maybe and not decoding the file content and then decode the matches you normalize, as by then all of the match strings can be decoded as they are of the form #334aff. Maybe in your project you didn’t have problematic files, but in some of mine, the indexer bombed.

[code]HEX_REGEX = b"#[a-f0-9]{3}(?:[a-f0-9]{3})?"

def normalize_color(color):
color = color.decode()
if (len(color) < 5):
c = “#”
for char in color.lstrip("#"):
c += char +char

	color = c

return color.upper()

def scan_files(self, files):
global HEX_REGEX
matches = ]
for file in files:
file_matches = ]
with open(file, “r+b”) as f:
mm = mmap.mmap(f.fileno(), 0)
mm.seek(0)
file_matches = re.findall(HEX_REGEX, mm.read())[/code]

  1. The way you are searching the projects is killing performance. If you are going to index, it has to be non-blocking and off the main thread. I haven’t looked at that part of the code. I see you are using a thread, so maybe you are attempted to not impact performance, but in my case, it appears it is not working. Maybe I need to filter files; I don’t know. Out of the box, everything slowed down. For instance, I have a project that has my sublime Packages folder with all of my plugins and such (it makes it easy to jump around working between different plugins), but I can barely type with your plugin enabled. I don’t know if you want to rethink your approach or not, but I simply can’t use this plugin with its current performance hits.

Performance is going to kill people adopting your plugin unless they all have really small projects, and if you are blindly decoding files, the indexer is going to bomb making it unusable as well.

0 Likes

#15

An aside, I know I mentioned earlier about generating images. Maybe it seems too complicated, or maybe you decided to go another route (which is fine). But if you are interested, and just need help, it can be implemented pretty easily and I wouldn’t mind assisting. The results look pretty good:

No worries though if this isn’t what you are going for.

0 Likes

#16

[quote=“facelessuser”]An aside, I know I mentioned earlier about generating images. Maybe it seems too complicated, or maybe you decided to go another route (which is fine). But if you are interested, and just need help, it can be implemented pretty easily and I wouldn’t mind assisting. The results look pretty good:

No worries though if this isn’t what you are going for.[/quote]

HOT DAMN!

0 Likes

#17

[quote=“jbrooksuk”]
HOT DAMN![/quote]

You guys have awakened an idea in me, and I have been playing around. That was really just a visualization test, but I am all about sharing the tech behind it with the community to help with their ideas :wink:.

0 Likes

#18

I modified what you had suggested. I am using the normalize function with the project colors which are strings in my latest check-in and I wanted to leave these as strings so they could be modified/added to the project file manually. I did convert the regex to bytes and I am only decoding the matched colors instead of decoding everything. Good call on this!

I tested this using a very large project that I had available and I did see the performance hit you mentioned. I will rework the indexer as the way that it is now doesn’t really make much sense. I’d like to get your option on what I have in mind if you don’t mind.

I was thinking of turning the indexer process into a global object and threaded process vs the instances I have in place now. I think some of the performance problems are coming from creating an instance of the indexer when each event listener is fired (very bad idea). Instead I want to create two separate pieces. The color collection which will be the global object and a separate indexer process which will be threaded.

I was planning on changing from indexing all appropriate files and getting a count for each color (to order the colors by frequency), to indexing each file and color found within the file. This way I can re-index a specific file on save and that will update that entry without affecting the other entries in the index. I would also have a project wide indexer which would run on plugin_load and on a timed interval to handle files added/modified outside of Sublime. Of course each process would be threaded to reduce the impact on performance.

I plan to try to do this within the next couple of days, but I have very limited time-frames when I can work on this as I have a 2 ½ year old and a 4 month old. That’s no excuse for the poor job I did architecting the indexer :stuck_out_tongue:, but just letting you know if it takes a bit for me to get to things.

0 Likes

#19

[quote=“facelessuser”]An aside, I know I mentioned earlier about generating images. Maybe it seems too complicated, or maybe you decided to go another route (which is fine). But if you are interested, and just need help, it can be implemented pretty easily and I wouldn’t mind assisting. The results look pretty good:

No worries though if this isn’t what you are going for.[/quote]

As for the screen shots you mocked-up, those look amazing. They are exactly what I was trying to achieve with html and css. I wanted to play around with the pypng library, but you beat me to it which is great! If you want to post the code you used to mock up the photos or create a pull request I would be more than happy to work your solution into the color picker. Another solution would be to create a “library” plugin and developers could include your library as a dependency for their plugin. I think @jbrooksuk might be able to make use of your color image code as well!

That’s why I love working with communities that are passionate about the product they are developing. You find developers who are willing to contribute and often times offer valuable feedback and solutions.

0 Likes

#20

There are a number of things I am playing around with, so things are in flux. For now, I will issue a pull request, and maybe later I will post my playground with some of the other things I am experimenting with.

0 Likes