1 # ###################################################
2 # Copyright (C) 2008 The OpenAnno Team
4 # This file is part of OpenAnno.
6 # OpenAnno is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # ###################################################
24 class ColorIter(object):
30 if hasattr(self
, 'last'):
31 id = game
.main
.db('SELECT rowid from data.colors where rowid > ? order by rowid limit 1', self
.last
)[0][0]
33 id = game
.main
.db('SELECT rowid from data.colors order by rowid limit 1')[0][0]
39 class ColorMeta(type):
40 def __getitem__(cls
, key
):
43 r
,g
,b
= game
.main
.db('SELECT red,green,blue from data.colors where %s = ?' % ('name' if isinstance(key
, str) else 'rowid',), key
)[0]
51 __metaclass__
= ColorMeta
52 def __init__(self
, r
= 0, g
= 0, b
= 0, a
= 255):
53 if isinstance(r
, float) and r
>= 0.0 and r
<= 1.0:
55 if isinstance(g
, float) and g
>= 0.0 and g
<= 1.0:
57 if isinstance(b
, float) and b
>= 0.0 and b
<= 1.0:
59 if isinstance(a
, float) and a
>= 0.0 and a
<= 1.0:
61 assert(isinstance(r
, int) and isinstance(b
, int) and isinstance(b
, int) and isinstance(a
, int))
62 self
.r
, self
.g
, self
.b
, self
.a
= r
, g
, b
, a
64 self
.name
, self
.id = game
.main
.db('SELECT name,rowid from data.colors where red = ? and green = ? and blue = ?', self
.r
, self
.g
, self
.b
)[0]
68 from game
.util
.encoder
import register_classes
69 register_classes(Color
)