PageRenderTime 38ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Lib/idlelib/aboutDialog.py

https://bitbucket.org/glix/python
Python | 150 lines | 135 code | 3 blank | 12 comment | 1 complexity | 280ebddbda12b45f3fd2c487a31f4bef MD5 | raw file
  1. """About Dialog for IDLE
  2. """
  3. from Tkinter import *
  4. import os
  5. import os.path
  6. import textView
  7. import idlever
  8. class AboutDialog(Toplevel):
  9. """Modal about dialog for idle
  10. """
  11. def __init__(self,parent,title):
  12. Toplevel.__init__(self, parent)
  13. self.configure(borderwidth=5)
  14. self.geometry("+%d+%d" % (parent.winfo_rootx()+30,
  15. parent.winfo_rooty()+30))
  16. self.bg = "#707070"
  17. self.fg = "#ffffff"
  18. self.CreateWidgets()
  19. self.resizable(height=FALSE, width=FALSE)
  20. self.title(title)
  21. self.transient(parent)
  22. self.grab_set()
  23. self.protocol("WM_DELETE_WINDOW", self.Ok)
  24. self.parent = parent
  25. self.buttonOk.focus_set()
  26. self.bind('<Return>',self.Ok) #dismiss dialog
  27. self.bind('<Escape>',self.Ok) #dismiss dialog
  28. self.wait_window()
  29. def CreateWidgets(self):
  30. frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
  31. frameButtons = Frame(self)
  32. frameButtons.pack(side=BOTTOM, fill=X)
  33. frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
  34. self.buttonOk = Button(frameButtons, text='Close',
  35. command=self.Ok)
  36. self.buttonOk.pack(padx=5, pady=5)
  37. #self.picture = Image('photo', data=self.pictureData)
  38. frameBg = Frame(frameMain, bg=self.bg)
  39. frameBg.pack(expand=TRUE, fill=BOTH)
  40. labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
  41. font=('courier', 24, 'bold'))
  42. labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
  43. #labelPicture = Label(frameBg, text='[picture]')
  44. #image=self.picture, bg=self.bg)
  45. #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
  46. # padx=0, pady=3)
  47. byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
  48. labelDesc = Label(frameBg, text=byline, justify=LEFT,
  49. fg=self.fg, bg=self.bg)
  50. labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
  51. labelEmail = Label(frameBg, text='email: idle-dev@python.org',
  52. justify=LEFT, fg=self.fg, bg=self.bg)
  53. labelEmail.grid(row=6, column=0, columnspan=2,
  54. sticky=W, padx=10, pady=0)
  55. labelWWW = Label(frameBg, text='www: http://www.python.org/idle/',
  56. justify=LEFT, fg=self.fg, bg=self.bg)
  57. labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
  58. Frame(frameBg, borderwidth=1, relief=SUNKEN,
  59. height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
  60. columnspan=3, padx=5, pady=5)
  61. labelPythonVer = Label(frameBg, text='Python version: ' + \
  62. sys.version.split()[0], fg=self.fg, bg=self.bg)
  63. labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
  64. # handle weird tk version num in windoze python >= 1.6 (?!?)
  65. tkVer = repr(TkVersion).split('.')
  66. tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
  67. if tkVer[len(tkVer)-1] == '':
  68. tkVer[len(tkVer)-1] = '0'
  69. tkVer = '.'.join(tkVer)
  70. labelTkVer = Label(frameBg, text='Tk version: '+
  71. tkVer, fg=self.fg, bg=self.bg)
  72. labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
  73. py_button_f = Frame(frameBg, bg=self.bg)
  74. py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
  75. buttonLicense = Button(py_button_f, text='License', width=8,
  76. highlightbackground=self.bg,
  77. command=self.ShowLicense)
  78. buttonLicense.pack(side=LEFT, padx=10, pady=10)
  79. buttonCopyright = Button(py_button_f, text='Copyright', width=8,
  80. highlightbackground=self.bg,
  81. command=self.ShowCopyright)
  82. buttonCopyright.pack(side=LEFT, padx=10, pady=10)
  83. buttonCredits = Button(py_button_f, text='Credits', width=8,
  84. highlightbackground=self.bg,
  85. command=self.ShowPythonCredits)
  86. buttonCredits.pack(side=LEFT, padx=10, pady=10)
  87. Frame(frameBg, borderwidth=1, relief=SUNKEN,
  88. height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
  89. columnspan=3, padx=5, pady=5)
  90. idle_v = Label(frameBg, text='IDLE version: ' + idlever.IDLE_VERSION,
  91. fg=self.fg, bg=self.bg)
  92. idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
  93. idle_button_f = Frame(frameBg, bg=self.bg)
  94. idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
  95. idle_about_b = Button(idle_button_f, text='README', width=8,
  96. highlightbackground=self.bg,
  97. command=self.ShowIDLEAbout)
  98. idle_about_b.pack(side=LEFT, padx=10, pady=10)
  99. idle_news_b = Button(idle_button_f, text='NEWS', width=8,
  100. highlightbackground=self.bg,
  101. command=self.ShowIDLENEWS)
  102. idle_news_b.pack(side=LEFT, padx=10, pady=10)
  103. idle_credits_b = Button(idle_button_f, text='Credits', width=8,
  104. highlightbackground=self.bg,
  105. command=self.ShowIDLECredits)
  106. idle_credits_b.pack(side=LEFT, padx=10, pady=10)
  107. def ShowLicense(self):
  108. self.display_printer_text('About - License', license)
  109. def ShowCopyright(self):
  110. self.display_printer_text('About - Copyright', copyright)
  111. def ShowPythonCredits(self):
  112. self.display_printer_text('About - Python Credits', credits)
  113. def ShowIDLECredits(self):
  114. self.display_file_text('About - Credits', 'CREDITS.txt', 'iso-8859-1')
  115. def ShowIDLEAbout(self):
  116. self.display_file_text('About - Readme', 'README.txt')
  117. def ShowIDLENEWS(self):
  118. self.display_file_text('About - NEWS', 'NEWS.txt')
  119. def display_printer_text(self, title, printer):
  120. printer._Printer__setup()
  121. text = '\n'.join(printer._Printer__lines)
  122. textView.view_text(self, title, text)
  123. def display_file_text(self, title, filename, encoding=None):
  124. fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
  125. textView.view_file(self, title, fn, encoding)
  126. def Ok(self, event=None):
  127. self.destroy()
  128. if __name__ == '__main__':
  129. # test the dialog
  130. root = Tk()
  131. def run():
  132. import aboutDialog
  133. aboutDialog.AboutDialog(root, 'About')
  134. Button(root, text='Dialog', command=run).pack()
  135. root.mainloop()