Skip to content
Snippets Groups Projects
Commit f1a283f7 authored by Olle Hansson's avatar Olle Hansson
Browse files

Recent files added to SFG GUI, saves between sessions with QSettings

parent 9bef2549
Branches
No related tags found
Loading
...@@ -101,7 +101,6 @@ class MainWindow(QMainWindow): ...@@ -101,7 +101,6 @@ class MainWindow(QMainWindow):
self.maxFileNr = 4 self.maxFileNr = 4
self.recentFilesList = [] self.recentFilesList = []
self.recentFilePaths = deque(maxlen=self.maxFileNr) self.recentFilePaths = deque(maxlen=self.maxFileNr)
#self.init_ui()
self.add_operations_from_namespace( self.add_operations_from_namespace(
b_asic.core_operations, self.ui.core_operations_list b_asic.core_operations, self.ui.core_operations_list
...@@ -139,7 +138,6 @@ class MainWindow(QMainWindow): ...@@ -139,7 +138,6 @@ class MainWindow(QMainWindow):
self.ui.custom_operations_list.itemClicked.connect( self.ui.custom_operations_list.itemClicked.connect(
self.on_list_widget_item_clicked self.on_list_widget_item_clicked
) )
self.ui.file_menu.aboutToShow.connect(self.updateRecentActionList)
self.ui.save_menu.triggered.connect(self.save_work) self.ui.save_menu.triggered.connect(self.save_work)
self.ui.load_menu.triggered.connect(self.load_work) self.ui.load_menu.triggered.connect(self.load_work)
self.ui.load_operations.triggered.connect(self.add_namespace) self.ui.load_operations.triggered.connect(self.add_namespace)
...@@ -233,8 +231,7 @@ class MainWindow(QMainWindow): ...@@ -233,8 +231,7 @@ class MainWindow(QMainWindow):
module, accepted = QFileDialog().getOpenFileName() module, accepted = QFileDialog().getOpenFileName()
if not accepted: if not accepted:
return return
recentFile = QFileInfo(module) self.addRecentFile(module)
self.recentFilePaths.append(recentFile)
self._load_from_file(module) self._load_from_file(module)
def _load_from_file(self, module) -> None: def _load_from_file(self, module) -> None:
...@@ -266,9 +263,7 @@ class MainWindow(QMainWindow): ...@@ -266,9 +263,7 @@ class MainWindow(QMainWindow):
if positions is None: if positions is None:
positions = {} positions = {}
# print(sfg)
for op in sfg.split(): for op in sfg.split():
# print(op)
self.create_operation( self.create_operation(
op, op,
positions[op.graph_id][0:2] if op.graph_id in positions else None, positions[op.graph_id][0:2] if op.graph_id in positions else None,
...@@ -324,23 +319,35 @@ class MainWindow(QMainWindow): ...@@ -324,23 +319,35 @@ class MainWindow(QMainWindow):
def updateRecentActionList(self): def updateRecentActionList(self):
settings = QSettings() settings = QSettings()
dequelen = len(self.recentFilePaths) rfp = settings.value("recentFiles")
dequelen = len(rfp)
if dequelen > 0: if dequelen > 0:
for i in range(dequelen): for i in range(dequelen):
action = self.recentFilesList[i] action = self.recentFilesList[i]
action.setText(self.recentFilePaths[i].fileName()) action.setText(rfp[i].fileName())
action.setData(self.recentFilePaths[i]) action.setData(rfp[i])
action.setVisible(True) action.setVisible(True)
for i in range(dequelen, self.maxFileNr): for i in range(dequelen, self.maxFileNr):
self.recentFilesList[i].setVisible(False) self.recentFilesList[i].setVisible(False)
def openRecent(self, action): def openRecent(self, action):
print(type(action)) self._load_from_file(action.data().filePath())
print(action)
print(action.data()) def addRecentFile(self, module):
print("openrecent") settings = QSettings()
rfp = settings.value("recentFiles")
recentFile = QFileInfo(module)
if recentFile not in rfp:
rfp.append(recentFile)
settings.setValue("recentFiles", rfp)
self.updateRecentActionList()
def exit_app(self) -> None: def exit_app(self) -> None:
self.logger.info("Exiting the application.") self.logger.info("Exiting the application.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment