Avoid generating a simple icon for a category when a tool is missing
This commit is contained in:
parent
bc2ebecb84
commit
5beabb129b
|
|
@ -95,7 +95,9 @@ BIG_ICON = 256
|
||||||
MID_ICON = 64
|
MID_ICON = 64
|
||||||
OUT_COLS = 12
|
OUT_COLS = 12
|
||||||
BIG_2_MID_REL = int(ceil(BIG_ICON/MID_ICON))
|
BIG_2_MID_REL = int(ceil(BIG_ICON/MID_ICON))
|
||||||
IMAGEABLES = {'png', 'jpg', 'pdf', 'eps', 'svg', 'ps'}
|
IMAGEABLES_SIMPLE = {'png', 'jpg'}
|
||||||
|
IMAGEABLES_GS = {'pdf', 'eps', 'ps'}
|
||||||
|
IMAGEABLES_SVG = {'svg'}
|
||||||
STYLE = """
|
STYLE = """
|
||||||
.cat-table { margin-left: auto; margin-right: auto; }
|
.cat-table { margin-left: auto; margin-right: auto; }
|
||||||
.cat-table td { padding: 20px 24px; }
|
.cat-table td { padding: 20px 24px; }
|
||||||
|
|
@ -199,6 +201,21 @@ class Navigate_ResultsOptions(BaseOptions):
|
||||||
self.copied_images[id] = name
|
self.copied_images[id] = name
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
def can_be_converted(self, ext):
|
||||||
|
if ext in IMAGEABLES_SVG and not self.svg2png_avail:
|
||||||
|
logger.warning(W_MISSTOOL+"Missing SVG to PNG converter: {}"+SVGCONV)
|
||||||
|
logger.warning(W_MISSTOOL+TRY_INSTALL_CHECK)
|
||||||
|
return False
|
||||||
|
if ext in IMAGEABLES_GS and not self.ps2img_avail:
|
||||||
|
logger.warning(W_MISSTOOL+"Missing PS/PDF to PNG converter: {}"+PS2IMG)
|
||||||
|
logger.warning(W_MISSTOOL+TRY_INSTALL_CHECK)
|
||||||
|
return False
|
||||||
|
if ext in IMAGEABLES_SIMPLE and not self.convert_avail:
|
||||||
|
logger.warning(W_MISSTOOL+"Missing Imagemagick converter: {}"+CONVERT)
|
||||||
|
logger.warning(W_MISSTOOL+TRY_INSTALL_CHECK)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def get_image_for_cat(self, cat):
|
def get_image_for_cat(self, cat):
|
||||||
img = None
|
img = None
|
||||||
# Check if we have an output that can represent this category
|
# Check if we have an output that can represent this category
|
||||||
|
|
@ -215,7 +232,7 @@ class Navigate_ResultsOptions(BaseOptions):
|
||||||
for tg in targets:
|
for tg in targets:
|
||||||
ext = os.path.splitext(tg)[1][1:].lower()
|
ext = os.path.splitext(tg)[1][1:].lower()
|
||||||
# Can be converted to an image?
|
# Can be converted to an image?
|
||||||
if ext in IMAGEABLES and os.path.isfile(tg):
|
if os.path.isfile(tg) and self.can_be_converted(ext):
|
||||||
rep_file = tg
|
rep_file = tg
|
||||||
break
|
break
|
||||||
if rep_file:
|
if rep_file:
|
||||||
|
|
@ -234,14 +251,6 @@ class Navigate_ResultsOptions(BaseOptions):
|
||||||
if not os.path.isfile(file):
|
if not os.path.isfile(file):
|
||||||
logger.warning(W_NOTYET+"{} not yet generated, using an icon".format(os.path.relpath(file)))
|
logger.warning(W_NOTYET+"{} not yet generated, using an icon".format(os.path.relpath(file)))
|
||||||
return False, None, None
|
return False, None, None
|
||||||
if ext == 'svg' and not self.svg2png_avail:
|
|
||||||
logger.warning(W_MISSTOOL+"Missing SVG to PNG converter: {}"+SVGCONV)
|
|
||||||
logger.warning(W_MISSTOOL+TRY_INSTALL_CHECK)
|
|
||||||
return False, None, None
|
|
||||||
if ext in ('ps', 'pdf') and not self.ps2img_avail:
|
|
||||||
logger.warning(W_MISSTOOL+"Missing PS/PDF to PNG converter: {}"+PS2IMG)
|
|
||||||
logger.warning(W_MISSTOOL+TRY_INSTALL_CHECK)
|
|
||||||
return False, None, None
|
|
||||||
# Create a unique name using the output name and the generated file name
|
# Create a unique name using the output name and the generated file name
|
||||||
bfname = os.path.splitext(os.path.basename(file))[0]
|
bfname = os.path.splitext(os.path.basename(file))[0]
|
||||||
fname = os.path.join(self.out_dir, 'images', out_name+'_'+bfname+'.png')
|
fname = os.path.join(self.out_dir, 'images', out_name+'_'+bfname+'.png')
|
||||||
|
|
@ -286,7 +295,7 @@ class Navigate_ResultsOptions(BaseOptions):
|
||||||
# The icon size
|
# The icon size
|
||||||
height = width = MID_ICON
|
height = width = MID_ICON
|
||||||
# Check if this file can be represented by an image
|
# Check if this file can be represented by an image
|
||||||
if self.convert_avail and ext in IMAGEABLES:
|
if self.can_be_converted(ext):
|
||||||
# Try to compose the image of the file with the icon
|
# Try to compose the image of the file with the icon
|
||||||
ok, fimg, new_img = self.compose_image(file_full, ext, img, 'cat_'+out_name, no_icon)
|
ok, fimg, new_img = self.compose_image(file_full, ext, img, 'cat_'+out_name, no_icon)
|
||||||
if ok:
|
if ok:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue