davemds pushed a commit to branch master.

commit bee7a39575435038653c0f14e444fbb05418be5b
Author: davemds <[email protected]>
Date:   Sun May 5 18:33:52 2013 +0200

    Python-EFL: espionage: new option to prettify the returns of methods
---
 examples/dbus/test_dbus_spy.py | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/examples/dbus/test_dbus_spy.py b/examples/dbus/test_dbus_spy.py
index fe3ce21..bfaa8d5 100755
--- a/examples/dbus/test_dbus_spy.py
+++ b/examples/dbus/test_dbus_spy.py
@@ -2,6 +2,7 @@
 # -*- coding: utf-8 -*-
 
 import dbus
+import json
 import xml.etree.ElementTree as ElementTree
 
 from efl import evas
@@ -10,6 +11,7 @@ from efl.elementary.window import StandardWindow
 from efl.elementary.background import Background
 from efl.elementary.box import Box
 from efl.elementary.button import Button
+from efl.elementary.check import Check
 from efl.elementary.entry import Entry, \
     Entry_markup_to_utf8 as markup_to_utf8, \
     Entry_utf8_to_markup as utf8_to_markup
@@ -26,6 +28,7 @@ class Options(object):
     """class to contain application options"""
     def __init__(self):
         self.hide_introspect_stuff = True
+        self.pretty_output = True
 
 
 ### connect to session and system buses, and set session as the current one
@@ -424,7 +427,7 @@ class MethodRunner(Popup):
         # params label + entry
         if len(method.params) > 0:
             label = Label(parent)
-            label.size_hint_align = 0.0, 0.0
+            label.size_hint_align = 0.0, 0.5
             label.text = 'Params: ' + method.params_str
             label.show()
             vbox.pack_end(label)
@@ -447,7 +450,7 @@ class MethodRunner(Popup):
         
         # returns label + entry
         label = Label(parent)
-        label.size_hint_align = 0.0, 0.0
+        label.size_hint_align = 0.0, 0.5
         label.text = 'Returns: '
         label.text += method.returns_str if method.returns_str else 'None'
         label.show()
@@ -465,6 +468,17 @@ class MethodRunner(Popup):
         en.show()
         vbox.pack_end(en)
 
+        # pretty print check button
+        def pretty_output_clicked_cb(chk):
+            options.pretty_output = chk.state
+        ch = Check(parent)
+        ch.size_hint_align = 0.0, 0.5
+        ch.text = "Prettify output (loosing type infos)"
+        ch.state = options.pretty_output
+        ch.callback_changed_add(pretty_output_clicked_cb)
+        ch.show()
+        vbox.pack_end(ch)
+
         # popup buttons
         btn = Button(parent)
         btn.text = 'Close'
@@ -515,7 +529,10 @@ class MethodRunner(Popup):
 
     def reply_handler(self, *rets):
         if rets:
-            s = utf8_to_markup(str(*rets))
+            if options.pretty_output:
+                s = utf8_to_markup(json.dumps(rets, indent=2))
+            else:
+                s = utf8_to_markup(str(rets))
         else:
             s = "Method executed successfully.<br>Nothing returned."
         self._return_entry.entry = s

-- 

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and 
their applications. This 200-page book is written by three acclaimed 
leaders in the field. The early access version is available now. 
Download your free book today! http://p.sf.net/sfu/neotech_d2d_may

Reply via email to