Skip to content

Commit 5f83b07

Browse files
authored
Update main.py
1 parent 42f4dec commit 5f83b07

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

main.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import argparse
1010
import logging
1111
from typing import List, Dict, Tuple, Any
12+
import sys
13+
import sys # Import sys again for clarity in EXE path context
1214

1315
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
1416

@@ -172,15 +174,15 @@ def generate_html(
172174
descriptor_colors: Dict[str, str],
173175
formatted_descriptors: pd.DataFrame,
174176
map_html: str,
175-
output_html: Path,
177+
output_html: Path, # output_html is already Path object, keep it as is.
176178
grid_height: int,
177179
grid_width: int,
178-
) -> None:
180+
) -> None: # output_html is Path
179181
legend_items_html = "\n".join(
180-
f'<div class="legend-item" data-descriptor="{row["DescriptorID"]}">\n'
181-
f'<span class="legend-color" style="background-color: {descriptor_colors[row["DescriptorID"]]}">\n</span>'
182-
f'<span class="legend-label">{row["FormattedDescriptorID"]}\n</span>'
183-
f'<input type="color" class="color-picker" data-descriptor="{row["DescriptorID"]}" value="{descriptor_colors[row["DescriptorID"]]}">\n'
182+
f'<div class="legend-item" data-descriptor="{row["DescriptorID"]}">'
183+
f'<span class="legend-color" style="background-color: {descriptor_colors[row["DescriptorID"]]}"></span>'
184+
f'<span class="legend-label">{row["FormattedDescriptorID"]}</span>'
185+
f'<input type="color" class="color-picker" data-descriptor="{row["DescriptorID"]}" value="{descriptor_colors[row["DescriptorID"]]}">'
184186
f"</div>"
185187
for _, row in formatted_descriptors.iterrows()
186188
)
@@ -204,7 +206,7 @@ def generate_html(
204206
grid_width=grid_width,
205207
)
206208

207-
with output_html.open("w", encoding="utf-8") as html_file:
209+
with output_html.open("w", encoding="utf-8") as html_file: # use output_html Path object
208210
html_file.write(html_content)
209211
logging.info(f"Map visualization saved as '{output_html}'.")
210212

@@ -229,6 +231,7 @@ def main() -> None:
229231
if save_files:
230232
display_save_files(save_files)
231233
user_choice = get_user_choice(len(save_files) + 1)
234+
display_save_files(save_files)
232235
selected_file_path = (
233236
save_files[user_choice - 1]
234237
if user_choice <= len(save_files)
@@ -270,14 +273,21 @@ def main() -> None:
270273
map_html = generate_map_html_optimized(
271274
map_df, descriptor_colors, x_min, x_max, y_min, y_max
272275
)
273-
script_dir = Path(__file__).parent
274-
output_file_path = Path(script_dir / f"{selected_file_path.stem}.html")
276+
277+
# --- Get the directory of the executable ---
278+
if getattr(sys, 'frozen', False): # Check if running as compiled EXE
279+
exe_dir = Path(sys.executable).parent
280+
else: # Running as script
281+
exe_dir = Path(__file__).parent # Fallback to script directory
282+
283+
output_file_name = f"{selected_file_path.stem}.html"
284+
output_file_path = exe_dir / output_file_name # Path relative to EXE dir
275285

276286
generate_html(
277287
descriptor_colors,
278288
formatted_descriptors,
279289
map_html,
280-
output_file_path,
290+
output_file_path, # Pass the Path object
281291
grid_height,
282292
grid_width,
283293
)
@@ -297,4 +307,4 @@ def main() -> None:
297307

298308

299309
if __name__ == "__main__":
300-
main()
310+
main()

0 commit comments

Comments
 (0)