~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/windowTheme.c

  • Committer: Bazaar Package Importer
  • Author(s): Kevin Roy
  • Date: 2011-02-08 22:20:54 UTC
  • mfrom: (1.4.2 upstream)
  • mto: (14.2.6 sid) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110208222054-kk0gwa4bu8h5lyq4
Tags: upstream-2.56.1-beta-svn34076
ImportĀ upstreamĀ versionĀ 2.56.1-beta-svn34076

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
 * $Id: windowTheme.c 14444 2008-04-16 22:40:48Z hos $
3
 
 *
4
 
 * ***** BEGIN GPL LICENSE BLOCK *****
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU General Public License
8
 
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version.
10
 
 *
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.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software Foundation,
18
 
 * Inc., 59 Temple Place - Suite 330, Boston, MA        02111-1307, USA.
19
 
 *
20
 
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
 
 * All rights reserved.
22
 
 *
23
 
 * This is a new part of Blender.
24
 
 *
25
 
 * Contributor(s): Willian P. Germano
26
 
 *
27
 
 * ***** END GPL LICENSE BLOCK *****
28
 
*/
29
 
 
30
 
#include "windowTheme.h" /*This must come first*/
31
 
 
32
 
#include "BLI_blenlib.h"
33
 
#include "BIF_interface_icons.h"
34
 
#include "BIF_resources.h"
35
 
#include "MEM_guardedalloc.h"
36
 
#include "charRGBA.h"
37
 
#include "gen_utils.h"
38
 
 
39
 
 
40
 
#define EXPP_THEME_VTX_SIZE_MIN 1
41
 
#define EXPP_THEME_VTX_SIZE_MAX 10
42
 
#define EXPP_THEME_FDOT_SIZE_MIN 1
43
 
#define EXPP_THEME_FDOT_SIZE_MAX 10
44
 
#define EXPP_THEME_DRAWTYPE_MIN 1
45
 
#define EXPP_THEME_DRAWTYPE_MAX 4
46
 
 
47
 
#define EXPP_THEME_NUMBEROFTHEMES 16
48
 
static const EXPP_map_pair themes_map[] = {
49
 
        {"ui", -1},
50
 
        {"buts", SPACE_BUTS},
51
 
        {"view3d", SPACE_VIEW3D},
52
 
        {"file", SPACE_FILE},
53
 
        {"ipo", SPACE_IPO},
54
 
        {"info", SPACE_INFO},
55
 
        {"sound", SPACE_SOUND},
56
 
        {"action", SPACE_ACTION},
57
 
        {"nla", SPACE_NLA},
58
 
        {"seq", SPACE_SEQ},
59
 
        {"image", SPACE_IMAGE},
60
 
        {"imasel", SPACE_IMASEL},
61
 
        {"text", SPACE_TEXT},
62
 
        {"oops", SPACE_OOPS},
63
 
        {"time", SPACE_TIME},
64
 
        {"node", SPACE_NODE},
65
 
        {NULL, 0}
66
 
};
67
 
 
68
 
static PyObject *M_Theme_New( PyObject * self, PyObject * args );
69
 
static PyObject *M_Theme_Get( PyObject * self, PyObject * args );
70
 
 
71
 
static char M_Theme_doc[] = "The Blender Theme module\n\n\
72
 
This module provides access to UI Theme data in Blender";
73
 
 
74
 
static char M_Theme_New_doc[] = "Theme.New (name = 'New Theme',\
75
 
theme = <default>):\n\
76
 
        Return a new Theme Data object.\n\
77
 
(name) - string: the Theme's name, it defaults to 'New Theme';\n\
78
 
(theme) - bpy Theme: a base Theme to copy all data from, it defaults to the\n\
79
 
current one.";
80
 
 
81
 
static char M_Theme_Get_doc[] = "Theme.Get (name = None):\n\
82
 
        Return the theme data with the given 'name', None if not found, or\n\
83
 
        Return a list with all Theme Data objects if no argument was given.";
84
 
 
85
 
/*****************************************************************************/
86
 
/* Python method structure definition for Blender.Theme module:            */
87
 
/*****************************************************************************/
88
 
struct PyMethodDef M_Theme_methods[] = {
89
 
        {"New", M_Theme_New, METH_VARARGS, M_Theme_New_doc},
90
 
        {"Get", M_Theme_Get, METH_VARARGS, M_Theme_Get_doc},
91
 
        {NULL, NULL, 0, NULL}
92
 
};
93
 
 
94
 
static void ThemeSpace_dealloc( BPy_ThemeSpace * self );
95
 
static int ThemeSpace_compare( BPy_ThemeSpace * a, BPy_ThemeSpace * b );
96
 
static PyObject *ThemeSpace_repr( BPy_ThemeSpace * self );
97
 
static PyObject *ThemeSpace_getAttr( BPy_ThemeSpace * self, char *name );
98
 
static int ThemeSpace_setAttr( BPy_ThemeSpace * self, char *name,
99
 
                               PyObject * val );
100
 
 
101
 
static PyMethodDef BPy_ThemeSpace_methods[] = {
102
 
        {NULL, NULL, 0, NULL}
103
 
};
104
 
 
105
 
