rework #6329 to remove duplicate code and add prevent tab names for showing in ids for scripts that only exist on one tab

This commit is contained in:
AUTOMATIC
2023-01-05 12:08:11 +03:00
parent 997461d3dd
commit f8d0cf6a6e
10 changed files with 10 additions and 53 deletions

View File

@@ -1,4 +1,5 @@
import os
import re
import sys
import traceback
from collections import namedtuple
@@ -128,6 +129,15 @@ class Script:
"""unused"""
return ""
def elem_id(self, item_id):
"""helper function to generate id for a HTML element, constructs final id out of script name, tab and user-supplied item_id"""
need_tabname = self.show(True) == self.show(False)
tabname = ('img2img' if self.is_img2img else 'txt2txt') + "_" if need_tabname else ""
title = re.sub(r'[^a-z_0-9]', '', re.sub(r'\s', '_', self.title().lower()))
return f'script_{tabname}{title}_{item_id}'
current_basedir = paths.script_path