PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/xbmc/interfaces/python/xbmcmodule/controlcheckmark.cpp

https://github.com/MaDDoGo/xbmc
C++ | 340 lines | 266 code | 46 blank | 28 comment | 19 complexity | 96a8b1ff575d9ccff29449dbdf3c16a7 MD5 | raw file
  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. #include <Python.h>
  22. #include "guilib/GUICheckMarkControl.h"
  23. #include "guilib/GUIFontManager.h"
  24. #include "control.h"
  25. #include "pyutil.h"
  26. using namespace std;
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. namespace PYXBMC
  31. {
  32. PyObject* ControlCheckMark_New(PyTypeObject *type, PyObject *args, PyObject *kwds )
  33. {
  34. static const char *keywords[] = {
  35. "x", "y", "width", "height", "label", "focusTexture", "noFocusTexture",
  36. "checkWidth", "checkHeight", "alignment", "font", "textColor", "disabledColor", NULL };
  37. ControlCheckMark *self;
  38. char* cFont = NULL;
  39. char* cTextureFocus = NULL;
  40. char* cTextureNoFocus = NULL;
  41. char* cTextColor = NULL;
  42. char* cDisabledColor = NULL;
  43. PyObject* pObjectText;
  44. self = (ControlCheckMark*)type->tp_alloc(type, 0);
  45. if (!self) return NULL;
  46. new(&self->strFont) string();
  47. new(&self->strText) string();
  48. new(&self->strTextureFocus) string();
  49. new(&self->strTextureNoFocus) string();
  50. // set up default values in case they are not supplied
  51. self->checkWidth = 30;
  52. self->checkHeight = 30;
  53. self->align = XBFONT_RIGHT;
  54. self->strFont = "font13";
  55. self->textColor = 0xffffffff;
  56. self->disabledColor = 0x60ffffff;
  57. // parse arguments to constructor
  58. if (!PyArg_ParseTupleAndKeywords(
  59. args,
  60. kwds,
  61. (char*)"llllO|sslllsss:ControlCheckMark",
  62. (char**)keywords,
  63. &self->dwPosX,
  64. &self->dwPosY,
  65. &self->dwWidth,
  66. &self->dwHeight,
  67. &pObjectText,
  68. &cTextureFocus,
  69. &cTextureNoFocus,
  70. &self->checkWidth,
  71. &self->checkHeight,
  72. &self->align,
  73. &cFont,
  74. &cTextColor,
  75. &cDisabledColor ))
  76. {
  77. Py_DECREF( self );
  78. return NULL;
  79. }
  80. if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
  81. {
  82. Py_DECREF( self );
  83. return NULL;
  84. }
  85. if (cFont) self->strFont = cFont;
  86. if (cTextColor) sscanf(cTextColor, "%x", &self->textColor);
  87. if (cDisabledColor)
  88. {
  89. sscanf( cDisabledColor, "%x", &self->disabledColor );
  90. }
  91. self->strTextureFocus = cTextureFocus ?
  92. cTextureFocus :
  93. PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturefocus", (char*)"check-box.png");
  94. self->strTextureNoFocus = cTextureNoFocus ?
  95. cTextureNoFocus :
  96. PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturenofocus", (char*)"check-boxNF.png");
  97. return (PyObject*)self;
  98. }
  99. void ControlCheckMark_Dealloc(ControlCheckMark* self)
  100. {
  101. self->strFont.~string();
  102. self->strText.~string();
  103. self->strTextureFocus.~string();
  104. self->strTextureNoFocus.~string();
  105. self->ob_type->tp_free((PyObject*)self);
  106. }
  107. CGUIControl* ControlCheckMark_Create(ControlCheckMark* pControl)
  108. {
  109. CLabelInfo label;
  110. label.disabledColor = pControl->disabledColor;
  111. label.textColor = label.focusedColor = pControl->textColor;
  112. label.font = g_fontManager.GetFont(pControl->strFont);
  113. label.align = pControl->align;
  114. CTextureInfo imageFocus(pControl->strTextureFocus);
  115. CTextureInfo imageNoFocus(pControl->strTextureNoFocus);
  116. pControl->pGUIControl = new CGUICheckMarkControl(
  117. pControl->iParentId,
  118. pControl->iControlId,
  119. (float)pControl->dwPosX,
  120. (float)pControl->dwPosY,
  121. (float)pControl->dwWidth,
  122. (float)pControl->dwHeight,
  123. imageFocus, imageNoFocus,
  124. (float)pControl->checkWidth,
  125. (float)pControl->checkHeight,
  126. label );
  127. CGUICheckMarkControl* pGuiCheckMarkControl = (CGUICheckMarkControl*)pControl->pGUIControl;
  128. pGuiCheckMarkControl->SetLabel(pControl->strText);
  129. return pControl->pGUIControl;
  130. }
  131. // setDisabledColor() Method
  132. PyDoc_STRVAR(setDisabledColor__doc__,
  133. "setDisabledColor(disabledColor) -- Set's this controls disabled color.\n"
  134. "\n"
  135. "disabledColor : hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
  136. "\n"
  137. "example:\n"
  138. " - self.checkmark.setDisabledColor('0xFFFF3300')\n");
  139. PyObject* ControlCheckMark_SetDisabledColor(ControlCheckMark *self, PyObject *args)
  140. {
  141. char *cDisabledColor = NULL;
  142. if (!PyArg_ParseTuple(args, (char*)"s", &cDisabledColor)) return NULL;
  143. if (cDisabledColor)
  144. {
  145. sscanf(cDisabledColor, "%x", &self->disabledColor);
  146. }
  147. PyXBMCGUILock();
  148. if (self->pGUIControl)
  149. {
  150. ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor( self->disabledColor );
  151. }
  152. PyXBMCGUIUnlock();
  153. Py_INCREF(Py_None);
  154. return Py_None;
  155. }
  156. // setLabel() Method
  157. PyDoc_STRVAR(setLabel__doc__,
  158. "setLabel(label[, font, textColor, disabledColor]) -- Set's this controls text attributes.\n"
  159. "\n"
  160. "label : string or unicode - text string.\n"
  161. "font : [opt] string - font used for label text. (e.g. 'font13')\n"
  162. "textColor : [opt] hexstring - color of enabled checkmark's label. (e.g. '0xFFFFFFFF')\n"
  163. "disabledColor : [opt] hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
  164. "\n"
  165. "example:\n"
  166. " - self.checkmark.setLabel('Status', 'font14', '0xFFFFFFFF', '0xFFFF3300')\n");
  167. PyObject* ControlCheckMark_SetLabel(ControlCheckMark *self, PyObject *args)
  168. {
  169. PyObject *pObjectText;
  170. char *cFont = NULL;
  171. char *cTextColor = NULL;
  172. char* cDisabledColor = NULL;
  173. if (!PyArg_ParseTuple(
  174. args, (char*)"O|sss",
  175. &pObjectText, &cFont,
  176. &cTextColor, &cDisabledColor))
  177. return NULL;
  178. if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 1))
  179. return NULL;
  180. if (cFont) self->strFont = cFont;
  181. if (cTextColor)
  182. {
  183. sscanf(cTextColor, "%x", &self->textColor);
  184. }
  185. if (cDisabledColor)
  186. {
  187. sscanf(cDisabledColor, "%x", &self->disabledColor);
  188. }
  189. PyXBMCGUILock();
  190. if (self->pGUIControl)
  191. {
  192. ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetLabel(
  193. self->strFont,
  194. self->strText,
  195. self->textColor );
  196. ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor(
  197. self->disabledColor );
  198. }
  199. PyXBMCGUIUnlock();
  200. Py_INCREF(Py_None);
  201. return Py_None;
  202. }
  203. // getSelected() Method
  204. PyDoc_STRVAR(getSelected__doc__,
  205. "getSelected() -- Returns the selected status for this checkmark as a bool.\n"
  206. "\n"
  207. "example:\n"
  208. " - selected = self.checkmark.getSelected()\n");
  209. PyObject* ControlCheckMark_GetSelected( ControlCheckMark *self )
  210. {
  211. bool isSelected = 0;
  212. PyXBMCGUILock();
  213. if (self->pGUIControl)
  214. {
  215. isSelected = ((CGUICheckMarkControl*)self->pGUIControl)->GetSelected();
  216. }
  217. PyXBMCGUIUnlock();
  218. return Py_BuildValue((char*)"b", isSelected);
  219. }
  220. // setSelected() Method
  221. PyDoc_STRVAR(setSelected__doc__,
  222. "setSelected(isOn) -- Sets this checkmark status to on or off.\n"
  223. "\n"
  224. "isOn : bool - True=selected (on) / False=not selected (off)\n"
  225. "\n"
  226. "example:\n"
  227. " - self.checkmark.setSelected(True)\n");
  228. PyObject* ControlCheckMark_SetSelected(ControlCheckMark *self, PyObject *args)
  229. {
  230. char isSelected = 0;
  231. if (!PyArg_ParseTuple(args, (char*)"b", &isSelected))
  232. return NULL;
  233. PyXBMCGUILock();
  234. if (self->pGUIControl)
  235. {
  236. ((CGUICheckMarkControl*)self->pGUIControl)->SetSelected(0 != isSelected);
  237. }
  238. PyXBMCGUIUnlock();
  239. Py_INCREF(Py_None);
  240. return Py_None;
  241. }
  242. PyMethodDef ControlCheckMark_methods[] = {
  243. {(char*)"getSelected", (PyCFunction)ControlCheckMark_GetSelected, METH_NOARGS, getSelected__doc__},
  244. {(char*)"setSelected", (PyCFunction)ControlCheckMark_SetSelected, METH_VARARGS, setSelected__doc__},
  245. {(char*)"setLabel", (PyCFunction)ControlCheckMark_SetLabel, METH_VARARGS, setLabel__doc__},
  246. {(char*)"setDisabledColor", (PyCFunction)ControlCheckMark_SetDisabledColor, METH_VARARGS, setDisabledColor__doc__},
  247. {NULL, NULL, 0, NULL}
  248. };
  249. // ControlCheckMark class
  250. PyDoc_STRVAR(controlCheckMark__doc__,
  251. "ControlCheckMark class.\n"
  252. "\n"
  253. "ControlCheckMark(x, y, width, height, label[, focusTexture, noFocusTexture,\n"
  254. " checkWidth, checkHeight, alignment, font, textColor, disabledColor])\n"
  255. "\n"
  256. "x : integer - x coordinate of control.\n"
  257. "y : integer - y coordinate of control.\n"
  258. "width : integer - width of control.\n"
  259. "height : integer - height of control.\n"
  260. "label : string or unicode - text string.\n"
  261. "focusTexture : [opt] string - filename for focus texture.\n"
  262. "noFocusTexture : [opt] string - filename for no focus texture.\n"
  263. "checkWidth : [opt] integer - width of checkmark.\n"
  264. "checkHeight : [opt] integer - height of checkmark.\n"
  265. "alignment : [opt] integer - alignment of label - *Note, see xbfont.h\n"
  266. "font : [opt] string - font used for label text. (e.g. 'font13')\n"
  267. "textColor : [opt] hexstring - color of enabled checkmark's label. (e.g. '0xFFFFFFFF')\n"
  268. "disabledColor : [opt] hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
  269. "\n"
  270. "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
  271. " Once you use a keyword, all following arguments require the keyword.\n"
  272. " After you create the control, you need to add it to the window with addControl().\n"
  273. "\n"
  274. "example:\n"
  275. " - self.checkmark = xbmcgui.ControlCheckMark(100, 250, 200, 50, 'Status', font='font14')\n");
  276. // Restore code and data sections to normal.
  277. PyTypeObject ControlCheckMark_Type;
  278. void initControlCheckMark_Type()
  279. {
  280. PyXBMCInitializeTypeObject(&ControlCheckMark_Type);
  281. ControlCheckMark_Type.tp_name = (char*)"xbmcgui.ControlCheckMark";
  282. ControlCheckMark_Type.tp_basicsize = sizeof(ControlCheckMark);
  283. ControlCheckMark_Type.tp_dealloc = (destructor)ControlCheckMark_Dealloc;
  284. ControlCheckMark_Type.tp_compare = 0;
  285. ControlCheckMark_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  286. ControlCheckMark_Type.tp_doc = controlCheckMark__doc__;
  287. ControlCheckMark_Type.tp_methods = ControlCheckMark_methods;
  288. ControlCheckMark_Type.tp_base = &Control_Type;
  289. ControlCheckMark_Type.tp_new = ControlCheckMark_New;
  290. }
  291. }
  292. #ifdef __cplusplus
  293. }
  294. #endif