weslly / ColorPicker

Color picker for Sublime Text
http://weslly.github.io/ColorPicker
511 stars 108 forks source link

Stopped working on selection (Linux) #48

Closed tarpan closed 9 years ago

tarpan commented 10 years ago

I have been using ST2 for a few months and everything worked fine until today. ColorPicker does not show when a hex value is selected. Otherwise it shows up on the usual ctrl+shift+c combination.

m4tm4t commented 10 years ago

Same issue here

efolio commented 10 years ago

Same issue here… although it stopped working at all (even outside selections) a few hours after installing.

De-install / re-install does not fix the issue. Nothing appearing in the console.

Ubuntu - sublime build 3059

LinuCC commented 10 years ago

The problem is in "lib/linux_colorpicker.py", it crashes with the message: Exception:"'gi.repository.Gtk' object has no attribute 'gdk'" Unfortunately, I dont know anything about Gtk and could not find a solution when banging my head on the keyboard. (I had python logging to a file so I could see the Exception, as Ornthalas said nothing appears in the console)

LinuCC commented 10 years ago

Well, I've at least found a working solution, but I am not sure if it breaks compatibility with older versions of pyGtk / Linux:

#!/usr/bin/env python

from gi.repository import Gtk
from gi.repository import Gdk
import sys

color_sel = Gtk.ColorSelectionDialog("Sublime Color Picker")

if len(sys.argv) > 1:
    if Gdk.color_parse(sys.argv[1]):
        color_sel.get_color_selection().set_current_color(Gdk.color_parse(sys.argv[1]))

if color_sel.run() == Gtk.ResponseType.OK:
    color = color_sel.get_color_selection().get_current_color()
    #Convert to 8bit channels
    red = int(color.red / 256)
    green = int(color.green / 256)
    blue = int(color.blue / 256)
    #Format
    finalcolor = "%02x%02x%02x" % (red, green, blue)
    print (finalcolor.upper())

color_sel.destroy()

Changes made:

Gtk.gdk         to from gi.repository import Gdk
colorsel        to get_color_selection()
Gtk.gdk.Color() to Gdk.color_parse()
tarpan commented 10 years ago

Works for me. Thanks.

bordaigorl commented 10 years ago

It should not be too difficult to catch exceptions to switch to one or the other version depending on the version of Gtk...any plans to update this @weslly ?

sambody commented 10 years ago

Same issue for me - it's not working with keyboard shortcut nor with the command. I'm on Linux Ubuntu, Sublime 3. No message in console.

thomporter commented 10 years ago

Ubuntu 14.04 x64 here with ST3. The fix works perfectly for me, love it!

enapupe commented 10 years ago

Worked here ubuntu 13.10 st3 3059

otger commented 10 years ago

Fix by @CaiusCaligulaCC worked for me.

Ubuntu 14.04 32bits, st3 3059

rakelley commented 10 years ago

Thank you for the fix.

Mint 17 x64, ST3

vespakoen commented 9 years ago

Had problems on Ubuntu 14.04 / ST3, made a fix and was going to post it here, to find out that other people already have solved it, shame on me for not using google first, anyways here is my fix:

(~/.config/sublime-text-3/Packages/User/ColorPicker/bin/linux_colorpicker.py)

#!/usr/bin/env python

import gtk
import sys

color_sel = gtk.ColorSelectionDialog("Sublime Color Picker")

if len(sys.argv) > 1:
    if gtk.gdk.Color(sys.argv[1]):
        color_sel.colorsel.set_current_color(gtk.gdk.Color(sys.argv[1]))

if color_sel.run() == gtk.RESPONSE_OK:
    color = color_sel.get_color_selection().get_current_color()
    #Convert to 8bit channels
    red = int(color.red / 256)
    green = int(color.green / 256)
    blue = int(color.blue / 256)
    #Format
    finalcolor = "%02x%02x%02x" % (red, green, blue)
    print (finalcolor.upper())

color_sel.destroy()

to test, run this on the console:

python ~/.config/sublime-text-3/Packages/User/ColorPicker/bin/linux_colorpicker.py #ff0000

changes made:

Hope it might help anyone

txtsd commented 9 years ago

@vespakoen I applied your changes, but I get this error when running the command in ST3's console.

>>> python ~/.config/sublime-text-3/Packages/User/ColorPicker/bin/linux_colorpicker.py #ff0000
  File "<string>", line 1
    python ~/.config/sublime-text-3/Packages/User/ColorPicker/bin/linux_colorpicker.py #ff0000
           ^
SyntaxError: invalid syntax

And the plugin doesn't work at all :/

EDIT: Nevermind. Changing this line to #!/usr/bin/env python2 fixed it

rafaelcanovas commented 9 years ago

I have a working version that maintains compatibility with the older versions, can you guys test it?

eyalzek commented 9 years ago

LinuCC's fix worked for me on ST2 (Xubuntu 14.04)

rafaelcanovas commented 9 years ago

@eyalzek can you test my version? It maintains backwards compatibility. So we can have a merge in the near future. Thank you!

eyalzek commented 9 years ago

@mstrcnvs it seems to be working fine

weslly commented 9 years ago

I've been using VIM for the last few months but I came back to sublime this week. I'll take a look at the issue(s) and merge the fixes as soon as possible (probably this week or so). Sorry for the waiting.

rafaelcanovas commented 9 years ago

Cheers @weslly!

slavugan commented 9 years ago

ubuntu 14.10 x64 plugin dont start if cursor placed on any color code, but if cusor don't point on color the plugin starts good. For some reasons it can't pick color from sublime. On ST2(2221) and ST3(3065) result the same.

markandrewj commented 9 years ago

Wanted to confirm this behaviour "ubuntu 14.10 x64 plugin dont start if cursor placed on any color code, but if cusor don't point on color the plugin starts good. For some reasons it can't pick color from sublime. On ST2(2221) and ST3(3065) result the same." on 14.04.1

rafaelcanovas commented 9 years ago

@slavugan @markandrewj Hi guys, can you test my working version? So that we can get a merge? It should work with cursor placed on a color code.

slavugan commented 9 years ago

@mstrcnvs Where can I take your working version for test?

rafaelcanovas commented 9 years ago

@slavugan http://github.com/mstrcnvs/ColorPicker

slavugan commented 9 years ago

@mstrcnvs it works good, so you can merge ))

Rob-ot commented 9 years ago

You guys rock!

weslly commented 9 years ago

The fix was merged and released.

markandrewj commented 9 years ago

sorry I didn't have a moment to test, glad the bug has been closed, ty for patching