summaryrefslogtreecommitdiffstats
path: root/superkaramba/examples/setIncomingData
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/setIncomingData
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/setIncomingData')
-rw-r--r--superkaramba/examples/setIncomingData/1.py27
-rw-r--r--superkaramba/examples/setIncomingData/1.theme2
-rw-r--r--superkaramba/examples/setIncomingData/2.py78
-rw-r--r--superkaramba/examples/setIncomingData/2.theme2
4 files changed, 109 insertions, 0 deletions
diff --git a/superkaramba/examples/setIncomingData/1.py b/superkaramba/examples/setIncomingData/1.py
new file mode 100644
index 0000000..8422de2
--- /dev/null
+++ b/superkaramba/examples/setIncomingData/1.py
@@ -0,0 +1,27 @@
+import karamba
+
+sequence_num = 0
+
+def initWidget(widget):
+ karamba.openTheme('2.theme')
+
+# pass over a sequence number as well - the reason is to
+# make it possible to identify the clicks uniquely.
+#
+# unfortunately, the recipient has to do "polling"
+# by calling getIncomingData - see 2.py for more info
+
+def widgetClicked(widget, x, y, button):
+
+ # do as you wish, but this is a good way:
+ # compact your stuff with repr() it can cope
+ # with pretty much any basic types - dictionaries, lists -
+ # and then use eval() at the other end.
+
+ global sequence_num
+ sequence_num += 1
+
+ vars = (sequence_num, x, y, button)
+ message = repr(vars)
+ karamba.setIncomingData(widget, "2", message)
+
diff --git a/superkaramba/examples/setIncomingData/1.theme b/superkaramba/examples/setIncomingData/1.theme
new file mode 100644
index 0000000..2e4bfcf
--- /dev/null
+++ b/superkaramba/examples/setIncomingData/1.theme
@@ -0,0 +1,2 @@
+KARAMBA x=200 y=50 w=100 h=20 INTERVAL=1000 LOCKED=true
+TEXT x=0 Y=0 w=300 h=20 value="Click me!"
diff --git a/superkaramba/examples/setIncomingData/2.py b/superkaramba/examples/setIncomingData/2.py
new file mode 100644
index 0000000..a411b60
--- /dev/null
+++ b/superkaramba/examples/setIncomingData/2.py
@@ -0,0 +1,78 @@
+#
+# Written by Luke Kenneth Casson Leighton <lkcl@lkcl.net>
+
+# This theme is demonstrates how to
+
+#this import statement allows access to the karamba functions
+import karamba
+
+drop_txt = None
+
+#this is called when you widget is initialized
+def initWidget(widget):
+
+ # this resets the text to "" so we know we've never
+ # received anything yet from the other theme
+ name = karamba.getPrettyThemeName(widget)
+ print "2.py name: ", name
+ karamba.setIncomingData(widget, name, "")
+
+ karamba.redrawWidget(widget)
+
+# this is a pain. in order to avoid memory-related threading problems,
+# and also locking, with the communication between themes, the
+# communication is done asynchronously. so you have to POLL for the
+# information, by reading getIncomingData().
+#
+# therefore, you must set an interval=time_in_ms in your receiving .theme
+# file (see 2.theme) and then call getIncomingData() in here.
+#
+# it's not ideal - but it works.
+#
+# NOTE: the data received - by getIncomingData - is NOT, i repeat NOT
+# deleted when you call getIncomingData.
+# so, obviously, you need to take care to not activate repeatedly.
+# you could do this in several ways. one of them is to send, in
+# the calling theme (the one that calls setIncomingData) a sequential
+# number as part of the message.
+#
+# alternatively, you could reset the text to "" (see above)
+
+
+expected_seq = 0
+
+def widgetUpdated(widget):
+
+ global expected_seq # i hate globals. please write better code than this example.
+
+ # get the "message"...
+ disp = karamba.getIncomingData(widget)
+ if disp == "":
+ return
+
+ # decode it...
+ (seq, x, y, button) = eval(disp)
+
+ # if it's been seen before, skip it...
+ if seq <= expected_seq:
+ pass
+
+ expected_seq += 1
+
+ message = "seq:%d x:%d y:%d btn:%d" % (seq, x, y, button)
+ # delete previous text if exists.
+ global drop_txt
+ if drop_txt is not None:
+ karamba.deleteText(widget, drop_txt)
+
+ # display it...
+ drop_txt = karamba.createText(widget, 0, 20, 300, 20, message)
+ karamba.changeTextColor(widget, drop_txt, 252,252,252)
+
+ karamba.redrawWidget(widget)
+
+ pass
+
+# This will be printed when the widget loads.
+print "Loaded my python 2.py extension!"
+
diff --git a/superkaramba/examples/setIncomingData/2.theme b/superkaramba/examples/setIncomingData/2.theme
new file mode 100644
index 0000000..df7d7b2
--- /dev/null
+++ b/superkaramba/examples/setIncomingData/2.theme
@@ -0,0 +1,2 @@
+KARAMBA x=200 y=100 w=300 h=40 INTERVAL=200 LOCKED=true
+TEXT x=0 y=0 w=300 h=20 value="you clicked on theme 1:"