@@ -581,7 +581,11 @@ def makegrid(self, rows, columns):
581581 self .rows = rows
582582 self .columns = columns
583583 self .gridcells = {}
584- # Create the top row of labels
584+ # Create the top left corner cell (which selects all)
585+ cell = Tk .Label (self .cellgrid , relief = 'raised' )
586+ cell .grid_configure (column = 0 , row = 0 , sticky = 'NSWE' )
587+ cell .bind ("<ButtonPress-1>" , self .selectall )
588+ # Create the top row of labels, and confiure the grid columns
585589 for x in range (1 , columns + 1 ):
586590 self .cellgrid .grid_columnconfigure (x , minsize = 64 )
587591 cell = Tk .Label (self .cellgrid , text = colnum2name (x ), relief = 'raised' )
@@ -609,7 +613,7 @@ def makegrid(self, rows, columns):
609613 for y in range (1 , rows + 1 ):
610614 cell = Tk .Label (self .cellgrid , relief = 'sunken' ,
611615 bg = 'white' , fg = 'black' )
612- cell .grid_configure (column = x , row = y , sticky = 'NWSE ' )
616+ cell .grid_configure (column = x , row = y , sticky = 'NSWE ' )
613617 self .gridcells [x , y ] = cell
614618 cell .__x = x
615619 cell .__y = y
@@ -619,27 +623,31 @@ def makegrid(self, rows, columns):
619623 cell .bind ("<ButtonRelease-1>" , self .release )
620624 cell .bind ("<Shift-Button-1>" , self .release )
621625
626+ def selectall (self , event ):
627+ self .setcurrent (1 , 1 )
628+ self .setcorner (sys .maxint , sys .maxint )
629+
622630 def selectcolumn (self , event ):
623631 x , y = self .whichxy (event )
624632 self .setcurrent (x , 1 )
625- self .setcorner (x , self . rows )
633+ self .setcorner (x , sys . maxint )
626634
627635 def extendcolumn (self , event ):
628636 x , y = self .whichxy (event )
629637 if x > 0 :
630638 self .setcurrent (self .currentxy [0 ], 1 )
631- self .setcorner (x , self . rows )
639+ self .setcorner (x , sys . maxint )
632640
633641 def selectrow (self , event ):
634642 x , y = self .whichxy (event )
635643 self .setcurrent (1 , y )
636- self .setcorner (self . columns , y )
644+ self .setcorner (sys . maxint , y )
637645
638646 def extendrow (self , event ):
639647 x , y = self .whichxy (event )
640648 if y > 0 :
641649 self .setcurrent (1 , self .currentxy [1 ])
642- self .setcorner (self . columns , y )
650+ self .setcorner (sys . maxint , y )
643651
644652 def press (self , event ):
645653 x , y = self .whichxy (event )
@@ -691,17 +699,32 @@ def setcorner(self, x, y):
691699 x1 , x2 = x2 , x1
692700 if y1 > y2 :
693701 y1 , y2 = y2 , y1
694- for x in range (x1 , x2 + 1 ):
695- for y in range (y1 , y2 + 1 ):
696- gridcell = self .gridcells .get ((x , y ))
697- if gridcell is not None :
698- gridcell ['bg' ] = 'lightBlue'
702+ for (x , y ), cell in self .gridcells .iteritems ():
703+ if x1 <= x <= x2 and y1 <= y <= y2 :
704+ cell ['bg' ] = 'lightBlue'
699705 gridcell = self .gridcells .get (self .currentxy )
700706 if gridcell is not None :
701707 gridcell ['bg' ] = 'yellow'
702- name1 = cellname (* self .currentxy )
703- name2 = cellname (* self .cornerxy )
704- self .beacon ['text' ] = "%s:%s" % (name1 , name2 )
708+ self .setbeacon (x1 , y1 , x2 , y2 )
709+
710+ def setbeacon (self , x1 , y1 , x2 , y2 ):
711+ if x1 == y1 == 1 and x2 == y2 == sys .maxint :
712+ name = ":"
713+ elif (x1 , x2 ) == (1 , sys .maxint ):
714+ if y1 == y2 :
715+ name = "%d" % y1
716+ else :
717+ name = "%d:%d" % (y1 , y2 )
718+ elif (y1 , y2 ) == (1 , sys .maxint ):
719+ if x1 == x2 :
720+ name = "%s" % colnum2name (x1 )
721+ else :
722+ name = "%s:%s" % (colnum2name (x1 ), colnum2name (x2 ))
723+ else :
724+ name1 = cellname (* self .currentxy )
725+ name2 = cellname (* self .cornerxy )
726+ name = "%s:%s" % (name1 , name2 )
727+ self .beacon ['text' ] = name
705728
706729
707730 def clearfocus (self ):
@@ -712,11 +735,9 @@ def clearfocus(self):
712735 x1 , x2 = x2 , x1
713736 if y1 > y2 :
714737 y1 , y2 = y2 , y1
715- for x in range (x1 , x2 + 1 ):
716- for y in range (y1 , y2 + 1 ):
717- gridcell = self .gridcells .get ((x , y ))
718- if gridcell is not None :
719- gridcell ['bg' ] = 'white'
738+ for (x , y ), cell in self .gridcells .iteritems ():
739+ if x1 <= x <= x2 and y1 <= y <= y2 :
740+ cell ['bg' ] = 'white'
720741
721742 def return_event (self , event ):
722743 "Callback for the Return key."
0 commit comments