summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/imagelabel_python.cpp
blob: 1251cc9a618ca02e187bbdb5cf58806d0327b997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/****************************************************************************
*  imagelabel_python.cpp  -  Imagelabel functions for python api
*
*  Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
*  Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
*  Copyright (c) 2004 Petri Damstén <damu@iki.fi>
*
*  This file is part of SuperKaramba.
*
*  SuperKaramba is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
*
*  SuperKaramba is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with SuperKaramba; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
****************************************************************************/

#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif

#include <Python.h>
#include <tqobject.h>
#include "karamba.h"
#include "imagelabel.h"
#include "meter_python.h"
#include "imagelabel_python.h"
#include "lineparser.h"

ImageLabel* createImageLabel(karamba *theme, long x, long y,
                             char* path, bool bg)
{
  TQString file;
  //TQString fakefile;

  /*tmp->setThemePath(theme->themePath);*/
  //FIXME: This is an ugly hack to ensure a unique reference
  //to add to the meterList.  It is a workaround for when a clickarea
  //is attached to an image, the image is deleted, and a new image is
  //created. A correct solution would be have dictionaries with a key/value
  //pair of ints->refs.
  ImageLabel *tmp2 = new ImageLabel(theme, x, y, 0, 0);
  ImageLabel *tmp = new ImageLabel(theme, x, y, 0, 0);
  delete tmp2;
  
  if(path)
  {
    file.setAscii(path);
    tmp->setValue(file);
    //tmp->parseImages(file, fakefile, x,y, 0, 0);
  }
  tmp->setBackground(bg);
  theme->setSensor(LineParser(file), tmp);
  theme->meterList->append (tmp);
  theme->imageList->append (tmp);
  if(bg)
    theme->kroot->repaint(true);
  return tmp;
}

PyObject* py_createImage(PyObject *, PyObject *args)
{
  long widget, x, y;
  char *text;
  if (!PyArg_ParseTuple(args, (char*)"llls:createImage", &widget, &x, &y, &text))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;

  ImageLabel *tmp = createImageLabel((karamba*)widget, x, y, text, 0);
  return (Py_BuildValue((char*)"l", (long)tmp));
}

PyObject* py_createBackgroundImage(PyObject *, PyObject *args)
{
  long widget, x, y;
  char *text;
  if (!PyArg_ParseTuple(args, (char*)"llls:createBackgroundImage", &widget, &x, &y,
                        &text))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;
  ImageLabel *tmp = createImageLabel((karamba*)widget, x, y, text, 1);
  return (Py_BuildValue((char*)"l", (long)tmp));
}

//Matthew Kay: new function for creating icons for tasks
/**
 * creates the icon for the specified task as a karamba image
 * @param ctask         the window id of the task to create the icon for
 */
PyObject* py_createTaskIcon(PyObject *, PyObject *args)
{
  long widget, x, y;
  long ctask;
  if (!PyArg_ParseTuple(args, (char*)"llll:createTaskIcon", &widget, &x, &y, &ctask))
    return NULL;
  if (!checkKaramba(widget))
    return NULL;

  //get the specified task and insure it exists
  TaskList taskList = ((karamba*)widget)->taskManager.tasks();
  Task* task = 0;
  Task* currTask = 0;
  for (task = taskList.first(); task; task = taskList.next())
  {
    if ((long)task == (long)ctask)
    {
      //task found
      currTask = task;
      break;
    }
  }
  if (currTask == 0)
  {
    //no task was found
    tqWarning("Task not found.");
    return NULL;
  }
  //retrieve the TQPixmap that represents this image
  TQPixmap iconPixmap = KWin::icon(currTask->window());

  ImageLabel *tmp = createImageLabel((karamba*)widget, x, y, 0, 0);
  tmp->setValue(iconPixmap);
  return (Py_BuildValue((char*)"l", (long)tmp));
}

PyObject* py_deleteImage(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:deleteImage", &widget, &meter))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;

  ((karamba*)widget)->deleteMeterFromSensors((Meter*)meter);
  ((karamba*)widget)->clickList->removeRef((Meter*)meter);
  ((karamba*)widget)->imageList->removeRef((Meter*)meter);
  return Py_BuildValue((char*)"l",
      ((karamba*)widget)->meterList->removeRef((Meter*)meter));
}

