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/GUILabelControl.h"
26 #include "guilib/GUIFontManager.h"
27 #include "guilib/GUIWindowManager.h"
34 #pragma code_seg("PY_TEXT")
35 #pragma data_seg("PY_DATA")
36 #pragma bss_seg("PY_BSS")
37 #pragma const_seg("PY_RDATA")
46 PyObject* ControlLabel_New(PyTypeObject *type, PyObject *args, PyObject *kwds)
48 static const char *keywords[] = {
49 "x", "y", "width", "height", "label", "font", "textColor",
50 "disabledColor", "alignment", "hasPath", "angle", NULL };
54 char *cTextColor = NULL;
55 char *cDisabledColor = NULL;
56 PyObject* pObjectText;
57 char bHasPath = false;
59 self = (ControlLabel*)type->tp_alloc(type, 0);
60 if (!self) return NULL;
61 new(&self->strText) string();
62 new(&self->strFont) string();
64 // set up default values in case they are not supplied
65 self->strFont = "font13";
66 self->textColor = 0xffffffff;
67 self->disabledColor = 0x60ffffff;
68 self->align = XBFONT_LEFT;
71 if (!PyArg_ParseTupleAndKeywords(
74 (char*)"llllO|ssslbl",
91 self->bHasPath = (0 != bHasPath);
92 if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 5))
98 if (cFont) self->strFont = cFont;
99 if (cTextColor) sscanf(cTextColor, "%x", &self->textColor);
102 sscanf( cDisabledColor, "%x", &self->disabledColor );
105 return (PyObject*)self;
108 void ControlLabel_Dealloc(ControlLabel* self)
110 self->strText.~string();
111 self->strFont.~string();
112 self->ob_type->tp_free((PyObject*)self);
115 CGUIControl* ControlLabel_Create(ControlLabel* pControl)
118 label.font = g_fontManager.GetFont(pControl->strFont);
119 label.textColor = label.focusedColor = pControl->textColor;
120 label.disabledColor = pControl->disabledColor;
121 label.align = pControl->align;
122 label.angle = (float)-pControl->iAngle;
123 pControl->pGUIControl = new CGUILabelControl(
125 pControl->iControlId,
126 (float)pControl->dwPosX,
127 (float)pControl->dwPosY,
128 (float)pControl->dwWidth,
129 (float)pControl->dwHeight,
133 ((CGUILabelControl *)pControl->pGUIControl)->SetLabel(pControl->strText);
134 return pControl->pGUIControl;
138 PyDoc_STRVAR(setLabel__doc__,
139 "setLabel(label) -- Set's text for this label.\n"
141 "label : string or unicode - text string.\n"
144 " - self.label.setLabel('Status')\n");
146 PyObject* ControlLabel_SetLabel(ControlLabel *self, PyObject *args)
148 PyObject *pObjectText;
150 if (!PyArg_ParseTuple(args, (char*)"O", &pObjectText)) return NULL;
151 if (!PyXBMCGetUnicodeString(self->strText, pObjectText, 1)) return NULL;
153 ControlLabel *pControl = (ControlLabel*)self;
154 CGUIMessage msg(GUI_MSG_LABEL_SET, pControl->iParentId, pControl->iControlId);
155 msg.SetLabel(self->strText);
156 g_windowManager.SendThreadMessage(msg, pControl->iParentId);
163 PyDoc_STRVAR(getLabel__doc__,
164 "getLabel() -- Returns the text value for this label.\n"
167 " - label = self.label.getLabel()\n");
169 PyObject* ControlLabel_GetLabel(ControlLabel *self, PyObject *args)
171 if (!self->pGUIControl) return NULL;
172 return Py_BuildValue((char*)"s", self->strText.c_str());
175 PyMethodDef ControlLabel_methods[] = {
176 {(char*)"setLabel", (PyCFunction)ControlLabel_SetLabel, METH_VARARGS, setLabel__doc__},
177 {(char*)"getLabel", (PyCFunction)ControlLabel_GetLabel, METH_VARARGS, getLabel__doc__},
178 {NULL, NULL, 0, NULL}
181 // ControlLabel class
182 PyDoc_STRVAR(controlLabel__doc__,
183 "ControlLabel class.\n"
185 "ControlLabel(x, y, width, height, label[, font, textColor, \n"
186 " disabledColor, alignment, hasPath, angle])\n"
188 "x : integer - x coordinate of control.\n"
189 "y : integer - y coordinate of control.\n"
190 "width : integer - width of control.\n"
191 "height : integer - height of control.\n"
192 "label : string or unicode - text string.\n"
193 "font : [opt] string - font used for label text. (e.g. 'font13')\n"
194 "textColor : [opt] hexstring - color of enabled label's label. (e.g. '0xFFFFFFFF')\n"
195 "disabledColor : [opt] hexstring - color of disabled label's label. (e.g. '0xFFFF3300')\n"
196 "alignment : [opt] integer - alignment of label - *Note, see xbfont.h\n"
197 "hasPath : [opt] bool - True=stores a path / False=no path.\n"
198 "angle : [opt] integer - angle of control. (+ rotates CCW, - rotates CW)"
200 "*Note, You can use the above as keywords for arguments and skip certain optional arguments.\n"
201 " Once you use a keyword, all following arguments require the keyword.\n"
202 " After you create the control, you need to add it to the window with addControl().\n"
205 " - self.label = xbmcgui.ControlLabel(100, 250, 125, 75, 'Status', angle=45)\n");
207 // Restore code and data sections to normal.
215 PyTypeObject ControlLabel_Type;
217 void initControlLabel_Type()
219 PyXBMCInitializeTypeObject(&ControlLabel_Type);
221 ControlLabel_Type.tp_name = (char*)"xbmcgui.ControlLabel";
222 ControlLabel_Type.tp_basicsize = sizeof(ControlLabel);
223 ControlLabel_Type.tp_dealloc = (destructor)ControlLabel_Dealloc;
224 ControlLabel_Type.tp_compare = 0;
225 ControlLabel_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
226 ControlLabel_Type.tp_doc = controlLabel__doc__;
227 ControlLabel_Type.tp_methods = ControlLabel_methods;
228 ControlLabel_Type.tp_base = &Control_Type;
229 ControlLabel_Type.tp_new = ControlLabel_New;