Petri Damstén - 2003-05-12

Hi,

I have made a little patch to get pointer to meters declared in themes from python script.
New parameter in theme NAME:
TEXT NAME=GETME X=20 Y=145 VALUE="TEXT"
New function in python getMeter:
getme = karamba.getMeter(widget, "GETME")

Reason for doing this was that I think places, fonts, etc... could be set in theme files and python code is just used  for modifying the contents. This way python code can be used for themes with different styles without modifying it.

diff -Naur superkaramba-0.24/src/karamba.cpp superkaramba-new/src/karamba.cpp
--- superkaramba-0.24/src/karamba.cpp    Sun May 11 10:14:55 2003
+++ superkaramba-new/src/karamba.cpp    Mon May 12 09:24:24 2003
@@ -1020,6 +1020,29 @@
   return Py_BuildValue("l", moveWidget(widget, x, y));
}

+/* now a method we need to expose to Python */
+long getMeter(long widget, char* name) {
+  karamba* currTheme = (karamba*)widget;
+  QObjectListIt it( *currTheme->meterList ); // iterate over meters
+
+  while ( it != 0 )
+  {
+    if (strcmp(((Meter*) *it)->name(), name) == 0)
+      return (long)*it;
+    ++it;
+  }
+  return 0;
+}
+
+static PyObject* py_get_meter(PyObject *self, PyObject *args)
+{
+  long widget;
+  char* name;
+  if (!PyArg_ParseTuple(args, "ls", &widget, &name))
+    return NULL;
+  return Py_BuildValue("l", getMeter(widget, name));
+}
+
static PyMethodDef karamba_methods[] = {
   {"moveWidget",     py_move_widget,     METH_VARARGS,  "Move Widget to x,y"},
   {"resizeWidget",     py_resize_widget,     METH_VARARGS,  "Resize Widget to width,height"},
@@ -1061,6 +1084,7 @@
   {"getTaskNames",     py_get_task_names,     METH_VARARGS,  "Get the system task list in name form"},
   {"getTaskInfo",     py_get_task_info,     METH_VARARGS,  "Get all the info for a task"},
   {"performTaskAction",     py_perform_task_action,     METH_VARARGS,  "Do something with a task, such as minimize it"},
+  {"getMeter",     py_get_meter,     METH_VARARGS,  "Get meter using it's name"},
   {NULL, NULL, 0 ,NULL}
    };

@@ -1486,6 +1510,7 @@
                 int xon = getInt("XROLL",line);
                 int yon = getInt("YROLL",line);
                 QString tiptext = getString("TOOLTIP",line);
+                QString name = getString("NAME",line);
                 xon = ( xon <= 0 ) ? x:xon;
                 yon = ( yon <= 0 ) ? y:yon;

@@ -1494,6 +1519,8 @@
                 tmp->setValue( file );
                 tmp->parseImages(file, file_roll, x,y, xon, yon);
                 tmp->setKaramba(this);
+                if (name != "")
+                    tmp->setName(name.ascii());

                 if (!tiptext.isEmpty())
                     tmp->setTooltip(tiptext);
@@ -1680,6 +1707,9 @@
                     TextLabel *tmp = new TextLabel( x, y, w, h );
                     tmp->setTextProps( tmpText );
                     tmp->setValue( getString( "VALUE", line ) );
+                    QString name = getString( "NAME", line);
+                    if (name != "")
+                        tmp->setName(name.ascii());

                     setSensor( line, (Meter*)tmp );
                     meterList->append ( tmp );