MCPcopy Create free account
hub / github.com/bhowiebkr/PyFlowGraph / FileOperationsManager

Class FileOperationsManager

src/data/file_operations.py:18–279  ·  view source on GitHub ↗

Manages file operations for loading and saving graphs in multiple formats.

Source from the content-addressed store, hash-verified

16
17
18class FileOperationsManager:
19 """Manages file operations for loading and saving graphs in multiple formats."""
20
21 def __init__(self, parent_window, graph, output_log, default_env_manager=None):
22 self.parent_window = parent_window
23 self.graph = graph
24 self.output_log = output_log
25 self.settings = QSettings("PyFlowGraph", "NodeEditor")
26
27 # Current file state
28 self.current_file_path = None
29 self.current_graph_name = "untitled"
30
31 # Environment management (lazy import to avoid circular dependencies)
32 self.default_env_manager = default_env_manager
33
34 def set_execution_controller(self, execution_controller):
35 """Set reference to execution controller for updating button state."""
36 self.execution_controller = execution_controller
37
38
39 def update_window_title(self):
40 """Updates the window title to show the current graph name."""
41 if self.current_graph_name == "untitled":
42 self.parent_window.setWindowTitle("PyFlowGraph - Untitled")
43 else:
44 self.parent_window.setWindowTitle(f"PyFlowGraph - {self.current_graph_name}")
45
46 def new_scene(self):
47 """Create a new empty scene."""
48 self.graph.clear_graph()
49 self.current_graph_name = "untitled"
50 self.current_requirements = []
51 self.current_file_path = None
52 self.update_window_title()
53 self.output_log.append("New scene created.")
54
55 def save(self):
56 """Save the current graph."""
57 if not self.current_file_path:
58 # Get last used directory
59 last_dir = self.settings.value("last_directory", "")
60 file_path, _ = QFileDialog.getSaveFileName(
61 self.parent_window,
62 "Save Graph As...",
63 last_dir,
64 "Flow Files (*.md)"
65 )
66 if not file_path:
67 return False
68 self.current_file_path = file_path
69 # Save directory for next time
70 self.settings.setValue("last_directory", os.path.dirname(file_path))
71
72 self.current_graph_name = os.path.splitext(os.path.basename(self.current_file_path))[0]
73 self.update_window_title()
74 return self._save_file(self.current_file_path)
75

Callers 1

_setup_managersMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected