Example #1
0
class BooleanChoice:
    def __init__(self, cb, container, label):
        self.cb = cb
        self.choice = False

        self.widget_label = QLabel(label)
        self.widget_checkbox = QCheckBox()
        self.widget_checkbox.stateChanged.connect(self.on_checkbox)

        row = container.rowCount()
        container.addWidget(self.widget_label, row, 0)
        container.addWidget(self.widget_checkbox, row, 1)

    def delete(self):
        self.widget_label.hide()
        self.widget_label.deleteLater()
        self.widget_checkbox.hide()
        self.widget_checkbox.deleteLater()

    def pack(self):
        return str(int(self.choice))

    def unpack(self, value):
        self.change(int(value))

    def change(self, value):
        self.choice = bool(value)
        self.widget_checkbox.setChecked(self.choice)

    def on_checkbox(self):
        self.choice = self.widget_checkbox.isChecked()
        self.cb()
Example #2
0
class BooleanOption(GenericOption):
    def __init__(self, option, container):
        super().__init__(option, container)

        self.qsid_bit = self.option["bit"]

        self.checkbox = QCheckBox()
        self.checkbox.stateChanged.connect(self.on_change)
        self.container.addWidget(self.checkbox, self.row, 1)

    def reload(self, keyboard):
        value = super().reload(keyboard)
        checked = value & (1 << self.qsid_bit)

        self.checkbox.blockSignals(True)
        self.checkbox.setChecked(checked != 0)
        self.checkbox.blockSignals(False)

    def value(self):
        checked = int(self.checkbox.isChecked())
        return checked << self.qsid_bit

    def delete(self):
        super().delete()
        self.checkbox.hide()
        self.checkbox.deleteLater()
Example #3
0
class ToDoItem(QWidget):
    def __init__(self,
                 label,
                 sessionGarden,
                 priority=1,
                 isChecked=False,
                 tags=[]):
        self.priority = priority
        self.tags = tags
        self.CheckBox = QCheckBox()
        self.Label = QLabel(label)
        self.isChecked = isChecked
        self.CheckBox.stateChanged.connect(lambda: self.crossOffTask())
        self.sessionGarden = sessionGarden

    def crossOffTask(self):
        self.isChecked = True
        self.CheckBox.deleteLater()
        self.Label.deleteLater()
        print('Checked off ' + self.Label.text())
        self.sessionGarden.addCompost(self.Label.text())
Example #4
0
class TaskWidget(QWidget):

    on_remove = pyqtSignal(int)
    on_review = pyqtSignal(int)

    def __init__(self, rid, text, actions, icon=None, max_text_width=200, parent=None):
        super().__init__(parent)
        self.rid = rid
        self.actions = actions
        self.setObjectName("TaskWidget")

        self.label = QLabel(text)
        self.label.setWordWrap(True)
        self.label.setFixedWidth(max_text_width)
        if icon:
            self.icon_btn = QToolButton()
            self.icon_btn.setIcon(icon)
            self.icon_btn.setMaximumSize(20, 20)
            self.icon_btn.setAutoRaise(True)
        else:
            self.icon_btn = None

        self.checker = None

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.label)
        if icon:
            self.layout.addWidget(self.icon_btn)
        self.layout.addStretch(0)
        self.setLayout(self.layout)

    def add_checker(self):
        # if checker is present just return
        if self.checker:
            return

        self.checker = QCheckBox()
        self.layout.insertWidget(0, self.checker)

    def remove_checker(self):
        self.layout.removeWidget(self.checker)
        self.checker.deleteLater()
        self.checker = None

    def set_text(self, text):
        self.label.setText(text)

    def mousePressEvent(self, event):
        super().mousePressEvent(event)

        if event.button() != Qt.RightButton:
            return
        action_menu = QMenu()
        action_map = {}
        for action in self.actions:
            if action.icon is None:
                a = action_menu.addAction(action.text)
            else:
                a = action_menu.addAction(action.icon, action.text)
            action_map[a] = action

        chosen_action = action_menu.exec_(self.mapToGlobal(event.pos()))
        if chosen_action is None:
            return
        action_map[chosen_action].signal.emit(self.mapToGlobal(event.pos()))
