summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2013-11-20 21:33:47 +0100
committerdavemds <dave@gurumeditation.it>2013-11-20 21:33:47 +0100
commitd35bf71a0867f0178b229167795dacabf4161197 (patch)
tree4a5e569e9634d77126dfacc10416a054b2c4771a
parente5980a3b53cfa7aa4bba99c4d416cf0e4fee72c7 (diff)
Espionage: add the new signal inspector.
A new Pane at the bottom of the window show ALL the signals that transit on both buses. Double clicking on a received signal you can see its full content (parameters). Now Espionage have more features than d-feet...efl beats gnome one more time :D
-rw-r--r--espionage/espionage.py139
1 files changed, 120 insertions, 19 deletions
diff --git a/espionage/espionage.py b/espionage/espionage.py
index ffd468a..b60ad00 100644
--- a/espionage/espionage.py
+++ b/espionage/espionage.py
@@ -38,6 +38,7 @@ from efl.elementary.panes import Panes
38from efl.elementary.popup import Popup 38from efl.elementary.popup import Popup
39from efl.elementary.separator import Separator 39from efl.elementary.separator import Separator
40from efl.elementary.table import Table 40from efl.elementary.table import Table
41from efl.elementary.frame import Frame
41from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass 42from efl.elementary.genlist import Genlist, GenlistItem, GenlistItemClass
42from efl.dbus_mainloop import DBusEcoreMainLoop 43from efl.dbus_mainloop import DBusEcoreMainLoop
43 44
@@ -48,6 +49,14 @@ class Options(object):
48 self.show_introspect_stuff = False 49 self.show_introspect_stuff = False
49 self.show_private_stuff = False 50 self.show_private_stuff = False
50 self.pretty_output = True 51 self.pretty_output = True
52 self.scroll_on_signal = True
53
54
55def prettify_if_needed(data):
56 if options.pretty_output:
57 return utf8_to_markup(json.dumps(data, indent=2))
58 else:
59 return utf8_to_markup(str(data))
51 60
52 61
53### connect to session and system buses, and set session as the current one 62### connect to session and system buses, and set session as the current one
@@ -548,21 +557,103 @@ class MethodRunner(Popup):
548 # wrong params for example are raised later :/ 557 # wrong params for example are raised later :/
549 558
550 def reply_handler(self, *rets): 559 def reply_handler(self, *rets):
551 if rets: 560 self._return_entry.entry = prettify_if_needed(rets) if rets \
552 if options.pretty_output: 561 else "Method executed successfully.<br>Nothing returned."
553 s = utf8_to_markup(json.dumps(rets, indent=2))
554 else:
555 s = utf8_to_markup(str(rets))
556 else:
557 s = "Method executed successfully.<br>Nothing returned."
558 self._return_entry.entry = s
559 562
560 def error_handler(self, *rets): 563 def error_handler(self, *rets):
561 self._return_entry.entry = 'Error executing method' 564 self._return_entry.entry = 'Error executing method'
562 565
563 566
567### Signals receiver
568class SignalItemClass(GenlistItemClass):
569 def __init__(self):
570 GenlistItemClass.__init__(self, item_style='default_style')
571 def text_get(self, gl, part, data):
572 return '<b>%s</> iface: <i>%s</> path: <i>%s</> sender: <i>%s</>' % \
573 (data['signal'], data['iface'], data['path'], data['sender'])
574
575class SignalReceiver(Frame):
576 def __init__(self, parent):
577 Frame.__init__(self, parent, text="Signals")
578 self._parent = parent
579
580 vbox = Box(self)
581 vbox.show()
582 self.content = vbox
583
584 self.siglist = Genlist(self, homogeneous=True, mode=elm.ELM_LIST_SCROLL)
585 self.siglist.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
586 self.siglist.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
587 self.siglist.callback_clicked_double_add(self.signal_clicked_cb)
588 self.siglist.show()
589 vbox.pack_end(self.siglist)
590 self.itc = SignalItemClass()
591
592 hbox = Box(self, horizontal=True)
593 hbox.size_hint_align = 0.0, 0.5
594 hbox.show()
595 vbox.pack_end(hbox)
596
597 bt = Button(self, text='Clear')
598 bt.callback_clicked_add(lambda b: self.siglist.clear())
599 hbox.pack_end(bt)
600 bt.show()
601
602 def scroll_on_signal_clicked_cb(chk):
603 options.scroll_on_signal = chk.state
604 ck = Check(self, text='Scroll on signal')
605 ck.state = options.scroll_on_signal
606 ck.callback_changed_add(scroll_on_signal_clicked_cb)
607 hbox.pack_end(ck)
608 ck.show()
609
610 for b in session_bus, system_bus:
611 b.add_signal_receiver(self.signal_cb, sender_keyword='sender',
612 destination_keyword='dest', interface_keyword='iface',
613 member_keyword='signal',path_keyword='path')
614
615 def signal_cb(self, *args, **kargs):
616 # print('*** SIGNAL RECEIVED ***')
617 # print(json.dumps(args, indent=2))
618 # print(json.dumps(kargs, indent=2))
619
620 kargs['args'] = args
621 item = self.siglist.item_append(self.itc, kargs)
622 if options.scroll_on_signal is True:
623 item.bring_in()
624
625 if self.siglist.items_count > 200:
626 self.siglist.first_item.delete()
627
628 def signal_clicked_cb(self, gl, item):
629 pp = Popup(self._parent)
630 pp.part_text_set('title,text', 'Signal content')
631
632 en = Entry(self, text = prettify_if_needed(item.data['args']))
633 en.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
634 en.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
635 en.size_hint_min = 800, 800 # TODO: this should be respected :/
636 en.editable = False
637 en.scrollable = True
638 pp.content = en
639
640 bt = Button(pp, text="Close")
641 bt.callback_clicked_add(lambda b: pp.delete())
642 pp.part_content_set('button2', bt)
643
644 def prettify_clicked_cb(chk):
645 options.pretty_output = chk.state
646 en.text = prettify_if_needed(item.data['args'])
647 ck = Check(pp, text="Prettify")
648 ck.state = options.pretty_output
649 ck.callback_changed_add(prettify_clicked_cb)
650 pp.part_content_set('button1', ck)
651
652 pp.show()
653
654
564### The main window 655### The main window
565class MyWin(StandardWindow): 656class EspionageWin(StandardWindow):
566 def __init__(self): 657 def __init__(self):
567 StandardWindow.__init__(self, "espionage", "EFL DBus Spy - Espionage") 658 StandardWindow.__init__(self, "espionage", "EFL DBus Spy - Espionage")
568 659
@@ -602,19 +693,29 @@ class MyWin(StandardWindow):
602 tb.pack(chk, 2, 1, 1, 1) 693 tb.pack(chk, 2, 1, 1, 1)
603 chk.show() 694 chk.show()
604 695
605 panes = Panes(self) 696 vpanes = Panes(self, horizontal=True)
606 panes.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND 697 vpanes.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
607 panes.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL 698 vpanes.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
608 panes.content_left_size = 1.0 / 3 699 vpanes.content_left_size = 2.0 / 3
609 box.pack_end(panes) 700 box.pack_end(vpanes)
610 self.panes = panes 701 vpanes.show()
611 panes.show() 702
703 hpanes = Panes(self)
704 hpanes.size_hint_weight = EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
705 hpanes.size_hint_align = EVAS_HINT_FILL, EVAS_HINT_FILL
706 hpanes.content_left_size = 1.0 / 3
707 vpanes.part_content_set("left", hpanes)
708 self.panes = hpanes
709 hpanes.show()
612 710
613 self.names_list = NamesList(self) 711 self.names_list = NamesList(self)
614 panes.part_content_set("left", self.names_list) 712 hpanes.part_content_set("left", self.names_list)
615 713
616 self.detail_list = DetailList(self) 714 self.detail_list = DetailList(self)
617 panes.part_content_set("right", self.detail_list) 715 hpanes.part_content_set("right", self.detail_list)
716
717 self.sigs_receiver = SignalReceiver(self)
718 vpanes.part_content_set("right", self.sigs_receiver)
618 719
619 self.resize(700, 500) 720 self.resize(700, 500)
620 self.show() 721 self.show()
@@ -639,7 +740,7 @@ class MyWin(StandardWindow):
639 740
640def main(): 741def main():
641 elm.init() 742 elm.init()
642 win = MyWin() 743 win = EspionageWin()
643 elm.run() 744 elm.run()
644 elm.shutdown() 745 elm.shutdown()
645 return 0 746 return 0