本文整理汇总了Python中history.History.undo方法的典型用法代码示例。如果您正苦于以下问题:Python History.undo方法的具体用法?Python History.undo怎么用?Python History.undo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.undo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import undo [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()
#.........这里部分代码省略.........
示例2: KibuVR
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import undo [as 别名]
#.........这里部分代码省略.........
except TypeError:
if received_data == COMM_RESTART:
raise RestartApplication
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def on_swipe_left_right(self, states):
if states['grabbed']:
return
# Get current position of hand
position = states['leap_hand'].palm_position
x1, y1, z1 = position[0], position[1], position[2]
# If this is not the first cycle of a swipe-measurement
try:
# Get stored values
x0, y0, z0 = states['swipe_left_right_start']
last_x = states['swipe_left_right_last_x']
# Get deltas between start and current
# and previous and current
dx0 = x0 - x1
dx1 = last_x - x1
# If the next move is "violating" the deviance or
# hand is not moving to the same direction
if (abs(y0 - y1) > SWIPE_DEVIANCE or
abs(z0 - z1) > SWIPE_DEVIANCE or
((dx0 > 0 and dx1 <= 0) or
(dx0 <= 0 and dx1 > 0))):
raise KeyError
# If this is the end of a swipe
if (abs(dx0) >= SWIPE_DISTANCE):
# Moved left
if dx0 > 0:
self._history.undo()
# Moved right
else:
self._history.redo()
raise KeyError
# If this is the first cycle of a swipe-measurement
except KeyError:
# Start a new swipe-measuring cycle
states['swipe_left_right_start'] = x1, y1, z1
states['swipe_left_right_last_x'] = x1
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
def on_swipe_front_back(self, states):
if states['grabbed']:
return
# Get current position of hand
position = states['leap_hand'].palm_position
x1, y1, z1 = position[0], position[1], position[2]
# If this is not the first cycle of a swipe-measurement
try:
# Get stored values
x0, y0, z0 = states['swipe_front_back_start']
last_z = states['swipe_front_back_last_z']
# Get deltas between start and current
# and previous and current
dz0 = z0 - z1
dz1 = last_z - z1
# If the next move is "violating" the deviance or
# hand is not moving to the same direction
if (abs(x0 - x1) > SWIPE_DEVIANCE or