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