PyTypeObject ThemeSpace_Type = {
106
 
        PyObject_HEAD_INIT( NULL ) 0,   /* ob_size */
107
 
        "Blender Space Theme",  /* tp_name */
108
 
        sizeof( BPy_ThemeSpace ),       /* tp_basicsize */
109
 
        0,                      /* tp_itemsize */
110
 
        /* methods */
111
 
        ( destructor ) ThemeSpace_dealloc,      /* tp_dealloc */
112
 
        0,                      /* tp_print */
113
 
        ( getattrfunc ) ThemeSpace_getAttr,     /* tp_getattr */
114
 
        ( setattrfunc ) ThemeSpace_setAttr,     /* tp_setattr */
115
 
        ( cmpfunc ) ThemeSpace_compare, /* tp_compare */
116
 
        ( reprfunc ) ThemeSpace_repr,   /* tp_repr */
117
 
        0,                      /* tp_as_number */
118
 
        0,                      /* tp_as_sequence */
119
 
        0,                      /* tp_as_mapping */
120
 
        0,                      /* tp_as_hash */
121
 
        0, 0, 0, 0, 0, 0,
122
 
        0,                      /* tp_doc */
123
 
        0, 0, 0, 0, 0, 0,
124
 
        0,                      //BPy_ThemeSpace_methods,            /* tp_methods */
125
 
        0,                      /* tp_members */
126
 
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
127
 
};
128
 
 
129
 
static void ThemeSpace_dealloc( BPy_ThemeSpace * self )
130
 
{
131
 
        PyObject_DEL( self );
132
 
}
133
 
 
134
 
#define ELSEIF_TSP_RGBA(attr)\
135
 
        else if (!strcmp(name, #attr))\
136
 
                attrib = charRGBA_New(&tsp->attr[0]);
137
 
 
138
 
/* Example: ELSEIF_TSP_RGBA(back) becomes:
139
 
 * else if (!strcmp(name, "back")
140
 
 *      attrib = charRGBA_New(&tsp->back[0])
141
 
 */
142
 
 
143
 
static PyObject *ThemeSpace_getAttr( BPy_ThemeSpace * self, char *name )
144
 
{
145
 
        PyObject *attrib = Py_None;
146
 
        ThemeSpace *tsp = self->tsp;
147
 
 
148
 
        if( !strcmp( name, "theme" ) )
149
 
                attrib = PyString_FromString( self->theme->name );
150
 
                ELSEIF_TSP_RGBA( back )
151
 
                ELSEIF_TSP_RGBA( text )
152
 
                ELSEIF_TSP_RGBA( text_hi )
153
 
                ELSEIF_TSP_RGBA( header )
154
 
                ELSEIF_TSP_RGBA( panel )
155
 
                ELSEIF_TSP_RGBA( shade1 )
156
 
                ELSEIF_TSP_RGBA( shade2 )
157
 
                ELSEIF_TSP_RGBA( hilite )
158
 
                ELSEIF_TSP_RGBA( grid )
159
 
                ELSEIF_TSP_RGBA( wire )
160
 
                ELSEIF_TSP_RGBA( select )
161
 
                ELSEIF_TSP_RGBA( lamp )
162
 
                ELSEIF_TSP_RGBA( active )
163
 
                ELSEIF_TSP_RGBA( group )
164
 
                ELSEIF_TSP_RGBA( group_active )
165
 
                ELSEIF_TSP_RGBA( transform )
166
 
                ELSEIF_TSP_RGBA( vertex )
167
 
                ELSEIF_TSP_RGBA( vertex_select )
168
 
                ELSEIF_TSP_RGBA( edge )
169
 
                ELSEIF_TSP_RGBA( edge_select )
170
 
                ELSEIF_TSP_RGBA( edge_seam )
171
 
                ELSEIF_TSP_RGBA( edge_sharp )
172
 
                ELSEIF_TSP_RGBA( editmesh_active )
173
 
                ELSEIF_TSP_RGBA( edge_facesel )
174
 
                ELSEIF_TSP_RGBA( face )
175
 
                ELSEIF_TSP_RGBA( face_select )
176
 
                ELSEIF_TSP_RGBA( face_dot )
177
 
                ELSEIF_TSP_RGBA( normal )
178
 
                ELSEIF_TSP_RGBA( bone_solid )
179
 
                ELSEIF_TSP_RGBA( bone_pose )
180
 
                ELSEIF_TSP_RGBA( strip )
181
 
                ELSEIF_TSP_RGBA( strip_select )
182
 
                ELSEIF_TSP_RGBA( syntaxl )
183
 
                ELSEIF_TSP_RGBA( syntaxn )
184
 
                ELSEIF_TSP_RGBA( syntaxb )
185
 
                ELSEIF_TSP_RGBA( syntaxv )
186
 
                ELSEIF_TSP_RGBA( syntaxc )
187
 
                ELSEIF_TSP_RGBA( movie )
188
 
                ELSEIF_TSP_RGBA( image )
189
 
                ELSEIF_TSP_RGBA( scene )
190
 
                ELSEIF_TSP_RGBA( audio )
191
 
                ELSEIF_TSP_RGBA( effect )
192
 
                ELSEIF_TSP_RGBA( plugin )
193
 
                ELSEIF_TSP_RGBA( transition )
194
 
                ELSEIF_TSP_RGBA( meta )
195
 
                else if( !strcmp( name, "vertex_size" ) )
196
 
                attrib = Py_BuildValue( "i", tsp->vertex_size );
197
 
                else if( !strcmp( name, "facedot_size" ) )
198
 
                attrib = Py_BuildValue( "i", tsp->facedot_size );
199
 
        else if( !strcmp( name, "__members__" ) )
200
 
                attrib = Py_BuildValue("[ssssssssssssssssssssssssssssssssssssssssssssssss]", "theme",
201
 
                                        "back", "text", "text_hi", "header",
202
 
                                        "panel", "shade1", "shade2", "hilite",
203
 
                                        "grid", "wire", "select", "lamp", "active",
204
 
                                        "group", "group_active",
205
 
                                        "transform", "vertex", "vertex_select",
206
 
                                        "edge", "edge_select", "edge_seam", "edge_sharp", "editmesh_active",
207
 
                                        "edge_facesel", "face", "face_select",
208
 
                                        "face_dot", "normal", "bone_solid", "bone_pose",
209
 
                                        "strip", "strip_select",
210
 
                                        "syntaxl", "syntaxn", "syntaxb", "syntaxv", "syntaxc",
211
 
                                        "movie", "image", "scene", "audio", "effect", "plugin",
212
 
                                        "transition", "meta", 
213
 
                                        "vertex_size", "facedot_size" );
214
 
 
215
 
        if( attrib != Py_None )
216
 
                return attrib;
217
 
 
218
 
        return Py_FindMethod( BPy_ThemeSpace_methods, ( PyObject * ) self,
219
 
                              name );
220
 
}
221
 
 
222
 
static int ThemeSpace_setAttr( BPy_ThemeSpace * self, char *name,
223
 
                               PyObject * value )
224
 
{
225
 
        PyObject *attrib = NULL;
226
 
        ThemeSpace *tsp = self->tsp;
227
 
        int ret = -1;
228
 
 
229
 
        if( !strcmp( name, "back" ) )
230
 
                attrib = charRGBA_New( &tsp->back[0] );
231
 
                ELSEIF_TSP_RGBA( text )
232
 
                ELSEIF_TSP_RGBA( text_hi )
233
 
                ELSEIF_TSP_RGBA( header )
234
 
                ELSEIF_TSP_RGBA( panel )
235
 
                ELSEIF_TSP_RGBA( shade1 )
236
 
                ELSEIF_TSP_RGBA( shade2 )
237
 
                ELSEIF_TSP_RGBA( hilite )
238
 
                ELSEIF_TSP_RGBA( grid )
239
 
                ELSEIF_TSP_RGBA( wire )
240
 
                ELSEIF_TSP_RGBA( select )
241
 
                ELSEIF_TSP_RGBA( lamp )
242
 
                ELSEIF_TSP_RGBA( active )
243
 
                ELSEIF_TSP_RGBA( group )
244
 
                ELSEIF_TSP_RGBA( group_active )
245
 
                ELSEIF_TSP_RGBA( transform )
246
 
                ELSEIF_TSP_RGBA( vertex )
247
 
                ELSEIF_TSP_RGBA( vertex_select )
248
 
                ELSEIF_TSP_RGBA( edge )
249
 
                ELSEIF_TSP_RGBA( edge_select )
250
 
                ELSEIF_TSP_RGBA( edge_seam )
251
 
                ELSEIF_TSP_RGBA( edge_sharp )
252
 
                ELSEIF_TSP_RGBA( editmesh_active )
253
 
                ELSEIF_TSP_RGBA( edge_facesel )
254
 
                ELSEIF_TSP_RGBA( face )
255
 
                ELSEIF_TSP_RGBA( face_select )
256
 
                ELSEIF_TSP_RGBA( face_dot )
257
 
                ELSEIF_TSP_RGBA( normal )
258
 
                ELSEIF_TSP_RGBA( bone_solid )
259
 
                ELSEIF_TSP_RGBA( bone_pose )
260
 
                ELSEIF_TSP_RGBA( strip )
261
 
                ELSEIF_TSP_RGBA( strip_select )
262
 
                ELSEIF_TSP_RGBA( syntaxl )
263
 
                ELSEIF_TSP_RGBA( syntaxn )
264
 
                ELSEIF_TSP_RGBA( syntaxb )
265
 
                ELSEIF_TSP_RGBA( syntaxv )
266
 
                ELSEIF_TSP_RGBA( syntaxc )
267
 
                ELSEIF_TSP_RGBA( movie )
268
 
                ELSEIF_TSP_RGBA( image )
269
 
                ELSEIF_TSP_RGBA( scene )
270
 
                ELSEIF_TSP_RGBA( audio )
271
 
                ELSEIF_TSP_RGBA( effect )
272
 
                ELSEIF_TSP_RGBA( plugin )
273
 
                ELSEIF_TSP_RGBA( transition )
274
 
                ELSEIF_TSP_RGBA( meta )
275
 
                else if( !strcmp( name, "vertex_size" ) ) {
276
 
                int val;
277
 
 
278
 
                if( !PyInt_Check( value ) )
279
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
280
 
                                                    "expected integer value" );
281
 
 
282
 
                val = ( int ) PyInt_AsLong( value );
283
 
                tsp->vertex_size = (char)EXPP_ClampInt( val,
284
 
                                                  EXPP_THEME_VTX_SIZE_MIN,
285
 
                                                  EXPP_THEME_VTX_SIZE_MAX );
286
 
                ret = 0;
287
 
        }
288
 
        else if( !strcmp( name, "facedot_size" ) ) {
289
 
                int val;
290
 
 
291
 
                if( !PyInt_Check( value ) )
292
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
293
 
                                                    "expected integer value" );
294
 
 
295
 
                val = ( int ) PyInt_AsLong( value );
296
 
                tsp->vertex_size = (char)EXPP_ClampInt( val,
297
 
                                                  EXPP_THEME_FDOT_SIZE_MIN,
298
 
                                                  EXPP_THEME_FDOT_SIZE_MAX );
299
 
                ret = 0;
300
 
        } else
301
 
                return EXPP_ReturnIntError( PyExc_AttributeError,
302
 
                                            "attribute not found" );
303
 
 
304
 
        if( attrib ) {
305
 
                PyObject *pyret = NULL;
306
 
                PyObject *valtuple = Py_BuildValue( "(O)", value );
307
 
 
308
 
                if( !valtuple )
309
 
                        return EXPP_ReturnIntError( PyExc_MemoryError,
310
 
                                                    "couldn't create tuple!" );
311
 
 
312
 
                pyret = charRGBA_setCol( ( BPy_charRGBA * ) attrib, valtuple );
313
 
                Py_DECREF( valtuple );
314
 
 
315
 
                if( pyret == Py_None ) {
316
 
                        Py_DECREF( Py_None );   /* was increfed by charRGBA_setCol */
317
 
                        ret = 0;
318
 
                }
319
 
 
320
 
                Py_DECREF( attrib );    /* we're done with it */
321
 
        }
322
 
 
323
 
        return ret;             /* 0 if all went well */
324
 
}
325
 
 
326
 
