Mercurial > traipse_dev
comparison orpg/tools/rgbhex.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | dcae32e219f1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: rgbhex.py | |
21 # Author: Chris Davis | |
22 # Maintainer: | |
23 # Version: | |
24 # $Id: rgbhex.py,v 1.10 2007/02/19 16:33:20 digitalxero Exp $ | |
25 # | |
26 # Description: rgb to hex utility | |
27 | |
28 from orpg.orpg_wx import * | |
29 | |
30 | |
31 ##################### | |
32 ## RPGHex Tool | |
33 ##################### | |
34 | |
35 class RGBHex: | |
36 "Tools for Converting from hex to rgb and versa vicea" | |
37 | |
38 def rgb_tuple(self,hexnum): | |
39 red = self.c2rgb(hexnum[1:3]) | |
40 green = self.c2rgb(hexnum[3:5]) | |
41 blue = self.c2rgb(hexnum[5:7]) | |
42 #print "Converted %s to %s, %s, %s" % (hexnum, red, green, blue) | |
43 return (red, green, blue) | |
44 | |
45 def hexstring(self, red, green, blue): | |
46 hexcolor = "#" + self.c2hex(red) | |
47 hexcolor = hexcolor + self.c2hex(green) | |
48 hexcolor = hexcolor + self.c2hex(blue) | |
49 return hexcolor | |
50 | |
51 def c2rgb(self,num): | |
52 "Converts from hex to rgb" | |
53 first = num[0] | |
54 second = num[1] | |
55 s = 0 | |
56 if first == 'a': s = 10 * 16 | |
57 elif first == 'b': s = 11 * 16 | |
58 elif first == 'c': s = 12 * 16 | |
59 elif first == 'd': s = 13 * 16 | |
60 elif first == 'e': s = 14 * 16 | |
61 elif first == 'f': s = 15 * 16 | |
62 else: s = s+ int(first) * 16 | |
63 if second == 'a': s = s + 10 | |
64 elif second == 'b': s = s + 11 | |
65 elif second == 'c': s = s + 12 | |
66 elif second == 'd': s = s + 13 | |
67 elif second == 'e': s = s + 14 | |
68 elif second == 'f': s = s + 15 | |
69 else: s = s + int(second) | |
70 return s | |
71 | |
72 def c2hex(self,num): | |
73 "Converts from RGB to Hex" | |
74 first = num/16 | |
75 second = num%16 | |
76 s = "" | |
77 if first == 10: s = s+"a" | |
78 elif first == 11: s = s+"b" | |
79 elif first == 12: s = s+"c" | |
80 elif first == 13: s = s+"d" | |
81 elif first == 14: s = s+"e" | |
82 elif first == 15: s = s+"f" | |
83 else: s = s+ str(first) | |
84 if second == 10: s = s+"a" | |
85 elif second == 11: s = s+"b" | |
86 elif second == 12: s = s+"c" | |
87 elif second == 13: s = s+"d" | |
88 elif second == 14: s = s+"e" | |
89 elif second == 15: s = s+"f" | |
90 else: s = s+ str(second) | |
91 return s | |
92 | |
93 def do_hex_color_dlg(self, parent): | |
94 data = wx.ColourData() | |
95 data.SetChooseFull(True) | |
96 dlg = wx.ColourDialog(parent, data) | |
97 if dlg.ShowModal() == wx.ID_OK: | |
98 data = dlg.GetColourData() | |
99 (red,green,blue) = data.GetColour().Get() | |
100 hexcolor = self.hexstring(red, green, blue) | |
101 dlg.Destroy() | |
102 return hexcolor | |
103 else: | |
104 dlg.Destroy() | |
105 return None |