2
* $Id: windowTheme.c 14444 2008-04-16 22:40:48Z hos $
4
* ***** BEGIN GPL LICENSE BLOCK *****
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.
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 Free Software Foundation,
18
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
* All rights reserved.
23
* This is a new part of Blender.
25
* Contributor(s): Willian P. Germano
27
* ***** END GPL LICENSE BLOCK *****
30
#include "windowTheme.h" /*This must come first*/
32
#include "BLI_blenlib.h"
33
#include "BIF_interface_icons.h"
34
#include "BIF_resources.h"
35
#include "MEM_guardedalloc.h"
37
#include "gen_utils.h"
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
47
#define EXPP_THEME_NUMBEROFTHEMES 16
48
static const EXPP_map_pair themes_map[] = {
51
{"view3d", SPACE_VIEW3D},
55
{"sound", SPACE_SOUND},
56
{"action", SPACE_ACTION},
59
{"image", SPACE_IMAGE},
60
{"imasel", SPACE_IMASEL},
68
static PyObject *M_Theme_New( PyObject * self, PyObject * args );
69
static PyObject *M_Theme_Get( PyObject * self, PyObject * args );
71
static char M_Theme_doc[] = "The Blender Theme module\n\n\
72
This module provides access to UI Theme data in Blender";
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\
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.";
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},
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,
101
static PyMethodDef BPy_ThemeSpace_methods[] = {
102
{NULL, NULL, 0, NULL}
105
PyTypeObject ThemeSpace_Type = {
106
PyObject_HEAD_INIT( NULL ) 0, /* ob_size */
107
"Blender Space Theme", /* tp_name */
108
sizeof( BPy_ThemeSpace ), /* tp_basicsize */
111
( destructor ) ThemeSpace_dealloc, /* tp_dealloc */
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 */
124
0, //BPy_ThemeSpace_methods, /* tp_methods */
126
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
129
static void ThemeSpace_dealloc( BPy_ThemeSpace * self )
131
PyObject_DEL( self );
134
#define ELSEIF_TSP_RGBA(attr)\
135
else if (!strcmp(name, #attr))\
136
attrib = charRGBA_New(&tsp->attr[0]);
138
/* Example: ELSEIF_TSP_RGBA(back) becomes:
139
* else if (!strcmp(name, "back")
140
* attrib = charRGBA_New(&tsp->back[0])
143
static PyObject *ThemeSpace_getAttr( BPy_ThemeSpace * self, char *name )
145
PyObject *attrib = Py_None;
146
ThemeSpace *tsp = self->tsp;
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" );
215
if( attrib != Py_None )
218
return Py_FindMethod( BPy_ThemeSpace_methods, ( PyObject * ) self,
222
static int ThemeSpace_setAttr( BPy_ThemeSpace * self, char *name,
225
PyObject *attrib = NULL;
226
ThemeSpace *tsp = self->tsp;
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" ) ) {
278
if( !PyInt_Check( value ) )
279
return EXPP_ReturnIntError( PyExc_TypeError,
280
"expected integer value" );
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 );
288
else if( !strcmp( name, "facedot_size" ) ) {
291
if( !PyInt_Check( value ) )
292
return EXPP_ReturnIntError( PyExc_TypeError,
293
"expected integer value" );
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 );
301
return EXPP_ReturnIntError( PyExc_AttributeError,
302
"attribute not found" );
305
PyObject *pyret = NULL;
306
PyObject *valtuple = Py_BuildValue( "(O)", value );
309
return EXPP_ReturnIntError( PyExc_MemoryError,
310
"couldn't create tuple!" );
312
pyret = charRGBA_setCol( ( BPy_charRGBA * ) attrib, valtuple );
313
Py_DECREF( valtuple );
315
if( pyret == Py_None ) {
316
Py_DECREF( Py_None ); /* was increfed by charRGBA_setCol */
320
Py_DECREF( attrib ); /* we're done with it */
323
return ret; /* 0 if all went well */
326
static int ThemeSpace_compare( BPy_ThemeSpace * a, BPy_ThemeSpace * b )
328
ThemeSpace *pa = a->tsp, *pb = b->tsp;
329
return ( pa == pb ) ? 0 : -1;
332
static PyObject *ThemeSpace_repr( BPy_ThemeSpace * self )
334
return PyString_FromFormat( "[Space theme from theme \"%s\"]",
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 );
344
static PyMethodDef BPy_ThemeUI_methods[] = {
345
{NULL, NULL, 0, NULL}
348
PyTypeObject ThemeUI_Type = {
349
PyObject_HEAD_INIT( NULL ) 0, /* ob_size */
350
"Blender UI Theme", /* tp_name */
351
sizeof( BPy_ThemeUI ), /* tp_basicsize */
354
( destructor ) ThemeUI_dealloc, /* tp_dealloc */
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 */
367
0, //BPy_ThemeUI_methods, /* tp_methods */
369
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
372
static void ThemeUI_dealloc( BPy_ThemeUI * self )
374
PyObject_DEL( self );
377
#define ELSEIF_TUI_RGBA(attr)\
378
else if (!strcmp(name, #attr))\
379
attrib = charRGBA_New(&tui->attr[0]);
381
/* Example: ELSEIF_TUI_RGBA(outline) becomes:
382
* else if (!strcmp(name, "outline")
383
* attr = charRGBA_New(&tui->outline[0])
386
static PyObject *ThemeUI_getAttr( BPy_ThemeUI * self, char *name )
388
PyObject *attrib = Py_None;
389
ThemeUI *tui = self->tui;
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" );
423
if( attrib != Py_None )
426
return Py_FindMethod( BPy_ThemeUI_methods, ( PyObject * ) self, name );
429
static int ThemeUI_setAttr( BPy_ThemeUI * self, char *name, PyObject * value )
431
PyObject *attrib = NULL;
432
ThemeUI *tui = self->tui;
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" ) ) {
456
if( !PyInt_Check( value ) )
457
return EXPP_ReturnIntError( PyExc_TypeError,
458
"expected integer value" );
460
val = ( int ) PyInt_AsLong( value );
461
tui->but_drawtype = (char)EXPP_ClampInt( val,
462
EXPP_THEME_DRAWTYPE_MIN,
463
EXPP_THEME_DRAWTYPE_MAX );
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);
472
BIF_icons_init(BIFICONID_LAST+1);
476
return EXPP_ReturnIntError( PyExc_AttributeError,
477
"attribute not found" );
480
PyObject *pyret = NULL;
481
PyObject *valtuple = Py_BuildValue( "(O)", value );
484
return EXPP_ReturnIntError( PyExc_MemoryError,
485
"couldn't create tuple!" );
487
pyret = charRGBA_setCol( ( BPy_charRGBA * ) attrib, valtuple );
488
Py_DECREF( valtuple );
490
if( pyret == Py_None ) {
491
Py_DECREF( Py_None ); /* was increfed by charRGBA_setCol */
495
Py_DECREF( attrib ); /* we're done with it */
498
return ret; /* 0 if all went well */
502
static int ThemeUI_compare( BPy_ThemeUI * a, BPy_ThemeUI * b )
504
ThemeUI *pa = a->tui, *pb = b->tui;
505
return ( pa == pb ) ? 0 : -1;
508
static PyObject *ThemeUI_repr( BPy_ThemeUI * self )
510
return PyString_FromFormat( "[UI theme from theme \"%s\"]",
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 );
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 );
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}
537
PyTypeObject Theme_Type = {
538
PyObject_HEAD_INIT( NULL )
540
"Blender Theme", /* tp_name */
541
sizeof( BPy_Theme ), /* tp_basicsize */
544
( destructor ) Theme_dealloc, /* tp_dealloc */
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 */
557
0, /*BPy_Theme_methods,*/ /* tp_methods */
559
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
562
static PyObject *M_Theme_New( PyObject * self, PyObject * args )
564
char *name = "New Theme";
565
BPy_Theme *pytheme = NULL, *base_pytheme = NULL;
566
bTheme *btheme = NULL, *newtheme = NULL;
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" );
574
btheme = base_pytheme->theme;
576
btheme = U.themes.first;
578
newtheme = MEM_callocN( sizeof( bTheme ), "theme" );
581
pytheme = PyObject_New( BPy_Theme, &Theme_Type );
583
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
584
"couldn't create Theme Data in Blender" );
586
memcpy( newtheme, btheme, sizeof( bTheme ) );
587
BLI_addhead( &U.themes, newtheme );
588
BLI_strncpy( newtheme->name, name, 32 );
590
pytheme->theme = newtheme;
592
return ( PyObject * ) pytheme;
595
static PyObject *M_Theme_Get( PyObject * self, PyObject * args )
601
if( !PyArg_ParseTuple( args, "|s", &name ) )
602
return EXPP_ReturnPyObjError( PyExc_TypeError,
603
"expected string argument (or nothing)" );
605
iter = U.themes.first;
607
if( name ) { /* (name) - return requested theme */
608
BPy_Theme *wanted = NULL;
611
if( strcmp( name, iter->name ) == 0 ) {
612
wanted = PyObject_New( BPy_Theme,
614
wanted->theme = iter;
622
PyOS_snprintf( emsg, sizeof( emsg ),
623
"Theme \"%s\" not found", name );
624
return EXPP_ReturnPyObjError( PyExc_NameError, emsg );
627
ret = ( PyObject * ) wanted;
630
else { /* () - return list with all themes */
632
PyObject *list = NULL;
633
BPy_Theme *pytheme = NULL;
635
list = PyList_New( BLI_countlist( &( U.themes ) ) );
638
return EXPP_ReturnPyObjError( PyExc_MemoryError,
639
"couldn't create PyList" );
642
pytheme = PyObject_New( BPy_Theme, &Theme_Type );
643
pytheme->theme = iter;
647
return EXPP_ReturnPyObjError
649
"couldn't create Theme PyObject" );
651
PyList_SET_ITEM( list, index, ( PyObject * ) pytheme );
663
static PyObject *Theme_get( BPy_Theme * self, PyObject * args )
665
bTheme *btheme = self->theme;
667
ThemeSpace *tsp = NULL;
668
PyObject *pyob = NULL;
669
BPy_ThemeUI *retUI = NULL;
670
BPy_ThemeSpace *retSpc = NULL;
673
if( !PyArg_ParseTuple( args, "|O", &pyob ) )
674
return EXPP_ReturnPyObjError( PyExc_TypeError,
675
"expected string or int argument or nothing" );
677
if( !pyob ) { /* (): return list with all names */
678
PyObject *ret = PyList_New( EXPP_THEME_NUMBEROFTHEMES );
681
return EXPP_ReturnPyObjError( PyExc_MemoryError,
682
"couldn't create pylist!" );
684
type = 0; /* using as a counter only */
686
while( type < EXPP_THEME_NUMBEROFTHEMES ) {
687
PyList_SET_ITEM( ret, type,
688
PyString_FromString( themes_map[type].sval ) );
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" );
703
return EXPP_ReturnPyObjError( PyExc_TypeError,
704
"expected string or int argument or nothing" );
711
tsp = &btheme->tbuts;
717
tsp = &btheme->tfile;
723
tsp = &btheme->tinfo;
741
tsp = &btheme->timasel;
747
tsp = &btheme->toops;
750
tsp = &btheme->ttime;
753
tsp = &btheme->tnode;
758
retUI = PyObject_New( BPy_ThemeUI, &ThemeUI_Type );
759
retUI->theme = btheme;
761
return ( PyObject * ) retUI;
763
retSpc = PyObject_New( BPy_ThemeSpace, &ThemeSpace_Type );
764
retSpc->theme = btheme;
766
return ( PyObject * ) retSpc;
768
return EXPP_ReturnPyObjError( PyExc_AttributeError,
769
"invalid parameter" );
772
static PyObject *Theme_getName( BPy_Theme * self )
774
return PyString_FromString( self->theme->name );
777
static PyObject *Theme_setName( BPy_Theme * self, PyObject * value )
779
char *name = PyString_AsString(value);
782
return EXPP_ReturnPyObjError( PyExc_TypeError,
783
"expected string argument" );
785
BLI_strncpy( self->theme->name, name, 32 );
787
return EXPP_incr_ret( Py_None );
790
PyObject *Theme_Init( void )
794
Theme_Type.ob_type = &PyType_Type;
796
submodule = Py_InitModule3( "Blender.Window.Theme",
797
M_Theme_methods, M_Theme_doc );
802
static void Theme_dealloc( BPy_Theme * self )
804
PyObject_DEL( self );
807
static PyObject *Theme_getAttr( BPy_Theme * self, char *name )
809
if( !strcmp( name, "name" ) )
810
return PyString_FromString( self->theme->name );
811
else if( !strcmp( name, "__members__" ) )
812
return Py_BuildValue( "[s]", "name" );
814
return Py_FindMethod( BPy_Theme_methods, ( PyObject * ) self, name );
817
static int Theme_compare( BPy_Theme * a, BPy_Theme * b )
819
bTheme *pa = a->theme, *pb = b->theme;
820
return ( pa == pb ) ? 0 : -1;
823
static PyObject *Theme_repr( BPy_Theme * self )
825
return PyString_FromFormat( "[Theme \"%s\"]", self->theme->name );