Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/configSectionNameDialog.py

    r2 r391  
    22Dialog that allows user to specify a new config file section name.
    33Used to get new highlight theme and keybinding set names.
     4The 'return value' for the dialog, used two placed in configDialog.py,
     5is the .result attribute set in the Ok and Cancel methods.
    46"""
    57from Tkinter import *
    68import tkMessageBox
    7 
    89class GetCfgSectionNameDialog(Toplevel):
    9     def __init__(self,parent,title,message,usedNames):
     10    def __init__(self, parent, title, message, used_names):
    1011        """
    1112        message - string, informational message to display
    12         usedNames - list, list of names already in use for validity check
     13        used_names - string collection, names already in use for validity check
    1314        """
    1415        Toplevel.__init__(self, parent)
    1516        self.configure(borderwidth=5)
    16         self.resizable(height=FALSE,width=FALSE)
     17        self.resizable(height=FALSE, width=FALSE)
    1718        self.title(title)
    1819        self.transient(parent)
     
    2021        self.protocol("WM_DELETE_WINDOW", self.Cancel)
    2122        self.parent = parent
    22         self.message=message
    23         self.usedNames=usedNames
    24         self.result=''
    25         self.CreateWidgets()
    26         self.withdraw() #hide while setting geometry
     23        self.message = message
     24        self.used_names = used_names
     25        self.create_widgets()
     26        self.withdraw()  #hide while setting geometry
    2727        self.update_idletasks()
    2828        #needs to be done here so that the winfo_reqwidth is valid
    2929        self.messageInfo.config(width=self.frameMain.winfo_reqwidth())
    30         self.geometry("+%d+%d" %
    31             ((parent.winfo_rootx()+((parent.winfo_width()/2)
    32                 -(self.winfo_reqwidth()/2)),
    33               parent.winfo_rooty()+((parent.winfo_height()/2)
    34                 -(self.winfo_reqheight()/2)) )) ) #centre dialog over parent
    35         self.deiconify() #geometry set, unhide
     30        self.geometry(
     31                "+%d+%d" % (
     32                parent.winfo_rootx() +
     33                (parent.winfo_width()/2 - self.winfo_reqwidth()/2),
     34                parent.winfo_rooty() +
     35                (parent.winfo_height()/2 - self.winfo_reqheight()/2)
     36                ) )  #centre dialog over parent
     37        self.deiconify()  #geometry set, unhide
    3638        self.wait_window()
     39    def create_widgets(self):
     40        self.name = StringVar(self.parent)
     41        self.fontSize = StringVar(self.parent)
     42        self.frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
     43        self.frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
     44        self.messageInfo = Message(self.frameMain, anchor=W, justify=LEFT,
     45                    padx=5, pady=5, text=self.message) #,aspect=200)
     46        entryName = Entry(self.frameMain, textvariable=self.name, width=30)
     47        entryName.focus_set()
     48        self.messageInfo.pack(padx=5, pady=5) #, expand=TRUE, fill=BOTH)
     49        entryName.pack(padx=5, pady=5)
     50        frameButtons = Frame(self, pady=2)
     51        frameButtons.pack(side=BOTTOM)
     52        self.buttonOk = Button(frameButtons, text='Ok',
     53                width=8, command=self.Ok)
     54        self.buttonOk.pack(side=LEFT, padx=5)
     55        self.buttonCancel = Button(frameButtons, text='Cancel',
     56                width=8, command=self.Cancel)
     57        self.buttonCancel.pack(side=RIGHT, padx=5)
    3758
    38     def CreateWidgets(self):
    39         self.name=StringVar(self)
    40         self.fontSize=StringVar(self)
    41         self.frameMain = Frame(self,borderwidth=2,relief=SUNKEN)
    42         self.frameMain.pack(side=TOP,expand=TRUE,fill=BOTH)
    43         self.messageInfo=Message(self.frameMain,anchor=W,justify=LEFT,padx=5,pady=5,
    44                 text=self.message)#,aspect=200)
    45         entryName=Entry(self.frameMain,textvariable=self.name,width=30)
    46         entryName.focus_set()
    47         self.messageInfo.pack(padx=5,pady=5)#,expand=TRUE,fill=BOTH)
    48         entryName.pack(padx=5,pady=5)
    49         frameButtons=Frame(self)
    50         frameButtons.pack(side=BOTTOM,fill=X)
    51         self.buttonOk = Button(frameButtons,text='Ok',
    52                 width=8,command=self.Ok)
    53         self.buttonOk.grid(row=0,column=0,padx=5,pady=5)
    54         self.buttonCancel = Button(frameButtons,text='Cancel',
    55                 width=8,command=self.Cancel)
    56         self.buttonCancel.grid(row=0,column=1,padx=5,pady=5)
    57 
    58     def NameOk(self):
    59         #simple validity check for a sensible
    60         #ConfigParser file section name
    61         nameOk=1
    62         name=self.name.get()
    63         name.strip()
     59    def name_ok(self):
     60        ''' After stripping entered name, check that it is a  sensible
     61        ConfigParser file section name. Return it if it is, '' if not.
     62        '''
     63        name = self.name.get().strip()
    6464        if not name: #no name specified
    6565            tkMessageBox.showerror(title='Name Error',
    6666                    message='No name specified.', parent=self)
    67             nameOk=0
    6867        elif len(name)>30: #name too long
    6968            tkMessageBox.showerror(title='Name Error',
    7069                    message='Name too long. It should be no more than '+
    7170                    '30 characters.', parent=self)
    72             nameOk=0
    73         elif name in self.usedNames:
     71            name = ''
     72        elif name in self.used_names:
    7473            tkMessageBox.showerror(title='Name Error',
    7574                    message='This name is already in use.', parent=self)
    76             nameOk=0
    77         return nameOk
     75            name = ''
     76        return name
     77    def Ok(self, event=None):
     78        name = self.name_ok()
     79        if name:
     80            self.result = name
     81            self.destroy()
     82    def Cancel(self, event=None):
     83        self.result = ''
     84        self.destroy()
     85if __name__ == '__main__':
     86    import unittest
     87    unittest.main('idlelib.idle_test.test_config_name', verbosity=2, exit=False)
    7888
    79     def Ok(self, event=None):
    80         if self.NameOk():
    81             self.result=self.name.get().strip()
    82             self.destroy()
    83 
    84     def Cancel(self, event=None):
    85         self.result=''
    86         self.destroy()
    87 
    88 if __name__ == '__main__':
    89     #test the dialog
    90     root=Tk()
     89    # also human test the dialog
     90    root = Tk()
    9191    def run():
    92         keySeq=''
    9392        dlg=GetCfgSectionNameDialog(root,'Get Name',
    94                 'The information here should need to be word wrapped. Test.')
     93                "After the text entered with [Ok] is stripped, <nothing>, "
     94                "'abc', or more that 30 chars are errors. "
     95                "Close with a valid entry (printed), [Cancel], or [X]",
     96                {'abc'})
    9597        print dlg.result
    96     Button(root,text='Dialog',command=run).pack()
     98    Message(root, text='').pack()  # will be needed for oher dialog tests
     99    Button(root, text='Click to begin dialog test', command=run).pack()
    97100    root.mainloop()
Note: See TracChangeset for help on using the changeset viewer.