From cb9a09f23df413ace428608e1a65a8e9922afe6c Mon Sep 17 00:00:00 2001 From: copper Date: Wed, 9 Nov 2022 21:23:49 +0800 Subject: [PATCH] fix filter bug add settings --- plugins/filter_collection/main.py | 6 ------ rscder/gui/actions.py | 19 +++++++++++++++++++ rscder/utils/project.py | 3 ++- rscder/utils/setting.py | 22 ++++++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/plugins/filter_collection/main.py b/plugins/filter_collection/main.py index feff259..f1c5f88 100644 --- a/plugins/filter_collection/main.py +++ b/plugins/filter_collection/main.py @@ -88,12 +88,6 @@ class MainPlugin(BasicPlugin): toolbar.addAction(action) ActionManager().filter_menu.addAction(action) - - # self.action = QAction('均值滤波', self.mainwindow) - # # self.action.setCheckable) - # # self.action.setChecked(False) - # self.action.triggered.connect(self.run) - # ActionManager().filter_menu.addAction(self.action) self.alg_ok.connect(self.alg_oked) # basic diff --git a/rscder/gui/actions.py b/rscder/gui/actions.py index 01bf8dd..cb7d64c 100644 --- a/rscder/gui/actions.py +++ b/rscder/gui/actions.py @@ -12,6 +12,7 @@ from rscder.utils.misc import singleton from rscder.gui.plugins import PluginDialog from rscder.utils.setting import Settings from rscder.gui.load import loader +from functools import partial def get_action_manager() -> 'ActionManager': return ActionManager() @@ -101,6 +102,21 @@ class ActionManager(QtCore.QObject): def set_status_bar(self, status_bar): self.status_bar = status_bar + def on_project_setup(self, path=None): + if path is not None: + Settings.General().history = path + history = Settings.General().history + print(history) + def reopen(p): + if Project().is_init: + Project().save() + Project().setup(p) + self.project_list.clear() + for h in history: + action = self.project_list.addAction(IconInstance().OPEN, h[-100:]) + func = partial(reopen, h) + action.triggered.connect(func) + def set_actions(self): ''' File menu @@ -108,6 +124,8 @@ class ActionManager(QtCore.QObject): project_create = self.add_action(QAction(IconInstance().CREATE, '&工程创建', self.w_parent), 'File') project_open = self.add_action(QAction(IconInstance().OPEN, '&打开工程', self.w_parent), 'File') project_save = self.add_action(QAction(IconInstance().SAVE,'&保存工程', self.w_parent), 'File') + self.project_list = self.file_menu.addMenu(IconInstance().OPEN, '最近项目') + self.on_project_setup(None) data_load = self.add_action(QAction(IconInstance().DATA_LOAD,'&数据加载', self.w_parent), 'File') view_setting = self.add_action(QAction(IconInstance().VIEW_SETTING,'&界面定制', self.w_parent), 'File') exit_app = self.add_action(QAction(IconInstance().EXCIT,'&退出', self.w_parent), 'File') @@ -188,6 +206,7 @@ class ActionManager(QtCore.QObject): project_open.setEnabled(True) Project().project_init.connect(self.project_init) + Project().project_setup.connect(self.on_project_setup) if self.status_bar is not None: corr_widget = QLabel(self.status_bar) diff --git a/rscder/utils/project.py b/rscder/utils/project.py index 6e8d4a6..17d5c2d 100644 --- a/rscder/utils/project.py +++ b/rscder/utils/project.py @@ -40,6 +40,7 @@ class Project(QObject): instance:'Project' project_init = pyqtSignal(bool) + project_setup = pyqtSignal(str) # layer_load = pyqtSignal() layer_tree_update = pyqtSignal() layer_show_update = pyqtSignal() @@ -125,7 +126,7 @@ class Project(QObject): pass else: self.load() - + self.project_setup.emit(self.file) self.is_init = True self.project_init.emit(True) except: diff --git a/rscder/utils/setting.py b/rscder/utils/setting.py index 268f77e..114f50f 100644 --- a/rscder/utils/setting.py +++ b/rscder/utils/setting.py @@ -4,6 +4,7 @@ from typing import Tuple from PyQt5.QtCore import QSettings from rscder.utils.license import LicenseHelper import yaml +from collections import OrderedDict BASE_DIR = os.environ['ECD_BASEDIR'] class Settings(QSettings): @@ -83,6 +84,27 @@ class Settings(QSettings): PRE='general' + @property + def history(self): + with Settings(Settings.General.PRE) as s: + history = s.value('history', []) + return history + + @history.setter + def history(self, v:str): + print(v) + with Settings(Settings.General.PRE) as s: + history:list = s.value('history', []) + if v in history: + history.remove(v) + history.insert(0, v) + + if len(history) > 10: + history = history[:10] + + with Settings(Settings.General.PRE) as s: + s.setValue('history', history) + @property def size(self): with Settings(Settings.General.PRE) as s: