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

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.1.2
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |