aboutsummaryrefslogtreecommitdiffstats
path: root/examples/ecore
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2014-05-13 17:59:48 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2014-05-13 17:59:48 +0300
commit1466ea72071e27380e6d86de4d1712e587fce3b3 (patch)
treed24bbb868725f7cf233aa66b52f005e2157ef4a8 /examples/ecore
parentefl.ecore: Transform into a package (diff)
downloadpython-efl-1466ea72071e27380e6d86de4d1712e587fce3b3.tar.gz
efl.ecore: Return of ecore.x (from python-ecore)
Made some corrections to make it compile and fixed doc formatting.
Diffstat (limited to 'examples/ecore')
-rw-r--r--examples/ecore/x/mplayer_embed.py44
-rw-r--r--examples/ecore/x/window_creation.py43
2 files changed, 87 insertions, 0 deletions
diff --git a/examples/ecore/x/mplayer_embed.py b/examples/ecore/x/mplayer_embed.py
new file mode 100644
index 0000000..079ded0
--- /dev/null
+++ b/examples/ecore/x/mplayer_embed.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+import sys
+import efl.ecore
+from efl.ecore.x import init, Window, on_window_configure_add
+from subprocess import Popen, PIPE
+
+init()
+
+try:
+ filename = sys.argv[1]
+except IndexError, e:
+ raise SystemExit("Usage: %s <filename>" % sys.argv[0])
+
+main_window = Window(w=800, h=600)
+main_window.background_color_set(0xffff, 0, 0)
+main_window.show()
+
+sub_window = Window(main_window, 10, 10, 780, 580)
+sub_window.background_color_set(0, 0, 0xffff)
+sub_window.show()
+
+cmd = ["/usr/bin/mplayer", "-slave", "-nomouseinput", "-quiet",
+ "-wid", str(sub_window.xid), filename]
+p = Popen(cmd, stdin=PIPE, stdout=PIPE, close_fds=True)
+
+
+def handle_read(fd_handler, file):
+ line = file.read(1)
+ r = bool(line and not fd_handler.has_error())
+ if not r:
+ efl.ecore.main_loop_quit()
+ return r
+
+
+def on_configure(event, main_window, sub_window):
+ if event.win == main_window:
+ sub_window.resize(event.w - 20, event.h - 20)
+ return True
+on_window_configure_add(on_configure, main_window, sub_window)
+
+efl.ecore.fd_handler_add(
+ p.stdout, efl.ecore.ECORE_FD_ALL, handle_read, p.stdout)
+efl.ecore.main_loop_begin()
diff --git a/examples/ecore/x/window_creation.py b/examples/ecore/x/window_creation.py
new file mode 100644
index 0000000..61c455a
--- /dev/null
+++ b/examples/ecore/x/window_creation.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+import efl.ecore
+from efl.ecore.x import init, Window, on_window_configure_add
+
+init()
+
+# method 1
+main_window = Window(w=800, h=600)
+main_window.background_color_set(0xffff, 0, 0)
+main_window.show()
+
+sub_window = Window(main_window, 10, 10, 780, 580)
+sub_window.background_color_set(0, 0, 0xffff)
+sub_window.show()
+
+
+def cb_on_configure(event, main_window, sub_window):
+ if event.win == main_window:
+ sub_window.resize(event.w - 20, event.h - 20)
+ return True
+on_window_configure_add(cb_on_configure, main_window, sub_window)
+
+
+# method 2: inheritance
+class MyWindow(Window):
+ def __init__(self, w, h):
+ Window.__init__(self, w=w, h=h)
+ self.background_color_set(0xffff, 0, 0)
+ self.sub_window = Window(self, 10, 10, w - 20, h - 20)
+ self.sub_window.background_color_set(0, 0, 0xffff)
+ self.sub_window.show()
+ on_window_configure_add(self._cb_on_configure)
+
+ def _cb_on_configure(self, event):
+ if event.win == self:
+ self.sub_window.resize(event.w - 20, event.h - 20)
+ return True
+
+other_window = MyWindow(400, 300)
+other_window.show()
+
+efl.ecore.main_loop_begin()