pygui: adjustments to have save as update the current session to the newly defined file, saves will then continue to use the new save as name

This commit is contained in:
Blake Harnden 2021-07-14 14:44:23 -07:00
parent 8d303bdc2a
commit 1347839200
2 changed files with 23 additions and 12 deletions

View file

@ -292,14 +292,17 @@ class CoreClient:
logger.info("exception event: %s", event)
self.app.statusbar.add_alert(event)
def update_session_title(self) -> None:
title_file = self.session.file.name if self.session.file else ""
self.master.title(f"CORE Session({self.session.id}) {title_file}")
def join_session(self, session_id: int) -> None:
logger.info("joining session(%s)", session_id)
self.reset()
try:
self.session = self.client.get_session(session_id)
self.session.user = self.user
title_file = self.session.file.name if self.session.file else ""
self.master.title(f"CORE Session({self.session.id}) {title_file}")
self.update_session_title()
self.handling_events = self.client.events(
self.session.id, self.handle_events
)
@ -542,15 +545,16 @@ class CoreClient:
def get_xml_dir(self) -> str:
return str(self.session.file.parent) if self.session.file else str(XMLS_PATH)
def save_xml(self, file_path: str = None) -> None:
def save_xml(self, file_path: Path = None) -> bool:
"""
Save core session as to an xml file
"""
if not file_path and not self.session.file:
logger.error("trying to save xml for session with no file")
return
return False
if not file_path:
file_path = str(self.session.file)
file_path = self.session.file
result = False
try:
if not self.is_runtime():
logger.debug("sending session data to the daemon")
@ -562,10 +566,15 @@ class CoreClient:
"Failed to define session",
message,
)
self.client.save_xml(self.session.id, file_path)
self.client.save_xml(self.session.id, str(file_path))
if self.session.file != file_path:
self.session.file = file_path
self.update_session_title()
logger.info("saved xml file %s", file_path)
result = True
except grpc.RpcError as e:
self.app.show_grpc_exception("Save XML Error", e)
return result
def open_xml(self, file_path: Path) -> None:
"""

View file

@ -78,7 +78,7 @@ class Menubar(tk.Menu):
self.app.bind_all("<Control-n>", lambda e: self.click_new())
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.click_save)
self.app.bind_all("<Control-s>", self.click_save)
menu.add_command(label="Save As...", command=self.click_save_xml)
menu.add_command(label="Save As...", command=self.click_save_as)
menu.add_command(
label="Open...", command=self.click_open_xml, accelerator="Ctrl+O"
)
@ -290,11 +290,12 @@ class Menubar(tk.Menu):
def click_save(self, _event: tk.Event = None) -> None:
if self.core.session.file:
self.core.save_xml()
if self.core.save_xml():
self.add_recent_file_to_gui_config(self.core.session.file)
else:
self.click_save_xml()
self.click_save_as()
def click_save_xml(self, _event: tk.Event = None) -> None:
def click_save_as(self, _event: tk.Event = None) -> None:
init_dir = self.core.get_xml_dir()
file_path = filedialog.asksaveasfilename(
initialdir=init_dir,
@ -303,8 +304,9 @@ class Menubar(tk.Menu):
defaultextension=".xml",
)
if file_path:
file_path = Path(file_path)
if self.core.save_xml(file_path):
self.add_recent_file_to_gui_config(file_path)
self.core.save_xml(file_path)
def click_open_xml(self, _event: tk.Event = None) -> None:
init_dir = self.core.get_xml_dir()