| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # The options of a widget are described by the following attributes | 
					
						
							|  |  |  | # of the Pack and Widget dialogs: | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Dialog.current: {name: value} | 
					
						
							|  |  |  | # -- changes during Widget's lifetime | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Dialog.options: {name: (default, klass)} | 
					
						
							|  |  |  | # -- depends on widget class only | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Dialog.classes: {klass: (v0, v1, v2, ...) | 'boolean' | 'other'} | 
					
						
							|  |  |  | # -- totally static, though different between PackDialog and WidgetDialog | 
					
						
							|  |  |  | #    (but even that could be unified) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from Tkinter import * | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Option: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	varclass = StringVar		# May be overridden | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, dialog, option): | 
					
						
							|  |  |  | 		self.dialog = dialog | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.option = option | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.master = dialog.top | 
					
						
							|  |  |  | 		self.default, self.klass = dialog.options[option] | 
					
						
							|  |  |  | 		self.var = self.varclass(self.master) | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.frame = Frame(self.master, | 
					
						
							|  |  |  | 				   {Pack: {'expand': 0, 'fill': 'x'}}) | 
					
						
							|  |  |  | 		self.label = Label(self.frame, | 
					
						
							|  |  |  | 				   {'text': option + ':', | 
					
						
							|  |  |  | 				    Pack: {'side': 'left'}, | 
					
						
							|  |  |  | 				    }) | 
					
						
							|  |  |  | 		self.update() | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.addoption() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	def refresh(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.dialog.refresh() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.update() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def update(self): | 
					
						
							|  |  |  | 		try: | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 			self.current = self.dialog.current[self.option] | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		except KeyError: | 
					
						
							|  |  |  | 			self.current = self.default | 
					
						
							|  |  |  | 		self.var.set(self.current) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	def set(self, e=None):		# Should be overridden | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BooleanOption(Option): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	varclass = BooleanVar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def addoption(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.button = Checkbutton(self.frame, | 
					
						
							|  |  |  | 					 {'text': 'on/off', | 
					
						
							|  |  |  | 					  'onvalue': '1', | 
					
						
							|  |  |  | 					  'offvalue': '0', | 
					
						
							|  |  |  | 					  'variable': self.var, | 
					
						
							|  |  |  | 					  'relief': 'raised', | 
					
						
							|  |  |  | 					  'borderwidth': 2, | 
					
						
							|  |  |  | 					  'command': self.set, | 
					
						
							|  |  |  | 					  Pack: {'side': 'right'}, | 
					
						
							|  |  |  | 					  }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class EnumOption(Option): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	def addoption(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.button = Menubutton(self.frame, | 
					
						
							|  |  |  | 					 {'textvariable': self.var, | 
					
						
							|  |  |  | 					  'relief': 'raised', | 
					
						
							|  |  |  | 					  'borderwidth': 2, | 
					
						
							|  |  |  | 					  Pack: {'side': 'right'}, | 
					
						
							|  |  |  | 					  }) | 
					
						
							|  |  |  | 		self.menu = Menu(self.button) | 
					
						
							|  |  |  | 		self.button['menu'] = self.menu | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		for v in self.dialog.classes[self.klass]: | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 			self.menu.add_radiobutton( | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				{'label': v, | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 				 'variable': self.var, | 
					
						
							|  |  |  | 				 'value': v, | 
					
						
							|  |  |  | 				 'command': self.set, | 
					
						
							|  |  |  | 				 }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StringOption(Option): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	def addoption(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.entry = Entry(self.frame, | 
					
						
							|  |  |  | 				   {'textvariable': self.var, | 
					
						
							|  |  |  | 				    'width': 10, | 
					
						
							|  |  |  | 				    'relief': 'sunken', | 
					
						
							|  |  |  | 				    'borderwidth': 2, | 
					
						
							|  |  |  | 				    Pack: {'side': 'right', | 
					
						
							|  |  |  | 					   'fill': 'x', 'expand': 1}, | 
					
						
							|  |  |  | 				    }) | 
					
						
							|  |  |  | 		self.entry.bind('<Return>', self.set) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | class ReadonlyOption(Option): | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	def addoption(self): | 
					
						
							|  |  |  | 		self.label = Label(self.frame, | 
					
						
							|  |  |  | 				   {'textvariable': self.var, | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 				    'anchor': 'e', | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				    Pack: {'side': 'right'}}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Dialog: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, master): | 
					
						
							|  |  |  | 		self.master = master | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 		self.fixclasses() | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.refresh() | 
					
						
							|  |  |  | 		self.top = Toplevel(self.master) | 
					
						
							|  |  |  | 		self.top.title(self.__class__.__name__) | 
					
						
							|  |  |  | 		self.top.minsize(1, 1) | 
					
						
							|  |  |  | 		self.addchoices() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 	def refresh(self): pass		# Must override | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def fixclasses(self): pass	# May override | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	def addchoices(self): | 
					
						
							|  |  |  | 		self.choices = {} | 
					
						
							|  |  |  | 		list = [] | 
					
						
							|  |  |  | 		for k, dc in self.options.items(): | 
					
						
							|  |  |  | 			list.append(k, dc) | 
					
						
							|  |  |  | 		list.sort() | 
					
						
							|  |  |  | 		for k, (d, c) in list: | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				cl = self.classes[c] | 
					
						
							|  |  |  | 			except KeyError: | 
					
						
							|  |  |  | 				cl = 'unknown' | 
					
						
							|  |  |  | 			if type(cl) == TupleType: | 
					
						
							|  |  |  | 				cl = self.enumoption | 
					
						
							|  |  |  | 			elif cl == 'boolean': | 
					
						
							|  |  |  | 				cl = self.booleanoption | 
					
						
							|  |  |  | 			elif cl == 'readonly': | 
					
						
							|  |  |  | 				cl = self.readonlyoption | 
					
						
							|  |  |  | 			else: | 
					
						
							|  |  |  | 				cl = self.stringoption | 
					
						
							|  |  |  | 			self.choices[k] = cl(self, k) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 	# Must override: | 
					
						
							|  |  |  | 	options = {} | 
					
						
							|  |  |  | 	classes = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# May override: | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	booleanoption = BooleanOption | 
					
						
							|  |  |  | 	stringoption = StringOption | 
					
						
							|  |  |  | 	enumoption = EnumOption | 
					
						
							|  |  |  | 	readonlyoption = ReadonlyOption | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PackDialog(Dialog): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, widget): | 
					
						
							|  |  |  | 		self.widget = widget | 
					
						
							|  |  |  | 		Dialog.__init__(self, widget) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def refresh(self): | 
					
						
							|  |  |  | 		self.current = self.widget.newinfo() | 
					
						
							|  |  |  | 		self.current['.class'] = self.widget.winfo_class() | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		self.current['.name'] = self.widget._w | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	class packoption: # Mix-in class | 
					
						
							|  |  |  | 		def set(self, e=None): | 
					
						
							|  |  |  | 			self.current = self.var.get() | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				Pack.config(self.dialog.widget, | 
					
						
							|  |  |  | 					    {self.option: self.current}) | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 			except TclError, msg: | 
					
						
							|  |  |  | 				print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				self.refresh() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	class booleanoption(packoption, BooleanOption): pass | 
					
						
							|  |  |  | 	class enumoption(packoption, EnumOption): pass | 
					
						
							|  |  |  | 	class stringoption(packoption, StringOption): pass | 
					
						
							|  |  |  | 	class readonlyoption(packoption, ReadonlyOption): pass | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	options = { | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		'.class': (None, 'Class'), | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		'.name': (None, 'Name'), | 
					
						
							|  |  |  | 		'after': (None, 'Widget'), | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		'anchor': ('center', 'Anchor'), | 
					
						
							|  |  |  | 		'before': (None, 'Widget'), | 
					
						
							|  |  |  | 		'expand': ('no', 'Boolean'), | 
					
						
							|  |  |  | 		'fill': ('none', 'Fill'), | 
					
						
							|  |  |  | 		'in': (None, 'Widget'), | 
					
						
							|  |  |  | 		'ipadx': (0, 'Pad'), | 
					
						
							|  |  |  | 		'ipady': (0, 'Pad'), | 
					
						
							|  |  |  | 		'padx': (0, 'Pad'), | 
					
						
							|  |  |  | 		'pady': (0, 'Pad'), | 
					
						
							|  |  |  | 		'side': ('top', 'Side'), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	classes = { | 
					
						
							|  |  |  | 		'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'), | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		'Boolean': 'boolean', | 
					
						
							|  |  |  | 		'Class': 'readonly', | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		'Expand': 'boolean', | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		'Fill': ('none', 'x', 'y', 'both'), | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		'Name': 'readonly', | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		'Pad': 'pixel', | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		'Side': ('top', 'right', 'bottom', 'left'), | 
					
						
							|  |  |  | 		'Widget': 'readonly', | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | class RemotePackDialog(PackDialog): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, master, app, widget): | 
					
						
							|  |  |  | 		self.master = master | 
					
						
							|  |  |  | 		self.app = app | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		self.widget = widget | 
					
						
							|  |  |  | 		self.refresh() | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.top = Toplevel(self.master) | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		self.top.title(self.app + ' PackDialog') | 
					
						
							|  |  |  | 		self.top.minsize(1, 1) | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.addchoices() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	def refresh(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		try: | 
					
						
							|  |  |  | 			words = self.master.tk.splitlist( | 
					
						
							|  |  |  | 				self.master.send(self.app, | 
					
						
							|  |  |  | 						 'pack', | 
					
						
							|  |  |  | 						 'newinfo', | 
					
						
							|  |  |  | 						 self.widget)) | 
					
						
							|  |  |  | 		except TclError, msg: | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 			print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		dict = {} | 
					
						
							|  |  |  | 		for i in range(0, len(words), 2): | 
					
						
							|  |  |  | 			key = words[i][1:] | 
					
						
							|  |  |  | 			value = words[i+1] | 
					
						
							|  |  |  | 			dict[key] = value | 
					
						
							|  |  |  | 		dict['.class'] = self.master.send(self.app, | 
					
						
							|  |  |  | 						  'winfo', | 
					
						
							|  |  |  | 						  'class', | 
					
						
							|  |  |  | 						  self.widget) | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		dict['.name'] = self.widget | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.current = dict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class remotepackoption: # Mix-in class | 
					
						
							|  |  |  | 		def set(self, e=None): | 
					
						
							|  |  |  | 			self.current = self.var.get() | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				self.dialog.master.send( | 
					
						
							|  |  |  | 					self.dialog.app, | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 					'pack', | 
					
						
							|  |  |  | 					'config', | 
					
						
							|  |  |  | 					self.dialog.widget, | 
					
						
							|  |  |  | 					'-'+self.option, | 
					
						
							|  |  |  | 					self.dialog.master.tk.merge( | 
					
						
							|  |  |  | 						self.current)) | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 			except TclError, msg: | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 				print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				self.refresh() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	class booleanoption(remotepackoption, BooleanOption): pass | 
					
						
							|  |  |  | 	class enumoption(remotepackoption, EnumOption): pass | 
					
						
							|  |  |  | 	class stringoption(remotepackoption, StringOption): pass | 
					
						
							|  |  |  | 	class readonlyoption(remotepackoption, ReadonlyOption): pass | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | class WidgetDialog(Dialog): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, widget): | 
					
						
							|  |  |  | 		self.widget = widget | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 		self.klass = widget.winfo_class() | 
					
						
							|  |  |  | 		Dialog.__init__(self, widget) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def fixclasses(self): | 
					
						
							|  |  |  | 		if self.addclasses.has_key(self.klass): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 			classes = {} | 
					
						
							|  |  |  | 			for c in (self.classes, | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 				  self.addclasses[self.klass]): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				for k in c.keys(): | 
					
						
							|  |  |  | 					classes[k] = c[k] | 
					
						
							|  |  |  | 			self.classes = classes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def refresh(self): | 
					
						
							|  |  |  | 		self.configuration = self.widget.config() | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		self.update() | 
					
						
							|  |  |  | 		self.current['.class'] = self.widget.winfo_class() | 
					
						
							|  |  |  | 		self.current['.name'] = self.widget._w | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def update(self): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		self.current = {} | 
					
						
							|  |  |  | 		self.options = {} | 
					
						
							|  |  |  | 		for k, v in self.configuration.items(): | 
					
						
							|  |  |  | 			if len(v) > 4: | 
					
						
							|  |  |  | 				self.current[k] = v[4] | 
					
						
							|  |  |  | 				self.options[k] = v[3], v[2] # default, klass | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		self.options['.class'] = (None, 'Class') | 
					
						
							|  |  |  | 		self.options['.name'] = (None, 'Name') | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	class widgetoption: # Mix-in class | 
					
						
							|  |  |  | 		def set(self, e=None): | 
					
						
							|  |  |  | 			self.current = self.var.get() | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				self.dialog.widget[self.option] = self.current | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 			except TclError, msg: | 
					
						
							|  |  |  | 				print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 				self.refresh() | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	class booleanoption(widgetoption, BooleanOption): pass | 
					
						
							|  |  |  | 	class enumoption(widgetoption, EnumOption): pass | 
					
						
							|  |  |  | 	class stringoption(widgetoption, StringOption): pass | 
					
						
							|  |  |  | 	class readonlyoption(widgetoption, ReadonlyOption): pass | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	# Universal classes | 
					
						
							|  |  |  | 	classes = { | 
					
						
							|  |  |  | 		'Anchor': ('n','ne', 'e','se', 's','sw', 'w','nw', 'center'), | 
					
						
							|  |  |  | 		'Aspect': 'integer', | 
					
						
							|  |  |  | 		'Background': 'color', | 
					
						
							|  |  |  | 		'Bitmap': 'bitmap', | 
					
						
							|  |  |  | 		'BorderWidth': 'pixel', | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		'Class': 'readonly', | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		'CloseEnough': 'double', | 
					
						
							|  |  |  | 		'Command': 'command', | 
					
						
							|  |  |  | 		'Confine': 'boolean', | 
					
						
							|  |  |  | 		'Cursor': 'cursor', | 
					
						
							|  |  |  | 		'CursorWidth': 'pixel', | 
					
						
							|  |  |  | 		'DisabledForeground': 'color', | 
					
						
							|  |  |  | 		'ExportSelection': 'boolean', | 
					
						
							|  |  |  | 		'Font': 'font', | 
					
						
							|  |  |  | 		'Foreground': 'color', | 
					
						
							|  |  |  | 		'From': 'integer', | 
					
						
							|  |  |  | 		'Geometry': 'geometry', | 
					
						
							|  |  |  | 		'Height': 'pixel', | 
					
						
							|  |  |  | 		'InsertWidth': 'time', | 
					
						
							|  |  |  | 		'Justify': ('left', 'center', 'right'), | 
					
						
							|  |  |  | 		'Label': 'string', | 
					
						
							|  |  |  | 		'Length': 'pixel', | 
					
						
							|  |  |  | 		'MenuName': 'widget', | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		'Name': 'readonly', | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		'OffTime': 'time', | 
					
						
							|  |  |  | 		'OnTime': 'time', | 
					
						
							|  |  |  | 		'Orient': ('horizontal', 'vertical'), | 
					
						
							|  |  |  | 		'Pad': 'pixel', | 
					
						
							|  |  |  | 		'Relief': ('raised', 'sunken', 'flat', 'ridge', 'groove'), | 
					
						
							|  |  |  | 		'RepeatDelay': 'time', | 
					
						
							|  |  |  | 		'RepeatInterval': 'time', | 
					
						
							|  |  |  | 		'ScrollCommand': 'command', | 
					
						
							|  |  |  | 		'ScrollIncrement': 'pixel', | 
					
						
							|  |  |  | 		'ScrollRegion': 'rectangle', | 
					
						
							|  |  |  | 		'ShowValue': 'boolean', | 
					
						
							|  |  |  | 		'SetGrid': 'boolean', | 
					
						
							|  |  |  | 		'Sliderforeground': 'color', | 
					
						
							|  |  |  | 		'SliderLength': 'pixel', | 
					
						
							|  |  |  | 		'Text': 'string', | 
					
						
							|  |  |  | 		'TickInterval': 'integer', | 
					
						
							|  |  |  | 		'To': 'integer', | 
					
						
							|  |  |  | 		'Underline': 'index', | 
					
						
							|  |  |  | 		'Variable': 'variable', | 
					
						
							|  |  |  | 		'Value': 'string', | 
					
						
							|  |  |  | 		'Width': 'pixel', | 
					
						
							|  |  |  | 		'Wrap': ('none', 'char', 'word'), | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# Classes that (may) differ per widget type | 
					
						
							|  |  |  | 	_tristate = {'State': ('normal', 'active', 'disabled')} | 
					
						
							|  |  |  | 	_bistate = {'State': ('normal', 'disabled')} | 
					
						
							|  |  |  | 	addclasses = { | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 		'Button': _tristate, | 
					
						
							|  |  |  | 		'Radiobutton': _tristate, | 
					
						
							|  |  |  | 		'Checkbutton': _tristate, | 
					
						
							|  |  |  | 		'Entry': _bistate, | 
					
						
							|  |  |  | 		'Text': _bistate, | 
					
						
							|  |  |  | 		'Menubutton': _tristate, | 
					
						
							|  |  |  | 		'Slider': _bistate, | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class RemoteWidgetDialog(WidgetDialog): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def __init__(self, master, app, widget): | 
					
						
							|  |  |  | 		self.app = app | 
					
						
							|  |  |  | 		self.widget = widget | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 		self.klass = master.send(self.app, | 
					
						
							|  |  |  | 					 'winfo', | 
					
						
							|  |  |  | 					 'class', | 
					
						
							|  |  |  | 					 self.widget) | 
					
						
							|  |  |  | 		Dialog.__init__(self, master) | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	def refresh(self): | 
					
						
							|  |  |  | 		try: | 
					
						
							|  |  |  | 			items = self.master.tk.splitlist( | 
					
						
							|  |  |  | 				self.master.send(self.app, | 
					
						
							|  |  |  | 						 self.widget, | 
					
						
							|  |  |  | 						 'config')) | 
					
						
							|  |  |  | 		except TclError, msg: | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 			print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		dict = {} | 
					
						
							|  |  |  | 		for item in items: | 
					
						
							|  |  |  | 			words = self.master.tk.splitlist(item) | 
					
						
							|  |  |  | 			key = words[0][1:] | 
					
						
							|  |  |  | 			value = (key,) + words[1:] | 
					
						
							|  |  |  | 			dict[key] = value | 
					
						
							|  |  |  | 		self.configuration = dict | 
					
						
							|  |  |  | 		self.update() | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 		self.current['.class'] = self.klass | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		self.current['.name'] = self.widget | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class remotewidgetoption: # Mix-in class | 
					
						
							|  |  |  | 		def set(self, e=None): | 
					
						
							|  |  |  | 			self.current = self.var.get() | 
					
						
							|  |  |  | 			try: | 
					
						
							|  |  |  | 				self.dialog.master.send( | 
					
						
							|  |  |  | 					self.dialog.app, | 
					
						
							|  |  |  | 					self.dialog.widget, | 
					
						
							|  |  |  | 					'config', | 
					
						
							|  |  |  | 					'-'+self.option, | 
					
						
							|  |  |  | 					self.current) | 
					
						
							|  |  |  | 			except TclError, msg: | 
					
						
							| 
									
										
										
										
											1994-08-03 08:10:35 +00:00
										 |  |  | 				print msg | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 				self.refresh() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	class booleanoption(remotewidgetoption, BooleanOption): pass | 
					
						
							|  |  |  | 	class enumoption(remotewidgetoption, EnumOption): pass | 
					
						
							|  |  |  | 	class stringoption(remotewidgetoption, StringOption): pass | 
					
						
							|  |  |  | 	class readonlyoption(remotewidgetoption, ReadonlyOption): pass | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def test(): | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	import sys | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 	root = Tk() | 
					
						
							|  |  |  | 	root.minsize(1, 1) | 
					
						
							| 
									
										
										
										
											1994-07-13 12:56:10 +00:00
										 |  |  | 	if sys.argv[1:]: | 
					
						
							|  |  |  | 		remotetest(root, sys.argv[1]) | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 	else: | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		frame = Frame(root, {'name': 'frame', | 
					
						
							|  |  |  | 				     Pack: {'expand': 1, 'fill': 'both'}, | 
					
						
							|  |  |  | 				     }) | 
					
						
							|  |  |  | 		button = Button(frame, {'name': 'button', | 
					
						
							|  |  |  | 					'text': 'button', | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 					Pack: {'expand': 1}}) | 
					
						
							| 
									
										
										
										
											1994-07-12 16:37:21 +00:00
										 |  |  | 		canvas = Canvas(frame, {'name': 'canvas', | 
					
						
							|  |  |  | 					Pack: {}}) | 
					
						
							|  |  |  | 		fpd = PackDialog(frame) | 
					
						
							|  |  |  | 		fwd = WidgetDialog(frame) | 
					
						
							| 
									
										
										
										
											1994-07-12 15:53:26 +00:00
										 |  |  | 		bpd = PackDialog(button) | 
					
						
							|  |  |  | 		bwd = WidgetDialog(button) | 
					
						
							|  |  |  | 		cpd = PackDialog(canvas) | 
					
						
							|  |  |  | 		cwd = WidgetDialog(canvas) | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | 	root.mainloop() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-13 12:56:10 +00:00
										 |  |  | def remotetest(root, app): | 
					
						
							|  |  |  | 	from listtree import listtree | 
					
						
							|  |  |  | 	list = listtree(root, app) | 
					
						
							|  |  |  | 	list.bind('<Any-Double-1>', opendialogs) | 
					
						
							|  |  |  | 	list.app = app			# Pass it on to handler | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def opendialogs(e): | 
					
						
							|  |  |  | 	import string | 
					
						
							|  |  |  | 	list = e.widget | 
					
						
							|  |  |  | 	sel = list.curselection() | 
					
						
							|  |  |  | 	for i in sel: | 
					
						
							|  |  |  | 		item = list.get(i) | 
					
						
							|  |  |  | 		widget = string.split(item)[0] | 
					
						
							|  |  |  | 		RemoteWidgetDialog(list, list.app, widget) | 
					
						
							|  |  |  | 		if widget == '.': continue | 
					
						
							|  |  |  | 		try: | 
					
						
							|  |  |  | 			RemotePackDialog(list, list.app, widget) | 
					
						
							|  |  |  | 		except TclError, msg: | 
					
						
							|  |  |  | 			print msg | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-07-12 08:58:25 +00:00
										 |  |  | test() |