home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / beeld / teken / scribus-1.3.3.9-win32-install.exe / share / scripts / CalendarWizard.py next >
Text File  |  2006-10-01  |  20KB  |  501 lines

  1. # -*- coding: utf-8 -*-
  2.  
  3. """ This is a simple 'Calendar creation wizard' for Scribus. It's a fully
  4. rewritten Calender.py from Scribus examples. Enjoy.
  5.  
  6. DESCRIPTION & USAGE:
  7. This script needs Tkinter. It will create a GUI with available options
  8. for easy calendar page creation. You'll get new pages with calendar
  9. tables into a new document you are asked for. Position of the
  10. objects in page is calculated with the "golden-ratio" aspect from the
  11. page margins.
  12.  
  13. Steps to create:
  14.     1) Fill requested values in the Calendar dialog
  15.     2) You will be prompted for new document
  16.     3) You will be prompted for new paragraph style which will be used
  17.        in calendar text frames. It could be changed later.
  18.  
  19. There are 2 types of calender supported:
  20.     1) Classic calendar with one month matrix per page. I suggest
  21.        here PORTRAIT orientation.
  22.     2) Event calendar with one week per page with huge place for
  23.        human inputs. There should be LANDSCAPE imho.
  24.  
  25. But everything works with both orientations well of course too.
  26.  
  27. AUTHOR:
  28.     Petr Vanek <petr@scribus.info>
  29.  
  30. LICENSE:
  31. This program is free software; you can redistribute it and/or modify
  32. it under the terms of the GNU General Public License as published by
  33. the Free Software Foundation; either version 2 of the License, or
  34. (at your option) any later version.
  35.  
  36. This program is distributed in the hope that it will be useful,
  37. but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. GNU General Public License for more details.
  40.  
  41. You should have received a copy of the GNU General Public License
  42. along with this program; if not, write to the Free Software
  43. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  44.  
  45. """
  46.  
  47. import sys
  48. import calendar
  49. import datetime
  50.  
  51. try:
  52.     from scribus import *
  53. except ImportError:
  54.     print "This Python script is written for the Scribus scripting interface."
  55.     print "It can only be run from within Scribus."
  56.     sys.exit(1)
  57.  
  58. try:
  59.     # I wish PyQt installed everywhere :-/
  60.     from Tkinter import *
  61.     from tkFont import Font
  62. except ImportError:
  63.     print "This script requires Python's Tkinter properly installed."
  64.     messageBox('Script failed',
  65.                'This script requires Python\'s Tkinter properly installed.',
  66.                ICON_CRITICAL)
  67.     sys.exit(1)
  68.  
  69.  
  70. localization = {
  71. 'Czech' :
  72.     [['Leden', '├Ünor', 'B┼Öezen', 'Duben', 'Kv─¢ten',
  73.         '─îerven', '─îervenec', 'Srpen', 'Z├í┼Ö├¡',
  74.         '┼ÿ├¡jen', 'Listopad', 'Prosinec'],
  75.      ['Pond─¢l├¡','├Üter├╜','St┼Öeda','─îtvrtek','P├ítek','Sobota', 'Ned─¢le']],
  76. 'Czech-short' :
  77.     [['Leden', '├Ünor', 'B┼Öezen', 'Duben', 'Kv─¢ten',
  78.         '─îerven', '─îervenec', 'Srpen', 'Z├í┼Ö├¡',
  79.         '┼ÿ├¡jen', 'Listopad', 'Prosinec'],
  80.      ['Po', '├Üt', 'St', '─ît', 'P├í', 'So', 'Ne']],
  81. 'English' :
  82.     [['January', 'February', 'March', 'April',
  83.       'May', 'June', 'July', 'August', 'September',
  84.       'October', 'November', 'December'],
  85.      ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday']],
  86. 'English-short' :
  87.     [['January', 'February', 'March', 'April', 'May',
  88.       'June', 'July', 'August', 'September', 'October',
  89.       'November', 'December'],
  90.      ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']],
  91. 'Finnish' :
  92.     [['Tammikuu', 'Helmikuu', 'Maaliskuu', 'Huhtikuu',
  93.       'Toukokuu', 'Kes├ñkuu', 'Hein├ñkuu', 'Elokuu', 'Syyskuu',
  94.       'Lokakuu', 'Marraskuu', 'Joulukuu'],
  95.      ['ma','ti','ke','to','pe','la', 'su']],
  96. 'French':
  97.     [['Janvier', u'F\xe9vrier', 'Mars', 'Avril',
  98.       'Mai', 'Juin', 'Juillet', u'Ao\xfbt', 'Septembre',
  99.       'Octobre', 'Novembre', u'D\xe9cembre'],
  100.      ['Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi','Dimanche']],
  101. 'German' :
  102.     [['Januar', 'Februar', u'M\xe4rz', 'April',
  103.       'Mai', 'Juni', 'Juli', 'August', 'September',
  104.       'Oktober', 'November', 'Dezember'],
  105.      ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag']],
  106. 'Italian' :
  107.     [['Gennaio', 'Febbraio', 'Marzo', 'Aprile',
  108.        'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre',
  109.        'Ottobre', 'Novembre', 'Dicembre'],
  110.     [u'Luned\xec', u'Marted\xec', u'Mercoled\xec', u'Gioved\exc', u'Venerd\xec', 'Sabato', 'Domenica']],
  111. # Polish by "┼üukasz [DeeJay1] Jerna┼¢" <deejay1@nsj.srem.pl>
  112. 'Polish' :
  113.     [['Stycze┼ä', 'Luty', 'Marzec', 'Kwiecie┼ä', 'Maj',
  114.       'Czerwiec', 'Lipiec', 'Sierpie┼ä', 'Wrzesie┼ä',
  115.       'Pa┼║dziernik', 'Listopad', 'Grudzie┼ä'],
  116.      ['Poniedzia┼éek', 'Wtorek', '┼Üroda', 'Czwartek', 'Pi─àtek', 'Sobota', 'Niedziela']],
  117. 'Portuguese' :
  118.     [['Janeiro', 'Fevereiro', u'Mar\xe7o', 'Abril',
  119.       'Pode', 'Junho', 'Julho', 'Agosto', 'Setembro',
  120.       'Outubro', 'Novembro', 'Dezembro'],
  121.      ['Segunda-feira', u'Ter\xe7a-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', u'S\xe1bado', 'Domingo']],
  122. 'Russian' :
  123.     [['╨»╨╜╨▓╨░╤Ç╤î', '╨ñ╨╡╨▓╤Ç╨░╨╗╤î', '╨£╨░╤Ç╤é', '╨É╨┐╤Ç╨╡╨╗╤î',
  124.       '╨£╨░╨╣', '╨ÿ╤Ä╨╜╤î', '╨ÿ╤Ä╨╗╤î', '╨É╨▓╨│╤â╤ü╤é', '╨í╨╡╨╜╤é╤Å╨▒╤Ç╤î',
  125.       '╨₧╨║╤é╤Å╨▒╤Ç╤î', '╨¥╨╛╤Å╨▒╤Ç╤î', '╨ö╨╡╨║╨░╨▒╤Ç╤î'],
  126.      ['╨ƒ╨╛╨╜╨╡╨┤╨╡╨╗╤î╨╜╨╕╨║','╨Æ╤é╨╛╤Ç╨╜╨╕╨║','╨í╤Ç╨╡╨┤╨░','╨º╨╡╤é╨▓╨╡╤Ç╨│','╨ƒ╤Å╤é╨╜╨╕╤å╨░','╨í╤â╨▒╨▒╨╛╤é╨░', '╨Æ╨╛╤ü╨║╤Ç╨╡╤ü╨╡╨╜╤î╨╡']],
  127. 'Spanish' :
  128.     [['Enero', 'Febrero', 'Marco', 'Abril', 'Mayo',
  129.       'Junio', 'Julio', 'Agosto', 'Septiembre',
  130.       'Octubre', 'Noviembre', 'Diciembre'],
  131.      ['Lunes', 'Martes', u'Mi\xe9rcoles', 'Jueves', 'Viernes', u'S\xe1bado', 'Domingo']],
  132. 'Swedish' :
  133.     [['Januari', 'Februari','Mars', 'April','Maj', 'Juni','Juli', 'Augusti','September', 'Oktober', 'November', 'December'],
  134.      ['M├Ñndag', 'Tisdag','Onsdag', 'Torsdag','Fredag', 'L├╢rdag','S├╢ndag']]
  135. }
  136.  
  137.  
  138. from math import sqrt
  139.  
  140. class ScCalendar:
  141.     """ Parent class for all calendar types """
  142.  
  143.     def __init__(self, year, months={}, dayOrder=[], firstDay=calendar.SUNDAY, drawSauce=True):
  144.         """ Setup base things """
  145.         # params
  146.         self.drawSauce = drawSauce # draw supplementary image?
  147.         self.year = year
  148.         self.months = months
  149.         self.dayOrder = dayOrder
  150.         self.layerImg = 'Calendar image'
  151.         self.layerCal = 'Calendar'
  152.         self.pStyle = None # paragraph style
  153.         # settings
  154.         self.firstPage = True # create only 2nd 3rd ... pages. No 1st one.
  155.         calendar.setfirstweekday(firstDay)
  156.         progressTotal(len(months))
  157.  
  158.     def setupDocVariables(self):
  159.         """ Compute base metrics here. Page layout is bordered by margins and
  160.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  161.         in the bottom part - top is occupied with empty image frame. """
  162.         page = getPageSize()
  163.         self.pagex = page[0]
  164.         self.pagey = page[1]
  165.         marg = getPageMargins()
  166.         self.marginl = marg[0]
  167.         self.marginr = marg[1]
  168.         self.margint = marg[2]
  169.         self.marginb = marg[3]
  170.         self.width = self.pagex - self.marginl - self.marginr
  171.         self.height = self.pagey - self.margint - self.marginb
  172.  
  173.     def goldenMean(self, aSize):
  174.         """ Taken from samples/golden-mean.py."""
  175.         return aSize * ((sqrt(5) - 1)/2)
  176.  
  177.     def applyTextToFrame(self, aText, aFrame):
  178.         """ Insert the text with style. """
  179.         setText(aText, aFrame)
  180.         setStyle(self.pStyle, aFrame)
  181.  
  182.     def createCalendar(self):
  183.         """ Walk throudh months dict and calls monthly sheet """
  184.         if not newDocDialog():
  185.             return 'Create a new document first, please'
  186.         self.pStyle = newStyleDialog()
  187.         if  self.pStyle == None:
  188.             closeDoc()
  189.             return 'Create a default paragraph style, please'
  190.         originalUnit = getUnit()
  191.         setUnit(UNIT_POINTS)
  192.         self.setupDocVariables()
  193.         if self.drawSauce:
  194.             createLayer(self.layerImg)
  195.         createLayer(self.layerCal)
  196.         run = 0
  197.         for i in self.months:
  198.             run += 1
  199.             progressSet(run)
  200.             self.createMonthCalendar(i)
  201.         setUnit(originalUnit)
  202.         return None
  203.  
  204.     def createLayout(self):
  205.         """ Create the page and optional bells and whistless around """
  206.         self.createPage()
  207.         if self.drawSauce:
  208.             setActiveLayer(self.layerImg)
  209.             self.createImage()
  210.         setActiveLayer(self.layerCal)
  211.  
  212.     def createPage(self):
  213.         """ Wrapper to the new page with layers """
  214.         if self.firstPage:
  215.             self.firstPage = False
  216.             gotoPage(1)
  217.             return
  218.         newPage(-1)
  219.  
  220.  
  221. class ScEventCalendar(ScCalendar):
  222.     """ One day = one row calendar. I suggest LANDSCAPE orientation.\
  223.         One week per page."""
  224.  
  225.     def __init__(self, year, months = {}, dayOrder = [], firstDay = calendar.SUNDAY, drawSauce=True):
  226.         ScCalendar.__init__(self, year, months, dayOrder, firstDay, drawSauce)
  227.  
  228.     def setupDocVariables(self):
  229.         """ Compute base metrics here. Page layout is bordered by margins and
  230.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  231.         in the bottom part - top is occupied with empty image frame. """
  232.         # gloden mean
  233.         ScCalendar.setupDocVariables(self)
  234.         self.gmean = self.width - self.goldenMean(self.width) + self.marginl
  235.         # calendar size = gmean
  236.         # rows and cols
  237.         self.rowSize = self.height / 8
  238.  
  239.     def createMonthCalendar(self, month):
  240.         cal = calendar.monthcalendar(self.year, month + 1)
  241.         for i in cal:
  242.             self.createLayout()
  243.             self.createHeader(self.months[month])
  244.             rowCnt = 1
  245.             for j in i: # days
  246.                 cel = createText(self.gmean + self.marginl,
  247.                                  self.margint + rowCnt * self.rowSize,
  248.                                  self.width - self.gmean, self.rowSize)
  249.                 rowCnt += 1
  250.                 if j != 0:
  251.                     self.applyTextToFrame(str(j), cel)
  252.  
  253.     def createHeader(self, monthName):
  254.         cel = createText(self.gmean + self.marginl, self.margint,
  255.                             self.width - self.gmean, self.rowSize)
  256.         self.applyTextToFrame(monthName, cel)
  257.  
  258.     def createImage(self):
  259.         """ Wrapper for everytime-the-same image frame. """
  260.         if self.drawSauce:
  261.             createImage(self.marginl, self.margint, self.gmean, self.height)
  262.  
  263. class ScClassicCalendar(ScCalendar):
  264.     """ Calendar matrix creator itself. I suggest PORTRAIT orientation.
  265.         One month per page."""
  266.  
  267.     def __init__(self, year, months = {}, dayOrder = [], firstDay = calendar.SUNDAY, drawSauce=True):
  268.         ScCalendar.__init__(self, year, months, dayOrder, firstDay, drawSauce)
  269.  
  270.     def setupDocVariables(self):
  271.         """ Compute base metrics here. Page layout is bordered by margins and
  272.         virtually divided by golden mean 'cut' in the bottom. The calendar is
  273.         in the bottom part - top is occupied with empty image frame. """
  274.         # gloden mean
  275.         ScCalendar.setupDocVariables(self)
  276.         self.gmean = self.height - self.goldenMean(self.height) + self.margint
  277.         # calendar size
  278.         self.calHeight = self.height - self.gmean + self.margint
  279.         # rows and cols
  280.         self.rowSize = self.gmean / 8
  281.         self.colSize = self.width / 7
  282.  
  283.     def createMonthCalendar(self, month):
  284.         """ Draw one month calendar per page """
  285.         cal = calendar.monthcalendar(self.year, month + 1)
  286.         self.createLayout()
  287.         self.createHeader(self.months[month])
  288.         # weeks
  289.         rowCnt = 2
  290.         for i in cal:
  291.             colCnt = 0
  292.             for j in i: # days
  293.                 cel = createText(self.marginl + colCnt * self.colSize,
  294.                                  self.calHeight + rowCnt * self.rowSize,
  295.                                  self.colSize, self.rowSize)
  296.                 colCnt += 1
  297.                 if j != 0:
  298.                     self.applyTextToFrame(str(j), cel)
  299.             rowCnt += 1
  300.  
  301.     def createHeader(self, monthName):
  302.         """ Draw calendar header. Month name and days of the week """
  303.         header = createText(self.marginl, self.calHeight, self.width, self.rowSize)
  304.         self.applyTextToFrame(monthName, header)
  305.         colCnt = 0
  306.         for i in self.dayOrder:
  307.             cel = createText(self.marginl + colCnt * self.colSize,
  308.                              self.calHeight + self.rowSize,
  309.                              self.colSize, self.rowSize)
  310.             self.applyTextToFrame(i, cel)
  311.             colCnt += 1
  312.  
  313.     def createImage(self):
  314.         """ Wrapper for everytime-the-same image frame. """
  315.         if self.drawSauce:
  316.             createImage(self.marginl, self.margint,
  317.                         self.width, self.calHeight - self.margint)
  318.  
  319.  
  320. class TkCalendar(Frame):
  321.     """ GUI interface for Scribus calendar wizard.
  322.         It's ugly and very simple. I can say I hate Tkinter :-/"""
  323.  
  324.     def __init__(self, master=None):
  325.         """ Setup the dialog """
  326.         # refernce to the localization dictionary
  327.         self.key = 'English'
  328.         Frame.__init__(self, master)
  329.         self.grid()
  330.         self.master.resizable(0, 0)
  331.         self.master.title('Scribus Calendar Wizard')
  332.         #define widgets
  333.         self.statusVar = StringVar()
  334.         self.statusLabel = Label(self, textvariable=self.statusVar)
  335.         self.statusVar.set('Select Options and Values')
  336.         # langs
  337.         self.langLabel = Label(self, text='Select language:')
  338.         self.langListbox = Listbox(self, selectmode=SINGLE, height=10)
  339.         keys = localization.keys()
  340.         keys.sort()
  341.         for i in keys:
  342.             self.langListbox.insert(END, i)
  343.         self.langButton = Button(self, text='Change language', command=self.languageChange)
  344.         # calendar type
  345.         self.typeLabel = Label(self, text='Calendar type')
  346.         self.typeVar = IntVar()
  347.         self.typeClRadio = Radiobutton(self, text='Classic', variable=self.typeVar, value=0)
  348.         self.typeEvRadio = Radiobutton(self, text='Event', variable=self.typeVar, value=1)
  349.         # start of week
  350.         self.weekStartsLabel = Label(self, text='Week begins with:')
  351.         self.weekVar = IntVar()
  352.         self.weekMondayRadio = Radiobutton(self, text='Mon', variable=self.weekVar, value=calendar.MONDAY)
  353.         self.weekSundayRadio = Radiobutton(self, text='Sun', variable=self.weekVar, value=calendar.SUNDAY)
  354.         # year
  355.         self.yearLabel = Label(self, text='Year:')
  356.         self.yearVar = StringVar()
  357.         self.yearEntry = Entry(self, textvariable=self.yearVar, width=4)
  358.         self.wholeYearLabel = Label(self, text='Whole year:')
  359.         self.wholeYear = IntVar()
  360.         self.wholeYearCheck = Checkbutton(self, command=self.setWholeYear, variable=self.wholeYear)
  361.         # months
  362.         self.monthLabel = Label(self, text='Months:')
  363.         self.monthListbox = Listbox(self, selectmode=MULTIPLE, height=12)
  364.         # layout stuff
  365.         self.imageLabel = Label(self, text='Draw Image Frame:')
  366.         self.imageVar = IntVar()
  367.         self.imageCheck = Checkbutton(self, variable=self.imageVar)
  368.         # closing/running
  369.         self.okButton = Button(self, text="OK", width=6, command=self.okButonn_pressed)
  370.         self.cancelButton = Button(self, text="Cancel", command=self.quit)
  371.         # setup values
  372.         self.weekMondayRadio.select()
  373.         self.typeClRadio.select()
  374.         self.yearVar.set(str(datetime.date(1, 1, 1).today().year))
  375.         self.imageCheck.select()
  376.         # make layout
  377.         self.columnconfigure(0, pad=6)
  378.         currRow = 0
  379.         self.statusLabel.grid(column=0, row=currRow, columnspan=4)
  380.         currRow += 1
  381.         self.langLabel.grid(column=0, row=currRow, sticky=W)
  382.         self.monthLabel.grid(column=3, row=currRow, sticky=W)
  383.         currRow += 1
  384.         self.langListbox.grid(column=0, row=currRow, rowspan=6, sticky=N)
  385.         self.typeLabel.grid(column=1, row=currRow, sticky=E)
  386.         self.typeClRadio.grid(column=2, row=currRow, sticky=W)
  387.         self.monthListbox.grid(column=3, row=currRow, rowspan=8)
  388.         currRow += 1
  389.         self.typeEvRadio.grid(column=2, row=currRow, sticky=W)
  390.         currRow += 1
  391.         self.weekStartsLabel.grid(column=1, row=currRow, sticky=N+E)
  392.         self.weekMondayRadio.grid(column=2, row=currRow, sticky=N+W)
  393.         currRow += 1
  394.         self.weekSundayRadio.grid(column=2, row=currRow, sticky=N+W)
  395.         currRow += 1
  396.         self.yearLabel.grid(column=1, row=currRow, sticky=N+E)
  397.         self.yearEntry.grid(column=2, row=currRow, sticky=N+W)
  398.         currRow += 1
  399.         self.wholeYearLabel.grid(column=1, row=currRow, sticky=N+E)
  400.         self.wholeYearCheck.grid(column=2, row=currRow, sticky=N+W)
  401.         currRow += 1
  402.         self.imageLabel.grid(column=1, row=currRow, sticky=N+E)
  403.         self.imageCheck.grid(column=2, row=currRow, sticky=N+W)
  404.         self.langButton.grid(column=0, row=currRow)
  405.         currRow += 3
  406.         self.rowconfigure(currRow, pad=6)
  407.         self.okButton.grid(column=1, row=currRow, sticky=E)
  408.         self.cancelButton.grid(column=2, row=currRow, sticky=W)
  409.         # fill the values
  410.         self.realLangChange()
  411.  
  412.     def languageChange(self, lang='English'):
  413.         """ Called by Change button. Get language list value and
  414.             call real re-filling. """
  415.         ix = self.langListbox.curselection()
  416.         if len(ix)==0:
  417.             self.statusVar.set('Select a language, please')
  418.             return
  419.         self.realLangChange(lang=self.langListbox.get(ix[0]))
  420.  
  421.     def realLangChange(self, lang='English'):
  422.         """ Real widget setup. Ot takes values from localization dictionary.
  423.         [0] = months, [1] Days """
  424.         self.key = lang
  425.         self.monthListbox.delete(0, END)
  426.         self.wholeYear.set(0)
  427.         for i in localization[lang][0]:
  428.             self.monthListbox.insert(END, i)
  429.  
  430.     def setWholeYear(self):
  431.         """ All/none months selection. It's called after "Whole year" check button
  432.         click. """
  433.         if self.wholeYear.get() == 1:
  434.             self.monthListbox.selection_set(0, END)
  435.         else:
  436.             self.monthListbox.selection_clear(0, END)
  437.  
  438.     def okButonn_pressed(self):
  439.         """ User variables testing and preparing """
  440.         # year
  441.         try:
  442.             year = self.yearVar.get().strip()
  443.             if len(year) != 4:
  444.                 raise ValueError
  445.             year = int(year, 10)
  446.         except ValueError:
  447.             self.statusVar.set('Year must be in the "YYYY" format e.g. 2005.')
  448.             return
  449.         # months
  450.         selMonths = self.monthListbox.curselection()
  451.         if len(selMonths) == 0:
  452.             self.statusVar.set('At least one month must be selected.')
  453.             return
  454.         months = {}
  455.         for i in selMonths:
  456.             months[int(i)] = self.monthListbox.get(i)
  457.         # day order
  458.         dayList = localization[self.key][1]
  459.         if self.weekVar.get() == calendar.SUNDAY:
  460.             dl = dayList[:6]
  461.             dl.insert(0, dayList[6])
  462.             dayList = dl
  463.         # draw images etc.
  464.         if self.imageVar.get() == 0:
  465.             draw = False
  466.         else:
  467.             draw = True
  468.         # create calendar (finally)
  469.         if self.typeVar.get() == 0:
  470.             cal = ScClassicCalendar(year, months, dayList, self.weekVar.get(), draw)
  471.         else:
  472.             cal = ScEventCalendar(year, months, dayList, self.weekVar.get(), draw)
  473.         self.master.withdraw()
  474.         err = cal.createCalendar()
  475.         if err != None:
  476.             self.master.deiconify()
  477.             self.statusVar.set(err)
  478.         else:
  479.             self.quit()
  480.  
  481.     def quit(self):
  482.         self.master.destroy()
  483.  
  484.  
  485. def main():
  486.     """ Application/Dialog loop with Scribus sauce around """
  487.     try:
  488.         statusMessage('Running script...')
  489.         progressReset()
  490.         root = Tk()
  491.         app = TkCalendar(root)
  492.         root.mainloop()
  493.     finally:
  494.         if haveDoc():
  495.             redrawAll()
  496.         statusMessage('Done.')
  497.         progressReset()
  498.  
  499. if __name__ == '__main__':
  500.     main()
  501.