static int ThemeSpace_compare( BPy_ThemeSpace * a, BPy_ThemeSpace * b )
327
 
{
328
 
        ThemeSpace *pa = a->tsp, *pb = b->tsp;
329
 
        return ( pa == pb ) ? 0 : -1;
330
 
}
331
 
 
332
 
static PyObject *ThemeSpace_repr( BPy_ThemeSpace * self )
333
 
{
334
 
        return PyString_FromFormat( "[Space theme from theme \"%s\"]",
335
 
                                    self->theme->name );
336
 
}
337
 
 
338
 
static void ThemeUI_dealloc( BPy_ThemeUI * self );
339
 
static int ThemeUI_compare( BPy_ThemeUI * a, BPy_ThemeUI * b );
340
 
static PyObject *ThemeUI_repr( BPy_ThemeUI * self );
341
 
static PyObject *ThemeUI_getAttr( BPy_ThemeUI * self, char *name );
342
 
static int ThemeUI_setAttr( BPy_ThemeUI * self, char *name, PyObject * val );
343
 
 
344
 
static PyMethodDef BPy_ThemeUI_methods[] = {
345
 
        {NULL, NULL, 0, NULL}
346
 
};
347
 
 
348
 
PyTypeObject ThemeUI_Type = {
349
 
        PyObject_HEAD_INIT( NULL ) 0,   /* ob_size */
350
 
        "Blender UI Theme",     /* tp_name */
351
 
        sizeof( BPy_ThemeUI ),  /* tp_basicsize */
352
 
        0,                      /* tp_itemsize */
353
 
        /* methods */
354
 
        ( destructor ) ThemeUI_dealloc, /* tp_dealloc */
355
 
        0,                      /* tp_print */
356
 
        ( getattrfunc ) ThemeUI_getAttr,        /* tp_getattr */
357
 
        ( setattrfunc ) ThemeUI_setAttr,        /* tp_setattr */
358
 
        ( cmpfunc ) ThemeUI_compare,    /* tp_compare */
359
 
        ( reprfunc ) ThemeUI_repr,      /* tp_repr */
360
 
        0,                      /* tp_as_number */
361
 
        0,                      /* tp_as_sequence */
362
 
        0,                      /* tp_as_mapping */
363
 
        0,                      /* tp_as_hash */
364
 
        0, 0, 0, 0, 0, 0,
365
 
        0,                      /* tp_doc */
366
 
        0, 0, 0, 0, 0, 0,
367
 
        0,                      //BPy_ThemeUI_methods,         /* tp_methods */
368
 
        0,                      /* tp_members */
369
 
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
370
 
};
371
 
 
372
 
static void ThemeUI_dealloc( BPy_ThemeUI * self )
373
 
{
374
 
        PyObject_DEL( self );
375
 
}
376
 
 
377
 
