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

superkaramba

  • superkaramba
  • src
karamba_python.cpp
1 /****************************************************************************
2 * karamba_python.cpp - Functions for calling python scripts
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 * Copyright (c) 2004 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
8 *
9 * This file is part of SuperKaramba.
10 *
11 * SuperKaramba is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * SuperKaramba is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with SuperKaramba; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 ****************************************************************************/
25 
26 #ifdef _XOPEN_SOURCE
27 #undef _XOPEN_SOURCE
28 #endif
29 
30 #include <Python.h>
31 #include "karambaapp.h"
32 #include "themefile.h"
33 
34 #include "karamba_python.h"
35 #include "meter_python.h"
36 #include "bar_python.h"
37 #include "graph_python.h"
38 #include "textlabel_python.h"
39 #include "richtextlabel_python.h"
40 #include "imagelabel_python.h"
41 #include "widget_python.h"
42 #include "menu_python.h"
43 #include "config_python.h"
44 #include "task_python.h"
45 #include "systray_python.h"
46 #include "svcgrp_python.h"
47 #include "misc_python.h"
48 #include "input_python.h"
49 
50 struct module_state {
51  PyObject *error;
52 };
53 
54 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
55 
56 static PyObject *
57 error_out(PyObject *m) {
58  struct module_state *st = GETSTATE(m);
59  PyErr_SetString(st->error, "something bad happened in karamba_python.cpp");
60  return NULL;
61 }
62 
63 /*******************************************
64  * Python methods are defined here.
65  * Each method accessible from python should have:
66  * - A wrapper function that returns a PyObject or appropriate python type
67  * - A C++ implementation of the python method, named the same as the python call
68  * - An entry in the python methods array so the call is accessible from python
69  *
70  * Example:
71  * py_move_systay - wrapper function
72  * moveSystray - actual implementation of method
73  * {"moveSystray", py_move_systray, METH_VARARGS, "Move the Systray"} - array entry
74  */
75 
76 static PyMethodDef karamba_methods[] = {
77  // Bar - bar_python.cpp
78  {(char*)"createBar", py_createBar, METH_VARARGS, (char*)"Create new Bar."},
79  {(char*)"deleteBar", py_deleteBar, METH_VARARGS, (char*)"Delete Bar."},
80  {(char*)"getThemeBar", py_getThemeBar, METH_VARARGS, (char*)"Get Bar from .theme using it's name."},
81  {(char*)"getBarSize", py_getBarSize, METH_VARARGS, (char*)"Get Bar size."},
82  {(char*)"resizeBar", py_resizeBar, METH_VARARGS, (char*)"Resize Bar."},
83  {(char*)"getBarPos", py_getBarPos, METH_VARARGS, (char*)"Get Bar position."},
84  {(char*)"moveBar", py_moveBar, METH_VARARGS, (char*)"Move Bar."},
85  {(char*)"hideBar", py_hideBar, METH_VARARGS, (char*)"Hide Bar."},
86  {(char*)"showBar", py_showBar, METH_VARARGS, (char*)"Show Bar."},
87  {(char*)"getBarSensor", py_getBarSensor, METH_VARARGS, (char*)"Get Bar sensor."},
88  {(char*)"setBarSensor", py_setBarSensor, METH_VARARGS, (char*)"Set Bar sensor."},
89  {(char*)"setBarImage", py_setBarImage, METH_VARARGS, (char*)"Set bar image"},
90  {(char*)"getBarImage", py_getBarImage, METH_VARARGS, (char*)"Get bar image"},
91  {(char*)"setBarVertical", py_setBarVertical, METH_VARARGS, (char*)"Set bar orientation"},
92  {(char*)"getBarVertical", py_getBarVertical, METH_VARARGS, (char*)"Get bar orientation"},
93  {(char*)"setBarValue", py_setBarValue, METH_VARARGS, (char*)"Set bar value"},
94  {(char*)"getBarValue", py_getBarValue, METH_VARARGS, (char*)"Get bar value"},
95  {(char*)"setBarMinMax", py_setBarMinMax, METH_VARARGS, (char*)"Set bar min & max"},
96  {(char*)"getBarMinMax", py_getBarMinMax, METH_VARARGS, (char*)"Get bar min & max"},
97  {(char*)"getIncomingData", py_get_incoming_data, METH_VARARGS, (char*)"Get incoming data passed from another theme"},
98  {(char*)"setIncomingData", py_set_incoming_data, METH_VARARGS, (char*)"Set incoming data passed in another theme"},
99 
100  // Graph - graph_python.cpp
101  {(char*)"createGraph", py_createGraph, METH_VARARGS, (char*)"Create new Graph."},
102  {(char*)"deleteGraph", py_deleteGraph, METH_VARARGS, (char*)"Delete Graph."},
103  {(char*)"getThemeGraph", py_getThemeGraph, METH_VARARGS, (char*)"Get Graph from .theme using it's name."},
104  {(char*)"getGraphSize", py_getGraphSize, METH_VARARGS, (char*)"Get Graph size."},
105  {(char*)"resizeGraph", py_resizeGraph, METH_VARARGS, (char*)"Resize Graph."},
106  {(char*)"getGraphPos", py_getGraphPos, METH_VARARGS, (char*)"Get Graph position."},
107  {(char*)"moveGraph", py_moveGraph, METH_VARARGS, (char*)"Move Graph."},
108  {(char*)"hideGraph", py_hideGraph, METH_VARARGS, (char*)"Hide Graph."},
109  {(char*)"showGraph", py_showGraph, METH_VARARGS, (char*)"Show Graph."},
110  {(char*)"getGraphSensor", py_getGraphSensor, METH_VARARGS, (char*)"Get Graph sensor."},
111  {(char*)"setGraphSensor", py_setGraphSensor, METH_VARARGS, (char*)"Set Graph sensor."},
112  {(char*)"setGraphValue", py_setGraphValue, METH_VARARGS, (char*)"Set graph value"},
113  {(char*)"getGraphValue", py_getGraphValue, METH_VARARGS, (char*)"Get graph value"},
114  {(char*)"setGraphMinMax", py_setGraphMinMax, METH_VARARGS, (char*)"Set graph min & max"},
115  {(char*)"getGraphMinMax", py_getGraphMinMax, METH_VARARGS, (char*)"Get graph min & max"},
116  {(char*)"setGraphColor", py_setGraphColor, METH_VARARGS, (char*)"Change a Graph Sensor's Color"},
117  {(char*)"getGraphColor", py_getGraphColor, METH_VARARGS, (char*)"Get a Graph Sensor's Color"},
118 
119  // TextLabel - textlabel_python.cpp
120  {(char*)"createText", py_createText, METH_VARARGS, (char*)"Create new Text."},
121  {(char*)"deleteText", py_deleteText, METH_VARARGS, (char*)"Delete Text."},
122  {(char*)"getThemeText", py_getThemeText, METH_VARARGS, (char*)"Get Text from .theme using it's name."},
123  {(char*)"getTextSize", py_getTextSize, METH_VARARGS, (char*)"Get Text size."},
124  {(char*)"resizeText", py_resizeText, METH_VARARGS, (char*)"Resize Text."},
125  {(char*)"getTextPos", py_getTextPos, METH_VARARGS, (char*)"Get Text position."},
126  {(char*)"moveText", py_moveText, METH_VARARGS, (char*)"Move Text."},
127  {(char*)"hideText", py_hideText, METH_VARARGS, (char*)"Hide Text."},
128  {(char*)"showText", py_showText, METH_VARARGS, (char*)"Show Text."},
129  {(char*)"getTextSensor", py_getTextSensor, METH_VARARGS, (char*)"Get Text sensor."},
130  {(char*)"setTextSensor", py_setTextSensor, METH_VARARGS, (char*)"Set Text sensor."},
131  {(char*)"changeText", py_setTextValue, METH_VARARGS, (char*)"Change a Text Sensor's Text"},
132  {(char*)"getTextValue", py_getTextValue, METH_VARARGS, (char*)"Get Text value"},
133  {(char*)"changeTextShadow", py_setTextShadow, METH_VARARGS, (char*)"Change a Text Shadow size"},
134  {(char*)"getTextShadow", py_getTextShadow, METH_VARARGS, (char*)"Get a Text Shadow size"},
135  {(char*)"changeTextFont", py_setTextFont, METH_VARARGS, (char*)"Change a Text Sensor's Font"},
136  {(char*)"getTextFont", py_getTextFont, METH_VARARGS, (char*)"Get a Text Sensor's Font"},
137  {(char*)"changeTextColor", py_setTextColor, METH_VARARGS, (char*)"Change a Text Sensor's Color"},
138  {(char*)"getTextColor", py_getTextColor, METH_VARARGS, (char*)"Get a Text Sensor's Color"},
139  {(char*)"changeTextSize", py_setTextFontSize, METH_VARARGS, (char*)"Change a Text Sensor's Font Size"},
140  {(char*)"getTextFontSize", py_getTextFontSize, METH_VARARGS, (char*)"Get a Text Sensor's Font Size"},
141  {(char*)"getTextAlign", py_getTextAlign, METH_VARARGS, (char*)"Get Text alignment."},
142  {(char*)"setTextAlign", py_setTextAlign, METH_VARARGS, (char*)"Set Text alignment."},
143  {(char*)"setTextScroll", py_setTextScroll, METH_VARARGS, (char*)"Set Text scroll."},
144 
145  // RichTextLabel - richtextlabel_python.cpp
146  {(char*)"createRichText", py_createRichText, METH_VARARGS, (char*)"Create a Rich Text Sensor"},
147  {(char*)"deleteRichText", py_deleteRichText, METH_VARARGS, (char*)"Deletes a Rich Text Sensor"},
148  {(char*)"getThemeRichText", py_getThemeRichText, METH_VARARGS, (char*)"Get Rich Text from .theme using it's name."},
149  {(char*)"getRichTextSize", py_getRichTextSize, METH_VARARGS, (char*)"Get the (width, height) of a Rich Text Sensor"},
150  {(char*)"resizeRichText", py_resizeRichText, METH_VARARGS, (char*)"Resize Rich Text."},
151  {(char*)"setRichTextWidth", py_set_rich_text_width, METH_VARARGS, (char*)"Sets the width of a Rich Text Sensor"},
152  {(char*)"getRichTextPos", py_getRichTextPos, METH_VARARGS, (char*)"Get Rich Text position."},
153  {(char*)"moveRichText", py_moveRichText, METH_VARARGS, (char*)"Moves a Rich Text Sensor"},
154  {(char*)"hideRichText", py_hideRichText, METH_VARARGS, (char*)"hides a Rich Text Sensor"},
155  {(char*)"showRichText", py_showRichText, METH_VARARGS, (char*)"shows a Rich Text Sensor"},
156  {(char*)"getRichTextSensor", py_getRichTextSensor, METH_VARARGS, (char*)"Get Rich Text sensor."},
157  {(char*)"setRichTextSensor", py_setRichTextSensor, METH_VARARGS, (char*)"Set Rich Text sensor."},
158  {(char*)"changeRichText", py_setRichTextValue, METH_VARARGS, (char*)"Change the content of a Rich Text Sensor"},
159  {(char*)"getRichTextValue", py_getRichTextValue, METH_VARARGS, (char*)"Get Rich Text value"},
160  {(char*)"changeRichTextFont", py_setRichTextFont, METH_VARARGS, (char*)"Change a Rich Text Sensor's Font"},
161  {(char*)"getRichTextFont", py_getRichTextFont, METH_VARARGS, (char*)"Get a Rich Text Sensor's Font"},
162  {(char*)"changeRichTextSize", py_setRichTextFontSize, METH_VARARGS, (char*)"Change a Rich Text Sensor's Font Size"},
163  {(char*)"getRichTextFontSize", py_getRichTextFontSize, METH_VARARGS, (char*)"Get a Rich Text Sensor's Font Size"},
164 
165  // ImageLabel - imagelabel_python.cpp
166  {(char*)"createImage", py_createImage, METH_VARARGS, (char*)"Create an Image"},
167  {(char*)"createTaskIcon", py_createTaskIcon, METH_VARARGS, (char*)"Create an Image of the Icon for a Task"},
168  {(char*)"createBackgroundImage", py_createBackgroundImage, METH_VARARGS, (char*)"Create an Image (only redraw it when background changes)"},
169  {(char*)"deleteImage", py_deleteImage, METH_VARARGS, (char*)"Delete an Image"},
170  {(char*)"getThemeImage", py_getThemeImage, METH_VARARGS, (char*)"Get image meter from .theme using it's name"},
171  {(char*)"getImageSize", py_getImageSize, METH_VARARGS, (char*)"Get Image size."},
172  {(char*)"getImageWidth", py_getImageWidth, METH_VARARGS, (char*)"Get the width of an Image"},
173  {(char*)"getImageHeight", py_getImageHeight, METH_VARARGS, (char*)"Get the height of an Image"},
174  {(char*)"getImagePos", py_getImagePos, METH_VARARGS, (char*)"Get Image position."},
175  {(char*)"moveImage", py_moveImage, METH_VARARGS, (char*)"Move an Image"},
176  {(char*)"hideImage", py_hideImage, METH_VARARGS, (char*)"Hide an Image"},
177  {(char*)"showImage", py_showImage, METH_VARARGS, (char*)"Show an Image"},
178  {(char*)"getImagePath", py_getImageValue, METH_VARARGS, (char*)"Get Image path."},
179  {(char*)"setImagePath", py_setImageValue, METH_VARARGS, (char*)"Set Image path."},
180  {(char*)"getImageSensor", py_getImageSensor, METH_VARARGS, (char*)"Get Image sensor."},
181  {(char*)"setImageSensor", py_setImageSensor, METH_VARARGS, (char*)"Set Image sensor."},
182  {(char*)"addImageTooltip", py_addImageTooltip, METH_VARARGS, (char*)"Create a Tooltip for an Image"},
183  {(char*)"resizeImage", py_resizeImage, METH_VARARGS, (char*)"Scale an Image"},
184  {(char*)"resizeImageSmooth", py_resizeImageSmooth, METH_VARARGS, (char*)"Scale an Image (slower, better looking)"},
185  {(char*)"rotateImage", py_rotateImage, METH_VARARGS, (char*)"Rotate an Image"},
186  {(char*)"removeImageTransformations", py_removeImageTransformations, METH_VARARGS, (char*)"Restore original size and orientation of an Image"},
187  {(char*)"removeImageEffects", py_removeImageEffects, METH_VARARGS, (char*)"Remove Effects of an Image"},
188  {(char*)"changeImageIntensity", py_changeImageIntensity, METH_VARARGS, (char*)"Change Intensity of an Image"},
189  {(char*)"changeImageChannelIntensity", py_changeImageChannelIntensity, METH_VARARGS, (char*)"Change Intensity of an Image Channel"},
190  {(char*)"changeImageToGray", py_changeImageToGray, METH_VARARGS, (char*)"Converts an Image to Grayscale"},
191 
192  // Menu - menu_python.cpp
193  {(char*)"createMenu", py_create_menu, METH_VARARGS, (char*)"Create a popup menu"},
194  {(char*)"deleteMenu", py_delete_menu, METH_VARARGS, (char*)"Delete a popup menu"},
195  {(char*)"addMenuItem", py_add_menu_item, METH_VARARGS, (char*)"Add a popup menu entry"},
196  {(char*)"addMenuSeparator", py_add_menu_separator, METH_VARARGS, (char*)"Add a popup menu seperator item"},
197  {(char*)"removeMenuItem", py_remove_menu_item, METH_VARARGS, (char*)"Remove a popup menu entry"},
198  {(char*)"popupMenu", py_popup_menu, METH_VARARGS, (char*)"Popup a menu at a specified location"},
199 
200  // Config - config_python.cpp
201  {(char*)"addMenuConfigOption", py_add_menu_config_option, METH_VARARGS, (char*)"Add a configuration entry to the menu"},
202  {(char*)"setMenuConfigOption", py_set_menu_config_option, METH_VARARGS, (char*)"Set a configuration entry in the menu"},
203  {(char*)"readMenuConfigOption", py_read_menu_config_option, METH_VARARGS, (char*)"Read a configuration entry in the menu"},
204  {(char*)"readConfigEntry", py_read_config_entry, METH_VARARGS, (char*)"Read a configuration entry"},
205  {(char*)"writeConfigEntry", py_write_config_entry, METH_VARARGS, (char*)"Writes a configuration entry"},
206 
207  // Widget - widget_python.cpp
208  {(char*)"moveWidget", py_move_widget, METH_VARARGS, (char*)"Move Widget to x,y"},
209  {(char*)"resizeWidget", py_resize_widget, METH_VARARGS, (char*)"Resize Widget to width,height"},
210  {(char*)"createWidgetMask", py_create_widget_mask, METH_VARARGS, (char*)"Create a clipping mask for this widget"},
211  {(char*)"redrawWidget", py_redraw_widget, METH_VARARGS, (char*)"Update Widget to reflect your changes"},
212  {(char*)"redrawWidgetBackground", py_redraw_widget_background, METH_VARARGS, (char*)"Update Widget to reflect background image changes"},
213  {(char*)"getWidgetPosition", py_get_widget_position, METH_VARARGS, (char*)"Get Widget Position"},
214  {(char*)"toggleWidgetRedraw", py_toggle_widget_redraw, METH_VARARGS, (char*)"Toggle Widget redrawing"},
215 
216  // Task - task_python.cpp
217  {(char*)"getStartupList", py_get_startup_list, METH_VARARGS, (char*)"Get the system startup list"},
218  {(char*)"getStartupInfo", py_get_startup_info, METH_VARARGS, (char*)"Get all the info for a startup"},
219  {(char*)"getTaskList", py_get_task_list, METH_VARARGS, (char*)"Get the system task list"},
220  {(char*)"getTaskNames", py_get_task_names, METH_VARARGS, (char*)"Get the system task list in name form"},
221  {(char*)"getTaskInfo", py_get_task_info, METH_VARARGS, (char*)"Get all the info for a task"},
222  {(char*)"performTaskAction", py_perform_task_action, METH_VARARGS, (char*)"Do something with a task, such as minimize it"},
223 
224  // System Tray - systray_python.cpp
225  {(char*)"createSystray", py_create_systray, METH_VARARGS, (char*)"Create a Systray"},
226  {(char*)"hideSystray", py_hide_systray, METH_VARARGS, (char*)"Hide the Systray"},
227  {(char*)"showSystray", py_show_systray, METH_VARARGS, (char*)"Show the Systray"},
228  {(char*)"moveSystray", py_move_systray, METH_VARARGS, (char*)"Move the Systray"},
229  {(char*)"getCurrentWindowCount", py_get_current_window_count, METH_VARARGS, (char*)"Get current Window count"},
230  {(char*)"updateSystrayLayout", py_update_systray_layout, METH_VARARGS, (char*)"Update Systray layout"},
231 
232  // Misc - misc_python.cpp
233  {(char*)"getThemePath", py_get_theme_path, METH_VARARGS, (char*)"Get the file path of the theme"},
234  {(char*)"readThemeFile", py_read_theme_file, METH_VARARGS,
235  (char*)"Read file from theme."},
236  {(char*)"language", py_language, METH_VARARGS,
237  (char*)"Return default language of a translation file."},
238  {(char*)"userLanguage", py_userLanguage, METH_VARARGS,
239  (char*)"Return user language."},
240  {(char*)"userLanguages", py_userLanguages, METH_VARARGS,
241  (char*)"Return preferred user languages."},
242  {(char*)"openTheme", py_open_theme, METH_VARARGS,
243  (char*)"Open a new theme"},
244  {(char*)"reloadTheme", py_reload_theme, METH_VARARGS,
245  (char*)"Reload current theme"},
246  {(char*)"acceptDrops", py_accept_drops, METH_VARARGS,
247  (char*)"Allows widget to receive Drop (I.E. Drag and Drop) events"},
248  {(char*)"toggleShowDesktop", py_toggle_show_desktop, METH_VARARGS,
249  (char*)"Show/Hide the desktop"},
250  {(char*)"execute", py_execute_command, METH_VARARGS, (char*)"Execute a command"},
251  {(char*)"executeInteractive", py_execute_command_interactive, METH_VARARGS, (char*)"Execute a command and get it's output (stdout)"},
252  {(char*)"attachClickArea", (PyCFunction)py_attach_clickArea, METH_VARARGS|METH_KEYWORDS, (char*)"Add a clickArea to the given text or image"},
253  {(char*)"createClickArea", py_create_click_area, METH_VARARGS, (char*)"Create a Click Area Sensor"},
254  {(char*)"getNumberOfDesktops", py_get_number_of_desktops, METH_VARARGS, (char*)"Get current number of virtual desktops"},
255  {(char*)"getIp", py_get_ip, METH_VARARGS, (char*)"Get current host's IP address"},
256  {(char*)"translateAll", py_translate_all, METH_VARARGS, (char*)"Translate all widgets in a theme"},
257  {(char*)"show", py_show, METH_VARARGS, (char*)"Show theme"},
258  {(char*)"hide", py_hide, METH_VARARGS, (char*)"Hide theme"},
259 
260  // Input Box - input_python.cpp
261  {(char*)"createInputBox", py_createInputBox, METH_VARARGS,
262  (char*)"Create new Input Box."},
263  {(char*)"deleteInputBox", py_deleteInputBox, METH_VARARGS,
264  (char*)"Delete Input Box."},
265  {(char*)"getThemeInputBox", py_getThemeInputBox, METH_VARARGS,
266  (char*)"Get Input Box from .theme using it's name."},
267  {(char*)"getInputBoxValue", py_getInputBoxValue, METH_VARARGS,
268  (char*)"Get Input Box value"},
269  {(char*)"changeInputBox", py_setInputBoxValue, METH_VARARGS,
270  (char*)"Change a Input Box Text"},
271  {(char*)"hideInputBox", py_hideInputBox, METH_VARARGS,
272  (char*)"Hide Input Box."},
273  {(char*)"showInputBox", py_showInputBox, METH_VARARGS,
274  (char*)"Show Input Box."},
275  {(char*)"getInputBoxPos", py_getInputBoxPos, METH_VARARGS,
276  (char*)"Get InputBox position."},
277  {(char*)"moveInputBox", py_moveInputBox, METH_VARARGS,
278  (char*)"Moves a Input Box"},
279  {(char*)"getInputBoxSize", py_getInputBoxSize, METH_VARARGS,
280  (char*)"Get the (width, height) of a Input Box"},
281  {(char*)"resizeInputBox", py_resizeInputBox, METH_VARARGS,
282  (char*)"Resize Input Box."},
283  {(char*)"changeInputBoxFont", py_setInputBoxFont, METH_VARARGS,
284  (char*)"Change a Input Box Font"},
285  {(char*)"getInputBoxFont", py_getInputBoxFont, METH_VARARGS,
286  (char*)"Get a Input Box Font"},
287  {(char*)"changeInputBoxFontColor", py_setInputBoxFontColor, METH_VARARGS,
288  (char*)"Change a Input Box Font Color"},
289  {(char*)"getInputBoxFontColor", py_getInputBoxFontColor, METH_VARARGS,
290  (char*)"Get a Input Box Font Color"},
291  {(char*)"changeInputBoxSelectionColor", py_setInputBoxSelectionColor,
292  METH_VARARGS, (char*)"Change a Input Box Selection Color"},
293  {(char*)"getInputBoxSelectionColor", py_getInputBoxSelectionColor,
294  METH_VARARGS, (char*)"Get a Input Box Selection Color"},
295  {(char*)"changeInputBoxBackgroundColor", py_setInputBoxBGColor,
296  METH_VARARGS, (char*)"Change a Input Box Background Color"},
297  {(char*)"getInputBoxBackgroundColor", py_getInputBoxBGColor, METH_VARARGS,
298  (char*)"Get a Input Box Background Color"},
299  {(char*)"changeInputBoxFrameColor", py_setInputBoxFrameColor, METH_VARARGS,
300  (char*)"Change a Input Box Frame Color"},
301  {(char*)"getInputBoxFrameColor", py_getInputBoxFrameColor, METH_VARARGS,
302  (char*)"Get a Input Box Frame Color"},
303  {(char*)"changeInputBoxSelectedTextColor", py_setInputBoxSelectedTextColor,
304  METH_VARARGS, (char*)"Change a Input Box Selected Text Color"},
305  {(char*)"getInputBoxSelectedTextColor", py_getInputBoxSelectedTextColor,
306  METH_VARARGS, (char*)"Get a Input Box Selected Text Color"},
307  {(char*)"changeInputBoxFontSize", py_setInputBoxFontSize, METH_VARARGS,
308  (char*)"Change a Input Box Font Size"},
309  {(char*)"getInputBoxFontSize", py_getInputBoxFontSize, METH_VARARGS,
310  (char*)"Get a Input Box Font Size"},
311  {(char*)"setInputFocus", py_setInputFocus, METH_VARARGS,
312  (char*)"Set the Input Focus to the Input Box"},
313  {(char*)"clearInputFocus", py_clearInputFocus, METH_VARARGS,
314  (char*)"Clear the Input Focus of the Input Box"},
315  {(char*)"getInputFocus", py_getInputFocus, METH_VARARGS,
316  (char*)"Get the Input Box currently focused"},
317 
318  {(char*)"setWidgetOnTop", py_set_widget_on_top, METH_VARARGS,
319  (char*)"changes 'on top' status"},
320  {(char*)"getSystraySize", py_get_systray_size, METH_VARARGS,
321  (char*)"Get the size of the Systray"},
322  {(char*)"getPrettyThemeName", py_get_pretty_name, METH_VARARGS,
323  (char*)"Get the pretty name of the theme"},
324  {(char*)"openNamedTheme", py_open_named_theme, METH_VARARGS,
325  (char*)"Open a new theme giving it a new name"},
326  {(char*)"callTheme", py_call_theme, METH_VARARGS,
327  (char*)"Pass a string to another theme"},
328  {(char*)"changeInterval", py_change_interval, METH_VARARGS,
329  (char*)"Change the refresh interval"},
330  {(char*)"run", py_run_command, METH_VARARGS,
331  (char*)"Execute a command with KRun"},
332  {(char*)"createServiceClickArea", py_create_service_click_area, METH_VARARGS,
333  (char*)"Create a Service-named Click Area Sensor"},
334  {(char*)"removeClickArea", py_remove_click_area, METH_VARARGS,
335  (char*)"Remove a Click Area Sensor"},
336  {(char*)"setUpdateTime", py_set_update_time, METH_VARARGS,
337  (char*)"Set last updated time"},
338  {(char*)"getUpdateTime", py_get_update_time, METH_VARARGS,
339  (char*)"Get last updated time"},
340  {(char*)"setWantRightButton", py_want_right_button, METH_VARARGS,
341  (char*)"Set to 1 to deactivate management popups"},
342  {(char*)"setWantMeterWheelEvent", py_want_wheel_event, METH_VARARGS,
343  (char*)"Enables wheel events over meters."},
344  {(char*)"managementPopup", py_management_popup, METH_VARARGS,
345  (char*)"Activates the Management Popup menu"},
346 
347  // service groups
348  {(char*)"getServiceGroups", py_get_service_groups, METH_VARARGS,
349  (char*)"Get KDE Service Groups"},
350 
351  {NULL, NULL, 0 ,NULL}
352 };
353 
354 static int karamba_traverse(PyObject *m, visitproc visit, void *arg) {
355  Py_VISIT(GETSTATE(m)->error);
356  return 0;
357 }
358 
359 static int karamba_clear(PyObject *m) {
360  Py_CLEAR(GETSTATE(m)->error);
361  return 0;
362 }
363 
364 static struct PyModuleDef karambadef = {
365  PyModuleDef_HEAD_INIT,
366  "karamba",
367  NULL,
368  sizeof(struct module_state),
369  karamba_methods,
370  NULL,
371  karamba_traverse,
372  karamba_clear,
373  NULL
374 };
375 
376 #define INITERROR return NULL
377 
378 PyMODINIT_FUNC PyInit_karamba(void)
379 {
380  return PyModule_Create(&karambadef);
381 }
382 
383 PyThreadState* KarambaPython::mainThreadState = 0;
384 
385 KarambaPython::KarambaPython(const ThemeFile& theme, bool reloading):
386  pythonThemeExtensionLoaded(false), pName(0), pModule(0), pDict(0)
387 {
388  char pypath[1024];
389 
390  // load the .py file for this .theme
391  PyRun_SimpleString((char*)"import sys");
392  //Add theme path to python path so that we can find the python file
393  snprintf(pypath, 1023, "sys.path.insert(0, '%s')", theme.path().ascii());
394  PyRun_SimpleString(pypath);
395  PyRun_SimpleString((char*)"sys.path.insert(0, '')");
396 
397  pName = PyUnicode_FromString(theme.pythonModule().utf8());
398  pModule = PyImport_Import(pName);
399 
400  fprintf(stderr, "%s\n", pypath);
401 
402  //Make sure the module is up to date.
403  if (reloading)
404  PyImport_ReloadModule(pModule);
405 
406  if (pModule != NULL)
407  {
408  pDict = PyModule_GetDict(pModule);
409  if (pDict != NULL)
410  {
411  pythonThemeExtensionLoaded = true;
412  }
413  }
414  else
415  {
416  PyErr_Print();
417  fprintf(stderr,
418  "------------------------------------------------------\n");
419  fprintf(stderr, "What does ImportError mean?\n");
420  fprintf(stderr, "\n");
421  fprintf(stderr,
422  "It means that I couldn't load a python add-on %s.py\n",
423  theme.pythonModule().ascii());
424  fprintf(stderr, "If this is a regular theme and doesn't use python\n");
425  fprintf(stderr, "extensions, then nothing is wrong.\n");
426  fprintf(stderr,
427  "------------------------------------------------------\n");
428  }
429 }
430 
431 KarambaPython::~KarambaPython()
432 {
433  //Clean up Python references
434  if (pythonThemeExtensionLoaded) {
435  //Displose of current python module so we can reload in constructor.
436  Py_DECREF(pModule);
437  Py_DECREF(pName);
438  }
439 }
440 
441 void KarambaPython::initPython()
442 {
443  // initialize Python
444  PyImport_AppendInittab((char*)"karamba", PyInit_karamba);
445  Py_Initialize();
446 
447 #if PY_VERSION_HEX < 0x03070000
448  // initialize thread support
449  PyEval_InitThreads();
450 #endif
451 
452  // save a pointer to the main PyThreadState object
453  mainThreadState = PyThreadState_Get();
454 }
455 
456 void KarambaPython::shutdownPython()
457 {
458  // shut down the interpreter
459  PyThreadState_Swap(mainThreadState);
460  Py_Finalize();
461 }
462 
463 PyObject* KarambaPython::getFunc(const char* function)
464 {
465  PyObject* pFunc = PyDict_GetItemString(pDict, (char*)function);
466  if (pFunc && PyCallable_Check(pFunc))
467  return pFunc;
468  return NULL;
469 }
470 
471 bool KarambaPython::callObject(const char* func, PyObject* pArgs)
472 {
473  bool result = false;
474 
475  PyObject* pFunc = getFunc(func);
476  if (pFunc != NULL)
477  {
478  PyObject* pValue = PyObject_CallObject(pFunc, pArgs);
479 
480  if (pValue != NULL)
481  {
482  Py_DECREF(pValue);
483  result = true;
484  }
485  else
486  {
487  tqWarning("Call to %s failed", func);
488  PyErr_Print();
489  }
490  }
491  Py_DECREF(pArgs);
492  return result;
493 }
494 
495 bool KarambaPython::initWidget(karamba* k)
496 {
497  PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
498  return callObject("initWidget", pArgs);
499 }
500 
501 bool KarambaPython::widgetUpdated(karamba* k)
502 {
503  PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
504  return callObject("widgetUpdated", pArgs);
505 }
506 
507 bool KarambaPython::widgetClosed(karamba* k)
508 {
509  PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
510  return callObject("widgetClosed", pArgs);
511 }
512 
513 bool KarambaPython::menuOptionChanged(karamba* k, TQString key, bool value)
514 {
515  PyObject* pArgs = Py_BuildValue((char*)"(lsi)", k, key.ascii(), (int)value);
516  return callObject("menuOptionChanged", pArgs);
517 }
518 
519 bool KarambaPython::menuItemClicked(karamba* k, TDEPopupMenu* menu, long id)
520 {
521  PyObject* pArgs = Py_BuildValue((char*)"(lll)", k, menu, id);
522  return callObject("menuItemClicked", pArgs);
523 }
524 
525 bool KarambaPython::meterClicked(karamba* k, Meter* meter, int button)
526 {
527  PyObject* pArgs = Py_BuildValue((char*)"(lli)", k, meter, button);
528  return callObject("meterClicked", pArgs);
529 }
530 
531 bool KarambaPython::meterClicked(karamba* k, TQString anchor, int button)
532 {
533  PyObject* pArgs = Py_BuildValue((char*)"(lsi)", k, anchor.ascii(), button);
534  return callObject("meterClicked", pArgs);
535 }
536 
537 bool KarambaPython::widgetClicked(karamba* k, int x, int y, int button)
538 {
539  PyObject* pArgs = Py_BuildValue((char*)"(liii)", k, x, y, button);
540  return callObject("widgetClicked", pArgs);
541 }
542 
543 bool KarambaPython::keyPressed(karamba* k, const Meter* meter, const TQString& text)
544 {
545  PyObject* pArgs = Py_BuildValue((char*)"(lls)", k, meter, text.ucs2());
546  return callObject("keyPressed", pArgs);
547 }
548 
549 bool KarambaPython::widgetMouseMoved(karamba* k, int x, int y, int button)
550 {
551  PyObject* pArgs = Py_BuildValue((char*)"(liii)", k, x, y, button);
552  return callObject("widgetMouseMoved", pArgs);
553 }
554 
555 bool KarambaPython::activeTaskChanged(karamba* k, Task* t)
556 {
557  PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
558  return callObject("activeTaskChanged", pArgs);
559 }
560 
561 bool KarambaPython::taskAdded(karamba* k, Task* t)
562 {
563  PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
564  return callObject("taskAdded", pArgs);
565 }
566 
567 bool KarambaPython::taskRemoved(karamba* k, Task* t)
568 {
569  PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
570  return callObject("taskRemoved", pArgs);
571 }
572 
573 bool KarambaPython::startupAdded(karamba* k, Startup* t)
574 {
575  PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
576  return callObject("startupAdded", pArgs);
577 }
578 
579 bool KarambaPython::startupRemoved(karamba* k, Startup* t)
580 {
581  PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
582  return callObject("startupRemoved", pArgs);
583 }
584 
585 bool KarambaPython::commandOutput(karamba* k, int pid, char *buffer)
586 {
587  PyObject* pArgs = Py_BuildValue((char*)"(lis)", k, pid, buffer);
588  return callObject("commandOutput", pArgs);
589 }
590 
591 bool KarambaPython::commandFinished(karamba* k, int pid)
592 {
593  PyObject* pArgs = Py_BuildValue((char*)"(li)", k, pid);
594  return callObject("commandFinished", pArgs);
595 }
596 
597 bool KarambaPython::itemDropped(karamba* k, TQString text, int x, int y)
598 {
599  PyObject* pArgs = Py_BuildValue((char*)"(lOii)", k, TQString2PyString(text), x, y);
600  return callObject("itemDropped", pArgs);
601 }
602 
603 bool KarambaPython::themeNotify(karamba* k, const char *from, const char *str)
604 {
605  PyObject* pArgs = Py_BuildValue((char*)"(lss)", k, from, str);
606  return callObject("themeNotify", pArgs);
607 }
608 
609 bool KarambaPython::systrayUpdated(karamba* k)
610 {
611  PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
612  return callObject("systrayUpdated", pArgs);
613 }
614 
615 bool KarambaPython::desktopChanged(karamba* k, int desktop)
616 {
617  PyObject* pArgs = Py_BuildValue((char*)"(li)", k, desktop);
618  return callObject("desktopChanged", pArgs);
619 }
620 
621 bool KarambaPython::wallpaperChanged(karamba* k, int desktop)
622 {
623  PyObject* pArgs = Py_BuildValue((char*)"(li)", k, desktop);
624  return callObject("wallpaperChanged", pArgs);
625 }
py_hide
PyObject * py_hide(PyObject *self, PyObject *args)
Misc/hide.
Definition: misc_python.cpp:641
py_reload_theme
PyObject * py_reload_theme(PyObject *self, PyObject *args)
Misc/reloadTheme.
Definition: misc_python.cpp:551
ThemeFile
Definition: themefile.h:42
py_get_theme_path
PyObject * py_get_theme_path(PyObject *self, PyObject *args)
Misc/getThemePath.
Definition: misc_python.cpp:283
Startup
Represents a task which is in the process of starting.
Definition: taskmanager.h:376
py_show
PyObject * py_show(PyObject *self, PyObject *args)
Misc/show.
Definition: misc_python.cpp:623
py_execute_command_interactive
PyObject * py_execute_command_interactive(PyObject *self, PyObject *args)
Misc/executeInteractive.
Definition: misc_python.cpp:108
py_attach_clickArea
PyObject * py_attach_clickArea(PyObject *self, PyObject *args, PyObject *dict)
Misc/attachClickArea.
Definition: misc_python.cpp:201
py_management_popup
PyObject * py_management_popup(PyObject *self, PyObject *args)
Misc/managementPopup.
Definition: misc_python.cpp:790
py_remove_click_area
PyObject * py_remove_click_area(PyObject *self, PyObject *args)
Misc/removeClickArea.
Definition: misc_python.cpp:394
py_toggle_show_desktop
PyObject * py_toggle_show_desktop(PyObject *self, PyObject *args)
Misc/toggleShowDesktop.
Definition: misc_python.cpp:251
py_get_ip
PyObject * py_get_ip(PyObject *self, PyObject *args)
Misc/getIp.
Definition: misc_python.cpp:773
py_get_update_time
PyObject * py_get_update_time(PyObject *self, PyObject *args)
Misc/getUpdateTime.
Definition: misc_python.cpp:763
py_create_click_area
PyObject * py_create_click_area(PyObject *self, PyObject *args)
Misc/createClickArea.
Definition: misc_python.cpp:414
py_set_incoming_data
PyObject * py_set_incoming_data(PyObject *self, PyObject *args)
Misc/setIncomingData.
Definition: misc_python.cpp:513
py_userLanguages
PyObject * py_userLanguages(PyObject *self, PyObject *args)
Misc/userLanguages.
Definition: misc_python.cpp:314
py_userLanguage
PyObject * py_userLanguage(PyObject *self, PyObject *args)
Misc/userLanguage.
Definition: misc_python.cpp:304
py_change_interval
PyObject * py_change_interval(PyObject *self, PyObject *args)
Misc/changeInterval.
Definition: misc_python.cpp:841
py_set_update_time
PyObject * py_set_update_time(PyObject *self, PyObject *args)
Misc/setUpdateTime.
Definition: misc_python.cpp:752
misc_python.h
These are global functions that are used to interpret certain Python calls.
py_execute_command
PyObject * py_execute_command(PyObject *self, PyObject *args)
Misc/execute.
Definition: misc_python.cpp:98
py_run_command
PyObject * py_run_command(PyObject *self, PyObject *args)
Misc/run.
Definition: misc_python.cpp:68
py_open_named_theme
PyObject * py_open_named_theme(PyObject *self, PyObject *args)
Misc/openNamedTheme.
Definition: misc_python.cpp:533
py_get_number_of_desktops
PyObject * py_get_number_of_desktops(PyObject *self, PyObject *args)
Misc/getNumberOfDesktop.
Definition: misc_python.cpp:570
py_accept_drops
PyObject * py_accept_drops(PyObject *self, PyObject *args)
Misc/acceptDrops.
Definition: misc_python.cpp:56
py_get_pretty_name
PyObject * py_get_pretty_name(PyObject *self, PyObject *args)
Misc/getPrettyThemeName.
Definition: misc_python.cpp:268
py_want_right_button
PyObject * py_want_right_button(PyObject *self, PyObject *args)
Misc/setWantRightButton.
Definition: misc_python.cpp:807
py_want_wheel_event
PyObject * py_want_wheel_event(PyObject *, PyObject *args)
Misc/setWantMeterWheelEvent.
Definition: misc_python.cpp:824
py_open_theme
PyObject * py_open_theme(PyObject *self, PyObject *args)
Misc/openTheme.
Definition: misc_python.cpp:543
py_read_theme_file
PyObject * py_read_theme_file(PyObject *self, PyObject *args)
Misc/readThemeFile.
Definition: misc_python.cpp:336
py_create_service_click_area
PyObject * py_create_service_click_area(PyObject *self, PyObject *args)
Misc/createServiceClickArea.
Definition: misc_python.cpp:402
py_language
PyObject * py_language(PyObject *self, PyObject *args)
Misc/language.
Definition: misc_python.cpp:293
Task
A dynamic interface to a task (main window).
Definition: taskmanager.h:49
py_get_incoming_data
PyObject * py_get_incoming_data(PyObject *self, PyObject *args)
Misc/getIncomingData.
Definition: misc_python.cpp:505
py_translate_all
PyObject * py_translate_all(PyObject *self, PyObject *args)
Misc/translateAll.
Definition: misc_python.cpp:604
py_call_theme
PyObject * py_call_theme(PyObject *self, PyObject *args)
Misc/callTheme.
Definition: misc_python.cpp:523

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.