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


Python History.reset方法代码示例

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


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

示例1: MainWindow

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import reset [as 别名]

#.........这里部分代码省略.........
            self.ui.menuCustom_filters.addAction(action)
            action.triggered.connect(lambda: self._image_editor_wrapper(self.image_editor.linear_filter,
                                     matrix, divisor))

    def _get_two_params_and_edit(self, param1, param2, editor_func):
        dialog = BaseTwoParamsDialog(param1, param2)
        if dialog.exec_():
            param1_value, param2_value = dialog.get_values()
            self._image_editor_wrapper(editor_func, param1_value, param2_value)

    @staticmethod
    def _choose_directory():
        return str(QtGui.QFileDialog.getExistingDirectory(None, 'Choose directory', '.', QtGui.QFileDialog.ShowDirsOnly))

    def _set_golden_images_dir(self, dirname):
        if dirname:
            self.golden_images_dir = dirname
            self.user_settings_dump_n_loader.set_golden_images_dir(dirname)

    def _set_diff_images_dir(self, dirname):
        if dirname:
            self.golden_images_dir = dirname
            self.user_settings_dump_n_loader.set_diff_images_dir(dirname)

    def _diff_images(self):
        self.image_editor.update_image(self.np_img)
        basename = os.path.basename(str(self.image_saver.filename))
        try:
            golden_np_img = scipy.misc.imread(os.path.join(str(self.golden_images_dir), basename))
            is_ok, diff_img, percentage = self.image_editor.diff_images(golden_np_img)
            if not is_ok:
                QtGui.QMessageBox.about(self, 'Error', 'Images have different size.s')
            else:
                QtGui.QMessageBox.about(self, 'Diff percentage', 'diff: %.1f %%' % percentage)
                diff_filename = os.path.join(str(self.diff_images_dir), basename)
                if percentage:
                    self.image_saver.save_any(diff_img, diff_filename)
        except IOError:
            QtGui.QMessageBox.about(self, 'Error', 'There is no golden image with corresponding name.')

    def _open_file(self):
        self.np_img = self.image_opener.open_file()
        self.image_history.reset()
        self.image_history.add_new_state(self.np_img)
        self.image_saver.filename = self.image_opener.filename

        # in case of png files swap channels
        if self.np_img.shape[2] == 4:
            self.np_img = utils.bgra2rgba(self.np_img)
        self._show_np_image()

        self._enable_menu_items(True)
        self._enable_undo_redo()
        self.ui.actionSave_As.setEnabled(True)

    def _save_file(self):
        self.image_saver.np_img = self.np_img
        self.image_saver.save_file()
        self.ui.actionSave.setEnabled(False)

    def _undo(self):
        if self.image_history.can_undo():
            self.np_img = self.image_history.undo()
            self._show_np_image()
            self._enable_undo_redo()

    def _redo(self):
        if self.image_history.can_redo():
            self.np_img = self.image_history.redo()
            self._show_np_image()
            self._enable_undo_redo()

    def _enable_undo_redo(self):
        undo_state, redo_state = True, True
        if not self.image_history.can_redo():
            redo_state = False
        if not self.image_history.can_undo():
            undo_state = False
        self.ui.actionRedo.setEnabled(redo_state)
        self.ui.actionUndo.setEnabled(undo_state)

    def _show_np_image(self):
        img = utils.np_to_qimage(self.np_img)
        self._show_image(img)

    def _show_image(self, img):
        pixmap = QtGui.QPixmap.fromImage(img)
        pixmap = self.scale_pixmap(pixmap)
        self.view.setPixmap(pixmap)

    def scale_pixmap(self, pixmap):
        dest_height, dest_width = self.view.size().height(), self.view.size().width()
        if dest_height < pixmap.size().height():
            pixmap = pixmap.scaledToHeight(self.view.size().height())
        elif dest_width < pixmap.size().width():
            pixmap = pixmap.scaledToWidth(self.view.size().width())
        return pixmap

    def show_window(self):
        self.show()            
开发者ID:Natsik,项目名称:S_Ch_Imaging,代码行数:104,代码来源:main.py

示例2: reset

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import reset [as 别名]
def reset():
    """Reset all message and other history"""
    Framework.reset()
    TimerManager.reset()
    History.reset()
开发者ID:TaoZong,项目名称:Python,代码行数:7,代码来源:frameworkBack.py