#define ELSEIF_TUI_RGBA(attr)\
378
 
        else if (!strcmp(name, #attr))\
379
 
                attrib = charRGBA_New(&tui->attr[0]);
380
 
 
381
 
/* Example: ELSEIF_TUI_RGBA(outline) becomes:
382
 
 * else if (!strcmp(name, "outline")
383
 
 *      attr = charRGBA_New(&tui->outline[0])
384
 
 */
385
 
 
386
 
static PyObject *ThemeUI_getAttr( BPy_ThemeUI * self, char *name )
387
 
{
388
 
        PyObject *attrib = Py_None;
389
 
        ThemeUI *tui = self->tui;
390
 
 
391
 
        if( !strcmp( name, "theme" ) )
392
 
                attrib = PyString_FromString( self->theme->name );
393
 
        ELSEIF_TUI_RGBA( outline )
394
 
                ELSEIF_TUI_RGBA( neutral )
395
 
                ELSEIF_TUI_RGBA( action )
396
 
                ELSEIF_TUI_RGBA( setting )
397
 
                ELSEIF_TUI_RGBA( setting1 )
398
 
                ELSEIF_TUI_RGBA( setting2 )
399
 
                ELSEIF_TUI_RGBA( num )
400
 
                ELSEIF_TUI_RGBA( textfield )
401
 
                ELSEIF_TUI_RGBA( textfield_hi )
402
 
                ELSEIF_TUI_RGBA( popup )
403
 
                ELSEIF_TUI_RGBA( text )
404
 
                ELSEIF_TUI_RGBA( text_hi )
405
 
                ELSEIF_TUI_RGBA( menu_back )
406
 
                ELSEIF_TUI_RGBA( menu_item )
407
 
                ELSEIF_TUI_RGBA( menu_hilite )
408
 
                ELSEIF_TUI_RGBA( menu_text )
409
 
                ELSEIF_TUI_RGBA( menu_text_hi )
410
 
                else if( !strcmp( name, "drawType" ) )
411
 
                attrib = PyInt_FromLong( ( char ) tui->but_drawtype );
412
 
                else if( !strcmp( name, "iconTheme" ) )
413
 
                attrib = PyString_FromString( tui->iconfile );
414
 
        else if( !strcmp( name, "__members__" ) )
415
 
                attrib = Py_BuildValue( "[ssssssssssssssssssss]", "theme",
416
 
                                        "outline", "neutral", "action",
417
 
                                        "setting", "setting1", "setting2",
418
 
                                        "num", "textfield", "textfield_hi", "popup", "text",
419
 
                                        "text_hi", "menu_back", "menu_item",
420
 
                                        "menu_hilite", "menu_text",
421
 
                                        "menu_text_hi", "drawType", "iconTheme" );
422
 
 
423
 
        if( attrib != Py_None )
424
 
                return attrib;
425
 
 
426
 
        return Py_FindMethod( BPy_ThemeUI_methods, ( PyObject * ) self, name );
427
 
}
428
 
 
429
 
static int ThemeUI_setAttr( BPy_ThemeUI * self, char *name, PyObject * value )
430
 
{
431
 
        PyObject *attrib = NULL;
432
 
        ThemeUI *tui = self->tui;
433
 
        int ret = -1;
434
 
 
435
 
        if( !strcmp( name, "outline" ) )
436
 
                attrib = charRGBA_New( &tui->outline[0] );
437
 
        ELSEIF_TUI_RGBA( neutral )
438
 
                ELSEIF_TUI_RGBA( action )
439
 
                ELSEIF_TUI_RGBA( setting )
440
 
                ELSEIF_TUI_RGBA( setting1 )
441
 
                ELSEIF_TUI_RGBA( setting2 )
442
 
                ELSEIF_TUI_RGBA( num )
443
 
                ELSEIF_TUI_RGBA( textfield )
444
 
                ELSEIF_TUI_RGBA( textfield_hi )
445
 
                ELSEIF_TUI_RGBA( popup )
446
 
                ELSEIF_TUI_RGBA( text )
447
 
                ELSEIF_TUI_RGBA( text_hi )
448
 
                ELSEIF_TUI_RGBA( menu_back )
449
 
                ELSEIF_TUI_RGBA( menu_item )
450
 
                ELSEIF_TUI_RGBA( menu_hilite )
451
 
                ELSEIF_TUI_RGBA( menu_text )
452
 
                ELSEIF_TUI_RGBA( menu_text_hi )
453
 
                else if( !strcmp( name, "drawType" ) ) {
454
 
                int val;
455
 
 
456
 
                if( !PyInt_Check( value ) )
457
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
458
 
                                                    "expected integer value" );
459
 
 
460
 
                val = ( int ) PyInt_AsLong( value );
461
 
                tui->but_drawtype = (char)EXPP_ClampInt( val,
462
 
                                                   EXPP_THEME_DRAWTYPE_MIN,
463
 
                                                   EXPP_THEME_DRAWTYPE_MAX );
464
 
                ret = 0;
465
 
        } else if ( !strcmp( name, "iconTheme" ) ) {
466
 
                if ( !PyString_Check(value) )
467
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
468
 
                                                    "expected string value" );
469
 
                BLI_strncpy(tui->iconfile, PyString_AsString(value), 80);
470
 
                
471
 
                BIF_icons_free();
472
 
                BIF_icons_init(BIFICONID_LAST+1);
473
 
                
474
 
                ret = 0;
475
 
        } else
476
 
                return EXPP_ReturnIntError( PyExc_AttributeError,
477
 
                                            "attribute not found" );
478
 
 
479
 
        if( attrib ) {
480
 
                PyObject *pyret = NULL;
481
 
                PyObject *valtuple = Py_BuildValue( "(O)", value );
482
 
 
483
 
                if( !valtuple )
484
 
                        return EXPP_ReturnIntError( PyExc_MemoryError,
485
 
                                                    "couldn't create tuple!" );
486
 
 
487
 
                pyret = charRGBA_setCol( ( BPy_charRGBA * ) attrib, valtuple );
488
 
                Py_DECREF( valtuple );
489
 
 
490
 
                if( pyret == Py_None ) {
491
 
                        Py_DECREF( Py_None );   /* was increfed by charRGBA_setCol */
492
 
                        ret = 0;
493
 
                }
494
 
 
495
 
                Py_DECREF( attrib );    /* we're done with it */
496
 
        }
497
 
 
498
 
        return ret;             /* 0 if all went well */
499
 
}
500
 
 
501
 
 
502
 
