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 "guilib/GUIProgressControl.h"
45 #pragma code_seg("PY_TEXT")
46 #pragma data_seg("PY_DATA")
47 #pragma bss_seg("PY_BSS")
48 #pragma const_seg("PY_RDATA")
57 PyObject* ControlProgress_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
59 static const char* keywords[] = { "x", "y", "width", "height", "texturebg", "textureleft", "texturemid", "textureright", "textureoverlay", NULL };
61 ControlProgress *self;
62 char *cTextureBg = NULL;
63 char *cTextureLeft = NULL;
64 char *cTextureMid = NULL;
65 char *cTextureRight = NULL;
66 char *cTextureOverLay = NULL;
68 self = (ControlProgress*)type->tp_alloc(type, 0);
69 if (!self) return NULL;
70 new(&self->strTextureLeft) string();
71 new(&self->strTextureMid) string();
72 new(&self->strTextureRight) string();
73 new(&self->strTextureBg) string();
74 new(&self->strTextureOverlay) string();
76 // parse arguments to constructor
77 if (!PyArg_ParseTupleAndKeywords(args, kwds,
94 // if texture is supplied use it, else get default ones
95 self->strTextureBg = cTextureBg ? cTextureBg : PyXBMCGetDefaultImage((char*)"progress", (char*)"texturebg", (char*)"progress_back.png");
96 self->strTextureLeft = cTextureLeft ? cTextureLeft : PyXBMCGetDefaultImage((char*)"progress", (char*)"lefttexture", (char*)"progress_left.png");
97 self->strTextureMid = cTextureMid ? cTextureMid : PyXBMCGetDefaultImage((char*)"progress", (char*)"midtexture", (char*)"progress_mid.png");
98 self->strTextureRight = cTextureRight ? cTextureRight : PyXBMCGetDefaultImage((char*)"progress", (char*)"righttexture", (char*)"progress_right.png");
99 self->strTextureOverlay = cTextureOverLay ? cTextureOverLay : PyXBMCGetDefaultImage((char*)"progress", (char*)"overlaytexture", (char*)"progress_over.png");
101 //if (cColorDiffuse) sscanf(cColorDiffuse, "%x", &self->colorDiffuse);
102 //else self->colorDiffuse = 0;
104 return (PyObject*)self;
107 void ControlProgress_Dealloc(ControlProgress* self)
109 self->strTextureLeft.~string();
110 self->strTextureMid.~string();
111 self->strTextureRight.~string();
112 self->strTextureBg.~string();
113 self->strTextureOverlay.~string();
114 self->ob_type->tp_free((PyObject*)self);
117 CGUIControl* ControlProgress_Create(ControlProgress* pControl)
119 pControl->pGUIControl = new CGUIProgressControl(pControl->iParentId, pControl->iControlId,(float)pControl->dwPosX, (float)pControl->dwPosY,
120 (float)pControl->dwWidth,(float)pControl->dwHeight,
121 (CStdString)pControl->strTextureBg,(CStdString)pControl->strTextureLeft,
122 (CStdString)pControl->strTextureMid,(CStdString)pControl->strTextureRight,
123 (CStdString)pControl->strTextureOverlay);
125 if (pControl->pGUIControl && pControl->colorDiffuse)
126 ((CGUIProgressControl *)pControl->pGUIControl)->SetColorDiffuse(pControl->colorDiffuse);
128 return pControl->pGUIControl;
131 PyDoc_STRVAR(setPercent__doc__,
132 "setPercent(percent) -- Sets the percentage of the progressbar to show.\n"
134 "percent : float - percentage of the bar to show.\n"
136 "*Note, valid range for percent is 0-100\n"
139 " - self.progress.setPercent(60)\n");
141 PyObject* ControlProgress_SetPercent(ControlProgress *self, PyObject *args)
144 if (!PyArg_ParseTuple(args, (char*)"f", &fPercent)) return NULL;
146 if (self->pGUIControl)
147 ((CGUIProgressControl*)self->pGUIControl)->SetPercentage(fPercent);
153 PyDoc_STRVAR(getPercent__doc__,
154 "getPercent() -- Returns a float of the percent of the progress.\n"
157 " - print self.progress.getValue()\n");
159 PyObject* ControlProgress_GetPercent(ControlProgress *self, PyObject *args)
162 if (self->pGUIControl)
164 fPercent = ((CGUIProgressControl*)self->pGUIControl)->GetPercentage();
165 return Py_BuildValue((char*)"f", fPercent);
167 return Py_BuildValue((char*)"f", 0);
170 PyMethodDef ControlProgress_methods[] = {
171 {(char*)"setPercent", (PyCFunction)ControlProgress_SetPercent, METH_VARARGS, setPercent__doc__},
172 {(char*)"getPercent", (PyCFunction)ControlProgress_GetPercent, METH_VARARGS, getPercent__doc__},
173 {NULL, NULL, 0, NULL}
176 // ControlProgress class
177 PyDoc_STRVAR(ControlProgress__doc__,
178 "ControlProgress class.\n"
180 "ControlProgress(x, y, width, height[, texturebg, textureleft, texturemid, textureright, textureoverlay])\n"
182 "x : integer - x coordinate of control.\n"
183 "y : integer - y coordinate of control.\n"
184 "width : integer - width of control.\n"
185 "height : integer - height of control.\n"
186 "texturebg : [opt] string - image filename.\n"
187 "textureleft : [opt] string - image filename.\n"
188 "texturemid : [opt] string - image filename.\n"
189 "textureright : [opt] string - image filename.\n"
190 "textureoverlay : [opt] string - image filename.\n"
192 "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
193 " Once you use a keyword, all following arguments require the keyword.\n"
194 " After you create the control, you need to add it to the window with addControl().\n"
197 " - self.progress = xbmcgui.ControlProgress(100, 250, 125, 75)\n");
199 // Restore code and data sections to normal.
207 PyTypeObject ControlProgress_Type;
209 void initControlProgress_Type()
211 PyXBMCInitializeTypeObject(&ControlProgress_Type);
213 ControlProgress_Type.tp_name = (char*)"xbmcgui.ControlProgress";
214 ControlProgress_Type.tp_basicsize = sizeof(ControlProgress);
215 ControlProgress_Type.tp_dealloc = (destructor)ControlProgress_Dealloc;
216 ControlProgress_Type.tp_compare = 0;
217 ControlProgress_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
218 ControlProgress_Type.tp_doc = ControlProgress__doc__;
219 ControlProgress_Type.tp_methods = ControlProgress_methods;
220 ControlProgress_Type.tp_base = &Control_Type;
221 ControlProgress_Type.tp_new = ControlProgress_New;