示例3: KMLoger

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import reset [as 别名]
class KMLoger(threading.Thread):
    """ Classe principal """
    def __init__(self):
        threading.Thread.__init__(self)
        self.devices = get_devices()
        self.keyfile = ".keymap"    # Arquivo padrão para o mapa de caracteres
        self.keymap = KeyMap(self.devices)
        self.listener = Listener(self.devices)
        self.history = History()
        self.lock = False
        self.listen()
        self.copy = False

    def record(self):
        if self.copy:
            self.copy = False
            print("\rComandos gravados" + " "*80)
            self.listener.del_key_sniffer("rec")
            # self.listener.del_mouse_sniffer("mouse")
        else:
            self.copy = True
            print("\rIniciando gravação" + " "*80)
            self.history.reset()
            self.listener.add_key_sniffer("rec", [self.keymap.get_key_by_func("rec")], self.history.append_event)
            # self.listener.add_mouse_sniffer("mouse", self.history.append_event)

    def pprint(self, *args):
        if not self.copy:
            print(args)

    def listen(self):
        """ Inicializando todas as fun """
        self.listener.add_listener("redefine", ecodes.EV_KEY, self.keymap.get_key_by_func("redefine"), self.change_keys)
        
        self.listener.add_listener("quit", ecodes.EV_KEY, self.keymap.get_key_by_func("quit"), self.exit)
        self.listener.add_listener("copy", ecodes.EV_KEY, self.keymap.get_key_by_func("rec"), self.record)
        self.listener.add_listener("run", ecodes.EV_KEY, self.keymap.get_key_by_func("run"), self.play)
        # self.listener.add_listener("save", ecodes.EV_KEY, self.keymap.get_key_by_func("save"), self.history.save)
        # self.listener.add_listener("load", ecodes.EV_KEY, self.keymap.get_key_by_func("load"), self.history.load)
        # self.listener.add_listener("pause", ecodes.EV_KEY, self.keymap.get_key_by_func("pause"), self.history.sleep)
        # self.listener.add_listener("stop", ecodes.EV_KEY, self.keymap.get_key_by_func("stop"), self.history.stop)
        # self.listener.add_listener("run_forever", ecodes.EV_KEY, self.keymap.get_key_by_func("run_forever"), self.play_forever)
        # self.listener.add_key_sniffer("rec", [self.keymap.get_key_by_func("rec")], self.history.append_event)

        
        # self.listener.add_listener("copy", ecodes.EV_KEY, self.keymap.get_key_by_func("rec"), pprint, "record")
        self.listener.add_listener("save", ecodes.EV_KEY, self.keymap.get_key_by_func("save"), self.pprint, "save")
        self.listener.add_listener("load", ecodes.EV_KEY, self.keymap.get_key_by_func("load"), self.pprint, "load")
        self.listener.add_listener("pause", ecodes.EV_KEY, self.keymap.get_key_by_func("pause"), self.pprint, "sleep")
        self.listener.add_listener("stop", ecodes.EV_KEY, self.keymap.get_key_by_func("stop"), self.pprint, "stop")
        # self.listener.add_listener("run", ecodes.EV_KEY, self.keymap.get_key_by_func("run"), self.pprint, "play")
        self.listener.add_listener("run_forever", ecodes.EV_KEY, self.keymap.get_key_by_func("run_forever"), self.pprint, "play_forever")
        

    def play(self):
    	if not self.copy:
    		print("\rplay" + " "*80)
	        self.history.set_n(1)
	        self.history.play()

    def play_forever(self):
    	if not self.copy:
	        self.history.set_n(0)
	        self.history.play()

    def run(self):
        self.history.start()
        self.listener.run()
        self.history.join()

    def save_key_map(self):
        """ Salva o mapa de caracteres no arquivo padrão. """
        pickle.dump( self.keymap, open(self.keyfile, 'wb'), -1)
    
    def exit(self):
        if not self.copy:
            self.history.exit()
            self.listener.exit()
            flush_input()
            print("\nBye!")

    def load_key_map(self):
        """ Carrega o mapa de caracteres do arquivo padrão. """
        try:
            self.keymap = pickle.load(open(self.keyfile, 'rb'))
        except IOError:
            self.save_key_map()
        self.listen()

    def change_keys(self):
        if not self.copy:
            self.keymap.setup()
            print("\rNovo mapa de teclas salvo.")
            self.save_key_map()
            print("\rPrograma precisa ser reiniciado")
            self.exit()

    def print_keys(self):
        self.keymap.print_keymap()
开发者ID:andredalton,项目名称:bcc,代码行数:101,代码来源:kmlogger.py


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