static int ThemeUI_compare( BPy_ThemeUI * a, BPy_ThemeUI * b )
503
 
{
504
 
        ThemeUI *pa = a->tui, *pb = b->tui;
505
 
        return ( pa == pb ) ? 0 : -1;
506
 
}
507
 
 
508
 
static PyObject *ThemeUI_repr( BPy_ThemeUI * self )
509
 
{
510
 
        return PyString_FromFormat( "[UI theme from theme \"%s\"]",
511
 
                                    self->theme->name );
512
 
}
513
 
 
514
 
static void Theme_dealloc( BPy_Theme * self );
515
 
static int Theme_compare( BPy_Theme * a, BPy_Theme * b );
516
 
static PyObject *Theme_getAttr( BPy_Theme * self, char *name );
517
 
static PyObject *Theme_repr( BPy_Theme * self );
518
 
 
519
 
static PyObject *Theme_get( BPy_Theme * self, PyObject * args );
520
 
static PyObject *Theme_getName( BPy_Theme * self );
521
 
static PyObject *Theme_setName( BPy_Theme * self, PyObject * value );
522
 
 
523
 
static PyMethodDef BPy_Theme_methods[] = {
524
 
        {"get", ( PyCFunction ) Theme_get, METH_VARARGS,
525
 
         "(param) - Return UI or Space theme object.\n\
526
 
(param) - the chosen theme object as an int or a string:\n\
527
 
- () - default: UI;\n\
528
 
- (i) - int: an entry from the Blender.Window.Types dictionary;\n\
529
 
- (s) - string: 'UI' or a space name, like 'VIEW3D', etc."},
530
 
        {"getName", ( PyCFunction ) Theme_getName, METH_NOARGS,
531
 
         "() - Return Theme name"},
532
 
        {"setName", ( PyCFunction ) Theme_setName, METH_O,
533
 
         "(s) - Set Theme name"},
534
 
        {NULL, NULL, 0, NULL}
535
 
};
536
 
 
537
 
PyTypeObject Theme_Type = {
538
 
        PyObject_HEAD_INIT( NULL ) 
539
 
        0,      /* ob_size */
540
 
        "Blender Theme",        /* tp_name */
541
 
        sizeof( BPy_Theme ),    /* tp_basicsize */
542
 
        0,                      /* tp_itemsize */
543
 
        /* methods */
544
 
        ( destructor ) Theme_dealloc,   /* tp_dealloc */
545
 
        0,                      /* tp_print */
546
 
        ( getattrfunc ) Theme_getAttr,  /* tp_getattr */
547
 
        0,                      //(setattrfunc) Theme_setAttr,        /* tp_setattr */
548
 
        ( cmpfunc ) Theme_compare,      /* tp_compare */
549
 
        ( reprfunc ) Theme_repr,        /* tp_repr */
550
 
        0,                      /* tp_as_number */
551
 
        0,                      /* tp_as_sequence */
552
 
        0,                      /* tp_as_mapping */
553
 
        0,                      /* tp_as_hash */
554
 
        0, 0, 0, 0, 0, 0,
555
 
        0,                      /* tp_doc */
556
 
        0, 0, 0, 0, 0, 0,
557
 
        0,                      /*BPy_Theme_methods,*/ /* tp_methods */
558
 
        0,                      /* tp_members */
559
 
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
560
 
};
561
 
 
562
 
static PyObject *M_Theme_New( PyObject * self, PyObject * args )
563
 
{
564
 
        char *name = "New Theme";
565
 
        BPy_Theme *pytheme = NULL, *base_pytheme = NULL;
566
 
        bTheme *btheme = NULL, *newtheme = NULL;
567
 
 
568
 
        if( !PyArg_ParseTuple
569
 
            ( args, "|sO!", &name, &Theme_Type, &base_pytheme ) )
570
 
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
571
 
                                              "expected nothing or a name and optional theme object as arguments" );
572
 
 
573
 
        if( base_pytheme )
574
 
                btheme = base_pytheme->theme;
575
 
        if( !btheme )
576
 
                btheme = U.themes.first;
577
 
 
578
 
        newtheme = MEM_callocN( sizeof( bTheme ), "theme" );
579
 
 
580
 
        if( newtheme )
581
 
                pytheme = PyObject_New( BPy_Theme, &Theme_Type );
582
 
        if( !pytheme )
583
 
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
584
 
                                              "couldn't create Theme Data in Blender" );
