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


Python Listener.exit方法代码示例

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


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

示例1: Main

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import exit [as 别名]
class Main(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        # make variables
        self.voltage = 0
        self.current = 0

        # load gui.ui
        self.ui = loadUi('../gui/gui.ui')

        self.ui.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
        self.ui.destroyed.connect(self.shutdown)

        # show window
        self.ui.show()

        # make new log object
        self.log = Log(self.ui)

        # make new sender object
        self.sender = Sender(self.ui, self.log)

        # set events
        self.set_events()

        # initial reset
        self.sender.reset()

        # new listener
        self.listener = Listener()

        # new_data_received signal
        self.listener.data_received.connect(self.new_data_received)

        # start listener
        self.listener.start()

        # new interpreter
        self.interpreter = Interpreter(self.log, self.ui)

        # add tree
        self.add_tree()

    def add_tree(self):
        # Items for tree
        voltage_item = QTreeWidgetItem(["Spannung", str(self.voltage) + " V"])
        self.ui.treeView.addTopLevelItem(voltage_item)

        current_item = QTreeWidgetItem(["Strom", str(self.current) + " A"])
        self.ui.treeView.addTopLevelItem(current_item)

        power_item = QTreeWidgetItem(["Watt", "0 W"])
        self.ui.treeView.addTopLevelItem(power_item)

    def set_events(self):
        # sendButton clicked
        self.ui.sendButton.clicked.connect(lambda: self.sender.send("debug"))

        # holdButton clicked
        self.ui.holdButton.clicked.connect(self.log.toggle_hold)

        # clearButton clicked
        self.ui.clearButton.clicked.connect(self.log.clear_log)

        # messageInput return pressed
        self.ui.messageInput.returnPressed.connect(lambda: self.sender.send("debug"))

        # sliders value changed
        self.ui.voltageSlider.sliderReleased.connect(lambda: self.sender.send("slider-voltage"))
        self.ui.currentSlider.sliderReleased.connect(lambda: self.sender.send("slider-current"))

        # reset action
        self.ui.resetActionButton.triggered.connect(self.sender.reset)

        # automode checkbox
        self.ui.automodeCheckbox.stateChanged.connect(lambda: self.sender.send("checkbox-automode"))

        # lamp checkboxes
        self.ui.lamp1Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp2Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp3Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))
        self.ui.lamp4Checkbox.stateChanged.connect(lambda: self.sender.send("checkbox-lamp"))

    def new_data_received(self, text):
        self.interpreter.interpret(text)

    def shutdown(self):
        self.listener.exit()
开发者ID:spaibs,项目名称:eCARus-IT,代码行数:91,代码来源:main.py

示例2: KMLoger

# 需要导入模块: from listener import Listener [as 别名]
# 或者: from listener.Listener import exit [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


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