2 * Copyright (C) 2005-2008 Team XBMC
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, or (at your option)
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.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
25 #if (defined USE_EXTERNAL_PYTHON)
26 #if (defined HAVE_LIBPYTHON2_6)
27 #include <python2.6/Python.h>
28 #elif (defined HAVE_LIBPYTHON2_5)
29 #include <python2.5/Python.h>
30 #elif (defined HAVE_LIBPYTHON2_4)
31 #include <python2.4/Python.h>
33 #error "Could not determine version of Python to use."
36 #include "python/Include/Python.h"
38 #include "../XBPythonDll.h"
39 #include "guilib/GUISpinControl.h"
46 #pragma code_seg("PY_TEXT")
47 #pragma data_seg("PY_DATA")
48 #pragma bss_seg("PY_BSS")
49 #pragma const_seg("PY_RDATA")
60 PyObject* ControlSpin_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
63 char* cTextureFocus = NULL;
64 char* cTextureNoFocus = NULL;
66 PyObject* pObjectText;
68 self = (ControlSpin*)type->tp_alloc(type, 0);
69 if (!self) return NULL;
70 new(&self->strTextureUp) string();
71 new(&self->strTextureDown) string();
72 new(&self->strTextureUpFocus) string();
73 new(&self->strTextureDownFocus) string();
75 if (!PyArg_ParseTuple(args, "llll|Oss", &self->dwPosX, &self->dwPosY, &self->dwWidth, &self->dwHeight,
76 &pObjectText, &cTextureFocus, &cTextureNoFocus)) return NULL;
77 if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5)) return NULL;
79 // SetLabel(const CStdString& strFontName,const CStdString& strLabel,D3DCOLOR dwColor)
80 self->strFont = "font13";
81 self->textColor = 0xffffffff;
82 self->disabledColor = 0x60ffffff;
84 self->strTextureFocus = cTextureFocus ? cTextureFocus : "button-focus.png";
85 self->strTextureNoFocus = cTextureNoFocus ? cTextureNoFocus : "button-nofocus.jpg";
87 return (PyObject*)self;
91 * allocate a new controlspin. Used for c++ and not the python user
93 PyObject* ControlSpin_New()
95 //ControlSpin* self = (ControlSpin*)_PyObject_New(&ControlSpin_Type);
96 ControlSpin*self = (ControlSpin*)ControlSpin_Type.tp_alloc(&ControlSpin_Type, 0);
97 if (!self) return NULL;
98 new(&self->strTextureUp) string();
99 new(&self->strTextureDown) string();
100 new(&self->strTextureUpFocus) string();
101 new(&self->strTextureDownFocus) string();
103 // default values for spin control
104 self->color = 0xffffffff;
110 // get default images
111 self->strTextureUp = PyXBMCGetDefaultImage((char*)"listcontrol", (char*)"textureup", (char*)"scroll-up.png");
112 self->strTextureDown = PyXBMCGetDefaultImage((char*)"listcontrol", (char*)"texturedown", (char*)"scroll-down.png");
113 self->strTextureUpFocus = PyXBMCGetDefaultImage((char*)"listcontrol", (char*)"textureupfocus", (char*)"scroll-up-focus.png");
114 self->strTextureDownFocus = PyXBMCGetDefaultImage((char*)"listcontrol", (char*)"texturedownfocus", (char*)"scroll-down-focus.png");
116 return (PyObject*)self;
119 void ControlSpin_Dealloc(ControlSpin* self)
121 self->strTextureUp.~string();
122 self->strTextureDown.~string();
123 self->strTextureUpFocus.~string();
124 self->strTextureDownFocus.~string();
125 self->ob_type->tp_free((PyObject*)self);
128 PyObject* ControlSpin_SetColor(ControlSpin *self, PyObject *args)
132 if (!PyArg_ParseTuple(args, (char*)"s", &cColor)) return NULL;
134 if (cColor) sscanf(cColor, "%x", &self->color);
137 //if (self->pGUIControl)
138 //((CGUISpinControl*)self->pGUIControl)->SetColor(self->dwDColor);
147 * (string textureUp, string textureDown, string textureUpFocus, string textureDownFocus)
149 PyDoc_STRVAR(setTextures__doc__,
150 "setTextures(up, down, upFocus, downFocus) -- Set's textures for this control.\n"
152 "texture are image files that are used for example in the skin");
154 PyObject* ControlSpin_SetTextures(ControlSpin *self, PyObject *args)
158 if (!PyArg_ParseTuple(args, (char*)"ssss", &cLine[0], &cLine[1], &cLine[2], &cLine[3])) return NULL;
160 self->strTextureUp = cLine[0];
161 self->strTextureDown = cLine[1];
162 self->strTextureUpFocus = cLine[2];
163 self->strTextureDownFocus = cLine[3];
166 if (self->pGUIControl)
168 CGUISpinControl* pControl = (CGUISpinControl*)self->pGUIControl;
176 PyMethodDef ControlSpin_methods[] = {
177 //{(char*)"setColor", (PyCFunction)ControlSpin_SetColor, METH_VARARGS, ""},
178 {(char*)"setTextures", (PyCFunction)ControlSpin_SetTextures, METH_VARARGS, setTextures__doc__},
179 {NULL, NULL, 0, NULL}
182 PyDoc_STRVAR(controlSpin__doc__,
183 "ControlSpin class.\n"
185 " - Not working yet -.\n"
187 "you can't create this object, it is returned by objects like ControlTextBox and ControlList.");
189 // Restore code and data sections to normal.
197 PyTypeObject ControlSpin_Type;
199 void initControlSpin_Type()
201 PyXBMCInitializeTypeObject(&ControlSpin_Type);
203 ControlSpin_Type.tp_name = (char*)"xbmcgui.ControlSpin";
204 ControlSpin_Type.tp_basicsize = sizeof(ControlSpin);
205 ControlSpin_Type.tp_dealloc = (destructor)ControlSpin_Dealloc;
206 ControlSpin_Type.tp_compare = 0;
207 ControlSpin_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
208 ControlSpin_Type.tp_doc = controlSpin__doc__;
209 ControlSpin_Type.tp_methods = ControlSpin_methods;
210 ControlSpin_Type.tp_base = &Control_Type;
211 ControlSpin_Type.tp_new = 0; //ControlSpin_New