[KiRi][Fixed] Navigate results content

- Now we can filter what the user sees, not all targets
- Now we can show a custom icon

Fixes #570
This commit is contained in:
Salvador E. Tropea 2024-01-25 09:27:43 -03:00
parent 2586e6aa88
commit f9e372f638
4 changed files with 36 additions and 8 deletions

View File

@ -117,6 +117,10 @@ class BaseOutput(RegOutput):
return []
return self.options.get_targets(out_dir)
def get_navigate_targets(self, out_dir):
""" Returns a list of targets suitable for the navigate results """
return self.get_targets(out_dir), None
def get_dependencies(self):
""" Returns a list of files needed to create this output """
if self._sch_related:

View File

@ -341,12 +341,14 @@ class KiKit_PresentOptions(BaseOptions):
except subprocess.CalledProcessError:
pass
def get_targets(self, out_dir):
def _get_targets(self, out_dir, only_index=False):
self.ensure_tool('markdown2')
from .PcbDraw.present import readTemplate
# The web page
out_dir = self._parent.expand_dirname(out_dir)
res = [os.path.join(out_dir, 'index.html')]
if only_index:
return res
# The resources
template = readTemplate(self.template)
for r in self.resources:
@ -356,6 +358,12 @@ class KiKit_PresentOptions(BaseOptions):
res.append(os.path.join(out_dir, 'boards'))
return res
def get_targets(self, out_dir):
return self._get_targets(out_dir)
def get_navigate_targets(self, out_dir):
return self._get_targets(out_dir, True)
def run(self, dir_name):
self.ensure_tool('markdown2')
from .PcbDraw.present import boardpage
@ -400,6 +408,9 @@ class KiKit_Present(BaseOutput):
""" *[dict] Options for the `kikit_present` output """
self._category = 'PCB/docs'
def get_navigate_targets(self, out_dir):
return self.options.get_navigate_targets(out_dir), None
@staticmethod
def get_conf_examples(name, layers):
if not GS.check_tool(name, 'markdown2'):

View File

@ -79,11 +79,13 @@ class KiRiOptions(AnyDiffOptions):
if self.max_commits < 0:
raise KiPlotConfigurationError(f"Wrong number of commits ({self.max_commits}) must be positive")
def get_targets(self, out_dir):
def _get_targets(self, out_dir, only_index=False):
self.init_tools(out_dir)
hashes, sch_dirty, pcb_dirty, sch_files = self.collect_hashes()
if len(hashes) + (1 if sch_dirty or pcb_dirty else 0) < 2:
return []
if only_index:
return [os.path.join(self.cache_dir, 'index.html')]
files = [os.path.join(self.cache_dir, f) for f in ['blank.svg', 'commits', 'index.html', 'kiri-server', 'project']]
for h in hashes:
files.append(os.path.join(self.cache_dir, h[0][:7]))
@ -91,6 +93,13 @@ class KiRiOptions(AnyDiffOptions):
files.append(os.path.join(self.cache_dir, HASH_LOCAL))
return files
def get_targets(self, out_dir):
return self._get_targets(out_dir)
def get_navigate_targets(self, out_dir):
""" Targets for the navigate results, just the index """
return self._get_targets(out_dir, True)
def create_layers_incl(self, layers):
self.incl_file = None
if isinstance(layers, type):
@ -375,7 +384,7 @@ class KiRi(BaseOutput): # noqa: F821
if len(hashes) < 2:
return None
if GS.debug_level > 1:
logger.debug(f'get_conf_examples found: {hashes}')
logger.debug(f'KiRi get_conf_examples found: {hashes}')
gb = {}
gb['name'] = 'basic_{}'.format(name)
gb['comment'] = 'Interactive diff between commits'
@ -387,6 +396,10 @@ class KiRi(BaseOutput): # noqa: F821
outs.append(gb)
return outs
def get_navigate_targets(self, out_dir):
return (self.options.get_navigate_targets(out_dir),
[os.path.join(GS.get_resource_path('kiri'), 'images', 'icon.svg')])
def run(self, name):
self.options.layers = self.layers
super().run(name)

View File

@ -200,7 +200,7 @@ class Navigate_ResultsOptions(BaseOptions):
if img_w in self.copied_images:
# Already copied, just return its name
return self.copied_images[img_w]
src = os.path.join(self.img_src_dir, img+'.svg')
src = os.path.join(self.img_src_dir, img+'.svg') if not img.endswith('.svg') else img
dst = os.path.join(self.out_dir, 'images', img_w)
id = img_w
if self.rsvg_command is not None and self.svg_to_png(src, dst+'.png', width):
@ -293,12 +293,12 @@ class Navigate_ResultsOptions(BaseOptions):
os.remove(tmp_name)
return res, fname, os.path.relpath(fname, start=self.out_dir)
def get_image_for_file(self, file, out_name, no_icon=False):
def get_image_for_file(self, file, out_name, no_icon=False, image=None):
ext = os.path.splitext(file)[1][1:].lower()
wide = False
# Copy the icon for this file extension
icon_name = 'folder' if os.path.isdir(file) else EXT_IMAGE.get(ext, 'unknown')
img = self.copy(icon_name, MID_ICON)
img = self.copy(image or icon_name, MID_ICON)
# Full name for the file
file_full = file
# Just the file, to display it
@ -387,10 +387,10 @@ class Navigate_ResultsOptions(BaseOptions):
f.write('<thead><tr><th colspan="{}">{}</th></tr></thead>\n'.format(OUT_COLS, oname))
out_dir = get_output_dir(out.dir, out, dry=True)
f.write('<tbody><tr>\n')
targets = out.get_targets(out_dir)
targets, icons = out.get_navigate_targets(out_dir)
if len(targets) == 1:
tg_rel = os.path.relpath(os.path.abspath(targets[0]), start=self.out_dir)
img, _ = self.get_image_for_file(targets[0], out_name)
img, _ = self.get_image_for_file(targets[0], out_name, image=icons[0] if icons else None)
f.write('<td class="out-cell" colspan="{}"><a href="{}">{}</a></td>\n'.
format(OUT_COLS, tg_rel, img))
else: