summaryrefslogtreecommitdiffstats
path: root/superkaramba/examples/globalMouse
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /superkaramba/examples/globalMouse
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'superkaramba/examples/globalMouse')
-rw-r--r--superkaramba/examples/globalMouse/README29
-rw-r--r--superkaramba/examples/globalMouse/extension/setup.py12
-rw-r--r--superkaramba/examples/globalMouse/extension/xcursor.c104
-rw-r--r--superkaramba/examples/globalMouse/eyes.py192
-rw-r--r--superkaramba/examples/globalMouse/eyes.theme3
-rw-r--r--superkaramba/examples/globalMouse/pics/eyes.pngbin0 -> 2819 bytes
-rw-r--r--superkaramba/examples/globalMouse/pics/eyes.xcfbin0 -> 18677 bytes
-rw-r--r--superkaramba/examples/globalMouse/pics/mask.pngbin0 -> 495 bytes
-rw-r--r--superkaramba/examples/globalMouse/pics/pupille.pngbin0 -> 256 bytes
-rwxr-xr-xsuperkaramba/examples/globalMouse/xcursor.sobin0 -> 7465 bytes
10 files changed, 340 insertions, 0 deletions
diff --git a/superkaramba/examples/globalMouse/README b/superkaramba/examples/globalMouse/README
new file mode 100644
index 0000000..758ce4b
--- /dev/null
+++ b/superkaramba/examples/globalMouse/README
@@ -0,0 +1,29 @@
+
+Karamba Eyes 0.6 by Wilfried.Huss@gmx.at
+----------------------------------------
+
+Karamba Eyes is a implementation of the classic xeyes for superkaramba.
+
+
+INSTALLATION:
+ Karamba Eyes needs a small Python extension module named xcursor
+ which is implemented in the file extension/xcursor.c.
+
+ To build it go to the extension subdirectory and type
+
+ python setup.py build
+
+ (The Python develop package needs to be installed)
+
+ This creates the shared library xcursor.so, probably in a subdirectory
+ named build. This file needs to be copied in the same directory as the
+ eyes.theme and eyes.py file.
+
+ A precompiled xcursor.so file is included (Compiled on Mandrake 9.1).
+
+CHANGES:
+ * Moving the theme now works as it should.
+ * Widget Mask added
+
+TODO:
+ Add Theme Support
diff --git a/superkaramba/examples/globalMouse/extension/setup.py b/superkaramba/examples/globalMouse/extension/setup.py
new file mode 100644
index 0000000..f33f8a6
--- /dev/null
+++ b/superkaramba/examples/globalMouse/extension/setup.py
@@ -0,0 +1,12 @@
+from distutils.core import setup, Extension
+
+module1 = Extension('xcursor',
+ include_dirs = ['/usr/X11R6/include'],
+ libraries = ['X11'],
+ library_dirs = ['/usr/X11R6/lib'],
+ sources = ['xcursor.c'])
+
+setup (name = 'XMouseCursor',
+ version = '1.0',
+ description = 'Determines the position of the X mouse cursor',
+ ext_modules = [module1])
diff --git a/superkaramba/examples/globalMouse/extension/xcursor.c b/superkaramba/examples/globalMouse/extension/xcursor.c
new file mode 100644
index 0000000..8dad240
--- /dev/null
+++ b/superkaramba/examples/globalMouse/extension/xcursor.c
@@ -0,0 +1,104 @@
+/*
+ * This module is based on code by found in comp.lang.python:
+ * http://groups.google.at/groups?q=%22Re:+X+Gurus%22+group:comp.lang.python.*&hl=de&lr=&ie=UTF-8&selm=imnv4.314%24qL4.17232%40newsread1.prod.itd.earthlink.net&rnum=2
+ *
+ * Build with:
+ * python setup.py build
+ *
+ * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
+ * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
+ * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net>
+ *
+ * This file is part of Superkaramba.
+ *
+ * Superkaramba is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Superkaramba is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Superkaramba; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ ****************************************************************************/
+
+#include <Python.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+static Display* display = 0;
+static Window root;
+static int screen;
+
+
+static PyObject* xcursor_position(self, args)
+ PyObject* self;
+ PyObject* args;
+{
+ /* Determine X Cursor coordinates */
+ Window root_return, child_return;
+ char* display_name;
+ int root_x_return, root_y_return;
+ int win_x_return, win_y_return;
+ unsigned int mask_return;
+
+ if (! (display_name = getenv("DISPLAY")) )
+ {
+ /* add error handling! */
+
+ /*
+ * fprintf(stderr,"environment variable DISPLAY must be set\n");
+ * exit(-1);
+ */
+
+ return NULL;
+ }
+
+ if ( display == 0)
+ {
+ if (! (display = XOpenDisplay(display_name)) )
+ {
+ /* add error handling! */
+
+ /*
+ * fprintf(stderr,"%s: Cannot open display %s\n", argv[0],
+ * display_name);
+ * exit(-1);
+ */
+
+ return NULL;
+ }
+
+ screen = DefaultScreen(display);
+ root = RootWindow(display, screen);
+ }
+
+ XQueryPointer(display, root, &root_return, &child_return,
+ &root_x_return, &root_y_return,
+ &win_x_return, &win_y_return,
+ &mask_return);
+
+ /* return Python Object */
+ return Py_BuildValue("(i,i)", root_x_return, root_y_return);
+}
+
+/* Method Table */
+static PyMethodDef xcursorMethods[] =
+{
+ {"position", xcursor_position, METH_VARARGS, "Query X Cursor Coordinates"},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+void initxcursor(void)
+{
+ (void) Py_InitModule("xcursor", xcursorMethods);
+}
+
+
diff --git a/superkaramba/examples/globalMouse/eyes.py b/superkaramba/examples/globalMouse/eyes.py
new file mode 100644
index 0000000..b95f86d
--- /dev/null
+++ b/superkaramba/examples/globalMouse/eyes.py
@@ -0,0 +1,192 @@
+#this import statement allows access to the karamba functions
+import karamba
+
+#import os
+import string
+import math
+import re
+
+import xcursor
+
+linkePupille = ""
+rechtePupille = ""
+
+init = 0
+
+#old curser pos
+x_old = -1
+y_old = -1
+
+#widget size
+w_width = 167
+w_height = 111
+
+#widget pos
+w_x = 10
+w_y = 850
+
+#eye center
+lx, ly = 39, 55
+rx, ry = 126, 55
+
+#eye size
+la, lb = 25, 38
+ra, rb = 25, 38
+
+#pupille size
+lp_width, lp_height = 11, 17
+rp_width, rp_height = 11, 17
+
+def pupille(mouse_x, mouse_y, eye_center_x, eye_center_y, eye_a, eye_b, widget_x, widget_y):
+ x = mouse_x - eye_center_x - widget_x
+ y = mouse_y - eye_center_y - widget_y
+ #print x, y
+
+ r = math.sqrt(x * x + y * y)
+ phi = math.atan2(y, x)
+ #print phi * math.pi
+
+ eye_x = eye_a * math.cos(phi)
+ eye_y = eye_b * math.sin(phi)
+
+ eye_r = math.sqrt(eye_x * eye_x + eye_y * eye_y)
+
+ if eye_r < r:
+ return int(eye_x + eye_center_x), int(eye_y + eye_center_y)
+
+ return int(x + eye_center_x), int(y + eye_center_y)
+
+
+#this is called when you widget is initialized
+def initWidget(widget):
+ pass
+
+#this is called everytime your widget is updated
+#the update inverval is specified in the .theme file
+def widgetUpdated(widget):
+ global init
+ global linkePupille
+ global rechtePupille
+
+ global w_width
+ global w_height
+
+ global w_x
+ global w_y
+
+ global lx
+ global ly
+ global la
+ global lb
+
+ global lp_width
+ global lp_height
+
+ global rx
+ global ry
+ global ra
+ global rb
+
+ global rp_width
+ global rp_height
+
+ global x_old
+ global y_old
+
+ if init == 0:
+ theme_path = karamba.getThemePath(widget) + "/"
+
+ # read widget coordinates from eyes.theme
+ # f = open(theme_path + "eyes.theme")
+
+ # karamba_line = ""
+ #while re.compile('KARAMBA').search(karamba_line) == None:
+ # karamba_line = f.readline()
+
+ #w_x = int(re.compile('X=([0-9]+)').search(karamba_line).group(1))
+ #w_y = int(re.compile('Y=([0-9]+)').search(karamba_line).group(1))
+
+ #f.close()
+
+ #karamba.createWidgetMask(widget, theme_path + "pics/mask.png")
+
+ linkePupille = karamba.createImage(widget, 15, 30, theme_path + "pics/pupille.png")
+ rechtePupille = karamba.createImage(widget, 100, 30, theme_path + "pics/pupille.png")
+ init = 1
+
+ karamba.redrawWidget(widget)
+
+ # query mouse-cursor position
+ x, y = xcursor.position()
+
+ #fp = os.popen("./xpos")
+ #output = fp.read()
+ #x, y = output.split()
+
+ #print x, y
+
+ if x != x_old or y != y_old:
+ x_old, y_old = x, y
+ # Get Widget Position
+ w_x, w_y = karamba.getWidgetPosition(widget)
+
+ # Calc left pupille
+ xp, yp = pupille (int(x), int(y), lx, ly, la, lb, w_x, w_y)
+
+ xp = xp - lp_width / 2
+ yp = yp - lp_height / 2
+ #print xp, yp
+
+ karamba.moveImage(widget, linkePupille, xp, yp)
+
+ # Calc right pupille
+ xp, yp = pupille (int(x), int(y), rx, ry, ra, rb, w_x, w_y)
+
+ xp = xp - rp_width / 2
+ yp = yp - rp_height / 2
+ #print xp, yp
+
+ karamba.moveImage(widget, rechtePupille, xp, yp)
+
+ karamba.redrawWidget(widget)
+
+#This gets called everytime our widget is clicked.
+#Notes:
+# widget = reference to our widget
+# x = x position (relative to our widget)
+# y = y position (relative to our widget)
+# botton = button clicked:
+# 1 = Left Mouse Button
+# 2 = Middle Mouse Button
+# 3 = Right Mouse Button, but this will never happen
+# because the right mouse button brings up the
+# Karamba menu.
+# 4,5 = Scroll wheel up and down
+def widgetClicked(widget, x, y, button):
+ pass
+
+#This gets called everytime our widget is clicked.
+#Notes
+# widget = reference to our widget
+# x = x position (relative to our widget)
+# y = y position (relative to our widget)
+# botton = button being held:
+# 0 = No Mouse Button
+# 1 = Left Mouse Button
+# 2 = Middle Mouse Button
+# 3 = Right Mouse Button, but this will never happen
+# because the right mouse button brings up the
+# Karamba menu.
+def widgetMouseMoved(widget, x, y, button):
+ #Warning: Don't do anything too intensive here
+ #You don't want to run some complex piece of code everytime the mouse moves
+ pass
+ #global linkePupille
+
+ #karamba.moveImage(widget, linkePupille, x, y)
+ #karamba.redrawWidget(widget)
+
+
+# This will be printed when the widget loads.
+print "Loaded Karamba Eyes"
+
diff --git a/superkaramba/examples/globalMouse/eyes.theme b/superkaramba/examples/globalMouse/eyes.theme
new file mode 100644
index 0000000..4f2417b
--- /dev/null
+++ b/superkaramba/examples/globalMouse/eyes.theme
@@ -0,0 +1,3 @@
+KARAMBA X=5 Y=850 W=167 H=111 MASK="pics/mask.png" LOCKED=false INTERVAL=100
+
+IMAGE X=0 Y=0 PATH="pics/eyes.png"
diff --git a/superkaramba/examples/globalMouse/pics/eyes.png b/superkaramba/examples/globalMouse/pics/eyes.png
new file mode 100644
index 0000000..50823d0
--- /dev/null
+++ b/superkaramba/examples/globalMouse/pics/eyes.png
Binary files differ
diff --git a/superkaramba/examples/globalMouse/pics/eyes.xcf b/superkaramba/examples/globalMouse/pics/eyes.xcf
new file mode 100644
index 0000000..3f097d1
--- /dev/null
+++ b/superkaramba/examples/globalMouse/pics/eyes.xcf
Binary files differ
diff --git a/superkaramba/examples/globalMouse/pics/mask.png b/superkaramba/examples/globalMouse/pics/mask.png
new file mode 100644
index 0000000..cf8fc03
--- /dev/null
+++ b/superkaramba/examples/globalMouse/pics/mask.png
Binary files differ
diff --git a/superkaramba/examples/globalMouse/pics/pupille.png b/superkaramba/examples/globalMouse/pics/pupille.png
new file mode 100644
index 0000000..11d971b
--- /dev/null
+++ b/superkaramba/examples/globalMouse/pics/pupille.png
Binary files differ
diff --git a/superkaramba/examples/globalMouse/xcursor.so b/superkaramba/examples/globalMouse/xcursor.so
new file mode 100755
index 0000000..1ff08d5
--- /dev/null
+++ b/superkaramba/examples/globalMouse/xcursor.so
Binary files differ