PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/interfaces/python/xbmcmodule/controlslider.cpp

https://github.com/malard/xbmc
C++ | 177 lines | 126 code | 28 blank | 23 comment | 5 complexity | 5c42c0c5e3ad5e76a472b252219b8ab7 MD5 | raw file
  1. /*
  2. * Copyright (C) 2005-2010 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. #include <Python.h>
  22. #include "guilib/GUISliderControl.h"
  23. #include "control.h"
  24. #include "pyutil.h"
  25. #include "utils/log.h"
  26. using namespace std;
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. namespace PYXBMC
  31. {
  32. PyObject * ControlSlider_New (PyTypeObject *type, PyObject *args, PyObject *kwds)
  33. {
  34. static const char* keywords[] = { "x", "y", "width", "height", "textureback", "texture", "texturefocus", NULL };
  35. ControlSlider *self;
  36. char *cTextureBack = NULL;
  37. char *cTexture = NULL;
  38. char *cTextureFoc = NULL;
  39. self = (ControlSlider *) type->tp_alloc (type, 0);
  40. if (!self) return NULL;
  41. new(&self->strTextureBack) string();
  42. new(&self->strTexture) string();
  43. new(&self->strTextureFoc) string();
  44. if (!PyArg_ParseTupleAndKeywords(args, kwds,
  45. (char*)"llll|sss",
  46. (char**)keywords,
  47. &self->dwPosX,
  48. &self->dwPosY,
  49. &self->dwWidth,
  50. &self->dwHeight,
  51. &cTextureBack,
  52. &cTexture,
  53. &cTextureFoc))
  54. {
  55. Py_DECREF( self );
  56. return NULL;
  57. }
  58. // if texture is supplied use it, else get default ones
  59. self->strTextureBack = cTextureBack ? cTextureBack : PyXBMCGetDefaultImage((char*)"slider", (char*)"texturesliderbar", (char*)"osd_slider_bg_2.png");
  60. self->strTexture = cTexture ? cTexture : PyXBMCGetDefaultImage((char*)"slider", (char*)"textureslidernib", (char*)"osd_slider_nibNF.png");
  61. self->strTextureFoc = cTextureFoc ? cTextureFoc : PyXBMCGetDefaultImage((char*)"slider", (char*)"textureslidernibfocus", (char*)"osd_slider_nib.png");
  62. return (PyObject*)self;
  63. }
  64. void ControlSlider_Dealloc(ControlSlider* self)
  65. {
  66. self->strTextureBack.~string();
  67. self->strTexture.~string();
  68. self->strTextureFoc.~string();
  69. self->ob_type->tp_free((PyObject*)self);
  70. }
  71. CGUIControl* ControlSlider_Create (ControlSlider* pControl)
  72. {
  73. pControl->pGUIControl = new CGUISliderControl(pControl->iParentId, pControl->iControlId,(float)pControl->dwPosX, (float)pControl->dwPosY,
  74. (float)pControl->dwWidth,(float)pControl->dwHeight,
  75. (CStdString)pControl->strTextureBack,(CStdString)pControl->strTexture,
  76. (CStdString)pControl->strTextureFoc,0);
  77. return pControl->pGUIControl;
  78. }
  79. PyDoc_STRVAR(getPercent__doc__,
  80. "getPercent() -- Returns a float of the percent of the slider.\n"
  81. "\n"
  82. "example:\n"
  83. " - print self.slider.getPercent()\n");
  84. PyObject* ControlSlider_GetPercent(ControlSlider*self, PyObject *args)
  85. {
  86. if (self->pGUIControl)
  87. {
  88. float fPercent = (float)((CGUISliderControl*)self->pGUIControl)->GetPercentage();
  89. return Py_BuildValue((char*)"f", fPercent);
  90. }
  91. return Py_BuildValue((char*)"f", 0);
  92. }
  93. PyDoc_STRVAR(setPercent__doc__,
  94. "setPercent(50) -- Sets the percent of the slider.\n"
  95. "\n"
  96. "example:\n"
  97. "self.slider.setPercent(50)\n");
  98. PyObject* ControlSlider_SetPercent(ControlProgress *self, PyObject *args)
  99. {
  100. float fPercent = 0;
  101. if (!PyArg_ParseTuple(args, (char*)"f", &fPercent)) return NULL;
  102. if (self->pGUIControl)
  103. ((CGUISliderControl*)self->pGUIControl)->SetPercentage((int)fPercent);
  104. Py_INCREF(Py_None);
  105. return Py_None;
  106. }
  107. PyMethodDef ControlSlider_methods[] = {
  108. {(char*)"getPercent", (PyCFunction)ControlSlider_GetPercent, METH_VARARGS, getPercent__doc__},
  109. {(char*)"setPercent", (PyCFunction)ControlSlider_SetPercent, METH_VARARGS, setPercent__doc__},
  110. {NULL, NULL, 0, NULL}
  111. };
  112. // ControlProgress class
  113. PyDoc_STRVAR(ControlSlider__doc__,
  114. "ControlSlider class.\n"
  115. "\n"
  116. "ControlSlider(x, y, width, height[, textureback, texture, texturefocus])\n"
  117. "\n"
  118. "x : integer - x coordinate of control.\n"
  119. "y : integer - y coordinate of control.\n"
  120. "width : integer - width of control.\n"
  121. "height : integer - height of control.\n"
  122. "textureback : [opt] string - image filename.\n"
  123. "texture : [opt] string - image filename.\n"
  124. "texturefocus : [opt] string - image filename.\n"
  125. "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
  126. " Once you use a keyword, all following arguments require the keyword.\n"
  127. " After you create the control, you need to add it to the window with addControl().\n"
  128. "\n"
  129. "example:\n"
  130. " - self.slider = xbmcgui.ControlSlider(100, 250, 350, 40)\n");
  131. // Restore code and data sections to normal.
  132. PyTypeObject ControlSlider_Type;
  133. void initControlSlider_Type()
  134. {
  135. PyXBMCInitializeTypeObject(&ControlSlider_Type);
  136. ControlSlider_Type.tp_name = (char*)"xbmcgui.ControlSlider";
  137. ControlSlider_Type.tp_basicsize = sizeof(ControlSlider);
  138. ControlSlider_Type.tp_dealloc = (destructor)ControlSlider_Dealloc;
  139. ControlSlider_Type.tp_compare = 0;
  140. ControlSlider_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  141. ControlSlider_Type.tp_doc = ControlSlider__doc__;
  142. ControlSlider_Type.tp_methods = ControlSlider_methods;
  143. ControlSlider_Type.tp_base = &Control_Type;
  144. ControlSlider_Type.tp_new = ControlSlider_New;
  145. }
  146. }
  147. #ifdef __cplusplus
  148. }
  149. #endif