summaryrefslogtreecommitdiffstats
path: root/Lib/lib-stdwin/wdbsrcwin.py
blob: f79fab94be5303f0c7e6fe6c15ca34fe1c0feb9b (plain)
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
97
98
99
100
# wdbsrcwin.py -- source window for wdb

import stdwin
from stdwinevents import *
import srcwin


class DebuggerSourceWindow(srcwin.SourceWindow):
	
	def __init__(self, debugger, filename):
		self.debugger = debugger
		self.curlineno = 0
		self.focus = 0
		srcwin.SourceWindow.__init__(self, filename)
	
	def close(self):
		del self.debugger.sourcewindows[self.filename]
		del self.debugger
		srcwin.SourceWindow.close(self)
	
	def dispatch(self, event):
		type, win, detail = event
		if type == WE_CHAR:
			self.char(detail)
		elif type == WE_COMMAND:
			self.command(detail)
		elif type == WE_MOUSE_DOWN:
			self.mouse_down(detail)
		else:
			srcwin.SourceWindow.dispatch(self, event)
	
	def char(self, detail):
		self.debugger.char(detail)
	
	def command(self, detail):
		self.debugger.command(detail)
	
	def mouse_down(self, detail):
		(h, v), clicks, button, mask = detail
		if h >= self.leftmargin:
			srcwin.SourceWindow.dispatch(self, \
				(WE_MOUSE_DOWN, self.win, detail))
			return
		lineno = v/self.lineheight + 1
		if 1 <= lineno <= self.linecount:
			if self.debugger.get_break(self.filename, lineno):
				f = self.debugger.clear_break
			else:
				f = self.debugger.set_break
			err = f(self.filename, lineno)
			if err: stdwin.message(err)
			else: self.changemark(lineno)
		else:
			stdwin.fleep()
	
	def getmark(self, lineno):
		s = `lineno`
		if lineno == self.focus:
			s = '[' + s + ']'
		else:
			s = ' ' + s + ' '
		if lineno == self.curlineno:
			s = s + '->'
		else:
			s = s + '  '
		br = self.debugger.breaks
		if br.has_key(self.filename) and lineno in br[self.filename]:
			s = s + 'B'
		else:
			s = s + ' '
		return s
	
	def getmargin(self):
		return stdwin.textwidth('[' + `self.linecount+1` + ']->B ')
	
	def setlineno(self, newlineno):
		if newlineno != self.curlineno:
			oldlineno = self.curlineno
			self.curlineno = newlineno
			self.changemark(oldlineno)
			self.changemark(newlineno)
		if newlineno != 0:
			self.showline(newlineno)
	
	def resetlineno(self):
		self.setlineno(0)
	
	def setfocus(self, newfocus):
		if newfocus != self.focus:
			oldfocus = self.focus
			self.focus = newfocus
			self.changemark(oldfocus)
			self.changemark(newfocus)
		if newfocus != 0:
			self.showline(newfocus)
	
	def resetfocus(self):
		self.setfocus(0)

# XXX Should get rid of focus stuff again