mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-08-06 10:18:42 +02:00
[ui] add Open Recent Project
This commit is contained in:
parent
d1ab458e56
commit
d001cc9e73
3 changed files with 87 additions and 1 deletions
|
@ -2,7 +2,7 @@ import logging
|
|||
import os
|
||||
import argparse
|
||||
|
||||
from PySide2.QtCore import Qt, QUrl, Slot, QJsonValue, Property, qInstallMessageHandler, QtMsgType
|
||||
from PySide2.QtCore import Qt, QUrl, Slot, QJsonValue, Property, Signal, qInstallMessageHandler, QtMsgType, QSettings
|
||||
from PySide2.QtGui import QIcon
|
||||
from PySide2.QtWidgets import QApplication
|
||||
|
||||
|
@ -141,6 +141,7 @@ class MeshroomApp(QApplication):
|
|||
|
||||
if args.project:
|
||||
r.load(args.project)
|
||||
self.addRecentProjectFile(args.project)
|
||||
else:
|
||||
r.new()
|
||||
|
||||
|
@ -164,9 +165,52 @@ class MeshroomApp(QApplication):
|
|||
"Invalid value: '{}'".format(args.save))
|
||||
os.mkdir(projectFolder)
|
||||
r.saveAs(args.save)
|
||||
self.addRecentProjectFile(args.save)
|
||||
|
||||
self.engine.load(os.path.normpath(url))
|
||||
|
||||
def _recentProjectFiles(self):
|
||||
projects = []
|
||||
settings = QSettings()
|
||||
settings.beginGroup("RecentFiles")
|
||||
size = settings.beginReadArray("Projects")
|
||||
for i in range(size):
|
||||
settings.setArrayIndex(i)
|
||||
p = settings.value("filepath")
|
||||
if p:
|
||||
projects.append(p)
|
||||
settings.endArray()
|
||||
return projects
|
||||
|
||||
@Slot(str)
|
||||
def addRecentProjectFile(self, projectFile):
|
||||
projectFile = QUrl(projectFile).path()
|
||||
projects = self._recentProjectFiles()
|
||||
|
||||
# remove duplicates while preserving order
|
||||
from collections import OrderedDict
|
||||
uniqueProjects = OrderedDict.fromkeys(projects)
|
||||
projects = list(uniqueProjects)
|
||||
# remove previous usage of the value
|
||||
if projectFile in uniqueProjects:
|
||||
projects.remove(projectFile)
|
||||
# add the new value in the first place
|
||||
projects.insert(0, projectFile)
|
||||
|
||||
# keep only the 10 first elements
|
||||
projects = projects[0:20]
|
||||
|
||||
settings = QSettings()
|
||||
settings.beginGroup("RecentFiles")
|
||||
size = settings.beginWriteArray("Projects")
|
||||
for i, p in enumerate(projects):
|
||||
settings.setArrayIndex(i)
|
||||
settings.setValue("filepath", p)
|
||||
settings.endArray()
|
||||
settings.sync()
|
||||
|
||||
self.recentProjectFilesChanged.emit()
|
||||
|
||||
@Slot(str, result=str)
|
||||
def markdownToHtml(self, md):
|
||||
"""
|
||||
|
@ -216,3 +260,7 @@ class MeshroomApp(QApplication):
|
|||
"onlineUrl": "https://raw.githubusercontent.com/alicevision/AliceVision/develop/COPYING.md"
|
||||
}
|
||||
]
|
||||
|
||||
recentProjectFilesChanged = Signal()
|
||||
recentProjectFiles = Property("QVariantList", _recentProjectFiles, notify=recentProjectFilesChanged)
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ ApplicationWindow {
|
|||
onAccepted: {
|
||||
_reconstruction.saveAs(file)
|
||||
closed(Platform.Dialog.Accepted)
|
||||
MeshroomApp.addRecentProjectFile(file.toString())
|
||||
}
|
||||
onRejected: closed(Platform.Dialog.Rejected)
|
||||
}
|
||||
|
@ -207,6 +208,7 @@ ApplicationWindow {
|
|||
nameFilters: ["Meshroom Graphs (*.mg)"]
|
||||
onAccepted: {
|
||||
_reconstruction.loadUrl(file.toString())
|
||||
MeshroomApp.addRecentProjectFile(file.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,10 +328,45 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
Action {
|
||||
id: openActionItem
|
||||
text: "Open"
|
||||
shortcut: "Ctrl+O"
|
||||
onTriggered: ensureSaved(function() { openFileDialog.open() })
|
||||
}
|
||||
Menu {
|
||||
id: openRecentMenu
|
||||
title: "Open Recent"
|
||||
enabled: recentFilesMenuItems.model != undefined && recentFilesMenuItems.model.length > 0
|
||||
property int maxWidth: 1000
|
||||
property int fullWidth: {
|
||||
var result = 0;
|
||||
for (var i = 0; i < count; ++i) {
|
||||
var item = itemAt(i);
|
||||
result = Math.max(item.implicitWidth + item.padding * 2, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
implicitWidth: fullWidth
|
||||
Repeater {
|
||||
id: recentFilesMenuItems
|
||||
model: MeshroomApp.recentProjectFiles
|
||||
MenuItem {
|
||||
onTriggered: ensureSaved(function() {
|
||||
openRecentMenu.dismiss();
|
||||
_reconstruction.load(modelData);
|
||||
MeshroomApp.addRecentProjectFile(modelData);
|
||||
})
|
||||
|
||||
text: fileTextMetrics.elidedText
|
||||
TextMetrics {
|
||||
id: fileTextMetrics
|
||||
text: modelData
|
||||
elide: Text.ElideLeft
|
||||
elideWidth: openRecentMenu.maxWidth
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Action {
|
||||
id: saveAction
|
||||
text: "Save"
|
||||
|
|
|
@ -426,6 +426,7 @@ class Reconstruction(UIGraph):
|
|||
# use the user-provided default photogrammetry project file
|
||||
self.load(p, setupProjectFile=False)
|
||||
|
||||
@Slot(str)
|
||||
def load(self, filepath, setupProjectFile=True):
|
||||
try:
|
||||
super(Reconstruction, self).load(filepath, setupProjectFile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue