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
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
import os
|
||||
import tkinter as tk
|
||||
from functools import partial
|
||||
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="Reload", underline=0, state=tk.DISABLED)
|
||||
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_command(label="Export 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)
|
||||
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):
|
||||
xml_file = self.app.core.xml_file
|
||||
if xml_file:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue