当前位置: 首页>>代码示例>>Python>>正文


Python History.add_new_state方法代码示例

本文整理汇总了Python中history.History.add_new_state方法的典型用法代码示例。如果您正苦于以下问题:Python History.add_new_state方法的具体用法?Python History.add_new_state怎么用?Python History.add_new_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在history.History的用法示例。


在下文中一共展示了History.add_new_state方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainWindow

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add_new_state [as 别名]
class MainWindow(QtGui.QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
        self.np_img = None
        self.image_actions = []
        self._init_ui()

        self.view = self.ui.imageLabel
        self.image_opener = ImageOpener(self)
        self.image_saver = ImageSaver(self)
        self.image_editor = ImageEditor()
        self.image_history = History()
        self.user_settings_dump_n_loader = UserSettingsDumpNLoader()
        self.diff_images_dir = self.user_settings_dump_n_loader.get_diff_images_dir()
        self.golden_images_dir = self.user_settings_dump_n_loader.get_golden_images_dir()

        self._init_file_actions()
        self._init_M2_actions()
        self._init_M3_actions()
        self._init_M4_actions()
        self._init_M5_actions()
        self._init_M6_actions()
        self._enable_menu_items(False)

    def _init_ui(self):
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.ui.imageLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.setCentralWidget(self.ui.imageLabel)

    def _init_file_actions(self):
        self.ui.actionExit.triggered.connect(QtGui.qApp.quit)
        self.ui.actionOpen.triggered.connect(self._open_file)
        self.ui.actionSave.triggered.connect(self._save_file)
        self.ui.actionSave_As.triggered.connect(self.image_saver.save_as_file)
        self.ui.actionUndo.triggered.connect(self._undo)
        self.ui.actionRedo.triggered.connect(self._redo)

        self.image_actions.append(self.ui.actionSave)
        self.ui.actionSave_As.setEnabled(False)
        self._enable_undo_redo()

    def _init_M2_actions(self):
        self.ui.actionErosion.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.erosion))
        self.ui.actionDilatation.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.dilatation))
        self.ui.actionInversion.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.inversion))
        self.image_actions.extend([self.ui.actionErosion, self.ui.actionDilatation, self.ui.actionInversion])

    def _init_M3_actions(self):
        self.ui.actionIntegrating_filter.triggered.connect(
            lambda: self._image_editor_wrapper(self.image_editor.linear_filter, ImageEditor.integration_filter_matrix,
                                               ImageEditor.integration_filter_divisor)
        )
        self.ui.actionBlur.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.linear_filter,
                                             ImageEditor.blur_matrix, ImageEditor.blur_divisor))
        self.ui.actionSharpen.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.linear_filter,
                                                ImageEditor.sharpen_matrix, ImageEditor.sharpen_divisor))
        self.ui.actionMake_new_custom_filter.triggered.connect(self._make_new_custom_filter)
        for filter_name, (matrix, divisor) in self.user_settings_dump_n_loader.get_filters().iteritems():
            action = QtGui.QAction(self)
            action.setText(filter_name)
            action.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.linear_filter,
                                     matrix, divisor))
            self.ui.menuCustom_filters.addAction(action)
        self.image_actions.extend([self.ui.actionIntegrating_filter, self.ui.actionBlur,
                                   self.ui.actionSharpen, self.ui.actionMake_new_custom_filter])

    def _init_M4_actions(self):
        self.ui.actionWhite_noise.triggered.connect(lambda: self._get_two_params_and_edit("Probability (%)", "Range",
                                                                                          self.image_editor.white_noise))
        self.ui.actionDust.triggered.connect(lambda: self._get_two_params_and_edit("Probability (%)", "Min value",
                                                                                   self.image_editor.dust))
        self.ui.actionGrid.triggered.connect(lambda: self._get_two_params_and_edit("Width", "Height",
                                                                                   self.image_editor.grid))
        self.image_actions.extend([self.ui.actionWhite_noise, self.ui.actionDust, self.ui.actionGrid])

    def _init_M5_actions(self):
        self.ui.actionDifference.triggered.connect(lambda: self._diff_images())
        self.ui.actionSet_diff_images_path.triggered.connect(lambda: self._set_diff_images_dir(self._choose_directory()))
        self.ui.actionSet_golden_images_path.triggered.connect(lambda: self._set_golden_images_dir(self._choose_directory()))
        self.image_actions.extend([self.ui.actionDifference,
                                   self.ui.actionSet_diff_images_path, self.ui.actionSet_golden_images_path])

    def _init_M6_actions(self):
        self.ui.actionMedian_filter_r_1.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.median_filter, 1))
        self.ui.actionMedian_filter_r_2.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.median_filter, 2))
        self.ui.actionMedian_filter_r_3.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.median_filter, 3))
        self.image_actions.extend([self.ui.actionMedian_filter_r_1, self.ui.actionMedian_filter_r_2,
                                   self.ui.actionMedian_filter_r_3])

    def _enable_menu_items(self, mode):
        for action in self.image_actions:
            action.setEnabled(mode)

    def _image_editor_wrapper(self, editor_func, *args):
        self.image_history.add_new_state(self.np_img)
        self.image_editor.update_image(self.np_img)
        self.np_img = editor_func(*args)
        self._show_np_image()
#.........这里部分代码省略.........
开发者ID:Natsik,项目名称:S_Ch_Imaging,代码行数:103,代码来源:main.py


注:本文中的history.History.add_new_state方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。