from WebPage import WebPage, read_webform

def_template = 'pagenumber_template'
def_script = 'pagenumber.js'


class PageNumberWindow(WebPage):
    def __init__(self, title, template=None, script=None, cnf={}, **kw):
        self.template = template or def_template
        self.script = script or def_script

        WebPage.__init__(self,
                         title=title,
                         template=self.template,
                         script=self.script)

        self.update(kw)
        self.update(cnf)


try:
    print PageNumberWindow(title="PageNumberWindow window", cnf=read_webform())
except KeyError:
    print WebPage(title='Error in template',
                  contents='Cannot build page.Sorry')
except:
    print """Content-type:   text/html

"""
        if not self.has_key('startimage'):
            self['startimage'] = 1

        if not self.has_key('nimages'):
            self['nimages'] = 0

        if not self.has_key('rows'):
            self['rows'] = self.def_rows
        if not self.has_key('columns'):
            self['columns'] = self.def_columns
        if not self.has_key('imgpath'):
            self['imgpath'] = self.def_imgpath


#
# end class Thumbnail
#

if __name__ == '__main__':
    if len(sys.argv) == 1:
        print ThumbnailWindow(title="Preservation Project", cnf=read_webform())
    else:
        print ThumbnailWindow(title="Preservation Project",
                              cnf={
                                  'group': 'seri',
                                  'journal': 'A+A..',
                                  'volume': '0002',
                                  'imageno': '-1',
                                  'rows': '4'
                              })
        scriptfile = 'thumbnail.js'

        WebPage.__init__(self,
                         title=title,
                         template=self.template,
                         script=scriptfile)
        self.pars = cnf
        self.update(self.pars)
        self.update(kw)


if __name__ == '__main__':

    try:
        if len(sys.argv) == 1:
            cnf = read_webform()
        else:
            cnf = {'bibstem': 'ade', 'columns': '3', 'rows': '3'}

        if cnf.has_key('imgdir'):
            data = ToP(cnf['imgdir'])

            files = data[0]
            images = data[1]
            pages = data[2]
            types = data[3]
            userpages = data[4]
            usertypes = data[5]

            total = len(files)
            self['jsdata'] = """