2 * Copyright (C) 2005-2010 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
24 #include "guilib/GUISliderControl.h"
27 #include "utils/log.h"
31 #pragma code_seg("PY_TEXT")
32 #pragma data_seg("PY_DATA")
33 #pragma bss_seg("PY_BSS")
34 #pragma const_seg("PY_RDATA")
43 PyObject * ControlSlider_New (PyTypeObject *type, PyObject *args, PyObject *kwds)
45 static const char* keywords[] = { "x", "y", "width", "height", "textureback", "texture", "texturefocus", NULL };
48 char *cTextureBack = NULL;
49 char *cTexture = NULL;
50 char *cTextureFoc = NULL;
52 self = (ControlSlider *) type->tp_alloc (type, 0);
53 if (!self) return NULL;
54 new(&self->strTextureBack) string();
55 new(&self->strTexture) string();
56 new(&self->strTextureFoc) string();
58 if (!PyArg_ParseTupleAndKeywords(args, kwds,
72 // if texture is supplied use it, else get default ones
73 self->strTextureBack = cTextureBack ? cTextureBack : PyXBMCGetDefaultImage((char*)"slider", (char*)"texturesliderbar", (char*)"osd_slider_bg_2.png");
74 self->strTexture = cTexture ? cTexture : PyXBMCGetDefaultImage((char*)"slider", (char*)"textureslidernib", (char*)"osd_slider_nibNF.png");
75 self->strTextureFoc = cTextureFoc ? cTextureFoc : PyXBMCGetDefaultImage((char*)"slider", (char*)"textureslidernibfocus", (char*)"osd_slider_nib.png");
77 return (PyObject*)self;
80 void ControlSlider_Dealloc(ControlSlider* self)
82 self->strTextureBack.~string();
83 self->strTexture.~string();
84 self->strTextureFoc.~string();
85 self->ob_type->tp_free((PyObject*)self);
88 CGUIControl* ControlSlider_Create (ControlSlider* pControl)
91 pControl->pGUIControl = new CGUISliderControl(pControl->iParentId, pControl->iControlId,(float)pControl->dwPosX, (float)pControl->dwPosY,
92 (float)pControl->dwWidth,(float)pControl->dwHeight,
93 (CStdString)pControl->strTextureBack,(CStdString)pControl->strTexture,
94 (CStdString)pControl->strTextureFoc,0);
97 return pControl->pGUIControl;
100 PyDoc_STRVAR(getPercent__doc__,
101 "getPercent() -- Returns a float of the percent of the slider.\n"
104 " - print self.slider.getPercent()\n");
106 PyObject* ControlSlider_GetPercent(ControlSlider*self, PyObject *args)
108 if (self->pGUIControl)
110 float fPercent = (float)((CGUISliderControl*)self->pGUIControl)->GetPercentage();
111 return Py_BuildValue((char*)"f", fPercent);
113 return Py_BuildValue((char*)"f", 0);
116 PyDoc_STRVAR(setPercent__doc__,
117 "setPercent(50) -- Sets the percent of the slider.\n"
120 "self.slider.setPercent(50)\n");
122 PyObject* ControlSlider_SetPercent(ControlProgress *self, PyObject *args)
125 if (!PyArg_ParseTuple(args, (char*)"f", &fPercent)) return NULL;
127 if (self->pGUIControl)
128 ((CGUISliderControl*)self->pGUIControl)->SetPercentage((int)fPercent);
135 PyMethodDef ControlSlider_methods[] = {
136 {(char*)"getPercent", (PyCFunction)ControlSlider_GetPercent, METH_VARARGS, getPercent__doc__},
137 {(char*)"setPercent", (PyCFunction)ControlSlider_SetPercent, METH_VARARGS, setPercent__doc__},
138 {NULL, NULL, 0, NULL}
141 // ControlProgress class
142 PyDoc_STRVAR(ControlSlider__doc__,
143 "ControlSlider class.\n"
145 "ControlSlider(x, y, width, height[, textureback, texture, texturefocus])\n"
147 "x : integer - x coordinate of control.\n"
148 "y : integer - y coordinate of control.\n"
149 "width : integer - width of control.\n"
150 "height : integer - height of control.\n"
151 "textureback : [opt] string - image filename.\n"
152 "texture : [opt] string - image filename.\n"
153 "texturefocus : [opt] string - image filename.\n"
154 "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
155 " Once you use a keyword, all following arguments require the keyword.\n"
156 " After you create the control, you need to add it to the window with addControl().\n"
159 " - self.slider = xbmcgui.ControlSlider(100, 250, 350, 40)\n");
161 // Restore code and data sections to normal.
169 PyTypeObject ControlSlider_Type;
171 void initControlSlider_Type()
173 PyXBMCInitializeTypeObject(&ControlSlider_Type);
175 ControlSlider_Type.tp_name = (char*)"xbmcgui.ControlSlider";
176 ControlSlider_Type.tp_basicsize = sizeof(ControlSlider);
177 ControlSlider_Type.tp_dealloc = (destructor)ControlSlider_Dealloc;
178 ControlSlider_Type.tp_compare = 0;
179 ControlSlider_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
180 ControlSlider_Type.tp_doc = ControlSlider__doc__;
181 ControlSlider_Type.tp_methods = ControlSlider_methods;
182 ControlSlider_Type.tp_base = &Control_Type;
183 ControlSlider_Type.tp_new = ControlSlider_New;