| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | # Module 'textwin' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Text windows, a subclass of gwin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import stdwin | 
					
						
							|  |  |  | import gwin | 
					
						
							| 
									
										
										
										
											1991-12-26 13:06:52 +00:00
										 |  |  | from stdwinevents import * | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def fixsize(w): | 
					
						
							|  |  |  | 	docwidth, docheight = w.text.getrect()[1] | 
					
						
							|  |  |  | 	winheight = w.getwinsize()[1] | 
					
						
							|  |  |  | 	if winheight > docheight: docheight = winheight | 
					
						
							|  |  |  | 	w.setdocsize(0, docheight) | 
					
						
							|  |  |  | 	fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def cut(w, m, id): | 
					
						
							|  |  |  | 	s = w.text.getfocustext() | 
					
						
							|  |  |  | 	if s: | 
					
						
							| 
									
										
										
										
											1990-12-26 15:40:31 +00:00
										 |  |  | 		stdwin.setcutbuffer(0, s) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 		w.text.replace('') | 
					
						
							|  |  |  | 		fixsize(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def copy(w, m, id): | 
					
						
							|  |  |  | 	s = w.text.getfocustext() | 
					
						
							|  |  |  | 	if s: | 
					
						
							| 
									
										
										
										
											1990-12-26 15:40:31 +00:00
										 |  |  | 		stdwin.setcutbuffer(0, s) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 		fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def paste(w, m, id): | 
					
						
							| 
									
										
										
										
											1990-12-26 15:40:31 +00:00
										 |  |  | 	w.text.replace(stdwin.getcutbuffer(0)) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 	fixsize(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def addeditmenu(w): | 
					
						
							|  |  |  | 	m = w.editmenu = w.menucreate('Edit') | 
					
						
							|  |  |  | 	m.action = [] | 
					
						
							|  |  |  | 	m.additem('Cut', 'X') | 
					
						
							|  |  |  | 	m.action.append(cut) | 
					
						
							|  |  |  | 	m.additem('Copy', 'C') | 
					
						
							|  |  |  | 	m.action.append(copy) | 
					
						
							|  |  |  | 	m.additem('Paste', 'V') | 
					
						
							|  |  |  | 	m.action.append(paste) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def fixeditmenu(w): | 
					
						
							|  |  |  | 	m = w.editmenu | 
					
						
							|  |  |  | 	f = w.text.getfocus() | 
					
						
							|  |  |  | 	can_copy = (f[0] < f[1]) | 
					
						
							|  |  |  | 	m.enable(1, can_copy) | 
					
						
							|  |  |  | 	if not w.readonly: | 
					
						
							|  |  |  | 		m.enable(0, can_copy) | 
					
						
							| 
									
										
										
										
											1990-12-26 15:40:31 +00:00
										 |  |  | 		m.enable(2, (stdwin.getcutbuffer(0) <> '')) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def draw(w, area):			# Draw method | 
					
						
							|  |  |  | 	w.text.draw(area) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def size(w, newsize):			# Size method | 
					
						
							|  |  |  | 	w.text.move((0, 0), newsize) | 
					
						
							|  |  |  | 	fixsize(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def close(w):				# Close method | 
					
						
							|  |  |  | 	del w.text  # Break circular ref | 
					
						
							|  |  |  | 	gwin.close(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def char(w, c):				# Char method | 
					
						
							|  |  |  | 	w.text.replace(c) | 
					
						
							|  |  |  | 	fixsize(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def backspace(w):			# Backspace method | 
					
						
							| 
									
										
										
										
											1991-12-26 13:06:52 +00:00
										 |  |  | 	void = w.text.event(WE_COMMAND, w, WC_BACKSPACE) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 	fixsize(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def arrow(w, detail):			# Arrow method | 
					
						
							|  |  |  | 	w.text.arrow(detail) | 
					
						
							|  |  |  | 	fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def mdown(w, detail):			# Mouse down method | 
					
						
							| 
									
										
										
										
											1991-12-26 13:06:52 +00:00
										 |  |  | 	void = w.text.event(WE_MOUSE_DOWN, w, detail) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 	fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def mmove(w, detail):			# Mouse move method | 
					
						
							| 
									
										
										
										
											1991-12-26 13:06:52 +00:00
										 |  |  | 	void = w.text.event(WE_MOUSE_MOVE, w, detail) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def mup(w, detail):			# Mouse up method | 
					
						
							| 
									
										
										
										
											1991-12-26 13:06:52 +00:00
										 |  |  | 	void = w.text.event(WE_MOUSE_UP, w, detail) | 
					
						
							| 
									
										
										
										
											1990-10-13 19:23:40 +00:00
										 |  |  | 	fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def activate(w):			# Activate method | 
					
						
							|  |  |  | 	fixeditmenu(w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def open(title, str):			# Display a string in a window | 
					
						
							|  |  |  | 	w = gwin.open(title) | 
					
						
							|  |  |  | 	w.readonly = 0 | 
					
						
							|  |  |  | 	w.text = w.textcreate((0, 0), w.getwinsize()) | 
					
						
							|  |  |  | 	w.text.replace(str) | 
					
						
							|  |  |  | 	w.text.setfocus(0, 0) | 
					
						
							|  |  |  | 	addeditmenu(w) | 
					
						
							|  |  |  | 	fixsize(w) | 
					
						
							|  |  |  | 	w.draw = draw | 
					
						
							|  |  |  | 	w.size = size | 
					
						
							|  |  |  | 	w.close = close | 
					
						
							|  |  |  | 	w.mdown = mdown | 
					
						
							|  |  |  | 	w.mmove = mmove | 
					
						
							|  |  |  | 	w.mup = mup | 
					
						
							|  |  |  | 	w.char = char | 
					
						
							|  |  |  | 	w.backspace = backspace | 
					
						
							|  |  |  | 	w.arrow = arrow | 
					
						
							|  |  |  | 	w.activate = activate | 
					
						
							|  |  |  | 	return w | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def open_readonly(title, str):		# Same with char input disabled | 
					
						
							|  |  |  | 	w = open(title, str) | 
					
						
							|  |  |  | 	w.readonly = 1 | 
					
						
							|  |  |  | 	w.char = w.backspace = gwin.nop | 
					
						
							|  |  |  | 	# Disable Cut and Paste menu item; leave Copy alone | 
					
						
							|  |  |  | 	w.editmenu.enable(0, 0) | 
					
						
							|  |  |  | 	w.editmenu.enable(2, 0) | 
					
						
							|  |  |  | 	return w |