/[ascend]/branches/adrian/pygtk/canvas/errorreporter.py
ViewVC logotype

Contents of /branches/adrian/pygtk/canvas/errorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2891 - (show annotations) (download) (as text)
Fri Apr 10 19:32:37 2015 UTC (4 years, 4 months ago) by adrian
File MIME type: text/x-python
File size: 2641 byte(s)
Ported all files, probably there are bugs
1 from gi.repository import Pango
2 import ascpy
3 from gi.repository import Gtk, GdkPixbuf
4
5 class ErrorReporter():
6
7 def __init__(self, ascpyreporter,iconok,iconinfo,iconwarning,iconerror):
8 self.iconok = iconok
9 self.iconinfo = iconinfo
10 self.iconwarning = iconwarning
11 self.iconerror = iconerror
12
13 # set up the error view
14 self.errorview = Gtk.TreeView()
15 #print dir(self.errorview)
16 #self.errorview.set_headers_visible(True)
17 errstorecolstypes = [GdkPixbuf.Pixbuf,str,str,str,int]
18 self.errorstore = Gtk.TreeStore(*errstorecolstypes)
19 errtitles = ["","Location","Message"];
20 self.errorview.set_model(self.errorstore)
21 self.errcols = [ Gtk.TreeViewColumn() for _type in errstorecolstypes]
22
23 i = 0
24 for tvcolumn in self.errcols[:len(errtitles)]:
25 tvcolumn.set_title(errtitles[i])
26 self.errorview.append_column(tvcolumn)
27
28 if i>0:
29 _renderer = Gtk.CellRendererText()
30 tvcolumn.pack_start(_renderer, True)
31 tvcolumn.add_attribute(_renderer, 'text', i)
32 if(i==2):
33 tvcolumn.add_attribute(_renderer, 'foreground', 3)
34 tvcolumn.add_attribute(_renderer, 'weight', 4)
35 else:
36 _renderer1 = Gtk.CellRendererPixbuf()
37 tvcolumn.pack_start(_renderer1, False)
38 tvcolumn.add_attribute(_renderer1, 'pixbuf', int(0))
39
40 i = i + 1
41
42
43 #--------------------
44 # set up the error reporter callback
45 self.reporter = ascpyreporter
46 self.reporter.setPythonErrorCallback(self.error_callback)
47
48
49
50
51 # ----------------------------------
52 # ERROR PANEL
53
54 def get_error_row_data(self,sev,filename,line,msg):
55 try:
56 _sevicon = {
57 0 : self.iconok
58 ,1 : self.iconinfo
59 ,2 : self.iconwarning
60 ,4 : self.iconerror
61 ,8 : self.iconinfo
62 ,16 : self.iconwarning
63 ,32 : self.iconerror
64 ,64 : self.iconerror
65 }[sev]
66 except KeyError:
67 _sevicon = self.iconerror
68
69 _fontweight = Pango.Weight.NORMAL
70 if sev==32 or sev==64:
71 _fontweight = Pango.Weight.BOLD
72
73 _fgcolor = "black"
74 if sev==8:
75 _fgcolor = "#888800"
76 elif sev==16:
77 _fgcolor = "#884400"
78 elif sev==32 or sev==64:
79 _fgcolor = "#880000"
80 elif sev==0:
81 _fgcolor = "#448844"
82
83 if not filename and not line:
84 _fileline = ""
85 else:
86 if(len(filename) > 25):
87 filename = "..."+filename[-22:]
88 _fileline = filename + ":" + str(line)
89
90 _res = (_sevicon,_fileline,msg.rstrip(),_fgcolor,_fontweight)
91 return _res
92
93 def error_callback(self,sev,filename,line,msg):
94 pos = self.errorstore.append(None, self.get_error_row_data(sev, filename,line,msg))
95 path = self.errorstore.get_path(pos)
96 col = self.errorview.get_column(3)
97 self.errorview.scroll_to_cell(path,col)
98 return 0;

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22