summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/input_python.cpp
blob: 0bf45e17d3401709b1c394b8610be080286835bc (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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/****************************************************************************
*  input_python.cpp  -  Functions for input box python api
*
*  Copyright (C) 2003 Hans Karlsson <[email protected]>
*  Copyright (C) 2003-2004 Adam Geitgey <[email protected]>
*  Copyright (c) 2004 Petri Damst�n <[email protected]>
*  Copyright (c) 2005 Alexander Wiedenbruch <[email protected]>
*
*  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 <qobject.h>
#include "karamba.h"
#include "meter.h"
#include "meter_python.h"
#include "input_python.h"

PyObject* py_createInputBox(PyObject *, PyObject *args)
{
  long widget, x, y, w, h;
  PyObject *text;
  if (!PyArg_ParseTuple(args, (char*)"lllllO:createInputBox", &widget, &x, &y, &w, &h, &text))
    return NULL;

  if (!checkKaramba(widget))
    return NULL;

  Input *tmp = new Input((karamba*)widget, (int)x, (int)y, (int)w, (int)h);
  tmp->setValue(PyString2QString(text));
  tmp->setTextProps(((karamba*)widget)->getDefaultTextProps());
  ((karamba*)widget)->meterList->append(tmp);
  tmp->show();

  ((karamba*)widget)->makeActive();

  return (Py_BuildValue((char*)"l", (long)tmp));
}

PyObject* py_deleteInputBox(PyObject *, PyObject *args)
{
  long widget, meter;
  if (!PyArg_ParseTuple(args, (char*)"ll:deleteInputBox", &widget, &meter))
    return NULL;

  if (!checkKarambaAndMeter(widget, meter, "Input"))
    return NULL;

  bool result = ((karamba*)widget)->meterList->removeRef((Meter*)meter);

  ((karamba*)widget)->makePassive();

  return Py_BuildValue((char*)"l", result);
}

PyObject* py_getThemeInputBox(PyObject *self, PyObject *args)
{
  return py_getThemeMeter(self, args, "Input");
}

PyObject* py_getInputBoxValue(PyObject *self, PyObject *args)
{
  return py_getStringValue(self, args, "Input");
}

PyObject* py_setInputBoxValue(PyObject *self, PyObject *args)
{
  return py_setStringValue(self, args, "Input");
}

PyObject* py_hideInputBox(PyObject *self, PyObject *args)
{
  return py_hide(self, args, "Input");
}

PyObject* py_showInputBox(PyObject *self, PyObject *args)
{
  return py_show(self, args, "Input");
}

PyObject* py_getInputBoxPos(PyObject *self, PyObject *args)
{
  return py_getPos(self, args, "Input");
}

PyObject* py_moveInputBox(PyObject *self, PyObject *args)
{
  return py_move(self, args, "Input");
}

PyObject* py_getInputBoxSize(PyObject *self, PyObject *args)
{
  return py_getSize(self, args, "Input");
}

PyObject* py_resizeInputBox(PyObject *self, PyObject *args)
{
  return py_resize(self, args, "Input");
}

PyObject* py_setInputBoxFont(PyObject *, PyObject *args)
{
  long widget, inputBox;
  char* text;
  if (!PyArg_ParseTuple(args, (char*)"lls:changeInputBoxFont",
                        &widget, &inputBox, &text))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setFont(text);
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxFont(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFont", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  return Py_BuildValue((char*)"s", ((Input*)inputBox)->getFont().ascii());
}

PyObject* py_setInputBoxFontColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long r, g, b;
  if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxFontColor", &widget, &inputBox, &r, &g, &b))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setFontColor(QColor(r, g, b));
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxFontColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:changeInputBoxFontColor", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  QColor color = ((Input*)inputBox)->getFontColor();
  return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue());
}

PyObject* py_setInputBoxSelectionColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long r, g, b;
  if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxSelectionColor", &widget, &inputBox, &r, &g, &b))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setSelectionColor(QColor(r, g, b));
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxSelectionColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:changeInputBoxSelectionColor", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  QColor color = ((Input*)inputBox)->getSelectionColor();
  return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue());
}

PyObject* py_setInputBoxBGColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long r, g, b;
  if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxBackgroundColor", &widget, &inputBox, &r, &g, &b))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setBGColor(QColor(r, g, b));
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxBGColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxBackgroundColor", &widget, &inputBox))
  return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  QColor color = ((Input*)inputBox)->getBGColor();
  return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue());
}

PyObject* py_setInputBoxFrameColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long r, g, b;
if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxFrameColor", &widget, &inputBox, &r, &g, &b))
  return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setColor(QColor(r, g, b));
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxFrameColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFrameColor", &widget, &inputBox))
  return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  QColor color = ((Input*)inputBox)->getColor();
  return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue());
}

PyObject* py_setInputBoxSelectedTextColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long r, g, b;
if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxSelectedTextColor", &widget, &inputBox, &r, &g, &b))
  return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setSelectedTextColor(QColor(r, g, b));
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxSelectedTextColor(PyObject *, PyObject *args)
{
  long widget, inputBox;
if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxSelectedTextColor", &widget, &inputBox))
  return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  QColor color = ((Input*)inputBox)->getSelectedTextColor();
  return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue());
}

PyObject* py_setInputBoxFontSize(PyObject *, PyObject *args)
{
  long widget, inputBox;
  long size;
  if (!PyArg_ParseTuple(args, (char*)"lll:changeInputBoxFontSize",
                      &widget, &inputBox, &size))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->setFontSize( size );
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputBoxFontSize(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFontSize", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  return Py_BuildValue((char*)"l", ((Input*)inputBox)->getFontSize());
}

PyObject* py_setInputFocus(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:setInputFocus", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  //((karamba*)widget)->setActiveWindow();

  ((Input*)inputBox)->setInputFocus();
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_clearInputFocus(PyObject *, PyObject *args)
{
  long widget, inputBox;
  if (!PyArg_ParseTuple(args, (char*)"ll:clearInputFocus", &widget, &inputBox))
    return NULL;

  if (!checkKarambaAndMeter(widget, inputBox, "Input"))
    return NULL;

  ((Input*)inputBox)->clearInputFocus();
  return Py_BuildValue((char*)"l", 1);
}

PyObject* py_getInputFocus(PyObject *, PyObject *args)
{
  long widget;
  if (!PyArg_ParseTuple(args, (char*)"l:getInputFocus", &widget))
    return NULL;

  if (!checkKaramba(widget))
    return NULL;
  
  //
  // FocusWidget() returns the currently focused line edit,
  // but unfortunately we need an 'Input' object here.
  //
  QWidget *obj = ((karamba*)widget)->focusWidget();
  
  if(obj->isA("QLineEdit")) // SKLineEdit is no Q_Object, but QLineEdit can only be here as a SKLineEdit
    return Py_BuildValue((char*)"l", ((SKLineEdit*)obj)->getInput());
  
  return Py_BuildValue((char*)"l", 0);
}