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:
parent
8d303bdc2a
commit
1347839200
2 changed files with 23 additions and 12 deletions
|
@ -292,14 +292,17 @@ class CoreClient:
|
||||||
logger.info("exception event: %s", event)
|
logger.info("exception event: %s", event)
|
||||||
self.app.statusbar.add_alert(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:
|
def join_session(self, session_id: int) -> None:
|
||||||
logger.info("joining session(%s)", session_id)
|
logger.info("joining session(%s)", session_id)
|
||||||
self.reset()
|
self.reset()
|
||||||
try:
|
try:
|
||||||
self.session = self.client.get_session(session_id)
|
self.session = self.client.get_session(session_id)
|
||||||
self.session.user = self.user
|
self.session.user = self.user
|
||||||
title_file = self.session.file.name if self.session.file else ""
|
self.update_session_title()
|
||||||
self.master.title(f"CORE Session({self.session.id}) {title_file}")
|
|
||||||
self.handling_events = self.client.events(
|
self.handling_events = self.client.events(
|
||||||
self.session.id, self.handle_events
|
self.session.id, self.handle_events
|
||||||
)
|
)
|
||||||
|
@ -542,15 +545,16 @@ class CoreClient:
|
||||||
def get_xml_dir(self) -> str:
|
def get_xml_dir(self) -> str:
|
||||||
return str(self.session.file.parent) if self.session.file else str(XMLS_PATH)
|
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
|
Save core session as to an xml file
|
||||||
"""
|
"""
|
||||||
if not file_path and not self.session.file:
|
if not file_path and not self.session.file:
|
||||||
logger.error("trying to save xml for session with no file")
|
logger.error("trying to save xml for session with no file")
|
||||||
return
|
return False
|
||||||
if not file_path:
|
if not file_path:
|
||||||
file_path = str(self.session.file)
|
file_path = self.session.file
|
||||||
|
result = False
|
||||||
try:
|
try:
|
||||||
if not self.is_runtime():
|
if not self.is_runtime():
|
||||||
logger.debug("sending session data to the daemon")
|
logger.debug("sending session data to the daemon")
|
||||||
|
@ -562,10 +566,15 @@ class CoreClient:
|
||||||
"Failed to define session",
|
"Failed to define session",
|
||||||
message,
|
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)
|
logger.info("saved xml file %s", file_path)
|
||||||
|
result = True
|
||||||
except grpc.RpcError as e:
|
except grpc.RpcError as e:
|
||||||
self.app.show_grpc_exception("Save XML Error", e)
|
self.app.show_grpc_exception("Save XML Error", e)
|
||||||
|
return result
|
||||||
|
|
||||||
def open_xml(self, file_path: Path) -> None:
|
def open_xml(self, file_path: Path) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Menubar(tk.Menu):
|
||||||
self.app.bind_all("<Control-n>", lambda e: self.click_new())
|
self.app.bind_all("<Control-n>", lambda e: self.click_new())
|
||||||
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.click_save)
|
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.click_save)
|
||||||
self.app.bind_all("<Control-s>", 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(
|
menu.add_command(
|
||||||
label="Open...", command=self.click_open_xml, accelerator="Ctrl+O"
|
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:
|
def click_save(self, _event: tk.Event = None) -> None:
|
||||||
if self.core.session.file:
|
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:
|
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()
|
init_dir = self.core.get_xml_dir()
|
||||||
file_path = filedialog.asksaveasfilename(
|
file_path = filedialog.asksaveasfilename(
|
||||||
initialdir=init_dir,
|
initialdir=init_dir,
|
||||||
|
@ -303,8 +304,9 @@ class Menubar(tk.Menu):
|
||||||
defaultextension=".xml",
|
defaultextension=".xml",
|
||||||
)
|
)
|
||||||
if file_path:
|
if file_path:
|
||||||
self.add_recent_file_to_gui_config(file_path)
|
file_path = Path(file_path)
|
||||||
self.core.save_xml(file_path)
|
if self.core.save_xml(file_path):
|
||||||
|
self.add_recent_file_to_gui_config(file_path)
|
||||||
|
|
||||||
def click_open_xml(self, _event: tk.Event = None) -> None:
|
def click_open_xml(self, _event: tk.Event = None) -> None:
|
||||||
init_dir = self.core.get_xml_dir()
|
init_dir = self.core.get_xml_dir()
|
||||||
|
|
Loading…
Reference in a new issue