9
9
import argparse
10
10
import logging
11
11
from typing import List , Dict , Tuple , Any
12
+ import sys
13
+ import sys # Import sys again for clarity in EXE path context
12
14
13
15
logging .basicConfig (level = logging .INFO , format = "%(levelname)s: %(message)s" )
14
16
@@ -172,15 +174,15 @@ def generate_html(
172
174
descriptor_colors : Dict [str , str ],
173
175
formatted_descriptors : pd .DataFrame ,
174
176
map_html : str ,
175
- output_html : Path ,
177
+ output_html : Path , # output_html is already Path object, keep it as is.
176
178
grid_height : int ,
177
179
grid_width : int ,
178
- ) -> None :
180
+ ) -> None : # output_html is Path
179
181
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" ]]} ">'
184
186
f"</div>"
185
187
for _ , row in formatted_descriptors .iterrows ()
186
188
)
@@ -204,7 +206,7 @@ def generate_html(
204
206
grid_width = grid_width ,
205
207
)
206
208
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
208
210
html_file .write (html_content )
209
211
logging .info (f"Map visualization saved as '{ output_html } '." )
210
212
@@ -229,6 +231,7 @@ def main() -> None:
229
231
if save_files :
230
232
display_save_files (save_files )
231
233
user_choice = get_user_choice (len (save_files ) + 1 )
234
+ display_save_files (save_files )
232
235
selected_file_path = (
233
236
save_files [user_choice - 1 ]
234
237
if user_choice <= len (save_files )
@@ -270,14 +273,21 @@ def main() -> None:
270
273
map_html = generate_map_html_optimized (
271
274
map_df , descriptor_colors , x_min , x_max , y_min , y_max
272
275
)
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
275
285
276
286
generate_html (
277
287
descriptor_colors ,
278
288
formatted_descriptors ,
279
289
map_html ,
280
- output_file_path ,
290
+ output_file_path , # Pass the Path object
281
291
grid_height ,
282
292
grid_width ,
283
293
)
@@ -297,4 +307,4 @@ def main() -> None:
297
307
298
308
299
309
if __name__ == "__main__" :
300
- main ()
310
+ main ()
0 commit comments