Example #5
0
class Sensor:
    def __init__(self, db_bridge, app):
        self.db_bridge = db_bridge
        self.app = app

        self.layout = None
        self.label = None
        self.checkbox = None

        self.checkbox_callback = None
        self.img_processor = ImageProcessor()

        self.start_time = None
        self.stop_time = None

        self.meas_list = None

    def set_sensor_values(self,
                          sensor_type,
                          sensor_id=None,
                          file_name=None,
                          data=None):
        self.sensor_type = sensor_type
        self.meas_list = data
        self.file_name = file_name
        self.sensor_id = sensor_id

    def checkbox_activate(self):
        self.checkbox_callback(self)

    def create_ui(self, callback):
        self.layout = QHBoxLayout()
        self.label = QLabel(
            f'{self.sensor_type}: {self.sensor_id if self.sensor_id is not None else self.file_name}'
        )
        self.checkbox = QCheckBox()
        self.layout.addWidget(self.label)
        self.layout.addWidget(self.checkbox)

        self.checkbox_callback = callback
        self.checkbox.stateChanged.connect(self.checkbox_activate)

        return self.layout

    def delete_ui(self):
        self.layout.deleteLater()
        self.label.deleteLater()
        self.checkbox.deleteLater()

    def data_loaded(self):
        return self.meas_list is not None

    def reload(self):
        if self.meas_list is not None:
            self.load_data()

    def is_active(self):
        return self.checkbox.isChecked()

    def get_data(self):
        if self.meas_list is None:
            print("WARNING attempting to load data that is not loaded")
        return self.meas_list

    def load_data(self):
        """
        This function takes a source and then looks at its type to find the function to get that data

        :param source: A dict containing all the information to load the data
        :return: list of measurements
        """
        if self.sensor_type == 'csv':
            self.meas_list = load_csv(self.file_name)
        elif self.sensor_type == 'sensor':
            self.meas_list = self.load_sensor()
        else:
            raise Exception('Source type was not recognized')

        self.start_time = self.meas_list[0].timestamp
        self.stop_time = self.meas_list[-1].timestamp

        for index, meas in enumerate(self.meas_list):
            meas.set_or_index(index)
            meas.set_sensor(self)
            meas.convert_to_numpy()

    def load_sensor(self):
        """
        Uses a database query to get measurements from the sensor with id == sensor_id
        Explanation for converting to different class is written in the data_model_helper.py

        :param sensor_id:
        :return:
        """
        param = self.app.get_query_param()
        db_values = self.db_bridge.get_values(self.sensor_id, param)
        sens_values = [Measurement(meas) for meas in db_values]

        return sens_values

    def get_default_vis(self, index):
        thermal_data = self.meas_list[index].data
        self.img_processor.set_thermal_data(thermal_data)
        imgs_batch_1 = self.img_processor.get_imgs()

        print(
            f'diff in thermal_data: {np.max(thermal_data) - np.min(thermal_data)}'
        )

        return imgs_batch_1

    def get_multi_processing(self, index):
        hist_amount = self.img_processor.get_hist_length()
        start_index = max(0, index - hist_amount)
        prev_frames = [meas.data for meas in self.meas_list[start_index:index]]
        cur_frame = self.meas_list[index].data

        self.img_processor.set_current_frame(cur_frame)
        self.img_processor.set_history(prev_frames)

        return self.img_processor.subtract_history()

    def get_closest_meas(self, time):
        cur_time = timedelta(seconds=time)

        min_diff = float('inf')
        min_index = 0

        for meas, index in enumerate(self.meas_list):
            if abs_diff(meas.timestamp, cur_time) < min_diff:
                min_diff = abs_diff(meas.timestamp, cur_time)
                min_index = index

        return min_index