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

superkaramba

  • superkaramba
  • src
task_python.cpp
1 /****************************************************************************
2 * task_python.cpp - Functions for task python api
3 *
4 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
5 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
6 * Copyright (c) 2004 Petri Damstén <damu@iki.fi>
7 *
8 * This file is part of SuperKaramba.
9 *
10 * SuperKaramba is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * SuperKaramba is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with SuperKaramba; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 ****************************************************************************/
24 
25 #ifdef _XOPEN_SOURCE
26 #undef _XOPEN_SOURCE
27 #endif
28 
29 #include <Python.h>
30 #include <tqobject.h>
31 #include "karamba.h"
32 #include "meter.h"
33 #include "meter_python.h"
34 #include "task_python.h"
35 
36 // This does something with a task, such as minimize or close it
37 int performTaskAction(long widget, long ctask, long action)
38 {
39  karamba* currTheme = (karamba*)widget;
40  Task* currTask = 0;
41  Task* task;
42 
43  TaskList taskList = currTheme -> taskManager.tasks();
44 
45  for (task = taskList.first(); task; task = taskList.next())
46  {
47  if ((long)task == (long)ctask)
48  {
49  currTask = task;
50  }
51  }
52 
53  if (currTask != 0)
54  {
55  switch (action)
56  {
57  case 1:
58  currTask->maximize();
59  break;
60 
61  case 2:
62  currTask->restore();
63  break;
64 
65  case 3:
66  currTask->iconify();
67  break;
68 
69  case 4:
70  currTask->close();
71  break;
72 
73  case 5:
74  currTask->activate();
75  break;
76 
77  case 6:
78  currTask->raise();
79  break;
80 
81  case 7:
82  currTask->lower();
83  break;
84 
85  case 8:
86  currTask->activateRaiseOrIconify();
87  break;
88 
89  case 9:
90  currTask->toggleAlwaysOnTop();
91  break;
92 
93  case 10:
94  currTask->toggleShaded();
95  break;
96 
97  default:
98  printf("You are trying to perform an invalid action in \
99  performTaskAction\n");
100  }
101  return 1;
102  }
103  else
104  {
105  return 0;
106  }
107 }
108 
109 PyObject* py_perform_task_action(PyObject *, PyObject *args)
110 {
111  long widget, task, action;
112  if (!PyArg_ParseTuple(args, (char*)"lll:performTaskAction",
113  &widget, &task, &action))
114  return NULL;
115  if (!checkKaramba(widget))
116  return NULL;
117  return Py_BuildValue((char*)"l", performTaskAction(widget, task, action));
118 }
119 
120 // This returns all the info about a certain task
121 // Return type is a Python List
122 PyObject* getTaskInfo(long widget, long ctask)
123 {
124  karamba* currTheme = (karamba*)widget;
125  Task* currTask = 0;
126  Task* task;
127 
128  TaskList taskList = currTheme -> taskManager.tasks();
129 
130  for (task = taskList.first(); task; task = taskList.next())
131  {
132  if ((long)task == (long)ctask)
133  {
134  currTask = task;
135  }
136 
137  }
138 
139  if (currTask != 0)
140  {
141  PyObject* pList = PyList_New(0);
142 
143  //Task Name
144  if (currTask->name() != NULL)
145  {
146  PyList_Append(pList, PyBytes_FromString(currTask->name().latin1()));
147  }
148  else
149  {
150  PyList_Append(pList, PyBytes_FromString(""));
151  }
152 
153  //Icon Name
154  if (currTask->iconName() != NULL)
155  {
156  PyList_Append(pList, PyBytes_FromString(currTask->iconName().latin1()));
157  }
158  else
159  {
160  PyList_Append(pList, PyBytes_FromString(""));
161  }
162 
163  //Class Name
164  if (currTask->className() != NULL)
165  {
166  PyList_Append(pList, PyBytes_FromString(currTask->className().latin1()));
167  }
168  else
169  {
170  PyList_Append(pList, PyBytes_FromString(""));
171  }
172 
173  // Desktop this task is on
174  PyList_Append(pList, PyLong_FromLong(currTask->desktop()));
175 
176  // is it maximized?
177  PyList_Append(pList, PyLong_FromLong(currTask->isMaximized()));
178 
179  // is it iconified?
180  PyList_Append(pList, PyLong_FromLong(currTask->isIconified()));
181 
182  // is it shaded?
183  PyList_Append(pList, PyLong_FromLong(currTask->isShaded()));
184 
185  // is it focused?
186  PyList_Append(pList, PyLong_FromLong(currTask->isActive()));
187 
188  // a reference back to itself
189  PyList_Append(pList, PyLong_FromLong((long)currTask));
190 
191  return pList;
192 
193  }
194  else
195  {
196  tqWarning("Task not found.");
197  return NULL;
198  }
199 }
200 
201 PyObject* py_get_task_info(PyObject *, PyObject *args)
202 {
203  long widget, task;
204  if (!PyArg_ParseTuple(args, (char*)"ll:getTaskInfo", &widget, &task))
205  return NULL;
206  if (!checkKaramba(widget))
207  return NULL;
208  return getTaskInfo(widget, task);
209 }
210 
211 // This returns all the info about a certain startup
212 // Return type is a Python List
213 PyObject* getStartupInfo(long widget, long cstartup)
214 {
215  karamba* currTheme = (karamba*)widget;
216  Startup* currentStartup = (Startup*) cstartup;
217  Startup* startup;
218 
219  StartupList startupList = currTheme -> taskManager.startups();
220 
221  for (startup = startupList.first(); startup; startup = startupList.next())
222  {
223  if ((long)startup == (long)cstartup)
224  {
225  break;
226  }
227  }
228 
229  startup = currentStartup;
230 
231  if (startup != 0)
232  {
233  PyObject* pList = PyList_New(0);
234 
235  //Startup Name
236  if (startup -> text() != NULL)
237  {
238  PyList_Append(pList, PyBytes_FromString(startup -> text().latin1()));
239  }
240  else
241  {
242  PyList_Append(pList, PyBytes_FromString(""));
243  }
244 
245  //Icon Name
246  if (startup -> icon() != NULL)
247  {
248  PyList_Append(pList, PyBytes_FromString(startup -> icon().latin1()));
249  }
250  else
251  {
252  PyList_Append(pList, PyBytes_FromString(""));
253  }
254 
255  //Executable Name
256  if (startup -> bin() != NULL)
257  {
258  PyList_Append(pList, PyBytes_FromString(startup -> bin().latin1()));
259  }
260  else
261  {
262  PyList_Append(pList, PyBytes_FromString(""));
263  }
264 
265  // a reference back to itself
266  PyList_Append(pList, PyLong_FromLong((long) startup));
267 
268  return pList;
269 
270  }
271  else
272  {
273  return NULL;
274  }
275 }
276 
277 PyObject* py_get_startup_info(PyObject*, PyObject* args)
278 {
279  long widget, startup;
280  if (!PyArg_ParseTuple(args, (char*)"ll:getStartupInfo", &widget, &startup))
281  return NULL;
282  if (!checkKaramba(widget))
283  return NULL;
284  return getStartupInfo(widget, startup);
285 }
286 
287 // This gets a system task list
288 // It returns a String List of task names
289 PyObject* getTaskNames(long widget)
290 {
291  karamba* currTheme = (karamba*)widget;
292  PyObject* pList = PyList_New(0);
293  PyObject* pString;
294 
295  TaskList taskList = currTheme -> taskManager.tasks();
296 
297  Task* task;
298  for (task = taskList.first(); task; task = taskList.next())
299  {
300  const char* tmp = task->name().latin1();
301  if(tmp == 0)
302  continue;
303  pString = PyBytes_FromString(tmp);
304  if(pString)
305  PyList_Append(pList, pString);
306  }
307  return pList;
308 }
309 
310 PyObject* py_get_task_names(PyObject *, PyObject *args)
311 {
312  long widget;
313  if(!PyArg_ParseTuple(args, (char*)"l:getTaskNames", &widget))
314  return NULL;
315  if (!checkKaramba(widget))
316  return NULL;
317  return getTaskNames(widget);
318 }
319 
320 // This gets a system task list
321 PyObject* getTaskList(long widget)
322 {
323  karamba* currTheme = (karamba*)widget;
324  PyObject* pList = PyList_New(0);
325  PyObject* pString;
326 
327  TaskList taskList = currTheme -> taskManager.tasks();
328 
329  Task* task;
330  for (task = taskList.first(); task; task = taskList.next())
331  {
332  pString = PyLong_FromLong((long)task);
333  PyList_Append(pList, pString);
334  }
335  return pList;
336 }
337 
338 PyObject* py_get_task_list(PyObject *, PyObject *args)
339 {
340  long widget;
341  if(!PyArg_ParseTuple(args, (char*)"l:getTaskList", &widget))
342  return NULL;
343  if (!checkKaramba(widget))
344  return NULL;
345  return getTaskList(widget);
346 }
347 
348 // This gets a system startup list
349 PyObject* getStartupList(long widget)
350 {
351  karamba* currTheme = (karamba*)widget;
352  PyObject* pList = PyList_New(0);
353  PyObject* pString;
354 
355  StartupList startupList = currTheme -> taskManager.startups();
356 
357  Startup* startup;
358 
359  for (startup = startupList.first(); startup; startup = startupList.next())
360  {
361  pString = PyLong_FromLong((long) startup);
362  PyList_Append(pList, pString);
363  }
364  return pList;
365 }
366 
367 PyObject* py_get_startup_list(PyObject *, PyObject *args)
368 {
369  long widget;
370  if(!PyArg_ParseTuple(args, (char*)"l:getStartupList", &widget))
371  return NULL;
372  if (!checkKaramba(widget))
373  return NULL;
374  return getStartupList(widget);
375 }
Task::activateRaiseOrIconify
void activateRaiseOrIconify()
Perform the action that is most appropriate for this task.
Definition: taskmanager.cpp:676
Task::maximize
void maximize()
Maximise the main window of this task.
Definition: taskmanager.cpp:621
Startup
Represents a task which is in the process of starting.
Definition: taskmanager.h:376
Task::isIconified
bool isIconified() const
Returns true if the task&#39;s window is iconified.
Definition: taskmanager.cpp:408
Task::isShaded
bool isShaded() const
Returns true if the task&#39;s window is shaded.
Definition: taskmanager.cpp:426
Task::desktop
int desktop() const
Returns the desktop on which this task&#39;s window resides.
Definition: taskmanager.h:92
Task::close
void close()
Activate the task&#39;s window.
Definition: taskmanager.cpp:651
Task::raise
void raise()
Raise the task&#39;s window.
Definition: taskmanager.cpp:657
Task::activate
void activate()
Activate the task&#39;s window.
Definition: taskmanager.cpp:669
Task::iconify
void iconify()
Iconify the task.
Definition: taskmanager.cpp:646
Task::restore
void restore()
Restore the main window of the task (if it was iconified).
Definition: taskmanager.cpp:634
Task::isActive
bool isActive() const
Returns true if the task&#39;s window is the active window.
Definition: taskmanager.cpp:453
Task
A dynamic interface to a task (main window).
Definition: taskmanager.h:49
Task::isMaximized
bool isMaximized() const
Returns true if the task&#39;s window is maximized.
Definition: taskmanager.cpp:399
Task::lower
void lower()
Lower the task&#39;s window.
Definition: taskmanager.cpp:663

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.8.13
This website is maintained by Timothy Pearson.