1
2
3
4 """
5 A status window for the Spark application.
6 """
7
8 from datetime import datetime
9 import gtk
10
11 from twisted.python import log
12 from twisted.internet import reactor
13 from sparked import events
14
15
17 """
18 The status window for the sparked application.
19 Contains the log area
20 """
21
22 maxLogLines = 2000
23
25 gtk.Window.__init__(self)
26 self.app = app
27 self.set_title(app.title + " - Status window")
28 self.connect("destroy", self.closed)
29
30 self.build()
31 log.addObserver(self.log)
32 self.created()
33
34
36 """
37 Called when the status window has been created and is showing
38 on the screen. Override to add custom functionality.
39 """
40
41
43 """
44 Create the status window
45 """
46 self.box = gtk.HBox()
47 self.log_area = gtk.TextView()
48 w = gtk.ScrolledWindow()
49 w.add(self.log_area)
50
51 self.box.pack_end(w, True, True, 0)
52
53 if self.app.monitors:
54
55 w = MonitorWidget(self.app.monitors)
56 self.box.pack_start(w, False, False, 0)
57
58 self.add(self.box)
59 self.set_size_request(720, 300)
60 self.show_all()
61
62
67
68
69 - def log(self, dict):
70 """
71 Log observer that writes into the log scroller area of the UI.
72
73 This method implements C{twisted.python.log.ILogObserver}.
74 """
75 b = self.log_area.get_buffer()
76
77 end = b.get_end_iter()
78 b.place_cursor(end)
79
80 for m in dict['message']:
81 b.insert_at_cursor("%s | %s\n" % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), m))
82
83 if b.get_line_count() > self.maxLogLines:
84 frm = b.get_start_iter()
85 to = b.get_iter_at_line(b.get_line_count() - self._max_log_lines)
86 b.delete(frm, to)
87 self.log_area.scroll_to_iter(b.get_end_iter(), 0.0)
88
89
90
130
131
132
133 guiEvents = events.EventDispatcher()
134