@@ -1067,31 +1067,32 @@ def _report_exception(self):
10671067 exc , val , tb = sys .exc_type , sys .exc_value , sys .exc_traceback
10681068 root = self ._root ()
10691069 root .report_callback_exception (exc , val , tb )
1070- # These used to be defined in Widget:
1071- def configure (self , cnf = None , ** kw ):
1072- """Configure resources of a widget.
1073-
1074- The values for resources are specified as keyword
1075- arguments. To get an overview about
1076- the allowed keyword arguments call the method keys.
1077- """
1078- # XXX ought to generalize this so tag_config etc. can use it
1070+ def _configure (self , cmd , cnf , kw ):
1071+ """Internal function."""
10791072 if kw :
10801073 cnf = _cnfmerge ((cnf , kw ))
10811074 elif cnf :
10821075 cnf = _cnfmerge (cnf )
10831076 if cnf is None :
10841077 cnf = {}
10851078 for x in self .tk .split (
1086- self .tk .call (self ._w , 'configure' )):
1079+ self .tk .call (_flatten (( self ._w , cmd )) )):
10871080 cnf [x [0 ][1 :]] = (x [0 ][1 :],) + x [1 :]
10881081 return cnf
10891082 if type (cnf ) is StringType :
1090- x = self .tk .split (self . tk . call (
1091- self ._w , 'configure' , '-' + cnf ))
1083+ x = self .tk .split (
1084+ self .tk . call ( _flatten (( self . _w , cmd , '-' + cnf )) ))
10921085 return (x [0 ][1 :],) + x [1 :]
1093- self .tk .call ((self ._w , 'configure' )
1094- + self ._options (cnf ))
1086+ self .tk .call (_flatten ((self ._w , cmd )) + self ._options (cnf ))
1087+ # These used to be defined in Widget:
1088+ def configure (self , cnf = None , ** kw ):
1089+ """Configure resources of a widget.
1090+
1091+ The values for resources are specified as keyword
1092+ arguments. To get an overview about
1093+ the allowed keyword arguments call the method keys.
1094+ """
1095+ return self ._configure ('configure' , cnf , kw )
10951096 config = configure
10961097 def cget (self , key ):
10971098 """Return the resource value for a KEY given as string."""
@@ -2043,19 +2044,7 @@ def itemconfigure(self, tagOrId, cnf=None, **kw):
20432044 arguments. To get an overview about
20442045 the allowed keyword arguments call the method without arguments.
20452046 """
2046- if cnf is None and not kw :
2047- cnf = {}
2048- for x in self .tk .split (
2049- self .tk .call (self ._w ,
2050- 'itemconfigure' , tagOrId )):
2051- cnf [x [0 ][1 :]] = (x [0 ][1 :],) + x [1 :]
2052- return cnf
2053- if type (cnf ) == StringType and not kw :
2054- x = self .tk .split (self .tk .call (
2055- self ._w , 'itemconfigure' , tagOrId , '-' + cnf ))
2056- return (x [0 ][1 :],) + x [1 :]
2057- self .tk .call ((self ._w , 'itemconfigure' , tagOrId ) +
2058- self ._options (cnf , kw ))
2047+ return self ._configure (('itemconfigure' , tagOrId ), cnf , kw )
20592048 itemconfig = itemconfigure
20602049 # lower, tkraise/lift hide Misc.lower, Misc.tkraise/lift,
20612050 # so the preferred name for them is tag_lower, tag_raise
@@ -2383,18 +2372,7 @@ def itemconfigure(self, index, cnf=None, **kw):
23832372 call the method without arguments.
23842373 Valid resource names: background, bg, foreground, fg,
23852374 selectbackground, selectforeground."""
2386- if cnf is None and not kw :
2387- cnf = {}
2388- for x in self .tk .split (
2389- self .tk .call (self ._w , 'itemconfigure' , index )):
2390- cnf [x [0 ][1 :]] = (x [0 ][1 :],) + x [1 :]
2391- return cnf
2392- if type (cnf ) == StringType and not kw :
2393- x = self .tk .split (self .tk .call (
2394- self ._w , 'itemconfigure' , index , '-' + cnf ))
2395- return (x [0 ][1 :],) + x [1 :]
2396- self .tk .call ((self ._w , 'itemconfigure' , index ) +
2397- self ._options (cnf , kw ))
2375+ return self ._configure (('itemconfigure' , index ), cnf , kw )
23982376 itemconfig = itemconfigure
23992377
24002378class Menu (Widget ):
@@ -2481,18 +2459,7 @@ def entrycget(self, index, option):
24812459 return self .tk .call (self ._w , 'entrycget' , index , '-' + option )
24822460 def entryconfigure (self , index , cnf = None , ** kw ):
24832461 """Configure a menu item at INDEX."""
2484- if cnf is None and not kw :
2485- cnf = {}
2486- for x in self .tk .split (self .tk .call (
2487- (self ._w , 'entryconfigure' , index ))):
2488- cnf [x [0 ][1 :]] = (x [0 ][1 :],) + x [1 :]
2489- return cnf
2490- if type (cnf ) == StringType and not kw :
2491- x = self .tk .split (self .tk .call (
2492- (self ._w , 'entryconfigure' , index , '-' + cnf )))
2493- return (x [0 ][1 :],) + x [1 :]
2494- self .tk .call ((self ._w , 'entryconfigure' , index )
2495- + self ._options (cnf , kw ))
2462+ return self ._configure (('entryconfigure' , index ), cnf , kw )
24962463 entryconfig = entryconfigure
24972464 def index (self , index ):
24982465 """Return the index of a menu item identified by INDEX."""
@@ -2719,18 +2686,9 @@ def image_cget(self, index, option):
27192686 if option [- 1 :] == "_" :
27202687 option = option [:- 1 ]
27212688 return self .tk .call (self ._w , "image" , "cget" , index , option )
2722- def image_configure (self , index , cnf = {} , ** kw ):
2689+ def image_configure (self , index , cnf = None , ** kw ):
27232690 """Configure an embedded image at INDEX."""
2724- if not cnf and not kw :
2725- cnf = {}
2726- for x in self .tk .split (
2727- self .tk .call (
2728- self ._w , "image" , "configure" , index )):
2729- cnf [x [0 ][1 :]] = (x [0 ][1 :],) + x [1 :]
2730- return cnf
2731- apply (self .tk .call ,
2732- (self ._w , "image" , "configure" , index )
2733- + self ._options (cnf , kw ))
2691+ return self ._configure (('image' , 'configure' , index ), cnf , kw )
27342692 def image_create (self , index , cnf = {}, ** kw ):
27352693 """Create an embedded image at INDEX."""
27362694 return apply (self .tk .call ,
@@ -2821,15 +2779,9 @@ def tag_cget(self, tagName, option):
28212779 if option [- 1 :] == '_' :
28222780 option = option [:- 1 ]
28232781 return self .tk .call (self ._w , 'tag' , 'cget' , tagName , option )
2824- def tag_configure (self , tagName , cnf = {} , ** kw ):
2782+ def tag_configure (self , tagName , cnf = None , ** kw ):
28252783 """Configure a tag TAGNAME."""
2826- if type (cnf ) == StringType :
2827- x = self .tk .split (self .tk .call (
2828- self ._w , 'tag' , 'configure' , tagName , '-' + cnf ))
2829- return (x [0 ][1 :],) + x [1 :]
2830- self .tk .call (
2831- (self ._w , 'tag' , 'configure' , tagName )
2832- + self ._options (cnf , kw ))
2784+ return self ._configure (('tag' , 'configure' , tagName ), cnf , kw )
28332785 tag_config = tag_configure
28342786 def tag_delete (self , * tagNames ):
28352787 """Delete all tags in TAGNAMES."""
@@ -2874,16 +2826,9 @@ def window_cget(self, index, option):
28742826 if option [- 1 :] == '_' :
28752827 option = option [:- 1 ]
28762828 return self .tk .call (self ._w , 'window' , 'cget' , index , option )
2877- def window_configure (self , index , cnf = {} , ** kw ):
2829+ def window_configure (self , index , cnf = None , ** kw ):
28782830 """Configure an embedded window at INDEX."""
2879- if type (cnf ) == StringType :
2880- x = self .tk .split (self .tk .call (
2881- self ._w , 'window' , 'configure' ,
2882- index , '-' + cnf ))
2883- return (x [0 ][1 :],) + x [1 :]
2884- self .tk .call (
2885- (self ._w , 'window' , 'configure' , index )
2886- + self ._options (cnf , kw ))
2831+ return self ._configure (('window' , 'configure' , index ), cnf , kw )
28872832 window_config = window_configure
28882833 def window_create (self , index , cnf = {}, ** kw ):
28892834 """Create a window at INDEX."""
0 commit comments