[Idle-dev] CVS: idle EditorWindow.py,1.30,1.31

Kurt B. Kaiser kbk@users.sourceforge.net
Sun, 15 Sep 2002 19:13:17 -0700


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

Modified Files:
	EditorWindow.py 
Log Message:
Merge Py Idle changes:

Rev 1.39 GvR
Properly fix SF bug #507298 (Gregor Lingl): shellpython2.2 -Qnew smart
indent error

Use // where int division is intended.  (This breaks IDLE for use with
previous Python versions -- I don't care.)

Rev 1.40 tim_one
Convert a pile of obvious "yes/no" functions to return bool.

Rev 1.41 foffani/loewis
(already merged)  - MS html help

Rev 1.42 
(skip, done differently in Idlefork)

Rev 1.43 tzot/rhettinger
Extended IDLE's open module menu item to handle hierarchical module names.
Will look at doing something similar in import.c so that the effort won't
have to be repeated elsewhere.
Closes SF patch 600152.

Rev 1.44 doerwalter
(string methods)


Index: EditorWindow.py
===================================================================
RCS file: /cvsroot/idlefork/idle/EditorWindow.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** EditorWindow.py	15 Sep 2002 21:31:30 -0000	1.30
--- EditorWindow.py	16 Sep 2002 02:13:15 -0000	1.31
***************
*** 20,23 ****
--- 20,37 ----
  TK_TABWIDTH_DEFAULT = 8
  
+ def _find_module(fullname, path=None):
+     """Version of imp.find_module() that handles hierarchical module names"""
+ 
+     file = None
+     for tgt in fullname.split('.'):
+         if file is not None:
+             file.close()            # close intermediate files
+         (file, filename, descr) = imp.find_module(tgt, path)
+         if descr[2] == imp.PY_SOURCE:
+             break                   # find but not load the source file
+         module = imp.load_module(tgt, file, filename, descr)
+         path = module.__path__
+     return file, filename, descr
+ 
  class EditorWindow:
      from Percolator import Percolator
***************
*** 184,188 ****
  
      def set_line_and_column(self, event=None):
!         line, column = string.split(self.text.index(INSERT), '.')
          self.status_bar.set_label('column', 'Col: %s' % column)
          self.status_bar.set_label('line', 'Ln: %s' % line)
--- 198,202 ----
  
      def set_line_and_column(self, event=None):
!         line, column = self.text.index(INSERT).split('.')
          self.status_bar.set_label('column', 'Col: %s' % column)
          self.status_bar.set_label('line', 'Ln: %s' % line)
***************
*** 347,351 ****
              name = ""
          else:
!             name = string.strip(name)
          if not name:
              name = tkSimpleDialog.askstring("Module",
--- 361,365 ----
              name = ""
          else:
!             name = name.strip()
          if not name:
              name = tkSimpleDialog.askstring("Module",
***************
*** 354,364 ****
                       parent=self.text)
              if name:
!                 name = string.strip(name)
              if not name:
                  return
-         # XXX Ought to support package syntax
          # XXX Ought to insert current file's directory in front of path
          try:
!             (f, file, (suffix, mode, type)) = imp.find_module(name)
          except (NameError, ImportError), msg:
              tkMessageBox.showerror("Import error", str(msg), parent=self.text)
--- 368,377 ----
                       parent=self.text)
              if name:
!                 name = name.strip()
              if not name:
                  return
          # XXX Ought to insert current file's directory in front of path
          try:
!             (f, file, (suffix, mode, type)) = _find_module(name)
          except (NameError, ImportError), msg:
              tkMessageBox.showerror("Import error", str(msg), parent=self.text)
***************
*** 402,409 ****
      def ispythonsource(self, filename):
          if not filename:
!             return 1
          base, ext = os.path.splitext(os.path.basename(filename))
          if os.path.normcase(ext) in (".py", ".pyw"):
!             return 1
          try:
              f = open(filename)
--- 415,422 ----
      def ispythonsource(self, filename):
          if not filename:
!             return True
          base, ext = os.path.splitext(os.path.basename(filename))
          if os.path.normcase(ext) in (".py", ".pyw"):
!             return True
          try:
              f = open(filename)
***************
*** 411,416 ****
              f.close()
          except IOError:
!             return 0
!         return line[:2] == '#!' and string.find(line, 'python') >= 0
  
      def close_hook(self):
--- 424,429 ----
              f.close()
          except IOError:
!             return False
!         return line.startswith('#!') and 'python' in line
  
      def close_hook(self):
***************
*** 622,626 ****
          lineno = self.getlineno(mark)
          height = bot - top
!         newtop = max(1, lineno - height/2)
          text.yview(float(newtop))
  
--- 635,639 ----
          lineno = self.getlineno(mark)
          height = bot - top
!         newtop = max(1, lineno - height//2)
          text.yview(float(newtop))
  
***************
*** 713,717 ****
              self.apply_bindings(keydefs)
              for vevent in keydefs.keys():
!                 methodname = string.replace(vevent, "-", "_")
                  while methodname[:1] == '<':
                      methodname = methodname[1:]
--- 726,730 ----
              self.apply_bindings(keydefs)
              for vevent in keydefs.keys():
!                 methodname = vevent.replace("-", "_")
                  while methodname[:1] == '<':
                      methodname = methodname[1:]
***************
*** 1301,1305 ****
      # Helper to extract the underscore from a string, e.g.
      # prepstr("Co_py") returns (2, "Copy").
!     i = string.find(s, '_')
      if i >= 0:
          s = s[:i] + s[i+1:]
--- 1314,1318 ----
      # Helper to extract the underscore from a string, e.g.
      # prepstr("Co_py") returns (2, "Copy").
!     i = s.find('_')
      if i >= 0:
          s = s[:i] + s[i+1:]
***************
*** 1318,1322 ****
          return ""
      s = keylist[0]
!     s = re.sub(r"-[a-z]\b", lambda m: string.upper(m.group()), s)
      s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
      s = re.sub("Key-", "", s)
--- 1331,1335 ----
          return ""
      s = keylist[0]
!     s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
      s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
      s = re.sub("Key-", "", s)