input_python.cpp
00001 /**************************************************************************** 00002 * input_python.cpp - Functions for input box 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 * Copyright (c) 2005 Alexander Wiedenbruch <mail@wiedenbruch.de> 00008 * 00009 * This file is part of SuperKaramba. 00010 * 00011 * SuperKaramba is free software; you can redistribute it and/or modify 00012 * it under the terms of the GNU General Public License as published by 00013 * the Free Software Foundation; either version 2 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * SuperKaramba is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with SuperKaramba; if not, write to the Free Software 00023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00024 ****************************************************************************/ 00025 00026 #ifdef _XOPEN_SOURCE 00027 #undef _XOPEN_SOURCE 00028 #endif 00029 00030 #include <Python.h> 00031 #include <tqobject.h> 00032 #include "karamba.h" 00033 #include "meter.h" 00034 #include "meter_python.h" 00035 #include "input_python.h" 00036 00037 PyObject* py_createInputBox(PyObject *, PyObject *args) 00038 { 00039 long widget, x, y, w, h; 00040 PyObject *text; 00041 if (!PyArg_ParseTuple(args, (char*)"lllllO:createInputBox", &widget, &x, &y, &w, &h, &text)) 00042 return NULL; 00043 00044 if (!checkKaramba(widget)) 00045 return NULL; 00046 00047 Input *tmp = new Input((karamba*)widget, (int)x, (int)y, (int)w, (int)h); 00048 tmp->setValue(PyString2TQString(text)); 00049 tmp->setTextProps(((karamba*)widget)->getDefaultTextProps()); 00050 ((karamba*)widget)->meterList->append(tmp); 00051 tmp->show(); 00052 00053 ((karamba*)widget)->makeActive(); 00054 00055 return (Py_BuildValue((char*)"l", (long)tmp)); 00056 } 00057 00058 PyObject* py_deleteInputBox(PyObject *, PyObject *args) 00059 { 00060 long widget, meter; 00061 if (!PyArg_ParseTuple(args, (char*)"ll:deleteInputBox", &widget, &meter)) 00062 return NULL; 00063 00064 if (!checkKarambaAndMeter(widget, meter, "Input")) 00065 return NULL; 00066 00067 bool result = ((karamba*)widget)->meterList->removeRef((Meter*)meter); 00068 00069 ((karamba*)widget)->makePassive(); 00070 00071 return Py_BuildValue((char*)"l", result); 00072 } 00073 00074 PyObject* py_getThemeInputBox(PyObject *self, PyObject *args) 00075 { 00076 return py_getThemeMeter(self, args, "Input"); 00077 } 00078 00079 PyObject* py_getInputBoxValue(PyObject *self, PyObject *args) 00080 { 00081 return py_getStringValue(self, args, "Input"); 00082 } 00083 00084 PyObject* py_setInputBoxValue(PyObject *self, PyObject *args) 00085 { 00086 return py_setStringValue(self, args, "Input"); 00087 } 00088 00089 PyObject* py_hideInputBox(PyObject *self, PyObject *args) 00090 { 00091 return py_hide(self, args, "Input"); 00092 } 00093 00094 PyObject* py_showInputBox(PyObject *self, PyObject *args) 00095 { 00096 return py_show(self, args, "Input"); 00097 } 00098 00099 PyObject* py_getInputBoxPos(PyObject *self, PyObject *args) 00100 { 00101 return py_getPos(self, args, "Input"); 00102 } 00103 00104 PyObject* py_moveInputBox(PyObject *self, PyObject *args) 00105 { 00106 return py_move(self, args, "Input"); 00107 } 00108 00109 PyObject* py_getInputBoxSize(PyObject *self, PyObject *args) 00110 { 00111 return py_getSize(self, args, "Input"); 00112 } 00113 00114 PyObject* py_resizeInputBox(PyObject *self, PyObject *args) 00115 { 00116 return py_resize(self, args, "Input"); 00117 } 00118 00119 PyObject* py_setInputBoxFont(PyObject *, PyObject *args) 00120 { 00121 long widget, inputBox; 00122 char* text; 00123 if (!PyArg_ParseTuple(args, (char*)"lls:changeInputBoxFont", 00124 &widget, &inputBox, &text)) 00125 return NULL; 00126 00127 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00128 return NULL; 00129 00130 ((Input*)inputBox)->setFont(text); 00131 return Py_BuildValue((char*)"l", 1); 00132 } 00133 00134 PyObject* py_getInputBoxFont(PyObject *, PyObject *args) 00135 { 00136 long widget, inputBox; 00137 if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFont", &widget, &inputBox)) 00138 return NULL; 00139 00140 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00141 return NULL; 00142 00143 return Py_BuildValue((char*)"s", ((Input*)inputBox)->getFont().ascii()); 00144 } 00145 00146 PyObject* py_setInputBoxFontColor(PyObject *, PyObject *args) 00147 { 00148 long widget, inputBox; 00149 long r, g, b; 00150 if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxFontColor", &widget, &inputBox, &r, &g, &b)) 00151 return NULL; 00152 00153 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00154 return NULL; 00155 00156 ((Input*)inputBox)->setFontColor(TQColor(r, g, b)); 00157 return Py_BuildValue((char*)"l", 1); 00158 } 00159 00160 PyObject* py_getInputBoxFontColor(PyObject *, PyObject *args) 00161 { 00162 long widget, inputBox; 00163 if (!PyArg_ParseTuple(args, (char*)"ll:changeInputBoxFontColor", &widget, &inputBox)) 00164 return NULL; 00165 00166 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00167 return NULL; 00168 00169 TQColor color = ((Input*)inputBox)->getFontColor(); 00170 return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue()); 00171 } 00172 00173 PyObject* py_setInputBoxSelectionColor(PyObject *, PyObject *args) 00174 { 00175 long widget, inputBox; 00176 long r, g, b; 00177 if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxSelectionColor", &widget, &inputBox, &r, &g, &b)) 00178 return NULL; 00179 00180 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00181 return NULL; 00182 00183 ((Input*)inputBox)->setSelectionColor(TQColor(r, g, b)); 00184 return Py_BuildValue((char*)"l", 1); 00185 } 00186 00187 PyObject* py_getInputBoxSelectionColor(PyObject *, PyObject *args) 00188 { 00189 long widget, inputBox; 00190 if (!PyArg_ParseTuple(args, (char*)"ll:changeInputBoxSelectionColor", &widget, &inputBox)) 00191 return NULL; 00192 00193 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00194 return NULL; 00195 00196 TQColor color = ((Input*)inputBox)->getSelectionColor(); 00197 return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue()); 00198 } 00199 00200 PyObject* py_setInputBoxBGColor(PyObject *, PyObject *args) 00201 { 00202 long widget, inputBox; 00203 long r, g, b; 00204 if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxBackgroundColor", &widget, &inputBox, &r, &g, &b)) 00205 return NULL; 00206 00207 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00208 return NULL; 00209 00210 ((Input*)inputBox)->setBGColor(TQColor(r, g, b)); 00211 return Py_BuildValue((char*)"l", 1); 00212 } 00213 00214 PyObject* py_getInputBoxBGColor(PyObject *, PyObject *args) 00215 { 00216 long widget, inputBox; 00217 if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxBackgroundColor", &widget, &inputBox)) 00218 return NULL; 00219 00220 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00221 return NULL; 00222 00223 TQColor color = ((Input*)inputBox)->getBGColor(); 00224 return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue()); 00225 } 00226 00227 PyObject* py_setInputBoxFrameColor(PyObject *, PyObject *args) 00228 { 00229 long widget, inputBox; 00230 long r, g, b; 00231 if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxFrameColor", &widget, &inputBox, &r, &g, &b)) 00232 return NULL; 00233 00234 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00235 return NULL; 00236 00237 ((Input*)inputBox)->setColor(TQColor(r, g, b)); 00238 return Py_BuildValue((char*)"l", 1); 00239 } 00240 00241 PyObject* py_getInputBoxFrameColor(PyObject *, PyObject *args) 00242 { 00243 long widget, inputBox; 00244 if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFrameColor", &widget, &inputBox)) 00245 return NULL; 00246 00247 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00248 return NULL; 00249 00250 TQColor color = ((Input*)inputBox)->getColor(); 00251 return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue()); 00252 } 00253 00254 PyObject* py_setInputBoxSelectedTextColor(PyObject *, PyObject *args) 00255 { 00256 long widget, inputBox; 00257 long r, g, b; 00258 if (!PyArg_ParseTuple(args, (char*)"lllll:changeInputBoxSelectedTextColor", &widget, &inputBox, &r, &g, &b)) 00259 return NULL; 00260 00261 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00262 return NULL; 00263 00264 ((Input*)inputBox)->setSelectedTextColor(TQColor(r, g, b)); 00265 return Py_BuildValue((char*)"l", 1); 00266 } 00267 00268 PyObject* py_getInputBoxSelectedTextColor(PyObject *, PyObject *args) 00269 { 00270 long widget, inputBox; 00271 if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxSelectedTextColor", &widget, &inputBox)) 00272 return NULL; 00273 00274 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00275 return NULL; 00276 00277 TQColor color = ((Input*)inputBox)->getSelectedTextColor(); 00278 return Py_BuildValue((char*)"(i,i,i)", color.red(), color.green(), color.blue()); 00279 } 00280 00281 PyObject* py_setInputBoxFontSize(PyObject *, PyObject *args) 00282 { 00283 long widget, inputBox; 00284 long size; 00285 if (!PyArg_ParseTuple(args, (char*)"lll:changeInputBoxFontSize", 00286 &widget, &inputBox, &size)) 00287 return NULL; 00288 00289 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00290 return NULL; 00291 00292 ((Input*)inputBox)->setFontSize( size ); 00293 return Py_BuildValue((char*)"l", 1); 00294 } 00295 00296 PyObject* py_getInputBoxFontSize(PyObject *, PyObject *args) 00297 { 00298 long widget, inputBox; 00299 if (!PyArg_ParseTuple(args, (char*)"ll:getInputBoxFontSize", &widget, &inputBox)) 00300 return NULL; 00301 00302 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00303 return NULL; 00304 00305 return Py_BuildValue((char*)"l", ((Input*)inputBox)->getFontSize()); 00306 } 00307 00308 PyObject* py_setInputFocus(PyObject *, PyObject *args) 00309 { 00310 long widget, inputBox; 00311 if (!PyArg_ParseTuple(args, (char*)"ll:setInputFocus", &widget, &inputBox)) 00312 return NULL; 00313 00314 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00315 return NULL; 00316 00317 //((karamba*)widget)->setActiveWindow(); 00318 00319 ((Input*)inputBox)->setInputFocus(); 00320 return Py_BuildValue((char*)"l", 1); 00321 } 00322 00323 PyObject* py_clearInputFocus(PyObject *, PyObject *args) 00324 { 00325 long widget, inputBox; 00326 if (!PyArg_ParseTuple(args, (char*)"ll:clearInputFocus", &widget, &inputBox)) 00327 return NULL; 00328 00329 if (!checkKarambaAndMeter(widget, inputBox, "Input")) 00330 return NULL; 00331 00332 ((Input*)inputBox)->clearInputFocus(); 00333 return Py_BuildValue((char*)"l", 1); 00334 } 00335 00336 PyObject* py_getInputFocus(PyObject *, PyObject *args) 00337 { 00338 long widget; 00339 if (!PyArg_ParseTuple(args, (char*)"l:getInputFocus", &widget)) 00340 return NULL; 00341 00342 if (!checkKaramba(widget)) 00343 return NULL; 00344 00345 // 00346 // FocusWidget() returns the currently focused line edit, 00347 // but unfortunately we need an 'Input' object here. 00348 // 00349 TQWidget *obj = ((karamba*)widget)->focusWidget(); 00350 00351 if(obj->isA(TQLINEEDIT_OBJECT_NAME_STRING)) // SKLineEdit is no TQ_Object, but TQLineEdit can only be here as a SKLineEdit 00352 return Py_BuildValue((char*)"l", ((SKLineEdit*)obj)->getInput()); 00353 00354 return Py_BuildValue((char*)"l", 0); 00355 }