Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched from gtk to gi, fixed print syntax
Now it should run under python2 and python3
- Loading branch information
Showing
1 changed file
with
11 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |