add a menu option for opening recent files, hard code some example xml files for testing
This commit is contained in:
parent
2c6307603a
commit
ede9e93b52
2 changed files with 27 additions and 4 deletions
|
@ -89,12 +89,15 @@ class MenuAction:
|
||||||
title="Open",
|
title="Open",
|
||||||
filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
|
filetypes=(("XML Files", "*.xml"), ("All Files", "*")),
|
||||||
)
|
)
|
||||||
if file_path:
|
self.open_xml_task(file_path)
|
||||||
self.app.core.xml_file = file_path
|
|
||||||
self.app.core.xml_dir = str(os.path.dirname(file_path))
|
def open_xml_task(self, filename):
|
||||||
|
if filename:
|
||||||
|
self.app.core.xml_file = filename
|
||||||
|
self.app.core.xml_dir = str(os.path.dirname(filename))
|
||||||
self.prompt_save_running_session()
|
self.prompt_save_running_session()
|
||||||
self.app.statusbar.progress_bar.start(5)
|
self.app.statusbar.progress_bar.start(5)
|
||||||
task = BackgroundTask(self.app, self.app.core.open_xml, args=(file_path,))
|
task = BackgroundTask(self.app, self.app.core.open_xml, args=(filename,))
|
||||||
task.start()
|
task.start()
|
||||||
|
|
||||||
def gui_preferences(self):
|
def gui_preferences(self):
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
@ -55,6 +57,17 @@ class Menubar(tk.Menu):
|
||||||
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
|
menu.add_command(label="Save", accelerator="Ctrl+S", command=self.save)
|
||||||
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
menu.add_command(label="Reload", underline=0, state=tk.DISABLED)
|
||||||
self.app.bind_all("<Control-s>", self.save)
|
self.app.bind_all("<Control-s>", self.save)
|
||||||
|
sample_xmls = [
|
||||||
|
"sample1.xml",
|
||||||
|
"/home/ncs/.coretk/xmls/sample1.xml",
|
||||||
|
"sample1.xml",
|
||||||
|
]
|
||||||
|
recent = tk.Menu(menu)
|
||||||
|
for i in sample_xmls:
|
||||||
|
recent.add_command(label=i, command=partial(self.open_recent_files, i))
|
||||||
|
menu.add_cascade(label="Recent files", menu=recent)
|
||||||
|
|
||||||
|
# menu.add_command(label="Recent files")
|
||||||
menu.add_separator()
|
menu.add_separator()
|
||||||
menu.add_command(label="Export Python script...", state=tk.DISABLED)
|
menu.add_command(label="Export Python script...", state=tk.DISABLED)
|
||||||
menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED)
|
menu.add_command(label="Execute XML or Python script...", state=tk.DISABLED)
|
||||||
|
@ -409,6 +422,13 @@ class Menubar(tk.Menu):
|
||||||
menu.add_command(label="About", command=self.menuaction.show_about)
|
menu.add_command(label="About", command=self.menuaction.show_about)
|
||||||
self.add_cascade(label="Help", menu=menu)
|
self.add_cascade(label="Help", menu=menu)
|
||||||
|
|
||||||
|
def open_recent_files(self, filename: str):
|
||||||
|
if os.path.isfile(filename):
|
||||||
|
logging.debug("Open recent file %s", filename)
|
||||||
|
self.menuaction.open_xml_task(filename)
|
||||||
|
else:
|
||||||
|
logging.warning("File does not exist %s", filename)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
xml_file = self.app.core.xml_file
|
xml_file = self.app.core.xml_file
|
||||||
if xml_file:
|
if xml_file:
|
||||||
|
|
Loading…
Add table
Reference in a new issue