def __init__(self, block, model, connected_ts):
        """Initialize the parent node"""
        super(LogBlockItem, self).__init__()
        self._block = block
        self.parent = None
        self.children = []
        self.name = block.name
        self.id = block.id
        self.period = block.period_in_ms
        self._model = model
        self._log_file_writer = LogWriter(block, connected_ts)

        self._block.started_cb.add_callback(self._set_started)
        self._block.added_cb.add_callback(self._set_added)
        self._block.error_cb.add_callback(self._log_error)

        self._var_list = ""

        for b in block.variables:
            self.children.append(LogBlockChildItem(self, b.name))
            self._var_list += "%s/" % b.name
        self._var_list = self._var_list[:-1]

        self._block_started = False
        self._doing_transaction = False
    def __init__(self, block, model, connected_ts):
        """Initialize the parent node"""
        super(LogBlockItem, self).__init__()
        self._block = block
        self.parent = None
        self.children = []
        self.name = block.name
        self.id = block.id
        self.period = block.period_in_ms
        self._model = model
        self._log_file_writer = LogWriter(block, connected_ts)

        self._block.started_cb.add_callback(self._set_started)
        self._block.added_cb.add_callback(self._set_added)
        self._block.error_cb.add_callback(self._log_error)

        self._var_list = ""

        for b in block.variables:
            self.children.append(LogBlockChildItem(self, b.name))
            self._var_list += "%s/" % b.name
        self._var_list = self._var_list[:-1]

        self._block_started = False
        self._doing_transaction = False
class LogBlockItem(object):
    """Class that acts as a parent in the tree view and represents a complete
    log block"""
    def __init__(self, block, model, connected_ts):
        """Initialize the parent node"""
        super(LogBlockItem, self).__init__()
        self._block = block
        self.parent = None
        self.children = []
        self.name = block.name
        self.id = block.id
        self.period = block.period_in_ms
        self._model = model
        self._log_file_writer = LogWriter(block, connected_ts)

        self._block.started_cb.add_callback(self._set_started)
        self._block.added_cb.add_callback(self._set_added)
        self._block.error_cb.add_callback(self._log_error)

        self._var_list = ""

        for b in block.variables:
            self.children.append(LogBlockChildItem(self, b.name))
            self._var_list += "%s/" % b.name
        self._var_list = self._var_list[:-1]

        self._block_started = False
        self._doing_transaction = False

    def _log_error(self, logconfig, msg):
        """
        Callback when there's an error starting the block in the Crazyflie
        """
        # Do nothing here, a pop-up will notify the user that the
        # starting failed
        self._doing_transaction = False

    def _set_started(self, conf, started):
        """Callback when a block has been started in the Crazyflie"""
        logger.debug("%s started: %s", self.name, started)
        if started:
            self._block_started = True
        else:
            self._block_started = False
        self._doing_transaction = False
        self._model.refresh()

    def logging_started(self):
        """Return True if the block has been started, otherwise False"""
        return self._block_started

    def writing_to_file(self):
        """Return True if the block is being logged to file, otherwise False"""
        return self._log_file_writer.writing()

    def start_writing_to_file(self):
        """Start logging to file for this block"""
        self._log_file_writer.start()

    def stop_writing_to_file(self):
        """Stop logging to file for this block"""
        self._log_file_writer.stop()

    def start(self):
        """Start the logging of this block"""
        self._doing_transaction = True
        self._block.start()

    def stop(self):
        """Stop the logging of this block"""
        self._doing_transaction = True
        self._block.delete()

    def doing_transaction(self):
        """Return True if a block is being added or started, False when it's
        been added/started/failed"""
        return self._doing_transaction

    def _set_added(self, conf, started):
        """Callback when a block has been added to the Crazyflie"""
        logger.debug("%s added: %s", self.name, started)

    def var_list(self):
        """Return a string containing all the variable names of the children"""
        return self._var_list

    def child_count(self):
        """Return the number of children this node has"""
        return len(self.children)

    def get_child(self, index):
        return self.children[index]
class LogBlockItem(object):
    """Class that acts as a parent in the tree view and represents a complete
    log block"""

    def __init__(self, block, model, connected_ts):
        """Initialize the parent node"""
        super(LogBlockItem, self).__init__()
        self._block = block
        self.parent = None
        self.children = []
        self.name = block.name
        self.id = block.id
        self.period = block.period_in_ms
        self._model = model
        self._log_file_writer = LogWriter(block, connected_ts)

        self._block.started_cb.add_callback(self._set_started)
        self._block.added_cb.add_callback(self._set_added)
        self._block.error_cb.add_callback(self._log_error)

        self._var_list = ""

        for b in block.variables:
            self.children.append(LogBlockChildItem(self, b.name))
            self._var_list += "%s/" % b.name
        self._var_list = self._var_list[:-1]

        self._block_started = False
        self._doing_transaction = False

    def _log_error(self, logconfig, msg):
        """
        Callback when there's an error starting the block in the Crazyflie
        """
        # Do nothing here, a pop-up will notify the user that the
        # starting failed
        self._doing_transaction = False

    def _set_started(self, conf, started):
        """Callback when a block has been started in the Crazyflie"""
        logger.debug("%s started: %s", self.name, started)
        if started:
            self._block_started = True
        else:
            self._block_started = False
        self._doing_transaction = False
        self._model.refresh()

    def logging_started(self):
        """Return True if the block has been started, otherwise False"""
        return self._block_started

    def writing_to_file(self):
        """Return True if the block is being logged to file, otherwise False"""
        return self._log_file_writer.writing()

    def start_writing_to_file(self):
        """Start logging to file for this block"""
        self._log_file_writer.start()

    def stop_writing_to_file(self):
        """Stop logging to file for this block"""
        self._log_file_writer.stop()

    def start(self):
        """Start the logging of this block"""
        self._doing_transaction = True
        self._block.start()

    def stop(self):
        """Stop the logging of this block"""
        self._doing_transaction = True
        self._block.delete()

    def doing_transaction(self):
        """Return True if a block is being added or started, False when it's
        been added/started/failed"""
        return self._doing_transaction

    def _set_added(self, conf, started):
        """Callback when a block has been added to the Crazyflie"""
        logger.debug("%s added: %s", self.name, started)

    def var_list(self):
        """Return a string containing all the variable names of the children"""
        return self._var_list

    def child_count(self):
        """Return the number of children this node has"""
        return len(self.children)

    def get_child(self, index):
        return self.children[index]