def test_app_model_using_local_setup(): from mesycontrol import application_registry from mesycontrol import app_model from mesycontrol import config from mesycontrol import hw_model from mesycontrol import mrc_connection from mesycontrol import mrc_controller logging.basicConfig(level=logging.INFO, format='[%(asctime)-15s] [%(name)s.%(levelname)s] %(message)s') signal.signum_to_name = dict((getattr(signal, n), n) for n in dir(signal) if n.startswith('SIG') and '_' not in n) signal.signal(signal.SIGINT, signal_handler) application_registry.instance = application_registry.ApplicationRegistry( sys.executable if getattr(sys, 'frozen', False) else __file__) app = QtGui.QApplication(sys.argv) timer = QtCore.QTimer() timer.timeout.connect(lambda: None) timer.start(500) con = mrc_connection.factory(serial_port='/dev/ttyUSB0', baud_rate=0) mrc_model = hw_model.MRCModel() mrc_model.controller = mrc_controller.MRCController(con, mrc_model) mrc_config = config.MRCConfig() mrc_config.connection_config = config.make_connection_config(con) mrc = app_model.AppMrc(mrc_model=mrc_model, mrc_config=mrc_config) setup = config.Setup() setup.add_mrc_config(mrc_config) def on_mrc_connecting(): print("connecting...") def on_mrc_connected(): print("connected!") def on_mrc_disconnected(info=None): print("disconnected!", info) def on_mrc_ready(): print("MRC is ready!") for device in mrc.get_devices(): print(device, device.model, device.config) print("Saving setup...") def on_device_added(device): print("Device added: %s" % device) mrc.connecting.connect(on_mrc_connecting) mrc.connected.connect(on_mrc_connected) mrc.disconnected.connect(on_mrc_disconnected) mrc.ready.connect(on_mrc_ready) mrc.device_added.connect(on_device_added) mrc.connect() return app.exec_()
self.append("".join(lines).strip()) except AttributeError: self.append("".join(traceback.format_exception(exc_type, exc_value, exc_trace)).strip()) finally: self.setTextColor(self._original_text_color) def contextMenuEvent(self, event): pos = event.globalPos() menu = self.createStandardContextMenu(pos) menu.addAction("Clear").triggered.connect(self.clear) menu.exec_(pos) if __name__ == "__main__": logging.basicConfig(level=logging.DEBUG, format='[%(asctime)-15s] [%(name)s.%(levelname)s] %(message)s') qapp = QtGui.QApplication(sys.argv) log_view = LogView() log_view.resize(400, 400) log_view.show() qt_logger = util.QtLogEmitter() qt_logger.log_record.connect(log_view.handle_log_record) logging.getLogger().addHandler(qt_logger.get_handler()) logger = logging.getLogger(__name__) def on_button_clicked(): logging.getLogger("testlogger").debug("Hello World!") button = QtWidgets.QPushButton("Log!", clicked=on_button_clicked) button.show()