aboutDialog.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. """About Dialog for IDLE
  2. """
  3. import os
  4. from sys import version
  5. from Tkinter import *
  6. from idlelib import textView
  7. class AboutDialog(Toplevel):
  8. """Modal about dialog for idle
  9. """
  10. def __init__(self, parent, title, _htest=False):
  11. """
  12. _htest - bool, change box location when running htest
  13. """
  14. Toplevel.__init__(self, parent)
  15. self.configure(borderwidth=5)
  16. # place dialog below parent if running htest
  17. self.geometry("+%d+%d" % (
  18. parent.winfo_rootx()+30,
  19. parent.winfo_rooty()+(30 if not _htest else 100)))
  20. self.bg = "#707070"
  21. self.fg = "#ffffff"
  22. self.CreateWidgets()
  23. self.resizable(height=FALSE, width=FALSE)
  24. self.title(title)
  25. self.transient(parent)
  26. self.grab_set()
  27. self.protocol("WM_DELETE_WINDOW", self.Ok)
  28. self.parent = parent
  29. self.buttonOk.focus_set()
  30. self.bind('<Return>',self.Ok) #dismiss dialog
  31. self.bind('<Escape>',self.Ok) #dismiss dialog
  32. self.wait_window()
  33. def CreateWidgets(self):
  34. release = version[:version.index(' ')]
  35. frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
  36. frameButtons = Frame(self)
  37. frameButtons.pack(side=BOTTOM, fill=X)
  38. frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
  39. self.buttonOk = Button(frameButtons, text='Close',
  40. command=self.Ok)
  41. self.buttonOk.pack(padx=5, pady=5)
  42. #self.picture = Image('photo', data=self.pictureData)
  43. frameBg = Frame(frameMain, bg=self.bg)
  44. frameBg.pack(expand=TRUE, fill=BOTH)
  45. labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
  46. font=('courier', 24, 'bold'))
  47. labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
  48. #labelPicture = Label(frameBg, text='[picture]')
  49. #image=self.picture, bg=self.bg)
  50. #labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
  51. # padx=0, pady=3)
  52. byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
  53. labelDesc = Label(frameBg, text=byline, justify=LEFT,
  54. fg=self.fg, bg=self.bg)
  55. labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
  56. labelEmail = Label(frameBg, text='email: idle-dev@python.org',
  57. justify=LEFT, fg=self.fg, bg=self.bg)
  58. labelEmail.grid(row=6, column=0, columnspan=2,
  59. sticky=W, padx=10, pady=0)
  60. labelWWW = Label(frameBg, text='https://docs.python.org/' +
  61. version[:3] + '/library/idle.html',
  62. justify=LEFT, fg=self.fg, bg=self.bg)
  63. labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
  64. Frame(frameBg, borderwidth=1, relief=SUNKEN,
  65. height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
  66. columnspan=3, padx=5, pady=5)
  67. labelPythonVer = Label(frameBg, text='Python version: ' +
  68. release, fg=self.fg, bg=self.bg)
  69. labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
  70. tkVer = self.tk.call('info', 'patchlevel')
  71. labelTkVer = Label(frameBg, text='Tk version: '+
  72. tkVer, fg=self.fg, bg=self.bg)
  73. labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
  74. py_button_f = Frame(frameBg, bg=self.bg)
  75. py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
  76. buttonLicense = Button(py_button_f, text='License', width=8,
  77. highlightbackground=self.bg,
  78. command=self.ShowLicense)
  79. buttonLicense.pack(side=LEFT, padx=10, pady=10)
  80. buttonCopyright = Button(py_button_f, text='Copyright', width=8,
  81. highlightbackground=self.bg,
  82. command=self.ShowCopyright)
  83. buttonCopyright.pack(side=LEFT, padx=10, pady=10)
  84. buttonCredits = Button(py_button_f, text='Credits', width=8,
  85. highlightbackground=self.bg,
  86. command=self.ShowPythonCredits)
  87. buttonCredits.pack(side=LEFT, padx=10, pady=10)
  88. Frame(frameBg, borderwidth=1, relief=SUNKEN,
  89. height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
  90. columnspan=3, padx=5, pady=5)
  91. idle_v = Label(frameBg, text='IDLE version: ' + release,
  92. fg=self.fg, bg=self.bg)
  93. idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
  94. idle_button_f = Frame(frameBg, bg=self.bg)
  95. idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
  96. idle_about_b = Button(idle_button_f, text='README', width=8,
  97. highlightbackground=self.bg,
  98. command=self.ShowIDLEAbout)
  99. idle_about_b.pack(side=LEFT, padx=10, pady=10)
  100. idle_news_b = Button(idle_button_f, text='NEWS', width=8,
  101. highlightbackground=self.bg,
  102. command=self.ShowIDLENEWS)
  103. idle_news_b.pack(side=LEFT, padx=10, pady=10)
  104. idle_credits_b = Button(idle_button_f, text='Credits', width=8,
  105. highlightbackground=self.bg,
  106. command=self.ShowIDLECredits)
  107. idle_credits_b.pack(side=LEFT, padx=10, pady=10)
  108. # License, et all, are of type _sitebuiltins._Printer
  109. def ShowLicense(self):
  110. self.display_printer_text('About - License', license)
  111. def ShowCopyright(self):
  112. self.display_printer_text('About - Copyright', copyright)
  113. def ShowPythonCredits(self):
  114. self.display_printer_text('About - Python Credits', credits)
  115. # Encode CREDITS.txt to utf-8 for proper version of Loewis.
  116. # Specify others as ascii until need utf-8, so catch errors.
  117. def ShowIDLECredits(self):
  118. self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
  119. def ShowIDLEAbout(self):
  120. self.display_file_text('About - Readme', 'README.txt', 'ascii')
  121. def ShowIDLENEWS(self):
  122. self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
  123. def display_printer_text(self, title, printer):
  124. printer._Printer__setup()
  125. text = '\n'.join(printer._Printer__lines)
  126. textView.view_text(self, title, text)
  127. def display_file_text(self, title, filename, encoding=None):
  128. fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
  129. textView.view_file(self, title, fn, encoding)
  130. def Ok(self, event=None):
  131. self.destroy()
  132. if __name__ == '__main__':
  133. import unittest
  134. unittest.main('idlelib.idle_test.test_helpabout', verbosity=2, exit=False)
  135. from idlelib.idle_test.htest import run
  136. run(AboutDialog)