summaryrefslogtreecommitdiffstats
path: root/Lib/stdwin/wdbsrcwin.py
blob: 6c5cde8e0231a526d07f6f5e9dff4f0bcab46b9d (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
		return 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