Python
  Home arrow Python arrow Page 2 - Finishing the PyMailGUI Client: User H...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Finishing the PyMailGUI Client: User Help Tools
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-08-09

    Table of Contents:
  • Finishing the PyMailGUI Client: User Help Tools
  • popuputil: General-Purpose GUI Pop Ups
  • wraplines: Line Split Tools
  • mailcon
  • PyMailGuiHelp: User Help Text
  • Ideas for Improvement

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Finishing the PyMailGUI Client: User Help Tools - popuputil: General-Purpose GUI Pop Ups
    (Page 2 of 6 )

    Example 15-6 implements a handful of utility pop-up windows in a module, in case they ever prove useful in other programs. Note that the same windows utility module is imported here, to give a common look-and-feel to the popups (icons, titles, and so on).

    Example 15-6. PP3E\Internet\Email\PyMailGui\popuputil.py

    ################################################################ # utility windows - may be useful in other programs ###############################################################

    from Tkinter import *
    from PP3E.Gui.Tools.windows import PopupWindow

    class HelpPopup(PopupWindow):
        """
        custom Toplevel that shows help text as scrolled text
        source button runs a passed-in callback handler
        alternative: use HTML file and webbrowser module
        """
        myfont = 'system' # customizable

        def __init__(self, appname, helptext, iconfile=None, showsource=lambda:0):  
            PopupWindow.__init__(self, appname, 'Help', iconfile)
           
    from ScrolledText import ScrolledText                       # a nonmodal dialog
            bar = Frame(self)          # pack first=clip last
            bar.pack(side=BOTTOM, fill=X)
           
    code = Button(bar, bg='beige', text="Source", command=showsource)
            quit = Button(bar, bg='beige', text="Cancel", command=self.destroy) 
            code.pack(pady=1, side=LEFT)
            quit.pack(pady=1, side=LEFT)
            text = ScrolledText(self)      # add
    Text + scrollbar
            text.config(font=self.myfont, width=70)                              # too big for showinfo
            text.config(bg='steelblue', fg='white')                            # erase on btn or return
            text.insert('0.0', helptext)
            text.pack(expand=YES, fill=BOTH)
            self.bind("<Return>", (lambda event: self.destroy()))

        def askPasswordWindow(appname, prompt):
            """
            modal dialog to input password string
            getpass.getpass uses stdin, not GUI
           
    tkSimpleDialog.askstring echos input
            """
            win = PopupWindow(appname,
    'Prompt')                            # a configured Toplevel
            Label(win, text=prompt).pack(side=LEFT)
            entvar = StringVar(win)
            ent = Entry(win, textvariable=entvar, show='*')       # display * for input
            ent.pack(side=RIGHT, expand=YES, fill=X)
            ent.bind('<Return>', lambda event: win.destroy())
           
    ent.focus_set(); win.grab_set(); win.wait_window()
            win.update()                # update forces redraw
            return entvar.get()         # ent widget is now gone

        class BusyBoxWait(PopupWindow):
            """
            pop up blocking wait message box: thread waits
            main GUI event thread stays alive during wait
            but GUI is inoperable during this wait state;
            uses quit redef here because lower, not leftmost;
            """
            def __init__(self, appname, message):
               
    PopupWindow.__init__(self, appname, 'Busy')
                self.protocol('WM_DELETE_WINDOW', lambda:0)      # ignore deletes
                label = Label(self,
    text=message + '...')               # win.quit() to erase
                label.config(height=10, width=40, cursor='watch')           # busy cursor
                label.pack()
                self.makeModal()
                self.message, self.label = message, label
           
    def makeModal(self):
                self.focus_set()        # grab application
                self.grab_set()         # wait for threadexit
           
    def changeText(self, newtext):
                self.label.config(text=self.message + ': ' + newtext)
            def quit(self):
                self.destroy()          # don't verify quit

        class BusyBoxNowait(BusyBoxWait):
            """
            pop up nonblocking wait window
            call changeText to show progress, quit to close
            """
            def makeModal(self):
               
    pass

        if __name__ == '__main__':
            HelpPopup('spam', 'See figure 1...\n')
            print askPasswordWindow('spam', 'enter password')
            raw_input('Enter to exit')

    More Python Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming Python, Third Edition,"...
     

    Buy this book now. This article is excerpted from chapter 15 of the book Programming Python, Third Edition, written by Mark Lutz (O'Reilly, 2006; ISBN: 0596009259). Check it out today at your favorite bookstore. Buy this book now.

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway