]> git.sthu.org Git - pygdb.git/blob - WatchesFrame.py
change from BufRead to Filetype in install notes
[pygdb.git] / WatchesFrame.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gobject
8 import gtk
9 import vte
10
11 import DbgTerminal
12 import StatusFrame
13
14
15 class WatchesFrame (StatusFrame.StatusFrame):
16
17
18 def __init__(self, debugger):
19
20 StatusFrame.StatusFrame.__init__(self, debugger)
21 self.set_label("Watches")
22
23 debugger.gotActiveCallback += [self.updateValues]
24
25 vbox = gtk.VBox(False, 5)
26 self.add(vbox)
27
28 hbox = gtk.HBox()
29 vbox.pack_start(hbox, False, False)
30
31 self.addBtn = gtk.Button(stock=gtk.STOCK_ADD)
32 self.delBtn = gtk.Button(stock=gtk.STOCK_REMOVE)
33 hbox.add(self.addBtn)
34 hbox.add(self.delBtn)
35
36 sw = gtk.ScrolledWindow()
37 sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
38 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
39 vbox.add(sw)
40
41 self.model = self.__createModel()
42 self.tv = gtk.TreeView(self.model)
43 self.tv.set_rules_hint(True)
44 self.tv.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
45
46 self.__addColumns(self.tv)
47 sw.add(self.tv)
48
49 self.addBtn.connect("clicked", self.addBtnClicked)
50 self.delBtn.connect("clicked", self.delBtnClicked)
51
52
53
54 def __createModel(self):
55
56 model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, \
57 gobject.TYPE_BOOLEAN)
58
59 return model
60
61
62 def __addColumns(self, tv):
63
64 model = tv.get_model()
65
66 renderer = gtk.CellRendererText()
67 renderer.connect("edited", self.onExprEdited, model)
68 renderer.set_data("column", 0)
69 col = gtk.TreeViewColumn("Expr", renderer, text=0, editable=2)
70 col.set_resizable(True)
71 tv.append_column(col)
72
73
74 renderer = gtk.CellRendererText()
75 renderer.set_data("column", 1)
76 col = gtk.TreeViewColumn("Result", renderer, text=1)
77 col.set_resizable(True)
78 tv.append_column(col)
79
80
81 def onExprEdited(self, cell, pathStr, expr, model):
82 iter = model.get_iter_from_string(pathStr)
83 path = model.get_path(iter)[0]
84 col = cell.get_data("column")
85
86 model.set(iter, 0, expr)
87
88 if self.debugger.isActive():
89 res = self.debugger.getExpression(expr)
90 model.set(iter, 1, res)
91
92
93 def applyConfiguration(self, conf):
94 for w in conf.watches:
95 iter = self.model.append()
96 self.model.set(iter, 0, w["expr"], 1, "<unkown>", 2, True)
97 self.updateValues(None, None)
98
99
100 def fillConfiguration(self, conf):
101
102 iter = self.model.get_iter_first()
103 while iter != None:
104 expr, = self.model.get(iter, 0)
105 conf.parseWatch(expr)
106 iter = self.model.iter_next(iter)
107
108
109 def addBtnClicked(self, btn):
110 iter = self.model.append()
111 self.model.set(iter, 0, "0", 1, "0", 2, True)
112
113 def delBtnClicked(self, btn):
114 selection = self.tv.get_selection()
115 model, paths = selection.get_selected_rows()
116
117 for path in reversed(paths):
118 iter = model.get_iter(path)
119 model.remove(iter)
120
121 def updateValues(self, status, param):
122 iter = self.model.get_iter_first()
123 while iter != None:
124 expr, = self.model.get(iter, 0)
125 res = self.debugger.getExpression(expr)
126 self.model.set(iter, 1, res)
127
128 iter = self.model.iter_next(iter)
129