PyObject* py_getThemeImage(PyObject *self, PyObject *args)
{
  return py_getThemeMeter(self, args, "ImageLabel");
}

PyObject* py_getImagePos(PyObject *self, PyObject *args)
{
  return py_getPos(self, args, "ImageLabel");
}

PyObject* py_getImageSize(PyObject *self, PyObject *args)
{
  return py_getSize(self, args, "ImageLabel");
}

PyObject* py_moveImage(PyObject *self, PyObject *args)
{
  return py_move(self, args, "ImageLabel");
}

PyObject* py_hideImage(PyObject *self, PyObject *args)
{
  return py_hide(self, args, "ImageLabel");
}

PyObject* py_showImage(PyObject *self, PyObject *args)
{
  return py_show(self, args, "ImageLabel");
}

PyObject* py_getImageValue(PyObject *self, PyObject *args)
{
  return py_getStringValue(self, args, "ImageLabel");
}

PyObject* py_setImageValue(PyObject *self, PyObject *args)
{
  return py_setStringValue(self, args, "ImageLabel");
}

PyObject* py_getImageSensor(PyObject *self, PyObject *args)
{
  return py_getSensor(self, args, "ImageLabel");
}

PyObject* py_setImageSensor(PyObject *self, PyObject *args)
{
  return py_setSensor(self, args, "ImageLabel");
}

PyObject* py_removeImageEffects(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:removeImageEffects", &widget, &meter))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->removeEffects();
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_changeImageIntensity(PyObject *, PyObject *args)
{
  long widget, meter;
  long millisec = 0;
  float ratio;
  if (!PyArg_ParseTuple(args, (char*)"llf|l:changeImageIntensity", &widget, &meter,
                        &ratio, &millisec))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->intensity(ratio, millisec);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_changeImageChannelIntensity(PyObject *, PyObject *args)
{
  long widget, meter;
  float ratio;
  char* channel;
  long millisec = 0;
  if (!PyArg_ParseTuple(args, (char*)"llfs|l:changeImageChannelIntensity", &widget,
                        &meter, &ratio, &channel, &millisec))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->channelIntensity(ratio, channel, millisec);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_changeImageToGray(PyObject *, PyObject *args)
{
  long widget, meter;
  long millisec = 0;
  if (!PyArg_ParseTuple(args, (char*)"ll|l:changeImageToGray", &widget, &meter,
                        &millisec))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->toGray(millisec);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_removeImageTransformations(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:removeImageTransformations", &widget, &meter))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->removeImageTransformations();
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_rotateImage(PyObject *, PyObject *args)
{
  long widget, meter;
  long deg;
  if (!PyArg_ParseTuple(args, (char*)"lll:rotateImage", &widget, &meter, &deg))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->rotate((int)deg);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getImageHeight(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:getImageHeight", &widget, &meter))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  return Py_BuildValue((char*)"l", ((ImageLabel*)meter)->getHeight());
}

PyObject* py_getImageWidth(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:getImageWidth", &widget, &meter))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  return Py_BuildValue((char*)"l", ((ImageLabel*)meter)->getWidth());
}

PyObject* py_resizeImageSmooth(PyObject *, PyObject *args)
{
  long widget, meter;
  long w, h;
  if (!PyArg_ParseTuple(args, (char*)"llll:resizeImageSmooth", &widget, &meter,
                        &w, &h))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->smoothScale((int)w, (int)h);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_resizeImage(PyObject *, PyObject *args)
{
  long widget, meter, w, h;
  if (!PyArg_ParseTuple(args, (char*)"llll:resizeImage", &widget, &meter,
                        &w, &h))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->scale((int)w, (int)h);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_addImageTooltip(PyObject *, PyObject *args)
{
  long widget, meter;
  PyObject* t;
  if (!PyArg_ParseTuple(args, (char*)"llO:addImageTooltip", &widget, &meter, &t))
    return NULL;
  if (!checkKarambaAndMeter(widget, meter, "ImageLabel"))
    return NULL;
  ((ImageLabel*)meter)->setTooltip(PyString2TQString(t));
  return Py_BuildValue((char*)"l", 1);
}