Esempio n. 1
0
    def __init__(self, cuboid, name, parent=None):
        """
        Args:

        """
        QtGui.QWidget.__init__(self, parent)

        self.cuboid_name = name
        self.ui = Ui_xndarrayBrowser()
        self.ui.setupUi(self)

        domains = cuboid.get_axes_domains()
        anames = cuboid.axes_names
        self.slicers = dict((an,AxisSlicer(an, domains[an])) \
                            for an in anames)

        self.slice_def = dict((an, domains[an][0]) for an in anames)

        for an in anames:
            slicer = self.slicers[an]
            self.ui.verticalLayout.addWidget(slicer)
            slicer._slice_value_changed.connect(self.handle_slice_value_changed)
            slicer.axis_state_changed.connect(self.set_axis_state)

        self.selection_fifo_max_size = 2
        self.selection_fifo = LimitedFifo(self.selection_fifo_max_size,
                                          on_pop=self.deselect_axis)

        checked = QtCore.Qt.Checked
        self.slicers[anames[0]].set_axis_selection_checkbox_state(checked)
        if len(anames) > 1:
            self.slicers[anames[1]].set_axis_selection_checkbox_state(checked)

        self.ui.swap_button.clicked.connect(self.swap_current_axes)
Esempio n. 2
0
class xndarrayBrowser(QtGui.QWidget):
    """
    Signals:
         - slice_changed(dict, tuple): emitted when the current slice changed                  Args are:
                 - (dict of <axis name (str)>:<DomainValue>): slice value for
                     each axis
                 - (tuple of <axis name (str)>): list of projected axes

    """

    slice_changed = QtCore.pyqtSignal(dict, tuple, name='SliceChanged')
    # projected_axes_changed = QtCore.pyqtSignal(name='ProjectedAxesChanged')
    # projected_axes_swapped = QtCore.pyqtSignal(name='ProjectedAxesSwapped')
    closing = QtCore.pyqtSignal(name='Closing')

    def __init__(self, cuboid, name, parent=None):
        """
        Args:

        """
        QtGui.QWidget.__init__(self, parent)

        self.cuboid_name = name
        self.ui = Ui_xndarrayBrowser()
        self.ui.setupUi(self)

        domains = cuboid.get_axes_domains()
        anames = cuboid.axes_names
        self.slicers = dict((an,AxisSlicer(an, domains[an])) \
                            for an in anames)

        self.slice_def = dict((an, domains[an][0]) for an in anames)

        for an in anames:
            slicer = self.slicers[an]
            self.ui.verticalLayout.addWidget(slicer)
            slicer._slice_value_changed.connect(self.handle_slice_value_changed)
            slicer.axis_state_changed.connect(self.set_axis_state)

        self.selection_fifo_max_size = 2
        self.selection_fifo = LimitedFifo(self.selection_fifo_max_size,
                                          on_pop=self.deselect_axis)

        checked = QtCore.Qt.Checked
        self.slicers[anames[0]].set_axis_selection_checkbox_state(checked)
        if len(anames) > 1:
            self.slicers[anames[1]].set_axis_selection_checkbox_state(checked)

        self.ui.swap_button.clicked.connect(self.swap_current_axes)


    def set_new_cuboid(self, c):
        """
        Set the current cuboid to c, while trying to maintain the current slice
        definition
        """
        print 'todo: set_new_cuboid:'
        print c.descrip()
        print 'current cuboid is:'
        print c.descrip()

    def get_slice_def(self):
        return self.slice_def

    def set_slice_value(self, axis, value):
        self.slicers[axis].set_slice_value(axis, value)

    def get_current_axes(self):
        return tuple(str(a) for a in self.selection_fifo)

    @QtCore.pyqtSlot(str, DomainValue)
    def handle_slice_value_changed(self, aname, dval):
        self.slice_def[str(aname)] = dval
        self.slice_changed.emit(self.slice_def, self.get_current_axes())

    @QtCore.pyqtSlot(str, bool)
    def set_axis_state(self, axis_name, state):
        print 'set_axis_state:', axis_name, '->', state
        print 'current selection_fifo:', self.selection_fifo
        state_changed = False
        if not state:
            if axis_name in self.selection_fifo:
                self.selection_fifo.remove(axis_name)
                state_changed = True
        else:
            if axis_name not in self.selection_fifo:
                self.selection_fifo.append(axis_name)
                state_changed = True

        if state_changed:
            self.update_current_axis_labels()

            print 'emit slice_changed:', self.slice_def, '|| ca:', self.get_current_axes()
            self.slice_changed.emit(self.slice_def, self.get_current_axes())

    def update_current_axis_labels(self):
        if len(self.selection_fifo) == 0:
            self.ui.label_axis_1.setText('')
            self.ui.label_axis_2.setText('')
        elif len(self.selection_fifo) == 1:
            self.ui.label_axis_1.setText(self.selection_fifo[0])
            self.ui.label_axis_2.setText('')
        else:
            self.ui.label_axis_1.setText(self.selection_fifo[0])
            self.ui.label_axis_2.setText(self.selection_fifo[1])

    def deselect_axis(self, axis_name):
        unchecked = QtCore.Qt.Unchecked
        self.slicers[str(axis_name)].set_axis_selection_checkbox_state(unchecked)

    def swap_current_axes(self):
        if self.selection_fifo.swap(0,1):
            self.slice_changed.emit(self.slice_def, self.get_current_axes())
            self.update_current_axis_labels()


    def closeEvent(self, event):
        """
        Override cloveEvent to emit a signal just before the widget is actually
        closed.
        """
        self.closing.emit()
        QtGui.QWidget.closeEvent(self, event)