Example #1
0
    def test_resize(self):
        fnames_in = [
            '../test/images/16x16.png',
            '../test/images/16x8.png',
            '../test/images/8x8.png',
            '../test/images/8x16.png',
            '../test/images/16x15.png',
            '../test/images/16x17.png',
            '../test/images/15x16.png',
            '../test/images/17x16.png',
            '../test/images/15x15.png',
            '../test/images/17x17.png',
            '../test/images/first.png',
            '../test/images/first_vertical.png',
        ]

        fname_out = join(self._tempDir, 'result.png')
        iconmaker = IconMaker()

        for fname in fnames_in:
            iconmaker.create(fname, fname_out)
            img = Image.open(fname_out)

            self.assertTrue(exists(fname_out), fname)
            self.assertEqual(img.size, (ICON_WIDTH, ICON_HEIGHT), fname)
Example #2
0
    def test_resize(self):
        fnames_in = [
            'testdata/images/16x16.png',
            'testdata/images/16x8.png',
            'testdata/images/8x8.png',
            'testdata/images/8x16.png',
            'testdata/images/16x15.png',
            'testdata/images/16x17.png',
            'testdata/images/15x16.png',
            'testdata/images/17x16.png',
            'testdata/images/15x15.png',
            'testdata/images/17x17.png',
            'testdata/images/first.png',
            'testdata/images/first_vertical.png',
        ]

        fname_out = join(self._tempDir, 'result.png')
        iconmaker = IconMaker()

        for fname in fnames_in:
            iconmaker.create(fname, fname_out)
            img = Image.open(fname_out)

            self.assertTrue(exists(fname_out), fname)
            self.assertEqual(img.size, (ICON_WIDTH, ICON_HEIGHT), fname)
Example #3
0
    def test_no_resize_png(self):
        fname_in = 'testdata/images/icon.png'
        fname_out = join(self._tempDir, 'result.png')

        iconmaker = IconMaker()
        iconmaker.create(fname_in, fname_out)

        self.assertTrue(exists(fname_out))

        img = Image.open(fname_out)
        self.assertEqual(img.size, (ICON_WIDTH, ICON_HEIGHT))
Example #4
0
    def test_no_resize_png(self):
        fname_in = '../test/images/icon.png'
        fname_out = join(self._tempDir, 'result.png')

        iconmaker = IconMaker()
        iconmaker.create(fname_in, fname_out)

        self.assertTrue(exists(fname_out))

        img = Image.open(fname_out)
        self.assertEqual(img.size, (ICON_WIDTH, ICON_HEIGHT))
Example #5
0
 def _prepareFavicon(self, favicon_src):
     if favicon_src is not None:
         ico_ext = u'.ico'
         iconname = favicon_src[::-1].replace(u'.', u'_16.'[::-1], 1)[::-1]
         if iconname.endswith(ico_ext):
             iconname = iconname[:-len(ico_ext)] + u'.png'
         iconmaker = IconMaker()
         try:
             iconmaker.create(favicon_src, iconname)
             return iconname
         except IOError:
             pass
Example #6
0
 def _prepareFavicon(self, favicon_src):
     if favicon_src is not None:
         ico_ext = u'.ico'
         iconname = favicon_src[::-1].replace(u'.', u'_16.'[::-1], 1)[::-1]
         if iconname.endswith(ico_ext):
             iconname = iconname[:-len(ico_ext)] + u'.png'
             iconmaker = IconMaker()
             try:
                 iconmaker.create(favicon_src, iconname)
                 return iconname
             except IOError:
                 pass
Example #7
0
    def test_overwrite(self):
        fname_in = u'../test/images/icon.png'
        fname_out = join(self._tempDir, u'result.png')

        iconmaker = IconMaker()
        iconmaker.create(fname_in, fname_out)
        iconmaker.create(fname_in, fname_out)

        img = Image.open(fname_out)

        self.assertTrue(exists(fname_out))
        self.assertEqual(img.size, (ICON_WIDTH, ICON_HEIGHT))
Example #8
0
    def _addIconToDir(self, grouppath, iconpath):
        '''
        Add single icon with full path iconpath into folder groupPath.
        Not images is skipped.
        '''
        if (not isImage(iconpath) or not os.path.exists(iconpath)):
            return

        iconname = os.path.basename(iconpath)
        newIconName = self._getNewIconName(grouppath, iconname)
        newIconPath = os.path.join(grouppath, newIconName)

        try:
            IconMaker().create(iconpath, newIconPath)
        except (IOError, ValueError):
            pass
Example #9
0
    def setCover(self, groupname, fname):
        if groupname is None:
            groupname = self._rootGroupName

        grouppath = os.path.join(self._iconsDir, groupname)

        if not os.path.exists(grouppath):
            raise KeyError

        if (not isImage(fname) or not os.path.exists(fname)):
            return

        newIconPath = os.path.join(grouppath, self.COVER_FILE_NAME)

        try:
            IconMaker().create(fname, newIconPath)
        except (IOError, ValueError):
            pass

        self._scanIconsDir(self._iconsDir)