Skip to content

Commit

Permalink
Switched from gtk to gi, fixed print syntax
Browse files Browse the repository at this point in the history
Now it should run under python2 and python3
  • Loading branch information
nextsux committed Mar 6, 2014
1 parent 7053709 commit 314d3f2
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions lib/linux_colorpicker.py
@@ -1,35 +1,22 @@
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk
from gi.repository import Gtk
import sys

color_sel = gtk.ColorSelectionDialog("Sublime Color Picker")
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 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.colorsel.get_current_color()
if color_sel.run() == Gtk.ResponseType.OK:
color = color_sel.get_color_selection().get_current_color()
#Convert to 8bit channels
red = color.red / 256
green = color.green / 256
blue = color.blue / 256
#Convert to hexa strings
red = str(hex(red))[2:]
green = str(hex(green))[2:]
blue = str(hex(blue))[2:]
red = int(color.red / 256)
green = int(color.green / 256)
blue = int(color.blue / 256)
#Format
if len(red) == 1:
red = "0%s" % red
if len(green) == 1:
green = "0%s" % green
if len(blue) == 1:
blue = "0%s" % blue

finalcolor = red+green+blue
print finalcolor.upper()
finalcolor = "%02x%02x%02x" % (red, green, blue)
print (finalcolor.upper())

color_sel.destroy()

0 comments on commit 314d3f2

Please sign in to comment.