[osx/ios] remove unused function
[vuplus_xbmc] / xbmc / interfaces / python / xbmcmodule / controlprogress.cpp
1 /*
2  *      Copyright (C) 2005-2008 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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
19  *
20  */
21
22 #if (defined HAVE_CONFIG_H) && (!defined WIN32)
23   #include "config.h"
24 #endif
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>
32   #else
33     #error "Could not determine version of Python to use."
34   #endif
35 #else
36   #include "python/Include/Python.h"
37 #endif
38 #include "guilib/GUIProgressControl.h"
39 #include "control.h"
40 #include "pyutil.h"
41
42 using namespace std;
43
44 #ifndef __GNUC__
45 #pragma code_seg("PY_TEXT")
46 #pragma data_seg("PY_DATA")
47 #pragma bss_seg("PY_BSS")
48 #pragma const_seg("PY_RDATA")
49 #endif
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 namespace PYXBMC
56 {
57   PyObject* ControlProgress_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
58   {
59     static const char* keywords[] = { "x", "y", "width", "height", "texturebg", "textureleft", "texturemid", "textureright", "textureoverlay", NULL };
60
61     ControlProgress *self;
62     char *cTextureBg = NULL;
63     char *cTextureLeft = NULL;
64     char *cTextureMid  = NULL;
65     char *cTextureRight  = NULL;
66     char *cTextureOverLay  = NULL;
67
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();
75
76     // parse arguments to constructor
77     if (!PyArg_ParseTupleAndKeywords(args, kwds,
78       (char*)"llll|sssss",
79       (char**)keywords,
80       &self->dwPosX,
81       &self->dwPosY,
82       &self->dwWidth,
83       &self->dwHeight,
84       &cTextureBg,
85       &cTextureLeft,
86       &cTextureMid,
87       &cTextureRight,
88       &cTextureOverLay))
89     {
90       Py_DECREF( self );
91       return NULL;
92     }
93
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");
100
101     //if (cColorDiffuse) sscanf(cColorDiffuse, "%x", &self->colorDiffuse);
102     //else self->colorDiffuse = 0;
103
104     return (PyObject*)self;
105   }
106
107   void ControlProgress_Dealloc(ControlProgress* self)
108   {
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);
115   }
116
117   CGUIControl* ControlProgress_Create(ControlProgress* pControl)
118   {
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);
124
125     if (pControl->pGUIControl && pControl->colorDiffuse)
126         ((CGUIProgressControl *)pControl->pGUIControl)->SetColorDiffuse(pControl->colorDiffuse);
127
128     return pControl->pGUIControl;
129   }
130
131   PyDoc_STRVAR(setPercent__doc__,
132     "setPercent(percent) -- Sets the percentage of the progressbar to show.\n"
133     "\n"
134     "percent       : float - percentage of the bar to show.\n"
135     "\n"
136     "*Note, valid range for percent is 0-100\n"
137     "\n"
138     "example:\n"
139     "  - self.progress.setPercent(60)\n");
140
141   PyObject* ControlProgress_SetPercent(ControlProgress *self, PyObject *args)
142   {
143     float fPercent = 0;
144     if (!PyArg_ParseTuple(args, (char*)"f", &fPercent)) return NULL;
145
146     if (self->pGUIControl)
147       ((CGUIProgressControl*)self->pGUIControl)->SetPercentage(fPercent);
148
149     Py_INCREF(Py_None);
150     return Py_None;
151   }
152
153   PyDoc_STRVAR(getPercent__doc__,
154     "getPercent() -- Returns a float of the percent of the progress.\n"
155     "\n"
156     "example:\n"
157     "  - print self.progress.getValue()\n");
158
159   PyObject* ControlProgress_GetPercent(ControlProgress *self, PyObject *args)
160   {
161     float fPercent;
162     if (self->pGUIControl)
163     {
164       fPercent = ((CGUIProgressControl*)self->pGUIControl)->GetPercentage();
165       return Py_BuildValue((char*)"f", fPercent);
166     }
167     return Py_BuildValue((char*)"f", 0);
168   }
169
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}
174   };
175
176   // ControlProgress class
177   PyDoc_STRVAR(ControlProgress__doc__,
178     "ControlProgress class.\n"
179     "\n"
180     "ControlProgress(x, y, width, height[, texturebg, textureleft, texturemid, textureright, textureoverlay])\n"
181     "\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"
191     "\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"
195     "\n"
196     "example:\n"
197     "  - self.progress = xbmcgui.ControlProgress(100, 250, 125, 75)\n");
198
199 // Restore code and data sections to normal.
200 #ifndef __GNUC__
201 #pragma code_seg()
202 #pragma data_seg()
203 #pragma bss_seg()
204 #pragma const_seg()
205 #endif
206
207   PyTypeObject ControlProgress_Type;
208
209   void initControlProgress_Type()
210   {
211     PyXBMCInitializeTypeObject(&ControlProgress_Type);
212
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;
222   }
223 }
224
225 #ifdef __cplusplus
226 }
227 #endif