Skip to content

Commit

Permalink
[KiRi][Fixed] Navigate results content
Browse files Browse the repository at this point in the history
- Now we can filter what the user sees, not all targets
- Now we can show a custom icon

Fixes #570
  • Loading branch information
set-soft committed Jan 25, 2024
1 parent 2586e6a commit f9e372f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
4 changes: 4 additions & 0 deletions kibot/out_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def get_targets(self, out_dir):
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:
Expand Down
13 changes: 12 additions & 1 deletion kibot/out_kikit_present.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,14 @@ def config(self, parent):
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:
Expand All @@ -356,6 +358,12 @@ def get_targets(self, out_dir):
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
Expand Down Expand Up @@ -400,6 +408,9 @@ def __init__(self):
""" *[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'):
Expand Down
17 changes: 15 additions & 2 deletions kibot/out_kiri.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,27 @@ def config(self, parent):
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]))
if sch_dirty or pcb_dirty:
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):
Expand Down Expand Up @@ -375,7 +384,7 @@ def get_conf_examples(name, layers):
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'
Expand All @@ -387,6 +396,10 @@ def get_conf_examples(name, layers):
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)
10 changes: 5 additions & 5 deletions kibot/out_navigate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def copy(self, img, width):
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):
Expand Down Expand Up @@ -293,12 +293,12 @@ def compose_image(self, file, ext, img, out_name, no_icon=False):
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
Expand Down Expand Up @@ -387,10 +387,10 @@ def generate_outputs(self, f, node):
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:
Expand Down

0 comments on commit f9e372f

Please sign in to comment.