31 #include "karambaapp.h"
32 #include "themefile.h"
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"
48 #include "input_python.h"
54 #if PY_MAJOR_VERSION >= 3
55 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
57 #define GETSTATE(m) (&_state)
58 static struct module_state _state;
62 error_out(PyObject *m) {
63 struct module_state *st = GETSTATE(m);
64 PyErr_SetString(st->error,
"something bad happened in karamba_python.cpp");
81 static PyMethodDef karamba_methods[] = {
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"},
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"},
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."},
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"},
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"},
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"},
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"},
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"},
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"},
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"},
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"},
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"},
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"},
353 {(
char*)
"getServiceGroups", py_get_service_groups, METH_VARARGS,
354 (
char*)
"Get KDE Service Groups"},
356 {NULL, NULL, 0 ,NULL}
359 #if PY_MAJOR_VERSION >= 3
361 static int karamba_traverse(PyObject *m, visitproc visit,
void *arg) {
362 Py_VISIT(GETSTATE(m)->error);
366 static int karamba_clear(PyObject *m) {
367 Py_CLEAR(GETSTATE(m)->error);
371 static struct PyModuleDef karambadef = {
372 PyModuleDef_HEAD_INIT,
375 sizeof(
struct module_state),
383 #define INITERROR return NULL
387 #define INITERROR return
391 PyThreadState* KarambaPython::mainThreadState = 0;
393 KarambaPython::KarambaPython(
const ThemeFile& theme,
bool reloading):
394 pythonThemeExtensionLoaded(false), pName(0), pModule(0), pDict(0)
396 PyThreadState* myThreadState;
399 getLock(&myThreadState);
402 PyRun_SimpleString((
char*)
"import sys");
404 snprintf(pypath, 1023,
"sys.path.insert(0, '%s')", theme.path().ascii());
405 PyRun_SimpleString(pypath);
406 PyRun_SimpleString((
char*)
"sys.path.insert(0, '')");
408 PyImport_AddModule((
char*)
"karamba");
409 #if PY_MAJOR_VERSION >= 3
410 PyModule_Create(&karambadef);
412 Py_InitModule((
char*)
"karamba", karamba_methods);
414 pName = PyBytes_FromString(theme.pythonModule().ascii());
415 pModule = PyImport_Import(pName);
417 fprintf(stderr,
"%s\n", pypath);
421 PyImport_ReloadModule(pModule);
425 pDict = PyModule_GetDict(pModule);
428 pythonThemeExtensionLoaded =
true;
435 "------------------------------------------------------\n");
436 fprintf(stderr,
"What does ImportError mean?\n");
437 fprintf(stderr,
"\n");
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");
444 "------------------------------------------------------\n");
446 releaseLock(myThreadState);
449 KarambaPython::~KarambaPython()
452 if (pythonThemeExtensionLoaded) {
453 PyThreadState* myThreadState;
454 getLock(&myThreadState);
460 releaseLock(myThreadState);
464 void KarambaPython::initPython()
470 PyEval_InitThreads();
473 mainThreadState = PyThreadState_Get();
476 PyEval_ReleaseLock();
479 void KarambaPython::shutdownPython()
482 PyInterpreterState * mainInterpreterState = mainThreadState->interp;
484 PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState);
485 PyThreadState_Swap(myThreadState);
486 PyEval_AcquireLock();
490 void KarambaPython::getLock(PyThreadState** myThreadState)
493 PyEval_AcquireLock();
496 *myThreadState = PyThreadState_New(mainThreadState->interp);
497 PyThreadState_Swap(*myThreadState);
500 void KarambaPython::releaseLock(PyThreadState* myThreadState)
503 PyThreadState_Swap(NULL);
505 PyThreadState_Clear(myThreadState);
507 PyThreadState_Delete(myThreadState);
509 PyEval_ReleaseLock();
512 PyObject* KarambaPython::getFunc(
const char*
function)
514 PyObject* pFunc = PyDict_GetItemString(pDict, (
char*)
function);
515 if (pFunc && PyCallable_Check(pFunc))
520 bool KarambaPython::callObject(
const char* func, PyObject* pArgs,
bool lock)
523 PyThreadState* myThreadState;
528 getLock(&myThreadState);
529 PyObject* pFunc = getFunc(func);
533 PyObject* pValue = PyObject_CallObject(pFunc, pArgs);
542 tqWarning(
"Call to %s failed", func);
548 releaseLock(myThreadState);
552 bool KarambaPython::initWidget(karamba* k)
554 PyObject* pArgs = Py_BuildValue((
char*)
"(l)", k);
555 return callObject(
"initWidget", pArgs);
558 bool KarambaPython::widgetUpdated(karamba* k)
560 PyObject* pArgs = Py_BuildValue((
char*)
"(l)", k);
561 return callObject(
"widgetUpdated", pArgs);
564 bool KarambaPython::widgetClosed(karamba* k)
566 PyObject* pArgs = Py_BuildValue((
char*)
"(l)", k);
567 return callObject(
"widgetClosed", pArgs);
570 bool KarambaPython::menuOptionChanged(karamba* k, TQString key,
bool value)
572 PyObject* pArgs = Py_BuildValue((
char*)
"(lsi)", k, key.ascii(), (int)value);
573 return callObject(
"menuOptionChanged", pArgs);
576 bool KarambaPython::menuItemClicked(karamba* k, TDEPopupMenu* menu,
long id)
578 PyObject* pArgs = Py_BuildValue((
char*)
"(lll)", k, menu,
id);
579 return callObject(
"menuItemClicked", pArgs);
582 bool KarambaPython::meterClicked(karamba* k, Meter* meter,
int button)
584 PyObject* pArgs = Py_BuildValue((
char*)
"(lli)", k, meter, button);
585 return callObject(
"meterClicked", pArgs);
588 bool KarambaPython::meterClicked(karamba* k, TQString anchor,
int button)
590 PyObject* pArgs = Py_BuildValue((
char*)
"(lsi)", k, anchor.ascii(), button);
591 return callObject(
"meterClicked", pArgs);
594 bool KarambaPython::widgetClicked(karamba* k,
int x,
int y,
int button)
596 PyObject* pArgs = Py_BuildValue((
char*)
"(liii)", k, x, y, button);
597 return callObject(
"widgetClicked", pArgs);
600 bool KarambaPython::keyPressed(karamba* k,
const Meter* meter,
601 const TQString& text)
603 PyObject* pArgs = Py_BuildValue((
char*)
"(lls)", k, meter, text.ucs2());
604 return callObject(
"keyPressed", pArgs);
607 bool KarambaPython::widgetMouseMoved(karamba* k,
int x,
int y,
int button)
609 PyObject* pArgs = Py_BuildValue((
char*)
"(liii)", k, x, y, button);
610 return callObject(
"widgetMouseMoved", pArgs);
613 bool KarambaPython::activeTaskChanged(karamba* k,
Task* t)
615 PyObject* pArgs = Py_BuildValue((
char*)
"(ll)", k, t);
616 return callObject(
"activeTaskChanged", pArgs);
619 bool KarambaPython::taskAdded(karamba* k,
Task* t)
621 PyObject* pArgs = Py_BuildValue((
char*)
"(ll)", k, t);
622 return callObject(
"taskAdded", pArgs);
625 bool KarambaPython::taskRemoved(karamba* k,
Task* t)
627 PyObject* pArgs = Py_BuildValue((
char*)
"(ll)", k, t);
628 return callObject(
"taskRemoved", pArgs);
631 bool KarambaPython::startupAdded(karamba* k,
Startup* t)
633 PyObject* pArgs = Py_BuildValue((
char*)
"(ll)", k, t);
634 return callObject(
"startupAdded", pArgs);
637 bool KarambaPython::startupRemoved(karamba* k,
Startup* t)
639 PyObject* pArgs = Py_BuildValue((
char*)
"(ll)", k, t);
640 return callObject(
"startupRemoved", pArgs);
643 bool KarambaPython::commandOutput(karamba* k,
int pid,
char *buffer)
645 PyObject* pArgs = Py_BuildValue((
char*)
"(lis)", k, pid, buffer);
646 return callObject(
"commandOutput", pArgs);
649 bool KarambaPython::commandFinished(karamba* k,
int pid)
651 PyObject* pArgs = Py_BuildValue((
char*)
"(li)", k, pid);
652 return callObject(
"commandFinished", pArgs);
655 bool KarambaPython::itemDropped(karamba* k, TQString text,
int x,
int y)
657 PyObject* pArgs = Py_BuildValue((
char*)
"(lOii)", k, TQString2PyString(text), x, y);
658 return callObject(
"itemDropped", pArgs);
661 bool KarambaPython::themeNotify(karamba* k,
const char *from,
const char *str)
668 PyObject* pArgs = Py_BuildValue((
char*)
"(lss)", k, from, str);
669 return callObject(
"themeNotify", pArgs,
false);
672 bool KarambaPython::systrayUpdated(karamba* k)
674 PyObject* pArgs = Py_BuildValue((
char*)
"(l)", k);
675 return callObject(
"systrayUpdated", pArgs);
678 bool KarambaPython::desktopChanged(karamba* k,
int desktop)
680 PyObject* pArgs = Py_BuildValue((
char*)
"(li)", k, desktop);
681 return callObject(
"desktopChanged", pArgs);
684 bool KarambaPython::wallpaperChanged(karamba* k,
int desktop)
686 PyObject* pArgs = Py_BuildValue((
char*)
"(li)", k, desktop);
687 return callObject(
"wallpaperChanged", pArgs);