Added a question widget
This commit is contained in:
		| @@ -426,12 +426,14 @@ readonly: whether to accept new text | |||||||
| 					self.ptr -= 1 | 					self.ptr -= 1 | ||||||
| 				else: | 				else: | ||||||
| 					self.beepIfNeeded() | 					self.beepIfNeeded() | ||||||
|  | 				return 1 | ||||||
| 			elif c in (6, 261):		# ^f, right arrow | 			elif c in (6, 261):		# ^f, right arrow | ||||||
| 				if self.ptr<len(self.currentLine): | 				if self.ptr<len(self.currentLine): | ||||||
| 					self.ptr += 1 | 					self.ptr += 1 | ||||||
| 				else: | 				else: | ||||||
| 					self.beepIfNeeded() | 					self.beepIfNeeded() | ||||||
| 					self.ptr = len(self.currentLine) | 					self.ptr = len(self.currentLine) | ||||||
|  | 				return 1 | ||||||
| 			elif c  ==  259:		# Up arrow | 			elif c  ==  259:		# Up arrow | ||||||
| 				if not self.history or self.historyPos == 0: #history will return non-zero if it has content | 				if not self.history or self.historyPos == 0: #history will return non-zero if it has content | ||||||
| 					self.beepIfNeeded() | 					self.beepIfNeeded() | ||||||
| @@ -525,7 +527,7 @@ multiple: whether to allow selecting multiple options | |||||||
| #if we've got a list of strings or a list of non-list objects, turn them into itemIndex,item | #if we've got a list of strings or a list of non-list objects, turn them into itemIndex,item | ||||||
| #so ["a","b","c"] would become [[0,"a"],[1,"b"],[2,"c"]] | #so ["a","b","c"] would become [[0,"a"],[1,"b"],[2,"c"]] | ||||||
| 		if items and type(items[0]) not in (tuple, list): | 		if items and type(items[0]) not in (tuple, list): | ||||||
| 			items = zip(xrange(len(items)),items) | 			items = zip(range(len(items)),items) | ||||||
| 		else: | 		else: | ||||||
| 			items = items | 			items = items | ||||||
| 		items = [(i,str(j)) for i, j in items] | 		items = [(i,str(j)) for i, j in items] | ||||||
| @@ -621,6 +623,34 @@ multiple: whether to allow selecting multiple options | |||||||
| 			return self.selections if self.multiple else self.pos | 			return self.selections if self.multiple else self.pos | ||||||
| 		self.draw() | 		self.draw() | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class question(Listbox): | ||||||
|  |  | ||||||
|  | 	def handleKey(self, c): | ||||||
|  | 		if c == -1: | ||||||
|  | 			return None | ||||||
|  | 		if c == curses.KEY_UP: | ||||||
|  | 			if self.pos == 0: | ||||||
|  | #we don't want to wrap around to the top | ||||||
|  | 				self.base.setStatus(self.title) | ||||||
|  | 				pass #self.pos = len(self.items)-1 | ||||||
|  | #				return 1 | ||||||
|  | 			else: | ||||||
|  | 				self.pos -= 1 | ||||||
|  | 		elif c == curses.KEY_DOWN: | ||||||
|  | 			if self.pos == len(self.items)-1: | ||||||
|  | 				self.setStatus(self.title) #self.pos = 0 | ||||||
|  | #				return 1 | ||||||
|  | 			else: | ||||||
|  | 				self.pos += 1 | ||||||
|  | 		elif c in (10, 261): # newline or right arrow | ||||||
|  | 			self.done = 1 | ||||||
|  | 			return self.selections if self.multiple else self.pos | ||||||
|  | 		elif c == 260: # left arrow quietly back out | ||||||
|  | 			self.done = -1 | ||||||
|  | 			return self.selections if self.multiple else self.pos | ||||||
|  | 		self.draw() | ||||||
|  |  | ||||||
| class fileBrowser(Listbox): | class fileBrowser(Listbox): | ||||||
|  |  | ||||||
| 	def __init__(self, dir="./", select_type="file", action="", *args, **kwargs): | 	def __init__(self, dir="./", select_type="file", action="", *args, **kwargs): | ||||||
| @@ -666,8 +696,10 @@ class fileBrowser(Listbox): | |||||||
| 				self.selections.remove(self.pos) | 				self.selections.remove(self.pos) | ||||||
| 			else: | 			else: | ||||||
| 				self.selections.append(self.pos) | 				self.selections.append(self.pos) | ||||||
|  | 			return 1 | ||||||
| 		elif curses.ascii.isprint(c): | 		elif curses.ascii.isprint(c): | ||||||
| 			self.search(chr(c)) | 			self.search(chr(c)) | ||||||
|  | 			return 1 | ||||||
| 		elif c == curses.KEY_UP: | 		elif c == curses.KEY_UP: | ||||||
| 			if self.pos == 0: | 			if self.pos == 0: | ||||||
| #we don't want to wrap around to the top | #we don't want to wrap around to the top | ||||||
| @@ -694,5 +726,6 @@ class fileBrowser(Listbox): | |||||||
| 			return 1 | 			return 1 | ||||||
| 		elif c == curses.KEY_LEFT or c == curses.KEY_BACKSPACE: # left arrow quietly back out | 		elif c == curses.KEY_LEFT or c == curses.KEY_BACKSPACE: # left arrow quietly back out | ||||||
| 			self.collapse() | 			self.collapse() | ||||||
|  | 			return 1 | ||||||
| 		self.draw() | 		self.draw() | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user