585
 
 
586
 
        memcpy( newtheme, btheme, sizeof( bTheme ) );
587
 
        BLI_addhead( &U.themes, newtheme );
588
 
        BLI_strncpy( newtheme->name, name, 32 );
589
 
 
590
 
        pytheme->theme = newtheme;
591
 
 
592
 
        return ( PyObject * ) pytheme;
593
 
}
594
 
 
595
 
static PyObject *M_Theme_Get( PyObject * self, PyObject * args )
596
 
{
597
 
        char *name = NULL;
598
 
        bTheme *iter;
599
 
        PyObject *ret;
600
 
 
601
 
        if( !PyArg_ParseTuple( args, "|s", &name ) )
602
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
603
 
                                              "expected string argument (or nothing)" );
604
 
 
605
 
        iter = U.themes.first;
606
 
 
607
 
        if( name ) {            /* (name) - return requested theme */
608
 
                BPy_Theme *wanted = NULL;
609
 
 
610
 
                while( iter ) {
611
 
                        if( strcmp( name, iter->name ) == 0 ) {
612
 
                                wanted = PyObject_New( BPy_Theme,
613
 
                                                       &Theme_Type );
614
 
                                wanted->theme = iter;
615
 
                                break;
616
 
                        }
617
 
                        iter = iter->next;
618
 
                }
619
 
 
620
 
                if( !wanted ) {
621
 
                        char emsg[64];
622
 
                        PyOS_snprintf( emsg, sizeof( emsg ),
623
 
                                       "Theme \"%s\" not found", name );
624
 
                        return EXPP_ReturnPyObjError( PyExc_NameError, emsg );
625
 
                }
626
 
 
627
 
                ret = ( PyObject * ) wanted;
628
 
        }
629
 
 
630
 
        else {                  /* () - return list with all themes */
631
 
                int index = 0;
632
 
                PyObject *list = NULL;
633
 
                BPy_Theme *pytheme = NULL;
634
 
 
635
 
                list = PyList_New( BLI_countlist( &( U.themes ) ) );
636
 
 
637
 
                if( !list )
638
 
                        return EXPP_ReturnPyObjError( PyExc_MemoryError,
639
 
                                                      "couldn't create PyList" );
640
 
 
641
 
                while( iter ) {
642
 
                        pytheme = PyObject_New( BPy_Theme, &Theme_Type );
643
 
                        pytheme->theme = iter;
644
 
 
645
 
                        if( !pytheme ) {
646
 
                                Py_DECREF(list);
647
 
                                return EXPP_ReturnPyObjError
648
 
                                        ( PyExc_MemoryError,
649
 
                                          "couldn't create Theme PyObject" );
650
 
                        }
651
 
                        PyList_SET_ITEM( list, index, ( PyObject * ) pytheme );
652
 
 
653
 
                        iter = iter->next;
654
 
                        index++;
655
 
                }
656
 
 
657
 
                ret = list;
658
 
        }
659
 
 
660
 
        return ret;
661
 
}
662
 
 
663
 
static PyObject *Theme_get( BPy_Theme * self, PyObject * args )
664
 
{
665
 
        bTheme *btheme = self->theme;
666
 
        ThemeUI *tui = NULL;
667
 
        ThemeSpace *tsp = NULL;
668
 
        PyObject *pyob = NULL;
669
 
        BPy_ThemeUI *retUI = NULL;
670
 
        BPy_ThemeSpace *retSpc = NULL;
671
 
        int type;
672
 
 
673
 
        if( !PyArg_ParseTuple( args, "|O", &pyob ) )
674
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
675
 
                                              "expected string or int argument or nothing" );
676
 
 
677
 
        if( !pyob ) {           /* (): return list with all names */
678
 
                PyObject *ret = PyList_New( EXPP_THEME_NUMBEROFTHEMES );
679
 
 
680
 
                if( !ret )
681
 
                        return EXPP_ReturnPyObjError( PyExc_MemoryError,
682
 
                                                      "couldn't create pylist!" );
683
 
 
684
 
                type = 0;       /* using as a counter only */
685
 
 
686
 
                while( type < EXPP_THEME_NUMBEROFTHEMES ) {
687
 
                        PyList_SET_ITEM( ret, type,
688
 
                                         PyString_FromString( themes_map[type].sval ) );
689
 
                        type++;
690
 
                }
691
 
 
692
 
                return ret;
693
 
        }
694
 
 
695
 
        else if( PyInt_Check( pyob ) )  /* (int) */
