[Idle-dev] Fw: Calltip's patch...
Josh Robb
josh_robb@fastmail.fm
Tue, 1 Oct 2002 01:14:23 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0186_01C268E7.E0739340
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Dam, dam, dam... sorry about that!
Here's the attatchment.
j.
------=_NextPart_000_0186_01C268E7.E0739340
Content-Type: application/octet-stream;
name="calltip.diffs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="calltip.diffs"
Index: CallTips.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/idlefork/idle/CallTips.py,v
retrieving revision 1.6
diff -c -r1.6 CallTips.py
*** CallTips.py 15 Sep 2002 22:02:58 -0000 1.6
--- CallTips.py 30 Sep 2002 20:33:27 -0000
***************
*** 13,18 ****
--- 13,28 ----
self.editwin =3D editwin
self.text =3D editwin.text
self.calltip =3D None
+=20
+ self.line =3D 0
+ self.member =3D None
+ self.members =3D []
+ self.sub_members =3D []
+ self.word =3D ""
+ self.wordchars =3D =
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' \
+ '!"#$%&\'()*+,-/:;<=3D>?@[\\]^_`{|}~ =
\t\n\r\x0b\x0c'
+ self.pattern =3D ""
+ =20
if hasattr(self.text, "make_calltip_window"):
self._make_calltip_window =3D =
self.text.make_calltip_window
else:
***************
*** 33,44 ****
self.calltip =3D None
=20
def paren_open_event(self, event):
self._remove_calltip_window()
arg_text =3D get_arg_text(self.get_object_at_cursor())
if arg_text:
! self.calltip_start =3D self.text.index("insert")
self.calltip =3D self._make_calltip_window()
! self.calltip.showtip(arg_text)
return "" #so the event is handled normally.
=20
def paren_close_event(self, event):
--- 43,56 ----
self.calltip =3D None
=20
def paren_open_event(self, event):
+ self.member =3D None =20
self._remove_calltip_window()
arg_text =3D get_arg_text(self.get_object_at_cursor())
if arg_text:
! self.calltip_start =3D self.text.index("insert+1c")
self.calltip =3D self._make_calltip_window()
! list =3D [arg_text]
! self.calltip.showtip(list)
return "" #so the event is handled normally.
=20
def paren_close_event(self, event):
***************
*** 47,52 ****
--- 59,160 ----
self._remove_calltip_window()
return "" #so the event is handled normally.
=20
+ def dot_check_event(self, event):
+ self._remove_calltip_window()
+ obj =3D self.get_object_at_cursor()
+=20
+ if obj:
+ names =3D dir(obj)
+ names.sort()
+ self.member =3D 'true'
+ self.members =3D []
+ self.word =3D ""
+ self.line =3D 0
+ for name in names:
+ if (name.find("__",0) =3D=3D 0):
+ pass
+ else:
+ subobj =3D getattr(obj, name)
+ if callable(subobj):
+ self.members.append(name + "(...)")
+ else:
+ self.members.append(name)
+=20
+ if self.members:
+ self.calltip_start =3D self.text.index("insert+1c")
+ self.calltip =3D self._make_calltip_window()
+ self.sub_members =3D self.members
+ self.calltip.showtip(self.members,1)
+=20
+ return "" #so the event is handled normally. =20
+=20
+ # TODO: rename event?
+ def check_key_event(self, event):
+ if not self.member:
+ return ""
+ =20
+ if self.calltip:
+ #TODO: customize keys.
+ if event.keysym =3D=3D 'space':
+ self._remove_calltip_window()
+ =20
+ if self.sub_members:
+ first =3D len(self.word)
+ last =3D self.sub_members[self.line].rfind("(")
+ if last < 0:
+ last =3D len(self.sub_members[self.line])
+ self.text.insert("insert", =
self.sub_members[self.line][first:last])
+ #TODO do we need to remove the calltip window?
+ return "break"
+ =20
+ elif (self.wordchars.find(event.keysym) > -1):
+ text =3D self.text
+ chars =3D text.get("insert linestart", "insert")
+ i =3D len(chars)
+ while i and chars[i-1] in self.wordchars:
+ i =3D i-1
+ self.word =3D chars[i:] + event.keysym
+ if self.word:
+ self.sub_members =3D []
+ self.line =3D 0
+ for member in self.members:
+ if member.find(self.word) =3D=3D 0:
+ self.sub_members.append(member)
+ if len(self.sub_members) =3D=3D 0:
+ self._remove_calltip_window()
+ else:
+ self._remove_calltip_window()
+ # self.calltip_start =3D =
self.text.index("insert")
+ self.calltip =3D self._make_calltip_window()
+ =
self.calltip.showtip(self.sub_members,1-len(self.word))
+ else:
+ pass
+ return "" #so the event is handled normally.
+=20
+ def calltip_down_event(self, event):
+ if self.calltip:
+ if self.line < (len(self.sub_members) - 1):
+ self.line +=3D 1
+ #TODO: can't we speed this up?
+ self._remove_calltip_window()
+ self.calltip =3D self._make_calltip_window()
+ =
self.calltip.showtip(self.sub_members,-len(self.word),self.line) =
=20
+ return "break" #skip further event handling.
+ else:
+ return "" #so the event is handled normally.
+=20
+ def calltip_up_event(self, event):
+ if self.calltip:
+ if self.line > 0:
+ self.line -=3D 1
+ #TODO: can't we speed this up?
+ self._remove_calltip_window()
+ self.calltip =3D self._make_calltip_window()
+ =
self.calltip.showtip(self.sub_members,-len(self.word),self.line) =20
+ return "break" #skip further event handling.
+ else:
+ return "" #so the event is handled normally.
+ =20
def check_calltip_cancel_event(self, event):
if self.calltip:
# If we have moved before the start of the calltip,
Index: CallTipWindow.py
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/idlefork/idle/CallTipWindow.py,v
retrieving revision 1.5
diff -c -r1.5 CallTipWindow.py
*** CallTipWindow.py 23 Sep 2002 01:04:05 -0000 1.5
--- CallTipWindow.py 30 Sep 2002 20:33:27 -0000
***************
*** 12,30 ****
self.id =3D None
self.x =3D self.y =3D 0
=20
! def showtip(self, text):
# SF bug 546078: IDLE calltips cause application error.
# There were crashes on various Windows flavors, and even a
# crashing X server on Linux, with very long calltips.
! if len(text) >=3D 79:
! text =3D text[:75] + ' ...'
! self.text =3D text
=20
! if self.tipwindow or not self.text:
return
self.widget.see("insert")
! x, y, cx, cy =3D self.widget.bbox("insert")
! x =3D x + self.widget.winfo_rootx() + 2
y =3D y + cy + self.widget.winfo_rooty()
self.tipwindow =3D tw =3D Toplevel(self.widget)
tw.wm_overrideredirect(1)
--- 12,54 ----
self.id =3D None
self.x =3D self.y =3D 0
=20
! def showtip(self, texts, xoffset=3D0, line=3D0, maxcount=3D10):
# SF bug 546078: IDLE calltips cause application error.
# There were crashes on various Windows flavors, and even a
# crashing X server on Linux, with very long calltips.
! tmp =3D []
! for text in texts:
! if len(text) >=3D 75:
! text =3D text[:75] + ' ...'
! tmp.append(text)
! texts =3D tmp
=20
! self.texts =3D texts # List of text strings
! if self.tipwindow or not self.texts:
return
+ # Setup visible region
+ if maxcount < 0:
+ maxcount =3D 1
+ first =3D 0
+ last =3D len(self.texts)
+ if line > first:
+ first =3D line
+ if first > last:
+ first =3D last
+ if (last - first + 1) > maxcount:
+ last =3D first + maxcount
+=20
+ # Extract visible region
+ self.text =3D "\n".join(self.texts[first:last])
+=20
self.widget.see("insert")
! # To avoid incorrect values for cx take "insert - 1 chars"
! x, y, cx, cy =3D self.widget.bbox("insert - 1 chars")
! # Estimate current cursor position
! x =3D x + cx
!=20
! # Top left coordinates for the new toplevel widget
! x =3D x + cx*xoffset + self.widget.winfo_rootx() - 1=20
y =3D y + cy + self.widget.winfo_rooty()
self.tipwindow =3D tw =3D Toplevel(self.widget)
tw.wm_overrideredirect(1)
***************
*** 68,77 ****
text.bind("<<calltip-hide>>", self.calltip_hide)
=20
text.focus_set()
! # root.mainloop() # not in idle
=20
def calltip_show(self, event):
! self.calltip.showtip("Hello world")
=20
def calltip_hide(self, event):
self.calltip.hidetip()
--- 92,101 ----
text.bind("<<calltip-hide>>", self.calltip_hide)
=20
text.focus_set()
! root.mainloop() # not in idle
=20
def calltip_show(self, event):
! self.calltip.showtip(["Hello world"])
=20
def calltip_hide(self, event):
self.calltip.hidetip()
Index: config-extensions.def
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/idlefork/idle/config-extensions.def,v
retrieving revision 1.7
diff -c -r1.7 config-extensions.def
*** config-extensions.def 14 Sep 2002 03:15:06 -0000 1.7
--- config-extensions.def 30 Sep 2002 20:33:27 -0000
***************
*** 47,52 ****
--- 47,56 ----
paren-close=3D<Key-parenright>
check-calltip-cancel=3D<KeyRelease>
calltip-cancel=3D<ButtonPress> <Key-Escape>
+ dot-check=3D<Key-.>
+ check-key=3D<Key>
+ calltip-down=3D<Key-Down>
+ calltip-up=3D<Key-Up>
=20
[ParenMatch]
enable=3D0
------=_NextPart_000_0186_01C268E7.E0739340--