summaryrefslogtreecommitdiffstats
path: root/Tools/pynche/PyncheWidget.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1998-12-03 19:50:24 (GMT)
committerBarry Warsaw <barry@python.org>1998-12-03 19:50:24 (GMT)
commitce0bbd270b6f8ae82d3e164c0d95a99a0c1c235c (patch)
treea0e0cc9a3360265d21e52aca64891edb240d73fd /Tools/pynche/PyncheWidget.py
parenteb6b9b7ebb30cc3e5abc4aec3f79a3b6f81c7ae5 (diff)
downloadcpython-ce0bbd270b6f8ae82d3e164c0d95a99a0c1c235c.zip
cpython-ce0bbd270b6f8ae82d3e164c0d95a99a0c1c235c.tar.gz
cpython-ce0bbd270b6f8ae82d3e164c0d95a99a0c1c235c.tar.bz2
Added Helpwin -- help in a text widget
Diffstat (limited to 'Tools/pynche/PyncheWidget.py')
-rw-r--r--Tools/pynche/PyncheWidget.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/Tools/pynche/PyncheWidget.py b/Tools/pynche/PyncheWidget.py
index 843efd7..1e651a3 100644
--- a/Tools/pynche/PyncheWidget.py
+++ b/Tools/pynche/PyncheWidget.py
@@ -4,6 +4,9 @@ This window provides the basic decorations, primarily including the menubar.
It is used to bring up other windows.
"""
+import sys
+import os
+import string
from Tkinter import *
import tkMessageBox
@@ -19,6 +22,7 @@ class PyncheWidget:
self.__textwin = None
self.__listwin = None
self.__detailswin = None
+ self.__helpwin = None
modal = self.__modal = not not master
# If a master was given, we are running as a modal dialog servant to
# some other application. We rearrange our UI in this case (there's
@@ -73,6 +77,9 @@ class PyncheWidget:
helpmenu.add_command(label='About Pynche...',
command=self.__popup_about,
underline=0)
+ helpmenu.add_command(label='Help...',
+ command=self.__popup_usage,
+ underline=0)
#
# Tie them all together
#
@@ -153,6 +160,11 @@ For information contact
author: Barry A. Warsaw
email : bwarsaw@python.org''' % __version__)
+ def __popup_usage(self, event=None):
+ if not self.__helpwin:
+ self.__helpwin = Helpwin(self.__root, self.__quit)
+ self.__helpwin.deiconify()
+
def __popup_text(self, event=None):
if not self.__textwin:
from TextViewer import TextViewer
@@ -179,3 +191,51 @@ email : bwarsaw@python.org''' % __version__)
def deiconify(self):
self.__root.deiconify()
+
+
+
+class Helpwin:
+ def __init__(self, master, quitfunc):
+ from Main import __version__, docstring
+ self.__root = root = Toplevel(master, class_='Pynche')
+ root.protocol('WM_DELETE_WINDOW', self.__withdraw)
+ root.title('Pynche Help Window')
+ root.iconname('Pynche Help Window')
+ root.bind('<Alt-q>', quitfunc)
+ root.bind('<Alt-Q>', quitfunc)
+ root.bind('<Alt-w>', self.__withdraw)
+ root.bind('<Alt-W>', self.__withdraw)
+
+ # more elaborate help is available in the README file
+ readmefile = os.path.join(sys.path[0], 'README')
+ try:
+ fp = None
+ try:
+ fp = open(readmefile)
+ contents = fp.read()
+ # wax the last page, it contains Emacs cruft
+ i = string.rfind(contents, '\f')
+ if i > 0:
+ contents = string.rstrip(contents[:i])
+ finally:
+ if fp:
+ fp.close()
+ except IOError:
+ sys.stderr.write("Couldn't open Pynche's README, "
+ 'using docstring instead.\n')
+ contents = docstring()
+
+ self.__text = text = Text(root, relief=SUNKEN,
+ width=80, height=24)
+ text.insert(0.0, contents)
+ scrollbar = Scrollbar(root)
+ scrollbar.pack(fill=Y, side=RIGHT)
+ text.pack(fill=BOTH, expand=YES)
+ text.configure(yscrollcommand=(scrollbar, 'set'))
+ scrollbar.configure(command=(text, 'yview'))
+
+ def __withdraw(self, event=None):
+ self.__root.withdraw()
+
+ def deiconify(self):
+ self.__root.deiconify()