only load python in vimrc when opening c,cpp files
[pygdb.git] / PositionFrame.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gobject
8 import gtk
9 import re
10 import os
11 import string
12 import vte
13
14 import DbgTerminal
15 import StatusFrame
16
17
18 class PositionFrame (StatusFrame.StatusFrame):
19
20
21 def __init__(self, debugger):
22
23 StatusFrame.StatusFrame.__init__(self, debugger)
24 self.set_label("Position")
25
26 debugger.gotActiveCallback += [self.updateValues]
27 debugger.gotInactiveCallback += [self.updateValues]
28
29 self.file = None
30 self.lineno = 0
31
32 vbox = gtk.VBox(False, 5)
33 self.add(vbox)
34
35 hbox = gtk.HBox(False, 10)
36 vbox.pack_start(hbox, False, False)
37 self.openBtn = gtk.Button(":e")
38 hbox.pack_start(self.openBtn, False, False)
39 self.positionLabel = gtk.Label()
40 hbox.pack_start(self.positionLabel, False, False)
41
42 sw = gtk.ScrolledWindow()
43 sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
44 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
45 vbox.add(sw)
46
47 self.srcview = gtk.TextView()
48 sw.add(self.srcview)
49
50 self.openBtn.connect("clicked", self.openBtnClicked)
51
52
53 def openBtnClicked(self, btn):
54
55 if not self.debugger.isActive():
56 return
57
58 if self.file!=None:
59 try:
60 cmd = 'gvim --servername pygdb -c ":GDBLoadConfig" %s' % (self.file)
61 os.system(cmd)
62 except OSError:
63 dialog = gtk.MessageDialog(None, \
64 gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, \
65 gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, \
66 "Error calling editor with '%s'." % cmd)
67 dialog.run()
68 dialog.destroy()
69
70
71 def updateValues(self, status, param):
72
73 #Create new text buffer for source view
74 buf = gtk.TextBuffer()
75
76 if status == "break":
77 self.file, self.lineno = param
78 self.positionLabel.set_label("%s:%d" % (self.file, self.lineno))
79
80 #Get some code
81 code = string.join(self.debugger.getBacktrace(), "\n")
82 buf.set_text(code)
83
84
85 else:
86 self.file, self.lineno = None, None
87 code = ""
88
89 if status == "exited":
90 self.positionLabel.set_label("Exited with code %d." % param)
91 elif status == "started":
92 self.positionLabel.set_label("Started.")
93 elif status == "continued":
94 self.positionLabel.set_label("Continued.")
95 else:
96 self.positionLabel.set_label(status)
97
98
99 #Set the buffer
100 self.srcview.set_buffer(buf)
101
102
103
104
105 def applyConfiguration(self, conf):
106 pass
107
108 def fillConfiguration(self, conf):
109 conf.setCurrpos(self.file, self.lineno)
110