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

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