[Idle-dev] CVS: idle ColorDelegator.py,1.2,1.3

Kurt B. Kaiser kbk@users.sourceforge.net
Thu, 12 Jul 2001 17:04:26 -0700


Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv1912

Modified Files:
	ColorDelegator.py 
Log Message:
py-cvs-rel2_1 (Rev 1.11 and 1.12) merge 
Colorize "as" after "import" / use DEBUG instead of __debug__


Index: ColorDelegator.py
===================================================================
RCS file: /cvsroot/idlefork/idle/ColorDelegator.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ColorDelegator.py	2001/07/04 03:15:10	1.2
--- ColorDelegator.py	2001/07/13 00:04:24	1.3
***************
*** 11,15 ****
  #$ unix <Control-slash>
  
! __debug__ = 0
  
  
--- 11,15 ----
  #$ unix <Control-slash>
  
! DEBUG = 0
  
  
***************
*** 29,32 ****
--- 29,33 ----
  prog = re.compile(make_pat(), re.S)
  idprog = re.compile(r"\s+(\w+)", re.S)
+ asprog = re.compile(r".*?\b(as)\b", re.S)
  
  class ColorDelegator(Delegator):
***************
*** 36,39 ****
--- 37,41 ----
          self.prog = prog
          self.idprog = idprog
+         self.asprog = asprog
  
      def setdelegate(self, delegate):
***************
*** 83,93 ****
          self.tag_add("TODO", index1, index2)
          if self.after_id:
!             if __debug__: print "colorizing already scheduled"
              return
          if self.colorizing:
              self.stop_colorizing = 1
!             if __debug__: print "stop colorizing"
          if self.allow_colorizing:
!             if __debug__: print "schedule colorizing"
              self.after_id = self.after(1, self.recolorize)
  
--- 85,95 ----
          self.tag_add("TODO", index1, index2)
          if self.after_id:
!             if DEBUG: print "colorizing already scheduled"
              return
          if self.colorizing:
              self.stop_colorizing = 1
!             if DEBUG: print "stop colorizing"
          if self.allow_colorizing:
!             if DEBUG: print "schedule colorizing"
              self.after_id = self.after(1, self.recolorize)
  
***************
*** 98,102 ****
              after_id = self.after_id
              self.after_id = None
!             if __debug__: print "cancel scheduled recolorizer"
              self.after_cancel(after_id)
          self.allow_colorizing = 0
--- 100,104 ----
              after_id = self.after_id
              self.after_id = None
!             if DEBUG: print "cancel scheduled recolorizer"
              self.after_cancel(after_id)
          self.allow_colorizing = 0
***************
*** 112,124 ****
              after_id = self.after_id
              self.after_id = None
!             if __debug__: print "cancel scheduled recolorizer"
              self.after_cancel(after_id)
          if self.allow_colorizing and self.colorizing:
!             if __debug__: print "stop colorizing"
              self.stop_colorizing = 1
          self.allow_colorizing = not self.allow_colorizing
          if self.allow_colorizing and not self.colorizing:
              self.after_id = self.after(1, self.recolorize)
!         if __debug__:
              print "auto colorizing turned", self.allow_colorizing and "on" or "off"
          return "break"
--- 114,126 ----
              after_id = self.after_id
              self.after_id = None
!             if DEBUG: print "cancel scheduled recolorizer"
              self.after_cancel(after_id)
          if self.allow_colorizing and self.colorizing:
!             if DEBUG: print "stop colorizing"
              self.stop_colorizing = 1
          self.allow_colorizing = not self.allow_colorizing
          if self.allow_colorizing and not self.colorizing:
              self.after_id = self.after(1, self.recolorize)
!         if DEBUG:
              print "auto colorizing turned", self.allow_colorizing and "on" or "off"
          return "break"
***************
*** 127,150 ****
          self.after_id = None
          if not self.delegate:
!             if __debug__: print "no delegate"
              return
          if not self.allow_colorizing:
!             if __debug__: print "auto colorizing is off"
              return
          if self.colorizing:
!             if __debug__: print "already colorizing"
              return
          try:
              self.stop_colorizing = 0
              self.colorizing = 1
!             if __debug__: print "colorizing..."
              t0 = time.clock()
              self.recolorize_main()
              t1 = time.clock()
!             if __debug__: print "%.3f seconds" % (t1-t0)
          finally:
              self.colorizing = 0
          if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
!             if __debug__: print "reschedule colorizing"
              self.after_id = self.after(1, self.recolorize)
          if self.close_when_done:
--- 129,152 ----
          self.after_id = None
          if not self.delegate:
!             if DEBUG: print "no delegate"
              return
          if not self.allow_colorizing:
!             if DEBUG: print "auto colorizing is off"
              return
          if self.colorizing:
!             if DEBUG: print "already colorizing"
              return
          try:
              self.stop_colorizing = 0
              self.colorizing = 1
!             if DEBUG: print "colorizing..."
              t0 = time.clock()
              self.recolorize_main()
              t1 = time.clock()
!             if DEBUG: print "%.3f seconds" % (t1-t0)
          finally:
              self.colorizing = 0
          if self.allow_colorizing and self.tag_nextrange("TODO", "1.0"):
!             if DEBUG: print "reschedule colorizing"
              self.after_id = self.after(1, self.recolorize)
          if self.close_when_done:
***************
*** 199,202 ****
--- 201,215 ----
                                                   head + "+%dc" % a,
                                                   head + "+%dc" % b)
+                             elif value == "import":
+                                 # color all the "as" words on same line;
+                                 # cheap approximation to the truth
+                                 while 1:
+                                     m1 = self.asprog.match(chars, b)
+                                     if not m1:
+                                         break
+                                     a, b = m1.span(1)
+                                     self.tag_add("KEYWORD",
+                                                  head + "+%dc" % a,
+                                                  head + "+%dc" % b)
                      m = self.prog.search(chars, m.end())
                  if "SYNC" in self.tag_names(next + "-1c"):
***************
*** 215,219 ****
                  self.update()
                  if self.stop_colorizing:
!                     if __debug__: print "colorizing stopped"
                      return
  
--- 228,232 ----
                  self.update()
                  if self.stop_colorizing:
!                     if DEBUG: print "colorizing stopped"
                      return