696
 
                type = ( int ) PyInt_AsLong( pyob );
697
 
        else if( PyString_Check( pyob ) ) {     /* (str) */
698
 
                char *str = PyString_AsString( pyob );
699
 
                if( !EXPP_map_case_getIntVal( themes_map, str, &type ) )
700
 
                        return EXPP_ReturnPyObjError( PyExc_AttributeError,
701
 
                                                      "unknown string argument" );
702
 
        } else
703
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
704
 
                                              "expected string or int argument or nothing" );
705
 
 
706
 
        switch ( type ) {
707
 
        case -1:                /* UI */
708
 
                tui = &btheme->tui;
709
 
                break;
710
 
        case SPACE_BUTS:
711
 
                tsp = &btheme->tbuts;
712
 
                break;
713
 
        case SPACE_VIEW3D:
714
 
                tsp = &btheme->tv3d;
715
 
                break;
716
 
        case SPACE_FILE:
717
 
                tsp = &btheme->tfile;
718
 
                break;
719
 
        case SPACE_IPO:
720
 
                tsp = &btheme->tipo;
721
 
                break;
722
 
        case SPACE_INFO:
723
 
                tsp = &btheme->tinfo;
724
 
                break;
725
 
        case SPACE_SOUND:
726
 
                tsp = &btheme->tsnd;
727
 
                break;
728
 
        case SPACE_ACTION:
729
 
                tsp = &btheme->tact;
730
 
                break;
731
 
        case SPACE_NLA:
732
 
                tsp = &btheme->tnla;
733
 
                break;
734
 
        case SPACE_SEQ:
735
 
                tsp = &btheme->tseq;
736
 
                break;
737
 
        case SPACE_IMAGE:
738
 
                tsp = &btheme->tima;
739
 
                break;
740
 
        case SPACE_IMASEL:
741
 
                tsp = &btheme->timasel;
742
 
                break;
743
 
        case SPACE_TEXT:
744
 
                tsp = &btheme->text;
745
 
                break;
746
 
        case SPACE_OOPS:
747
 
                tsp = &btheme->toops;
748
 
                break;
749
 
        case SPACE_TIME:
750
 
                tsp = &btheme->ttime;
751
 
                break;
752
 
        case SPACE_NODE:
753
 
                tsp = &btheme->tnode;
754
 
                break;
755
 
        }
756
 
 
757
 
        if( tui ) {
758
 
                retUI = PyObject_New( BPy_ThemeUI, &ThemeUI_Type );
759
 
                retUI->theme = btheme;
760
 
                retUI->tui = tui;
761
 
                return ( PyObject * ) retUI;
762
 
        } else if( tsp ) {
763
 
                retSpc = PyObject_New( BPy_ThemeSpace, &ThemeSpace_Type );
764
 
                retSpc->theme = btheme;
765
 
                retSpc->tsp = tsp;
766
 
                return ( PyObject * ) retSpc;
767
 
        } else
768
 
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
769
 
                                              "invalid parameter" );
770
 
}
771
 
 
772
 
static PyObject *Theme_getName( BPy_Theme * self )
773
 
{
774
 
        return PyString_FromString( self->theme->name );
775
 
}
776
 
 
777
 
static PyObject *Theme_setName( BPy_Theme * self, PyObject * value )
778
 
{
779
 
        char *name = PyString_AsString(value);
780
 
 
781
 
        if( !name )
782
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
783
 
                                              "expected string argument" );
784
 
 
785
 
        BLI_strncpy( self->theme->name, name, 32 );
786
 
 
787
 
        return EXPP_incr_ret( Py_None );
788
 
}
789
 
 
790
 
PyObject *Theme_Init( void )
791
 
{
792
 
        PyObject *submodule;
793
 
 
794
 
        Theme_Type.ob_type = &PyType_Type;
795
 
 
796
 
        submodule = Py_InitModule3( "Blender.Window.Theme",
797
 
                                    M_Theme_methods, M_Theme_doc );
798
 
 
799
 
        return submodule;
800
 
}
801
 
 
802
 
static void Theme_dealloc( BPy_Theme * self )
803
 
{
804
 
        PyObject_DEL( self );
805
 
}
806
 
 
807
 
static PyObject *Theme_getAttr( BPy_Theme * self, char *name )
808
 
{
809
 
        if( !strcmp( name, "name" ) )
810
 
                return PyString_FromString( self->theme->name );
811
 
        else if( !strcmp( name, "__members__" ) )
812
 
                return Py_BuildValue( "[s]", "name" );
813
 
 
814
 
        return Py_FindMethod( BPy_Theme_methods, ( PyObject * ) self, name );
815
 
}
816
 
 
817
 
static int Theme_compare( BPy_Theme * a, BPy_Theme * b )
818
 
{
819
 
        bTheme *pa = a->theme, *pb = b->theme;
820
 
        return ( pa == pb ) ? 0 : -1;
821
 
}
822
 
 
823
 
static PyObject *Theme_repr( BPy_Theme * self )
824
 
{
825
 
        return PyString_FromFormat( "[Theme \"%s\"]", self->theme->name );
826
 
}