MCPcopy Create free account
hub / github.com/Bleemsys/Artisan-Core / load_and_highlight_json

Method load_and_highlight_json

AGUI/JSONtreeview.py:324–385  ·  view source on GitHub ↗
(self, onSave=True)

Source from the content-addressed store, hash-verified

322 self.main_gui.save_file()
323
324 def load_and_highlight_json(self, onSave=True):
325 self.save_data()
326 """Load the JSON data and highlight it in a new Text widget window"""
327 formatted_json = json.dumps(self.data, indent=4)
328
329 # Create a new Toplevel window
330 new_window = tk.Toplevel(self.root)
331 new_window.title("JSON Viewer")
332 new_window.geometry("600x600")
333
334 # Create a Frame to hold Text widget and Scrollbars
335 frame = tk.Frame(new_window)
336 frame.pack(fill='both', expand=True)
337
338 # Add vertical scrollbar
339 scrollbar_y = tk.Scrollbar(frame)
340 scrollbar_y.pack(side=tk.RIGHT, fill=tk.Y)
341
342 # Add horizontal scrollbar
343 scrollbar_x = tk.Scrollbar(frame, orient=tk.HORIZONTAL)
344 scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X)
345
346 # Add the Text widget
347 text_widget = tk.Text(frame, wrap=tk.NONE, yscrollcommand=scrollbar_y.set, xscrollcommand=scrollbar_x.set)
348 text_widget.pack(fill='both', expand=True)
349
350 self.text_widget = text_widget
351
352 # Configure scrollbars to control Text widget
353 scrollbar_y.config(command=text_widget.yview)
354 scrollbar_x.config(command=text_widget.xview)
355
356 # Apply tags and highlight JSON
357 self.setup_tags(text_widget)
358 self.highlight_json(text_widget, formatted_json)
359
360 # Bind Enter key to rehighlight JSON
361 text_widget.bind('<Return>', self.rehighlight_json_on_enter)
362
363 # Add button frame below the Text widget
364 button_frame = tk.Frame(new_window)
365 button_frame.pack(pady=10)
366
367 self.fresh_icon = tk.PhotoImage(file=".//AGUI//resources//update.png")
368 self.Edsave_icon = tk.PhotoImage(file=".//AGUI//resources//save.png")
369 self.close_icon = tk.PhotoImage(file=".//AGUI//resources//close.png")
370
371 # Add Update button
372 update_button = tk.Button(button_frame, text="Update", image=self.fresh_icon, command=lambda: self.update_treeview_from_json(text_widget))
373 update_button.pack(side='left', padx=5)
374 self.create_tooltip(update_button, "Refresh")
375
376 # Add Save button (calls the main GUI's save_file method)
377 if onSave:
378 save_button = tk.Button(button_frame, text="Save", image=self.Edsave_icon, command=self.Save_File)
379 save_button.pack(side='left', padx=5)
380 self.create_tooltip(save_button, "Save to file")
381

Callers 1

setup_uiMethod · 0.80

Calls 5

save_dataMethod · 0.95
setup_tagsMethod · 0.95
highlight_jsonMethod · 0.95
create_tooltipMethod · 0.95

Tested by

no test coverage detected