00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef _XOPEN_SOURCE
00027 #undef _XOPEN_SOURCE
00028 #endif
00029
00030 #include <Python.h>
00031 #include "karambaapp.h"
00032 #include "themefile.h"
00033
00034 #include "karamba_python.h"
00035 #include "meter_python.h"
00036 #include "bar_python.h"
00037 #include "graph_python.h"
00038 #include "textlabel_python.h"
00039 #include "richtextlabel_python.h"
00040 #include "imagelabel_python.h"
00041 #include "widget_python.h"
00042 #include "menu_python.h"
00043 #include "config_python.h"
00044 #include "task_python.h"
00045 #include "systray_python.h"
00046 #include "svcgrp_python.h"
00047 #include "misc_python.h"
00048 #include "input_python.h"
00049
00050 struct module_state {
00051 PyObject *error;
00052 };
00053
00054 #if PY_MAJOR_VERSION >= 3
00055 #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
00056 #else
00057 #define GETSTATE(m) (&_state)
00058 static struct module_state _state;
00059 #endif
00060
00061 static PyObject *
00062 error_out(PyObject *m) {
00063 struct module_state *st = GETSTATE(m);
00064 PyErr_SetString(st->error, "something bad happened in karamba_python.cpp");
00065 return NULL;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 static PyMethodDef karamba_methods[] = {
00082
00083 {(char*)"createBar", py_createBar, METH_VARARGS, (char*)"Create new Bar."},
00084 {(char*)"deleteBar", py_deleteBar, METH_VARARGS, (char*)"Delete Bar."},
00085 {(char*)"getThemeBar", py_getThemeBar, METH_VARARGS, (char*)"Get Bar from .theme using it's name."},
00086 {(char*)"getBarSize", py_getBarSize, METH_VARARGS, (char*)"Get Bar size."},
00087 {(char*)"resizeBar", py_resizeBar, METH_VARARGS, (char*)"Resize Bar."},
00088 {(char*)"getBarPos", py_getBarPos, METH_VARARGS, (char*)"Get Bar position."},
00089 {(char*)"moveBar", py_moveBar, METH_VARARGS, (char*)"Move Bar."},
00090 {(char*)"hideBar", py_hideBar, METH_VARARGS, (char*)"Hide Bar."},
00091 {(char*)"showBar", py_showBar, METH_VARARGS, (char*)"Show Bar."},
00092 {(char*)"getBarSensor", py_getBarSensor, METH_VARARGS, (char*)"Get Bar sensor."},
00093 {(char*)"setBarSensor", py_setBarSensor, METH_VARARGS, (char*)"Set Bar sensor."},
00094 {(char*)"setBarImage", py_setBarImage, METH_VARARGS, (char*)"Set bar image"},
00095 {(char*)"getBarImage", py_getBarImage, METH_VARARGS, (char*)"Get bar image"},
00096 {(char*)"setBarVertical", py_setBarVertical, METH_VARARGS, (char*)"Set bar orientation"},
00097 {(char*)"getBarVertical", py_getBarVertical, METH_VARARGS, (char*)"Get bar orientation"},
00098 {(char*)"setBarValue", py_setBarValue, METH_VARARGS, (char*)"Set bar value"},
00099 {(char*)"getBarValue", py_getBarValue, METH_VARARGS, (char*)"Get bar value"},
00100 {(char*)"setBarMinMax", py_setBarMinMax, METH_VARARGS, (char*)"Set bar min & max"},
00101 {(char*)"getBarMinMax", py_getBarMinMax, METH_VARARGS, (char*)"Get bar min & max"},
00102 {(char*)"getIncomingData", py_get_incoming_data, METH_VARARGS, (char*)"Get incoming data passed from another theme"},
00103 {(char*)"setIncomingData", py_set_incoming_data, METH_VARARGS, (char*)"Set incoming data passed in another theme"},
00104
00105
00106 {(char*)"createGraph", py_createGraph, METH_VARARGS, (char*)"Create new Graph."},
00107 {(char*)"deleteGraph", py_deleteGraph, METH_VARARGS, (char*)"Delete Graph."},
00108 {(char*)"getThemeGraph", py_getThemeGraph, METH_VARARGS, (char*)"Get Graph from .theme using it's name."},
00109 {(char*)"getGraphSize", py_getGraphSize, METH_VARARGS, (char*)"Get Graph size."},
00110 {(char*)"resizeGraph", py_resizeGraph, METH_VARARGS, (char*)"Resize Graph."},
00111 {(char*)"getGraphPos", py_getGraphPos, METH_VARARGS, (char*)"Get Graph position."},
00112 {(char*)"moveGraph", py_moveGraph, METH_VARARGS, (char*)"Move Graph."},
00113 {(char*)"hideGraph", py_hideGraph, METH_VARARGS, (char*)"Hide Graph."},
00114 {(char*)"showGraph", py_showGraph, METH_VARARGS, (char*)"Show Graph."},
00115 {(char*)"getGraphSensor", py_getGraphSensor, METH_VARARGS, (char*)"Get Graph sensor."},
00116 {(char*)"setGraphSensor", py_setGraphSensor, METH_VARARGS, (char*)"Set Graph sensor."},
00117 {(char*)"setGraphValue", py_setGraphValue, METH_VARARGS, (char*)"Set graph value"},
00118 {(char*)"getGraphValue", py_getGraphValue, METH_VARARGS, (char*)"Get graph value"},
00119 {(char*)"setGraphMinMax", py_setGraphMinMax, METH_VARARGS, (char*)"Set graph min & max"},
00120 {(char*)"getGraphMinMax", py_getGraphMinMax, METH_VARARGS, (char*)"Get graph min & max"},
00121 {(char*)"setGraphColor", py_setGraphColor, METH_VARARGS, (char*)"Change a Graph Sensor's Color"},
00122 {(char*)"getGraphColor", py_getGraphColor, METH_VARARGS, (char*)"Get a Graph Sensor's Color"},
00123
00124
00125 {(char*)"createText", py_createText, METH_VARARGS, (char*)"Create new Text."},
00126 {(char*)"deleteText", py_deleteText, METH_VARARGS, (char*)"Delete Text."},
00127 {(char*)"getThemeText", py_getThemeText, METH_VARARGS, (char*)"Get Text from .theme using it's name."},
00128 {(char*)"getTextSize", py_getTextSize, METH_VARARGS, (char*)"Get Text size."},
00129 {(char*)"resizeText", py_resizeText, METH_VARARGS, (char*)"Resize Text."},
00130 {(char*)"getTextPos", py_getTextPos, METH_VARARGS, (char*)"Get Text position."},
00131 {(char*)"moveText", py_moveText, METH_VARARGS, (char*)"Move Text."},
00132 {(char*)"hideText", py_hideText, METH_VARARGS, (char*)"Hide Text."},
00133 {(char*)"showText", py_showText, METH_VARARGS, (char*)"Show Text."},
00134 {(char*)"getTextSensor", py_getTextSensor, METH_VARARGS, (char*)"Get Text sensor."},
00135 {(char*)"setTextSensor", py_setTextSensor, METH_VARARGS, (char*)"Set Text sensor."},
00136 {(char*)"changeText", py_setTextValue, METH_VARARGS, (char*)"Change a Text Sensor's Text"},
00137 {(char*)"getTextValue", py_getTextValue, METH_VARARGS, (char*)"Get Text value"},
00138 {(char*)"changeTextShadow", py_setTextShadow, METH_VARARGS, (char*)"Change a Text Shadow size"},
00139 {(char*)"getTextShadow", py_getTextShadow, METH_VARARGS, (char*)"Get a Text Shadow size"},
00140 {(char*)"changeTextFont", py_setTextFont, METH_VARARGS, (char*)"Change a Text Sensor's Font"},
00141 {(char*)"getTextFont", py_getTextFont, METH_VARARGS, (char*)"Get a Text Sensor's Font"},
00142 {(char*)"changeTextColor", py_setTextColor, METH_VARARGS, (char*)"Change a Text Sensor's Color"},
00143 {(char*)"getTextColor", py_getTextColor, METH_VARARGS, (char*)"Get a Text Sensor's Color"},
00144 {(char*)"changeTextSize", py_setTextFontSize, METH_VARARGS, (char*)"Change a Text Sensor's Font Size"},
00145 {(char*)"getTextFontSize", py_getTextFontSize, METH_VARARGS, (char*)"Get a Text Sensor's Font Size"},
00146 {(char*)"getTextAlign", py_getTextAlign, METH_VARARGS, (char*)"Get Text alignment."},
00147 {(char*)"setTextAlign", py_setTextAlign, METH_VARARGS, (char*)"Set Text alignment."},
00148 {(char*)"setTextScroll", py_setTextScroll, METH_VARARGS, (char*)"Set Text scroll."},
00149
00150
00151 {(char*)"createRichText", py_createRichText, METH_VARARGS, (char*)"Create a Rich Text Sensor"},
00152 {(char*)"deleteRichText", py_deleteRichText, METH_VARARGS, (char*)"Deletes a Rich Text Sensor"},
00153 {(char*)"getThemeRichText", py_getThemeRichText, METH_VARARGS, (char*)"Get Rich Text from .theme using it's name."},
00154 {(char*)"getRichTextSize", py_getRichTextSize, METH_VARARGS, (char*)"Get the (width, height) of a Rich Text Sensor"},
00155 {(char*)"resizeRichText", py_resizeRichText, METH_VARARGS, (char*)"Resize Rich Text."},
00156 {(char*)"setRichTextWidth", py_set_rich_text_width, METH_VARARGS, (char*)"Sets the width of a Rich Text Sensor"},
00157 {(char*)"getRichTextPos", py_getRichTextPos, METH_VARARGS, (char*)"Get Rich Text position."},
00158 {(char*)"moveRichText", py_moveRichText, METH_VARARGS, (char*)"Moves a Rich Text Sensor"},
00159 {(char*)"hideRichText", py_hideRichText, METH_VARARGS, (char*)"hides a Rich Text Sensor"},
00160 {(char*)"showRichText", py_showRichText, METH_VARARGS, (char*)"shows a Rich Text Sensor"},
00161 {(char*)"getRichTextSensor", py_getRichTextSensor, METH_VARARGS, (char*)"Get Rich Text sensor."},
00162 {(char*)"setRichTextSensor", py_setRichTextSensor, METH_VARARGS, (char*)"Set Rich Text sensor."},
00163 {(char*)"changeRichText", py_setRichTextValue, METH_VARARGS, (char*)"Change the content of a Rich Text Sensor"},
00164 {(char*)"getRichTextValue", py_getRichTextValue, METH_VARARGS, (char*)"Get Rich Text value"},
00165 {(char*)"changeRichTextFont", py_setRichTextFont, METH_VARARGS, (char*)"Change a Rich Text Sensor's Font"},
00166 {(char*)"getRichTextFont", py_getRichTextFont, METH_VARARGS, (char*)"Get a Rich Text Sensor's Font"},
00167 {(char*)"changeRichTextSize", py_setRichTextFontSize, METH_VARARGS, (char*)"Change a Rich Text Sensor's Font Size"},
00168 {(char*)"getRichTextFontSize", py_getRichTextFontSize, METH_VARARGS, (char*)"Get a Rich Text Sensor's Font Size"},
00169
00170
00171 {(char*)"createImage", py_createImage, METH_VARARGS, (char*)"Create an Image"},
00172 {(char*)"createTaskIcon", py_createTaskIcon, METH_VARARGS, (char*)"Create an Image of the Icon for a Task"},
00173 {(char*)"createBackgroundImage", py_createBackgroundImage, METH_VARARGS, (char*)"Create an Image (only redraw it when background changes)"},
00174 {(char*)"deleteImage", py_deleteImage, METH_VARARGS, (char*)"Delete an Image"},
00175 {(char*)"getThemeImage", py_getThemeImage, METH_VARARGS, (char*)"Get image meter from .theme using it's name"},
00176 {(char*)"getImageSize", py_getImageSize, METH_VARARGS, (char*)"Get Image size."},
00177 {(char*)"getImageWidth", py_getImageWidth, METH_VARARGS, (char*)"Get the width of an Image"},
00178 {(char*)"getImageHeight", py_getImageHeight, METH_VARARGS, (char*)"Get the height of an Image"},
00179 {(char*)"getImagePos", py_getImagePos, METH_VARARGS, (char*)"Get Image position."},
00180 {(char*)"moveImage", py_moveImage, METH_VARARGS, (char*)"Move an Image"},
00181 {(char*)"hideImage", py_hideImage, METH_VARARGS, (char*)"Hide an Image"},
00182 {(char*)"showImage", py_showImage, METH_VARARGS, (char*)"Show an Image"},
00183 {(char*)"getImagePath", py_getImageValue, METH_VARARGS, (char*)"Get Image path."},
00184 {(char*)"setImagePath", py_setImageValue, METH_VARARGS, (char*)"Set Image path."},
00185 {(char*)"getImageSensor", py_getImageSensor, METH_VARARGS, (char*)"Get Image sensor."},
00186 {(char*)"setImageSensor", py_setImageSensor, METH_VARARGS, (char*)"Set Image sensor."},
00187 {(char*)"addImageTooltip", py_addImageTooltip, METH_VARARGS, (char*)"Create a Tooltip for an Image"},
00188 {(char*)"resizeImage", py_resizeImage, METH_VARARGS, (char*)"Scale an Image"},
00189 {(char*)"resizeImageSmooth", py_resizeImageSmooth, METH_VARARGS, (char*)"Scale an Image (slower, better looking)"},
00190 {(char*)"rotateImage", py_rotateImage, METH_VARARGS, (char*)"Rotate an Image"},
00191 {(char*)"removeImageTransformations", py_removeImageTransformations, METH_VARARGS, (char*)"Restore original size and orientation of an Image"},
00192 {(char*)"removeImageEffects", py_removeImageEffects, METH_VARARGS, (char*)"Remove Effects of an Image"},
00193 {(char*)"changeImageIntensity", py_changeImageIntensity, METH_VARARGS, (char*)"Change Intensity of an Image"},
00194 {(char*)"changeImageChannelIntensity", py_changeImageChannelIntensity, METH_VARARGS, (char*)"Change Intensity of an Image Channel"},
00195 {(char*)"changeImageToGray", py_changeImageToGray, METH_VARARGS, (char*)"Converts an Image to Grayscale"},
00196
00197
00198 {(char*)"createMenu", py_create_menu, METH_VARARGS, (char*)"Create a popup menu"},
00199 {(char*)"deleteMenu", py_delete_menu, METH_VARARGS, (char*)"Delete a popup menu"},
00200 {(char*)"addMenuItem", py_add_menu_item, METH_VARARGS, (char*)"Add a popup menu entry"},
00201 {(char*)"addMenuSeparator", py_add_menu_separator, METH_VARARGS, (char*)"Add a popup menu seperator item"},
00202 {(char*)"removeMenuItem", py_remove_menu_item, METH_VARARGS, (char*)"Remove a popup menu entry"},
00203 {(char*)"popupMenu", py_popup_menu, METH_VARARGS, (char*)"Popup a menu at a specified location"},
00204
00205
00206 {(char*)"addMenuConfigOption", py_add_menu_config_option, METH_VARARGS, (char*)"Add a configuration entry to the menu"},
00207 {(char*)"setMenuConfigOption", py_set_menu_config_option, METH_VARARGS, (char*)"Set a configuration entry in the menu"},
00208 {(char*)"readMenuConfigOption", py_read_menu_config_option, METH_VARARGS, (char*)"Read a configuration entry in the menu"},
00209 {(char*)"readConfigEntry", py_read_config_entry, METH_VARARGS, (char*)"Read a configuration entry"},
00210 {(char*)"writeConfigEntry", py_write_config_entry, METH_VARARGS, (char*)"Writes a configuration entry"},
00211
00212
00213 {(char*)"moveWidget", py_move_widget, METH_VARARGS, (char*)"Move Widget to x,y"},
00214 {(char*)"resizeWidget", py_resize_widget, METH_VARARGS, (char*)"Resize Widget to width,height"},
00215 {(char*)"createWidgetMask", py_create_widget_mask, METH_VARARGS, (char*)"Create a clipping mask for this widget"},
00216 {(char*)"redrawWidget", py_redraw_widget, METH_VARARGS, (char*)"Update Widget to reflect your changes"},
00217 {(char*)"redrawWidgetBackground", py_redraw_widget_background, METH_VARARGS, (char*)"Update Widget to reflect background image changes"},
00218 {(char*)"getWidgetPosition", py_get_widget_position, METH_VARARGS, (char*)"Get Widget Position"},
00219 {(char*)"toggleWidgetRedraw", py_toggle_widget_redraw, METH_VARARGS, (char*)"Toggle Widget redrawing"},
00220
00221
00222 {(char*)"getStartupList", py_get_startup_list, METH_VARARGS, (char*)"Get the system startup list"},
00223 {(char*)"getStartupInfo", py_get_startup_info, METH_VARARGS, (char*)"Get all the info for a startup"},
00224 {(char*)"getTaskList", py_get_task_list, METH_VARARGS, (char*)"Get the system task list"},
00225 {(char*)"getTaskNames", py_get_task_names, METH_VARARGS, (char*)"Get the system task list in name form"},
00226 {(char*)"getTaskInfo", py_get_task_info, METH_VARARGS, (char*)"Get all the info for a task"},
00227 {(char*)"performTaskAction", py_perform_task_action, METH_VARARGS, (char*)"Do something with a task, such as minimize it"},
00228
00229
00230 {(char*)"createSystray", py_create_systray, METH_VARARGS, (char*)"Create a Systray"},
00231 {(char*)"hideSystray", py_hide_systray, METH_VARARGS, (char*)"Hide the Systray"},
00232 {(char*)"showSystray", py_show_systray, METH_VARARGS, (char*)"Show the Systray"},
00233 {(char*)"moveSystray", py_move_systray, METH_VARARGS, (char*)"Move the Systray"},
00234 {(char*)"getCurrentWindowCount", py_get_current_window_count, METH_VARARGS, (char*)"Get current Window count"},
00235 {(char*)"updateSystrayLayout", py_update_systray_layout, METH_VARARGS, (char*)"Update Systray layout"},
00236
00237
00238 {(char*)"getThemePath", py_get_theme_path, METH_VARARGS, (char*)"Get the file path of the theme"},
00239 {(char*)"readThemeFile", py_read_theme_file, METH_VARARGS,
00240 (char*)"Read file from theme."},
00241 {(char*)"language", py_language, METH_VARARGS,
00242 (char*)"Return default language of a translation file."},
00243 {(char*)"userLanguage", py_userLanguage, METH_VARARGS,
00244 (char*)"Return user language."},
00245 {(char*)"userLanguages", py_userLanguages, METH_VARARGS,
00246 (char*)"Return preferred user languages."},
00247 {(char*)"openTheme", py_open_theme, METH_VARARGS,
00248 (char*)"Open a new theme"},
00249 {(char*)"reloadTheme", py_reload_theme, METH_VARARGS,
00250 (char*)"Reload current theme"},
00251 {(char*)"acceptDrops", py_accept_drops, METH_VARARGS,
00252 (char*)"Allows widget to receive Drop (I.E. Drag and Drop) events"},
00253 {(char*)"toggleShowDesktop", py_toggle_show_desktop, METH_VARARGS,
00254 (char*)"Show/Hide the desktop"},
00255 {(char*)"execute", py_execute_command, METH_VARARGS, (char*)"Execute a command"},
00256 {(char*)"executeInteractive", py_execute_command_interactive, METH_VARARGS, (char*)"Execute a command and get it's output (stdout)"},
00257 {(char*)"attachClickArea", (PyCFunction)py_attach_clickArea, METH_VARARGS|METH_KEYWORDS, (char*)"Add a clickArea to the given text or image"},
00258 {(char*)"createClickArea", py_create_click_area, METH_VARARGS, (char*)"Create a Click Area Sensor"},
00259 {(char*)"getNumberOfDesktops", py_get_number_of_desktops, METH_VARARGS, (char*)"Get current number of virtual desktops"},
00260 {(char*)"getIp", py_get_ip, METH_VARARGS, (char*)"Get current host's IP address"},
00261 {(char*)"translateAll", py_translate_all, METH_VARARGS, (char*)"Translate all widgets in a theme"},
00262 {(char*)"show", py_show, METH_VARARGS, (char*)"Show theme"},
00263 {(char*)"hide", py_hide, METH_VARARGS, (char*)"Hide theme"},
00264
00265
00266 {(char*)"createInputBox", py_createInputBox, METH_VARARGS,
00267 (char*)"Create new Input Box."},
00268 {(char*)"deleteInputBox", py_deleteInputBox, METH_VARARGS,
00269 (char*)"Delete Input Box."},
00270 {(char*)"getThemeInputBox", py_getThemeInputBox, METH_VARARGS,
00271 (char*)"Get Input Box from .theme using it's name."},
00272 {(char*)"getInputBoxValue", py_getInputBoxValue, METH_VARARGS,
00273 (char*)"Get Input Box value"},
00274 {(char*)"changeInputBox", py_setInputBoxValue, METH_VARARGS,
00275 (char*)"Change a Input Box Text"},
00276 {(char*)"hideInputBox", py_hideInputBox, METH_VARARGS,
00277 (char*)"Hide Input Box."},
00278 {(char*)"showInputBox", py_showInputBox, METH_VARARGS,
00279 (char*)"Show Input Box."},
00280 {(char*)"getInputBoxPos", py_getInputBoxPos, METH_VARARGS,
00281 (char*)"Get InputBox position."},
00282 {(char*)"moveInputBox", py_moveInputBox, METH_VARARGS,
00283 (char*)"Moves a Input Box"},
00284 {(char*)"getInputBoxSize", py_getInputBoxSize, METH_VARARGS,
00285 (char*)"Get the (width, height) of a Input Box"},
00286 {(char*)"resizeInputBox", py_resizeInputBox, METH_VARARGS,
00287 (char*)"Resize Input Box."},
00288 {(char*)"changeInputBoxFont", py_setInputBoxFont, METH_VARARGS,
00289 (char*)"Change a Input Box Font"},
00290 {(char*)"getInputBoxFont", py_getInputBoxFont, METH_VARARGS,
00291 (char*)"Get a Input Box Font"},
00292 {(char*)"changeInputBoxFontColor", py_setInputBoxFontColor, METH_VARARGS,
00293 (char*)"Change a Input Box Font Color"},
00294 {(char*)"getInputBoxFontColor", py_getInputBoxFontColor, METH_VARARGS,
00295 (char*)"Get a Input Box Font Color"},
00296 {(char*)"changeInputBoxSelectionColor", py_setInputBoxSelectionColor,
00297 METH_VARARGS, (char*)"Change a Input Box Selection Color"},
00298 {(char*)"getInputBoxSelectionColor", py_getInputBoxSelectionColor,
00299 METH_VARARGS, (char*)"Get a Input Box Selection Color"},
00300 {(char*)"changeInputBoxBackgroundColor", py_setInputBoxBGColor,
00301 METH_VARARGS, (char*)"Change a Input Box Background Color"},
00302 {(char*)"getInputBoxBackgroundColor", py_getInputBoxBGColor, METH_VARARGS,
00303 (char*)"Get a Input Box Background Color"},
00304 {(char*)"changeInputBoxFrameColor", py_setInputBoxFrameColor, METH_VARARGS,
00305 (char*)"Change a Input Box Frame Color"},
00306 {(char*)"getInputBoxFrameColor", py_getInputBoxFrameColor, METH_VARARGS,
00307 (char*)"Get a Input Box Frame Color"},
00308 {(char*)"changeInputBoxSelectedTextColor", py_setInputBoxSelectedTextColor,
00309 METH_VARARGS, (char*)"Change a Input Box Selected Text Color"},
00310 {(char*)"getInputBoxSelectedTextColor", py_getInputBoxSelectedTextColor,
00311 METH_VARARGS, (char*)"Get a Input Box Selected Text Color"},
00312 {(char*)"changeInputBoxFontSize", py_setInputBoxFontSize, METH_VARARGS,
00313 (char*)"Change a Input Box Font Size"},
00314 {(char*)"getInputBoxFontSize", py_getInputBoxFontSize, METH_VARARGS,
00315 (char*)"Get a Input Box Font Size"},
00316 {(char*)"setInputFocus", py_setInputFocus, METH_VARARGS,
00317 (char*)"Set the Input Focus to the Input Box"},
00318 {(char*)"clearInputFocus", py_clearInputFocus, METH_VARARGS,
00319 (char*)"Clear the Input Focus of the Input Box"},
00320 {(char*)"getInputFocus", py_getInputFocus, METH_VARARGS,
00321 (char*)"Get the Input Box currently focused"},
00322
00323 {(char*)"setWidgetOnTop", py_set_widget_on_top, METH_VARARGS,
00324 (char*)"changes 'on top' status"},
00325 {(char*)"getSystraySize", py_get_systray_size, METH_VARARGS,
00326 (char*)"Get the size of the Systray"},
00327 {(char*)"getPrettyThemeName", py_get_pretty_name, METH_VARARGS,
00328 (char*)"Get the pretty name of the theme"},
00329 {(char*)"openNamedTheme", py_open_named_theme, METH_VARARGS,
00330 (char*)"Open a new theme giving it a new name"},
00331 {(char*)"callTheme", py_call_theme, METH_VARARGS,
00332 (char*)"Pass a string to another theme"},
00333 {(char*)"changeInterval", py_change_interval, METH_VARARGS,
00334 (char*)"Change the refresh interval"},
00335 {(char*)"run", py_run_command, METH_VARARGS,
00336 (char*)"Execute a command with KRun"},
00337 {(char*)"createServiceClickArea", py_create_service_click_area, METH_VARARGS,
00338 (char*)"Create a Service-named Click Area Sensor"},
00339 {(char*)"removeClickArea", py_remove_click_area, METH_VARARGS,
00340 (char*)"Remove a Click Area Sensor"},
00341 {(char*)"setUpdateTime", py_set_update_time, METH_VARARGS,
00342 (char*)"Set last updated time"},
00343 {(char*)"getUpdateTime", py_get_update_time, METH_VARARGS,
00344 (char*)"Get last updated time"},
00345 {(char*)"setWantRightButton", py_want_right_button, METH_VARARGS,
00346 (char*)"Set to 1 to deactivate management popups"},
00347 {(char*)"setWantMeterWheelEvent", py_want_wheel_event, METH_VARARGS,
00348 (char*)"Enables wheel events over meters."},
00349 {(char*)"managementPopup", py_management_popup, METH_VARARGS,
00350 (char*)"Activates the Management Popup menu"},
00351
00352
00353 {(char*)"getServiceGroups", py_get_service_groups, METH_VARARGS,
00354 (char*)"Get KDE Service Groups"},
00355
00356 {NULL, NULL, 0 ,NULL}
00357 };
00358
00359 #if PY_MAJOR_VERSION >= 3
00360
00361 static int karamba_traverse(PyObject *m, visitproc visit, void *arg) {
00362 Py_VISIT(GETSTATE(m)->error);
00363 return 0;
00364 }
00365
00366 static int karamba_clear(PyObject *m) {
00367 Py_CLEAR(GETSTATE(m)->error);
00368 return 0;
00369 }
00370
00371 static struct PyModuleDef karambadef = {
00372 PyModuleDef_HEAD_INIT,
00373 "karamba",
00374 NULL,
00375 sizeof(struct module_state),
00376 karamba_methods,
00377 NULL,
00378 karamba_traverse,
00379 karamba_clear,
00380 NULL
00381 };
00382
00383 #define INITERROR return NULL
00384
00385 #else
00386
00387 #define INITERROR return
00388
00389 #endif
00390
00391 PyThreadState* KarambaPython::mainThreadState = 0;
00392
00393 KarambaPython::KarambaPython(const ThemeFile& theme, bool reloading):
00394 pythonThemeExtensionLoaded(false), pName(0), pModule(0), pDict(0)
00395 {
00396 PyThreadState* myThreadState;
00397 char pypath[1024];
00398
00399 getLock(&myThreadState);
00400
00401
00402 PyRun_SimpleString((char*)"import sys");
00403
00404 snprintf(pypath, 1023, "sys.path.insert(0, '%s')", theme.path().ascii());
00405 PyRun_SimpleString(pypath);
00406 PyRun_SimpleString((char*)"sys.path.insert(0, '')");
00407
00408 PyImport_AddModule((char*)"karamba");
00409 #if PY_MAJOR_VERSION >= 3
00410 PyModule_Create(&karambadef);
00411 #else
00412 Py_InitModule((char*)"karamba", karamba_methods);
00413 #endif
00414 pName = PyBytes_FromString(theme.pythonModule().ascii());
00415 pModule = PyImport_Import(pName);
00416
00417 fprintf(stderr, "%s\n", pypath);
00418
00419
00420 if (reloading)
00421 PyImport_ReloadModule(pModule);
00422
00423 if (pModule != NULL)
00424 {
00425 pDict = PyModule_GetDict(pModule);
00426 if (pDict != NULL)
00427 {
00428 pythonThemeExtensionLoaded = true;
00429 }
00430 }
00431 else
00432 {
00433 PyErr_Print();
00434 fprintf(stderr,
00435 "------------------------------------------------------\n");
00436 fprintf(stderr, "What does ImportError mean?\n");
00437 fprintf(stderr, "\n");
00438 fprintf(stderr,
00439 "It means that I couldn't load a python add-on %s.py\n",
00440 theme.pythonModule().ascii());
00441 fprintf(stderr, "If this is a regular theme and doesn't use python\n");
00442 fprintf(stderr, "extensions, then nothing is wrong.\n");
00443 fprintf(stderr,
00444 "------------------------------------------------------\n");
00445 }
00446 releaseLock(myThreadState);
00447 }
00448
00449 KarambaPython::~KarambaPython()
00450 {
00451
00452 if (pythonThemeExtensionLoaded) {
00453 PyThreadState* myThreadState;
00454 getLock(&myThreadState);
00455
00456
00457 Py_DECREF(pModule);
00458 Py_DECREF(pName);
00459
00460 releaseLock(myThreadState);
00461 }
00462 }
00463
00464 void KarambaPython::initPython()
00465 {
00466
00467 Py_Initialize();
00468
00469
00470 PyEval_InitThreads();
00471
00472
00473 mainThreadState = PyThreadState_Get();
00474
00475
00476 PyEval_ReleaseLock();
00477 }
00478
00479 void KarambaPython::shutdownPython()
00480 {
00481
00482 PyInterpreterState * mainInterpreterState = mainThreadState->interp;
00483
00484 PyThreadState * myThreadState = PyThreadState_New(mainInterpreterState);
00485 PyThreadState_Swap(myThreadState);
00486 PyEval_AcquireLock();
00487 Py_Finalize();
00488 }
00489
00490 void KarambaPython::getLock(PyThreadState** myThreadState)
00491 {
00492
00493 PyEval_AcquireLock();
00494
00495
00496 *myThreadState = PyThreadState_New(mainThreadState->interp);
00497 PyThreadState_Swap(*myThreadState);
00498 }
00499
00500 void KarambaPython::releaseLock(PyThreadState* myThreadState)
00501 {
00502
00503 PyThreadState_Swap(NULL);
00504
00505 PyThreadState_Clear(myThreadState);
00506
00507 PyThreadState_Delete(myThreadState);
00508
00509 PyEval_ReleaseLock();
00510 }
00511
00512 PyObject* KarambaPython::getFunc(const char* function)
00513 {
00514 PyObject* pFunc = PyDict_GetItemString(pDict, (char*)function);
00515 if (pFunc && PyCallable_Check(pFunc))
00516 return pFunc;
00517 return NULL;
00518 }
00519
00520 bool KarambaPython::callObject(const char* func, PyObject* pArgs, bool lock)
00521 {
00522 bool result = false;
00523 PyThreadState* myThreadState;
00524
00525
00526
00527 if (lock)
00528 getLock(&myThreadState);
00529 PyObject* pFunc = getFunc(func);
00530
00531 if (pFunc != NULL)
00532 {
00533 PyObject* pValue = PyObject_CallObject(pFunc, pArgs);
00534
00535 if (pValue != NULL)
00536 {
00537 Py_DECREF(pValue);
00538 result = true;
00539 }
00540 else
00541 {
00542 tqWarning("Call to %s failed", func);
00543 PyErr_Print();
00544 }
00545 }
00546 Py_DECREF(pArgs);
00547 if (lock)
00548 releaseLock(myThreadState);
00549 return result;
00550 }
00551
00552 bool KarambaPython::initWidget(karamba* k)
00553 {
00554 PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
00555 return callObject("initWidget", pArgs);
00556 }
00557
00558 bool KarambaPython::widgetUpdated(karamba* k)
00559 {
00560 PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
00561 return callObject("widgetUpdated", pArgs);
00562 }
00563
00564 bool KarambaPython::widgetClosed(karamba* k)
00565 {
00566 PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
00567 return callObject("widgetClosed", pArgs);
00568 }
00569
00570 bool KarambaPython::menuOptionChanged(karamba* k, TQString key, bool value)
00571 {
00572 PyObject* pArgs = Py_BuildValue((char*)"(lsi)", k, key.ascii(), (int)value);
00573 return callObject("menuOptionChanged", pArgs);
00574 }
00575
00576 bool KarambaPython::menuItemClicked(karamba* k, TDEPopupMenu* menu, long id)
00577 {
00578 PyObject* pArgs = Py_BuildValue((char*)"(lll)", k, menu, id);
00579 return callObject("menuItemClicked", pArgs);
00580 }
00581
00582 bool KarambaPython::meterClicked(karamba* k, Meter* meter, int button)
00583 {
00584 PyObject* pArgs = Py_BuildValue((char*)"(lli)", k, meter, button);
00585 return callObject("meterClicked", pArgs);
00586 }
00587
00588 bool KarambaPython::meterClicked(karamba* k, TQString anchor, int button)
00589 {
00590 PyObject* pArgs = Py_BuildValue((char*)"(lsi)", k, anchor.ascii(), button);
00591 return callObject("meterClicked", pArgs);
00592 }
00593
00594 bool KarambaPython::widgetClicked(karamba* k, int x, int y, int button)
00595 {
00596 PyObject* pArgs = Py_BuildValue((char*)"(liii)", k, x, y, button);
00597 return callObject("widgetClicked", pArgs);
00598 }
00599
00600 bool KarambaPython::keyPressed(karamba* k, const Meter* meter,
00601 const TQString& text)
00602 {
00603 PyObject* pArgs = Py_BuildValue((char*)"(lls)", k, meter, text.ucs2());
00604 return callObject("keyPressed", pArgs);
00605 }
00606
00607 bool KarambaPython::widgetMouseMoved(karamba* k, int x, int y, int button)
00608 {
00609 PyObject* pArgs = Py_BuildValue((char*)"(liii)", k, x, y, button);
00610 return callObject("widgetMouseMoved", pArgs);
00611 }
00612
00613 bool KarambaPython::activeTaskChanged(karamba* k, Task* t)
00614 {
00615 PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
00616 return callObject("activeTaskChanged", pArgs);
00617 }
00618
00619 bool KarambaPython::taskAdded(karamba* k, Task* t)
00620 {
00621 PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
00622 return callObject("taskAdded", pArgs);
00623 }
00624
00625 bool KarambaPython::taskRemoved(karamba* k, Task* t)
00626 {
00627 PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
00628 return callObject("taskRemoved", pArgs);
00629 }
00630
00631 bool KarambaPython::startupAdded(karamba* k, Startup* t)
00632 {
00633 PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
00634 return callObject("startupAdded", pArgs);
00635 }
00636
00637 bool KarambaPython::startupRemoved(karamba* k, Startup* t)
00638 {
00639 PyObject* pArgs = Py_BuildValue((char*)"(ll)", k, t);
00640 return callObject("startupRemoved", pArgs);
00641 }
00642
00643 bool KarambaPython::commandOutput(karamba* k, int pid, char *buffer)
00644 {
00645 PyObject* pArgs = Py_BuildValue((char*)"(lis)", k, pid, buffer);
00646 return callObject("commandOutput", pArgs);
00647 }
00648
00649 bool KarambaPython::commandFinished(karamba* k, int pid)
00650 {
00651 PyObject* pArgs = Py_BuildValue((char*)"(li)", k, pid);
00652 return callObject("commandFinished", pArgs);
00653 }
00654
00655 bool KarambaPython::itemDropped(karamba* k, TQString text, int x, int y)
00656 {
00657 PyObject* pArgs = Py_BuildValue((char*)"(lOii)", k, TQString2PyString(text), x, y);
00658 return callObject("itemDropped", pArgs);
00659 }
00660
00661 bool KarambaPython::themeNotify(karamba* k, const char *from, const char *str)
00662 {
00663
00664
00665
00666
00667
00668 PyObject* pArgs = Py_BuildValue((char*)"(lss)", k, from, str);
00669 return callObject("themeNotify", pArgs, false);
00670 }
00671
00672 bool KarambaPython::systrayUpdated(karamba* k)
00673 {
00674 PyObject* pArgs = Py_BuildValue((char*)"(l)", k);
00675 return callObject("systrayUpdated", pArgs);
00676 }
00677
00678 bool KarambaPython::desktopChanged(karamba* k, int desktop)
00679 {
00680 PyObject* pArgs = Py_BuildValue((char*)"(li)", k, desktop);
00681 return callObject("desktopChanged", pArgs);
00682 }
00683
00684 bool KarambaPython::wallpaperChanged(karamba* k, int desktop)
00685 {
00686 PyObject* pArgs = Py_BuildValue((char*)"(li)", k, desktop);
00687 return callObject("wallpaperChanged", pArgs);
00688 }