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
24 #include "../XBPythonDll.h"
25 #include "guilib/GUICheckMarkControl.h"
26 #include "guilib/GUIFontManager.h"
33 #pragma code_seg("PY_TEXT")
34 #pragma data_seg("PY_DATA")
35 #pragma bss_seg("PY_BSS")
36 #pragma const_seg("PY_RDATA")
45 PyObject* ControlCheckMark_New(PyTypeObject *type, PyObject *args, PyObject *kwds )
47 static const char *keywords[] = {
48 "x", "y", "width", "height", "label", "focusTexture", "noFocusTexture",
49 "checkWidth", "checkHeight", "alignment", "font", "textColor", "disabledColor", NULL };
50 ControlCheckMark *self;
52 char* cTextureFocus = NULL;
53 char* cTextureNoFocus = NULL;
54 char* cTextColor = NULL;
55 char* cDisabledColor = NULL;
57 PyObject* pObjectText;
59 self = (ControlCheckMark*)type->tp_alloc(type, 0);
60 if (!self) return NULL;
61 new(&self->strFont) string();
62 new(&self->strText) string();
63 new(&self->strTextureFocus) string();
64 new(&self->strTextureNoFocus) string();
66 // set up default values in case they are not supplied
67 self->checkWidth = 30;
68 self->checkHeight = 30;
69 self->align = XBFONT_RIGHT;
70 self->strFont = "font13";
71 self->textColor = 0xffffffff;
72 self->disabledColor = 0x60ffffff;
74 // parse arguments to constructor
75 if (!PyArg_ParseTupleAndKeywords(
78 (char*)"llllO|sslllsss:ControlCheckMark",
97 if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
103 if (cFont) self->strFont = cFont;
104 if (cTextColor) sscanf(cTextColor, "%x", &self->textColor);
107 sscanf( cDisabledColor, "%x", &self->disabledColor );
109 self->strTextureFocus = cTextureFocus ?
111 PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturefocus", (char*)"check-box.png");
112 self->strTextureNoFocus = cTextureNoFocus ?
114 PyXBMCGetDefaultImage((char*)"checkmark", (char*)"texturenofocus", (char*)"check-boxNF.png");
116 return (PyObject*)self;
119 void ControlCheckMark_Dealloc(ControlCheckMark* self)
121 self->strFont.~string();
122 self->strText.~string();
123 self->strTextureFocus.~string();
124 self->strTextureNoFocus.~string();
125 self->ob_type->tp_free((PyObject*)self);
128 CGUIControl* ControlCheckMark_Create(ControlCheckMark* pControl)
131 label.disabledColor = pControl->disabledColor;
132 label.textColor = label.focusedColor = pControl->textColor;
133 label.font = g_fontManager.GetFont(pControl->strFont);
134 label.align = pControl->align;
135 CTextureInfo imageFocus(pControl->strTextureFocus);
136 CTextureInfo imageNoFocus(pControl->strTextureNoFocus);
137 pControl->pGUIControl = new CGUICheckMarkControl(
139 pControl->iControlId,
140 (float)pControl->dwPosX,
141 (float)pControl->dwPosY,
142 (float)pControl->dwWidth,
143 (float)pControl->dwHeight,
144 imageFocus, imageNoFocus,
145 (float)pControl->checkWidth,
146 (float)pControl->checkHeight,
149 CGUICheckMarkControl* pGuiCheckMarkControl = (CGUICheckMarkControl*)pControl->pGUIControl;
150 pGuiCheckMarkControl->SetLabel(pControl->strText);
152 return pControl->pGUIControl;
155 // setDisabledColor() Method
156 PyDoc_STRVAR(setDisabledColor__doc__,
157 "setDisabledColor(disabledColor) -- Set's this controls disabled color.\n"
159 "disabledColor : hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
162 " - self.checkmark.setDisabledColor('0xFFFF3300')\n");
164 PyObject* ControlCheckMark_SetDisabledColor(ControlCheckMark *self, PyObject *args)
166 char *cDisabledColor = NULL;
168 if (!PyArg_ParseTuple(args, (char*)"s", &cDisabledColor)) return NULL;
172 sscanf(cDisabledColor, "%x", &self->disabledColor);
176 if (self->pGUIControl)
178 ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor( self->disabledColor );
187 PyDoc_STRVAR(setLabel__doc__,
188 "setLabel(label[, font, textColor, disabledColor]) -- Set's this controls text attributes.\n"
190 "label : string or unicode - text string.\n"
191 "font : [opt] string - font used for label text. (e.g. 'font13')\n"
192 "textColor : [opt] hexstring - color of enabled checkmark's label. (e.g. '0xFFFFFFFF')\n"
193 "disabledColor : [opt] hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
196 " - self.checkmark.setLabel('Status', 'font14', '0xFFFFFFFF', '0xFFFF3300')\n");
198 PyObject* ControlCheckMark_SetLabel(ControlCheckMark *self, PyObject *args)
200 PyObject *pObjectText;
202 char *cTextColor = NULL;
203 char* cDisabledColor = NULL;
205 if (!PyArg_ParseTuple(
206 args, (char*)"O|sss",
207 &pObjectText, &cFont,
208 &cTextColor, &cDisabledColor))
211 if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 1))
214 if (cFont) self->strFont = cFont;
217 sscanf(cTextColor, "%x", &self->textColor);
221 sscanf(cDisabledColor, "%x", &self->disabledColor);
225 if (self->pGUIControl)
227 ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetLabel(
231 ((CGUICheckMarkControl*)self->pGUIControl)->PythonSetDisabledColor(
232 self->disabledColor );
240 // getSelected() Method
241 PyDoc_STRVAR(getSelected__doc__,
242 "getSelected() -- Returns the selected status for this checkmark as a bool.\n"
245 " - selected = self.checkmark.getSelected()\n");
247 PyObject* ControlCheckMark_GetSelected( ControlCheckMark *self )
252 if (self->pGUIControl)
254 isSelected = ((CGUICheckMarkControl*)self->pGUIControl)->GetSelected();
258 return Py_BuildValue((char*)"b", isSelected);
261 // setSelected() Method
262 PyDoc_STRVAR(setSelected__doc__,
263 "setSelected(isOn) -- Sets this checkmark status to on or off.\n"
265 "isOn : bool - True=selected (on) / False=not selected (off)\n"
268 " - self.checkmark.setSelected(True)\n");
270 PyObject* ControlCheckMark_SetSelected(ControlCheckMark *self, PyObject *args)
274 if (!PyArg_ParseTuple(args, (char*)"b", &isSelected))
278 if (self->pGUIControl)
280 ((CGUICheckMarkControl*)self->pGUIControl)->SetSelected(0 != isSelected);
288 PyMethodDef ControlCheckMark_methods[] = {
289 {(char*)"getSelected", (PyCFunction)ControlCheckMark_GetSelected, METH_NOARGS, getSelected__doc__},
290 {(char*)"setSelected", (PyCFunction)ControlCheckMark_SetSelected, METH_VARARGS, setSelected__doc__},
291 {(char*)"setLabel", (PyCFunction)ControlCheckMark_SetLabel, METH_VARARGS, setLabel__doc__},
292 {(char*)"setDisabledColor", (PyCFunction)ControlCheckMark_SetDisabledColor, METH_VARARGS, setDisabledColor__doc__},
293 {NULL, NULL, 0, NULL}
296 // ControlCheckMark class
297 PyDoc_STRVAR(controlCheckMark__doc__,
298 "ControlCheckMark class.\n"
300 "ControlCheckMark(x, y, width, height, label[, focusTexture, noFocusTexture,\n"
301 " checkWidth, checkHeight, alignment, font, textColor, disabledColor])\n"
303 "x : integer - x coordinate of control.\n"
304 "y : integer - y coordinate of control.\n"
305 "width : integer - width of control.\n"
306 "height : integer - height of control.\n"
307 "label : string or unicode - text string.\n"
308 "focusTexture : [opt] string - filename for focus texture.\n"
309 "noFocusTexture : [opt] string - filename for no focus texture.\n"
310 "checkWidth : [opt] integer - width of checkmark.\n"
311 "checkHeight : [opt] integer - height of checkmark.\n"
312 "alignment : [opt] integer - alignment of label - *Note, see xbfont.h\n"
313 "font : [opt] string - font used for label text. (e.g. 'font13')\n"
314 "textColor : [opt] hexstring - color of enabled checkmark's label. (e.g. '0xFFFFFFFF')\n"
315 "disabledColor : [opt] hexstring - color of disabled checkmark's label. (e.g. '0xFFFF3300')\n"
317 "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
318 " Once you use a keyword, all following arguments require the keyword.\n"
319 " After you create the control, you need to add it to the window with addControl().\n"
322 " - self.checkmark = xbmcgui.ControlCheckMark(100, 250, 200, 50, 'Status', font='font14')\n");
325 // Restore code and data sections to normal.
333 PyTypeObject ControlCheckMark_Type;
335 void initControlCheckMark_Type()
337 PyXBMCInitializeTypeObject(&ControlCheckMark_Type);
339 ControlCheckMark_Type.tp_name = (char*)"xbmcgui.ControlCheckMark";
340 ControlCheckMark_Type.tp_basicsize = sizeof(ControlCheckMark);
341 ControlCheckMark_Type.tp_dealloc = (destructor)ControlCheckMark_Dealloc;
342 ControlCheckMark_Type.tp_compare = 0;
343 ControlCheckMark_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
344 ControlCheckMark_Type.tp_doc = controlCheckMark__doc__;
345 ControlCheckMark_Type.tp_methods = ControlCheckMark_methods;
346 ControlCheckMark_Type.tp_base = &Control_Type;
347 ControlCheckMark_Type.tp_new = ControlCheckMark_New;