File: Show_Logs.py

package info (click to toggle)
xpn 1.2.6-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,500 kB
  • ctags: 1,685
  • sloc: python: 12,693; xml: 206; makefile: 16; sh: 1
file content (96 lines) | stat: -rw-r--r-- 3,591 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gtk
import os
from xpn_src.UserDir import get_wdir


class Logs_Window:
    def delete_event(self,widget,event,data=None):
        return False  

    def destroy(self,widget):
        self.window.destroy()
        if __name__=="__main__":
            gtk.mainquit()

    def insert(self,string):
        mark=self.buffer.get_insert()
        iter=self.buffer.get_iter_at_mark(mark)
        time,log=string.split("::")
        if ">>" in string:
            self.buffer.insert_with_tags_by_name(iter,(time+"::").encode("utf-8"),"time")
            mark=self.buffer.get_insert()
            iter=self.buffer.get_iter_at_mark(mark)
            self.buffer.insert_with_tags_by_name(iter,log.encode("utf-8"),"blue")
        else:
            self.buffer.insert_with_tags_by_name(iter,(time+"::").encode("utf-8"),"time")
            mark=self.buffer.get_insert()
            iter=self.buffer.get_iter_at_mark(mark)
            self.buffer.insert_with_tags_by_name(iter,log.encode("utf-8"),"red")
            

    def load_logs(self):
        try:
            f=open(self.FILENAME,"r")
        except IOError:
            length="0"
        else:
            logs=f.readlines()
            for line in logs:
                self.insert(line)
            f.close()
        
    def __init__(self,main_win):
        self.FILENAME=os.path.join(get_wdir(),"server_logs.dat")
        self.window=gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event",self.delete_event)
        self.window.connect("destroy",self.destroy)
        self.window.set_title(_("Server Logs Viewer"))
        self.window.set_position(gtk.WIN_POS_CENTER)
        if main_win!=None:
            self.window.set_modal(True)    
            self.window.set_transient_for(main_win)
        vbox=gtk.VBox(False,0)
        vbox.set_border_width(2)
        label=gtk.Label()
        label.set_markup("\n<b>"+_("Server Logs")+"</b>\n")
        vbox.pack_start(label,False,True,0)
        self.buffer=gtk.TextBuffer()
        scrolledwin=gtk.ScrolledWindow()
        scrolledwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
        scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        scrolledwin.set_border_width(4)
        self.view=gtk.TextView(self.buffer)
        self.view.set_wrap_mode(gtk.WRAP_WORD)
        self.view.set_justification(gtk.JUSTIFY_LEFT)
        self.view.set_cursor_visible(False)
        self.view.set_editable(False)
        self.view.set_indent(2)
        scrolledwin.add(self.view)

        blue_color=gtk.gdk.color_parse("blue")
        red_color=gtk.gdk.color_parse("red")
        black_color=gtk.gdk.color_parse("black")
        self.tag_table=self.buffer.get_tag_table()
        self.blue_tag=gtk.TextTag("blue")
        self.red_tag=gtk.TextTag("red")
        self.time_tag=gtk.TextTag("time")
        self.tag_table.add(self.blue_tag)
        self.tag_table.add(self.red_tag)
        self.tag_table.add(self.time_tag)
        self.blue_tag.set_property("foreground-gdk",blue_color)
        self.red_tag.set_property("foreground-gdk",red_color)
        self.time_tag.set_property("foreground-gdk",black_color)

        vbox.pack_start(scrolledwin,True,True,0)
        self.button=gtk.Button(None,gtk.STOCK_OK)
        self.button.set_border_width(4)
        self.button.connect("clicked",self.destroy)
        vbox.pack_start(self.button,False,True,0)
        self.window.add(vbox)
        self.window.set_default_size(550,500)
        self.window.show_all()
        self.load_logs()

if __name__=="__main__":
    logs_win=Logs_Window(None)
    gtk.mainloop()