PDA

View Full Version : ControlLabel and xbmcgui


internick
2007-07-24, 11:15
Hello all:

i'm doing some things in python and it seems to need in some circunstancies some new features in xbmcgui such as string ControlLabel.getLabel().
I know... when someone create a new label he knows the text in this label, but in some cases it will be useful and would save use of innecessary global variables.

When you want to make a ControlLabel that dinamically and conditionally change its text you should make a variable to store that text and evaluate it. In some cases that variable needs to be a global variable. It should not be neccesary.

Thanks for read :) and much many thanks for be there trying to understand what i mean

SAME (Sorry About My English)

internick
2007-08-01, 22:46
I think it's simple and you must only modify the file:

trunk/XBMC/guilib/GUILabelControl.cpp

adding ( i guess):

String CGUILabelControl::SetLabel(void)
{
return strLabel;
}

It could be useful since i'm trying to write on a standard usb keyboard and don't want to use On Screen Keyboard.
I'm doing something like:

def onAction(self, action):
key_code=action.getButtonCode()
ascii_code=key_code - KEY_VKEY
global msginputbox
if ascii_code < 256:
thechar=chr(ascii_code)
if key_code == (KEY_VKEY + 59): #Esc -> exit
self.close()
elif key_code == (KEY_VKEY + 45): #enter
self.addLine(msginputbox)
msginputbox=""
elif key_code == (KEY_VKEY + 40): #backspace
msginputbox=msginputbox[:len(msginputbox)-1]
else:
msginputbox+=thechar
self.lblinputbox.setLabel(msginputbox)
self.mymsg.setLabel(str(ascii_code))

I know... it's not complete. If i could get the label directly the variable msginputbox would be a local variable instead of a global variable and the code could be cleaner ( cleaner? )

Thx

jmarshall
2007-08-01, 23:09
GetDescription() code should already to this in the label control.

You "just" have to add the python method to access that.

internick
2007-08-02, 01:31
Ups!
various corrections ...

String CGUILabelControl::GetLabel(void)
{
return strLabel;
}

heheh ... i wrote SetLabel before :P sorry

KEY_VKEY=61408 ( i use this value to... you know that)

Nuka1195
2007-08-02, 02:09
Index: xbmc/lib/libPython/xbmcmodule/controllabel.cpp
================================================== =================
--- xbmc/lib/libPython/xbmcmodule/controllabel.cpp (revision 9759)
+++ xbmc/lib/libPython/xbmcmodule/controllabel.cpp (working copy)
@@ -133,8 +133,27 @@
return Py_None;
}

+ // getLabel() Method
+ PyDoc_STRVAR(getLabel__doc__,
+ "getLabel() -- Returns the text value for this label.\n"
+ "\n"
+ "example:\n"
+ " - label = self.label.getLabel()\n");
+
+ PyObject* ControlLabel_GetLabel(ControlLabel *self, PyObject *args)
+ {
+ if (!self->pGUIControl) return NULL;
+
+ PyGUILock();
+ const char *cLabel = self->strText.c_str();
+ PyGUIUnlock();
+
+ return Py_BuildValue("s", cLabel);
+ }
+
PyMethodDef ControlLabel_methods[] = {
{"setLabel", (PyCFunction)ControlLabel_SetLabel, METH_VARARGS, setLabel__doc__},
+ {"getLabel", (PyCFunction)ControlLabel_GetLabel, METH_VARARGS, getLabel__doc__},
{NULL, NULL, 0, NULL}
};

jmarshall
2007-08-02, 03:12
Indeed - commit away ;)

Nuka1195
2007-08-02, 05:42
Thanks, Revision 9765

internick
2007-08-02, 13:59
Nuka1195 thanks again. Great job.
That issues make XBMC a great mediacenter.

Thanks