mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add recent files menu
This commit is contained in:
parent
77aef90607
commit
70c251761f
@ -451,6 +451,15 @@
|
|||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="recent_menu">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="use_action_appearance">False</property>
|
||||||
|
<property name="label" translatable="yes">Recent Files</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSeparatorMenuItem" id="separatormenuitem2">
|
<object class="GtkSeparatorMenuItem" id="separatormenuitem2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
@ -27,7 +27,8 @@ SCRIPTS_PATH = IDE_PATH+"/scripts"
|
|||||||
FWBIN_PATH = ""
|
FWBIN_PATH = ""
|
||||||
|
|
||||||
SCALE =1
|
SCALE =1
|
||||||
flash_offsets= [0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
RECENT_FILES_LIMIT=5
|
||||||
|
FLASH_OFFSETS= [0x08000000, 0x08004000, 0x08008000, 0x0800C000,
|
||||||
0x08010000, 0x08020000, 0x08040000, 0x08060000,
|
0x08010000, 0x08020000, 0x08040000, 0x08060000,
|
||||||
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000]
|
0x08080000, 0x080A0000, 0x080C0000, 0x080E0000]
|
||||||
|
|
||||||
@ -138,19 +139,27 @@ class OMVGtk:
|
|||||||
# if os.path.isfile(path):
|
# if os.path.isfile(path):
|
||||||
# self._load_file(path)
|
# self._load_file(path)
|
||||||
|
|
||||||
# build examples menu
|
# built-in examples menu
|
||||||
if os.path.isdir(EXAMPLE_PATH):
|
if os.path.isdir(EXAMPLE_PATH):
|
||||||
exmenu = gtk.Menu()
|
submenu = gtk.Menu()
|
||||||
example_menu = self.builder.get_object('example_menu')
|
menu = self.builder.get_object('example_menu')
|
||||||
examples = sorted(os.listdir(EXAMPLE_PATH))
|
files = sorted(os.listdir(EXAMPLE_PATH))
|
||||||
for f in examples:
|
for f in files:
|
||||||
if f.endswith(".py"):
|
if f.endswith(".py"):
|
||||||
label = os.path.basename(f)
|
label = os.path.basename(f)
|
||||||
mitem =gtk.MenuItem(label)
|
mitem = gtk.MenuItem(label)
|
||||||
mitem.connect("activate", self.open_example)
|
mitem.connect("activate", self.open_example, EXAMPLE_PATH)
|
||||||
exmenu.append(mitem)
|
submenu.append(mitem)
|
||||||
|
|
||||||
|
menu.set_submenu(submenu)
|
||||||
|
|
||||||
|
# recent files menu
|
||||||
|
self.files = []
|
||||||
|
files =self.config.get("main", "recent")
|
||||||
|
if files:
|
||||||
|
self.files = files.split(',')
|
||||||
|
self.update_recent_files()
|
||||||
|
|
||||||
example_menu.set_submenu(exmenu)
|
|
||||||
|
|
||||||
def show_message_dialog(self, msg_type, msg):
|
def show_message_dialog(self, msg_type, msg):
|
||||||
message = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT,
|
message = gtk.MessageDialog(parent=self.window, flags=gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||||
@ -245,8 +254,8 @@ class OMVGtk:
|
|||||||
return True
|
return True
|
||||||
elif (state["erase"]):
|
elif (state["erase"]):
|
||||||
page = state["page"]
|
page = state["page"]
|
||||||
total = len(flash_offsets)
|
total = len(FLASH_OFFSETS)
|
||||||
pydfu.page_erase(flash_offsets[page])
|
pydfu.page_erase(FLASH_OFFSETS[page])
|
||||||
page +=1
|
page +=1
|
||||||
state["bar"].set_fraction(page/float(total))
|
state["bar"].set_fraction(page/float(total))
|
||||||
if (page == total):
|
if (page == total):
|
||||||
@ -405,6 +414,7 @@ class OMVGtk:
|
|||||||
def save_config(self):
|
def save_config(self):
|
||||||
# TODO set config items from GUI
|
# TODO set config items from GUI
|
||||||
#self.config.set("section", "key", value)
|
#self.config.set("section", "key", value)
|
||||||
|
self.config.set("main", "recent", ','.join(self.files))
|
||||||
with open(CONFIG_PATH, "w") as file:
|
with open(CONFIG_PATH, "w") as file:
|
||||||
self.config.write(file)
|
self.config.write(file)
|
||||||
|
|
||||||
@ -418,6 +428,24 @@ class OMVGtk:
|
|||||||
self.window.set_title(title)
|
self.window.set_title(title)
|
||||||
|
|
||||||
|
|
||||||
|
def update_recent_files(self):
|
||||||
|
if (self.file_path and self.file_path not in self.files ):
|
||||||
|
self.files.insert(0, self.file_path)
|
||||||
|
|
||||||
|
if len(self.files)>RECENT_FILES_LIMIT:
|
||||||
|
self.files.pop()
|
||||||
|
|
||||||
|
submenu = gtk.Menu()
|
||||||
|
menu = self.builder.get_object('recent_menu')
|
||||||
|
for f in self.files:
|
||||||
|
if f.endswith(".py"):
|
||||||
|
mitem =gtk.MenuItem(f)
|
||||||
|
mitem.connect("activate", self.open_example, "")
|
||||||
|
submenu.append(mitem)
|
||||||
|
|
||||||
|
menu.set_submenu(submenu)
|
||||||
|
menu.show_all()
|
||||||
|
|
||||||
def _load_file(self, path):
|
def _load_file(self, path):
|
||||||
self.file_path = path
|
self.file_path = path
|
||||||
if path == None: # New file
|
if path == None: # New file
|
||||||
@ -427,6 +455,7 @@ class OMVGtk:
|
|||||||
self.save_button.set_sensitive(False)
|
self.save_button.set_sensitive(False)
|
||||||
with open(path, "r") as file:
|
with open(path, "r") as file:
|
||||||
self.buffer.set_text(file.read())
|
self.buffer.set_text(file.read())
|
||||||
|
self.update_recent_files()
|
||||||
self._update_title()
|
self._update_title()
|
||||||
|
|
||||||
def _save_file(self, new_file):
|
def _save_file(self, new_file):
|
||||||
@ -444,6 +473,7 @@ class OMVGtk:
|
|||||||
self.file_path = dialog.get_filename()
|
self.file_path = dialog.get_filename()
|
||||||
self.save_button.set_sensitive(False)
|
self.save_button.set_sensitive(False)
|
||||||
self._update_title()
|
self._update_title()
|
||||||
|
self.update_recent_files()
|
||||||
with open(dialog.get_filename(), "w") as file:
|
with open(dialog.get_filename(), "w") as file:
|
||||||
file.write(self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter()))
|
file.write(self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter()))
|
||||||
|
|
||||||
@ -516,8 +546,9 @@ class OMVGtk:
|
|||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
def open_example(self, widget):
|
def open_example(self, widget, basedir):
|
||||||
self._load_file(os.path.join(EXAMPLE_PATH, widget.get_label()))
|
self.file_path = os.path.join(basedir, widget.get_label())
|
||||||
|
self._load_file(self.file_path)
|
||||||
|
|
||||||
def text_changed(self, widget):
|
def text_changed(self, widget):
|
||||||
self.save_button.set_sensitive(True)
|
self.save_button.set_sensitive(True)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
[main]
|
[main]
|
||||||
board = openmv1
|
board = openmv1
|
||||||
serial_port = /dev/openmvcam
|
serial_port = /dev/openmvcam
|
||||||
|
recent =
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user