• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

task_python.cpp

00001 /****************************************************************************
00002 *  task_python.cpp  -  Functions for task python api
00003 *
00004 *  Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
00005 *  Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
00006 *  Copyright (c) 2004 Petri Damstén <damu@iki.fi>
00007 *
00008 *  This file is part of SuperKaramba.
00009 *
00010 *  SuperKaramba is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  SuperKaramba is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with SuperKaramba; if not, write to the Free Software
00022 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 ****************************************************************************/
00024 
00025 #ifdef _XOPEN_SOURCE
00026 #undef _XOPEN_SOURCE
00027 #endif
00028 
00029 #include <Python.h>
00030 #include <tqobject.h>
00031 #include "karamba.h"
00032 #include "meter.h"
00033 #include "meter_python.h"
00034 #include "task_python.h"
00035 
00036 // This does something with a task, such as minimize or close it
00037 int performTaskAction(long widget, long ctask, long action)
00038 {
00039   karamba* currTheme = (karamba*)widget;
00040   Task* currTask = 0;
00041   Task* task;
00042 
00043   TaskList taskList = currTheme -> taskManager.tasks();
00044 
00045   for (task = taskList.first(); task; task = taskList.next())
00046   {
00047     if ((long)task == (long)ctask)
00048     {
00049       currTask = task;
00050     }
00051   }
00052 
00053   if (currTask != 0)
00054   {
00055     switch (action)
00056     {
00057       case 1:
00058         currTask->maximize();
00059         break;
00060 
00061       case 2:
00062         currTask->restore();
00063         break;
00064 
00065       case 3:
00066         currTask->iconify();
00067         break;
00068 
00069       case 4:
00070         currTask->close();
00071         break;
00072 
00073       case 5:
00074         currTask->activate();
00075         break;
00076 
00077       case 6:
00078         currTask->raise();
00079         break;
00080 
00081       case 7:
00082         currTask->lower();
00083         break;
00084 
00085       case 8:
00086         currTask->activateRaiseOrIconify();
00087         break;
00088 
00089       case 9:
00090         currTask->toggleAlwaysOnTop();
00091         break;
00092 
00093       case 10:
00094         currTask->toggleShaded();
00095         break;
00096 
00097       default:
00098         printf("You are trying to perform an invalid action in \
00099                 performTaskAction\n");
00100     }
00101     return 1;
00102   }
00103   else
00104   {
00105     return 0;
00106   }
00107 }
00108 
00109 PyObject* py_perform_task_action(PyObject *, PyObject *args)
00110 {
00111   long widget, task, action;
00112   if (!PyArg_ParseTuple(args, (char*)"lll:performTaskAction",
00113                         &widget, &task, &action))
00114     return NULL;
00115   if (!checkKaramba(widget))
00116     return NULL;
00117   return Py_BuildValue((char*)"l", performTaskAction(widget, task, action));
00118 }
00119 
00120 // This returns all the info about a certain task
00121 // Return type is a Python List
00122 PyObject* getTaskInfo(long widget, long ctask)
00123 {
00124   karamba* currTheme = (karamba*)widget;
00125   Task* currTask = 0;
00126   Task* task;
00127 
00128   TaskList taskList = currTheme -> taskManager.tasks();
00129 
00130   for (task = taskList.first(); task; task = taskList.next())
00131   {
00132     if ((long)task == (long)ctask)
00133     {
00134       currTask = task;
00135     }
00136 
00137   }
00138 
00139   if (currTask != 0)
00140   {
00141     PyObject* pList = PyList_New(0);
00142 
00143     //Task Name
00144     if (currTask->name() != NULL)
00145     {
00146       PyList_Append(pList, PyBytes_FromString(currTask->name().latin1()));
00147     }
00148     else
00149     {
00150       PyList_Append(pList, PyBytes_FromString(""));
00151     }
00152 
00153     //Icon Name
00154     if (currTask->iconName() != NULL)
00155     {
00156       PyList_Append(pList, PyBytes_FromString(currTask->iconName().latin1()));
00157     }
00158     else
00159     {
00160       PyList_Append(pList, PyBytes_FromString(""));
00161     }
00162 
00163     //Class Name
00164     if (currTask->className() != NULL)
00165     {
00166       PyList_Append(pList, PyBytes_FromString(currTask->className().latin1()));
00167     }
00168     else
00169     {
00170       PyList_Append(pList, PyBytes_FromString(""));
00171     }
00172 
00173     // Desktop this task is on
00174     PyList_Append(pList, PyLong_FromLong(currTask->desktop()));
00175 
00176     // is it maximized?
00177     PyList_Append(pList, PyLong_FromLong(currTask->isMaximized()));
00178 
00179     // is it iconified?
00180     PyList_Append(pList, PyLong_FromLong(currTask->isIconified()));
00181 
00182     // is it shaded?
00183     PyList_Append(pList, PyLong_FromLong(currTask->isShaded()));
00184 
00185     // is it focused?
00186     PyList_Append(pList, PyLong_FromLong(currTask->isActive()));
00187 
00188     // a reference back to itself
00189     PyList_Append(pList, PyLong_FromLong((long)currTask));
00190 
00191     return pList;
00192 
00193   }
00194   else
00195   {
00196     tqWarning("Task not found.");
00197     return NULL;
00198   }
00199 }
00200 
00201 PyObject* py_get_task_info(PyObject *, PyObject *args)
00202 {
00203   long widget, task;
00204   if (!PyArg_ParseTuple(args, (char*)"ll:getTaskInfo", &widget, &task))
00205     return NULL;
00206   if (!checkKaramba(widget))
00207     return NULL;
00208   return getTaskInfo(widget, task);
00209 }
00210 
00211 // This returns all the info about a certain startup
00212 // Return type is a Python List
00213 PyObject* getStartupInfo(long widget, long cstartup)
00214 {
00215     karamba* currTheme = (karamba*)widget;
00216     Startup* currentStartup = (Startup*) cstartup;
00217     Startup* startup;
00218 
00219     StartupList startupList = currTheme -> taskManager.startups();
00220 
00221     for (startup = startupList.first(); startup; startup = startupList.next())
00222     {
00223         if ((long)startup == (long)cstartup)
00224         {
00225             break;
00226         }
00227     }
00228 
00229     startup = currentStartup;
00230 
00231     if (startup != 0)
00232     {
00233         PyObject* pList = PyList_New(0);
00234 
00235         //Startup Name
00236         if (startup -> text() != NULL)
00237         {
00238             PyList_Append(pList, PyBytes_FromString(startup -> text().latin1()));
00239         }
00240         else
00241         {
00242             PyList_Append(pList, PyBytes_FromString(""));
00243         }
00244 
00245         //Icon Name
00246         if (startup -> icon() != NULL)
00247         {
00248             PyList_Append(pList, PyBytes_FromString(startup -> icon().latin1()));
00249         }
00250         else
00251         {
00252             PyList_Append(pList, PyBytes_FromString(""));
00253         }
00254 
00255         //Executable Name
00256         if (startup -> bin() != NULL)
00257         {
00258             PyList_Append(pList, PyBytes_FromString(startup -> bin().latin1()));
00259         }
00260         else
00261         {
00262             PyList_Append(pList, PyBytes_FromString(""));
00263         }
00264 
00265         // a reference back to itself
00266         PyList_Append(pList, PyLong_FromLong((long) startup));
00267 
00268         return pList;
00269 
00270     }
00271     else
00272     {
00273         return NULL;
00274     }
00275 }
00276 
00277 PyObject* py_get_startup_info(PyObject*, PyObject* args)
00278 {
00279   long widget, startup;
00280   if (!PyArg_ParseTuple(args, (char*)"ll:getStartupInfo", &widget, &startup))
00281     return NULL;
00282   if (!checkKaramba(widget))
00283     return NULL;
00284   return getStartupInfo(widget, startup);
00285 }
00286 
00287 // This gets a system task list
00288 // It returns a String List of task names
00289 PyObject* getTaskNames(long widget)
00290 {
00291     karamba* currTheme = (karamba*)widget;
00292     PyObject* pList = PyList_New(0);
00293     PyObject* pString;
00294 
00295     TaskList taskList = currTheme -> taskManager.tasks();
00296 
00297     Task* task;
00298     for (task = taskList.first(); task; task = taskList.next())
00299     {
00300         const char* tmp = task->name().latin1();
00301         if(tmp == 0)
00302           continue;
00303         pString = PyBytes_FromString(tmp);
00304         if(pString)
00305           PyList_Append(pList, pString);
00306     }
00307     return pList;
00308 }
00309 
00310 PyObject* py_get_task_names(PyObject *, PyObject *args)
00311 {
00312   long widget;
00313   if(!PyArg_ParseTuple(args, (char*)"l:getTaskNames", &widget))
00314     return NULL;
00315   if (!checkKaramba(widget))
00316     return NULL;
00317   return getTaskNames(widget);
00318 }
00319 
00320 // This gets a system task list
00321 PyObject* getTaskList(long widget)
00322 {
00323     karamba* currTheme = (karamba*)widget;
00324     PyObject* pList = PyList_New(0);
00325     PyObject* pString;
00326 
00327     TaskList taskList = currTheme -> taskManager.tasks();
00328 
00329     Task* task;
00330     for (task = taskList.first(); task; task = taskList.next())
00331     {
00332         pString = PyLong_FromLong((long)task);
00333         PyList_Append(pList, pString);
00334     }
00335     return pList;
00336 }
00337 
00338 PyObject* py_get_task_list(PyObject *, PyObject *args)
00339 {
00340   long widget;
00341   if(!PyArg_ParseTuple(args, (char*)"l:getTaskList", &widget))
00342     return NULL;
00343   if (!checkKaramba(widget))
00344     return NULL;
00345   return getTaskList(widget);
00346 }
00347 
00348 // This gets a system startup list
00349 PyObject* getStartupList(long widget)
00350 {
00351     karamba* currTheme = (karamba*)widget;
00352     PyObject* pList = PyList_New(0);
00353     PyObject* pString;
00354 
00355     StartupList startupList = currTheme -> taskManager.startups();
00356 
00357     Startup* startup;
00358 
00359     for (startup = startupList.first(); startup; startup = startupList.next())
00360     {
00361         pString = PyLong_FromLong((long) startup);
00362         PyList_Append(pList, pString);
00363     }
00364     return pList;
00365 }
00366 
00367 PyObject* py_get_startup_list(PyObject *, PyObject *args)
00368 {
00369   long widget;
00370   if(!PyArg_ParseTuple(args, (char*)"l:getStartupList", &widget))
00371     return NULL;
00372   if (!checkKaramba(widget))
00373     return NULL;
00374   return getStartupList(widget);
00375 }

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.6.3
This website is maintained by Timothy Pearson.