Пример #1
0
    def __init__(self, browser, model, x, y):
        # the GUI that enables selection and manipulation of
        # astropy spectral components is actually handled by
        # the SpectralModelManager class.
        self.manager = SpectralModelManager()
        # any change in the model manager should trigger
        # a refresh of the local spectral model. Component
        # selection should cause the component to be painted
        # in a distinct color.
        self.manager.changed.connect(browser._sync_model_list)
        self.manager.selected.connect(browser._display_selected_model)
        # the model manager needs to know the actual
        # data being plotted and fitted.
        self.manager.setArrays(x, y)

        model_list_gui = self.manager.buildMainPanel(model)
        model_list_gui.setStretchFactor(0,0)
        model_tree = self.manager.treeWidget

        win = QMainWindow()
        wid = QWidget()
        win.setCentralWidget(wid)
        l = QHBoxLayout()
        l.setSpacing(2)
        l.setContentsMargins(3, 3, 3, 3)
        wid.setLayout(l)

        widget = MplWidget()
        win.addToolBar(GlueToolbar(widget.canvas, win))
        l.addWidget(widget)

        right = QVBoxLayout()
        right.setSpacing(2)
        right.setContentsMargins(2, 0, 2, 0)

        right.addWidget(model_list_gui)

        buttons = QHBoxLayout()
        buttons.setSpacing(2)
        buttons.setContentsMargins(2, 0, 2, 0)

        right.addLayout(buttons)
        add = QPushButton(get_icon('glue_cross'), '')
        add.setToolTip('Add a spectral component')
        remove = QPushButton(get_icon('glue_delete'), '')
        remove.setToolTip('Remove the current spectral component')
        fit = QPushButton('Fit')
        fit.setToolTip("Fit model to spectrum")

        buttons.insertStretch(0, 1)
        buttons.addWidget(fit)
        l.addLayout(right)

        self.canvas = widget.canvas
        self.window = win
        self.model_list_gui = model_list_gui
        self.model_tree = model_tree
        self.remove = remove
        self.add = add
        self.fit = fit
Пример #2
0
    def __init__(self, browser, model, x, y):
        # the GUI that enables selection and manipulation of
        # astropy spectral components is actually handled by
        # the SpectralModelManager class.
        self.manager = SpectralModelManager()
        # any change in the model manager should trigger
        # a refresh of the local spectral model. Component
        # selection should cause the component to be painted
        # in a distinct color.
        self.manager.changed.connect(browser._sync_model_list)
        self.manager.selected.connect(browser._display_selected_model)
        # the model manager needs to know the actual
        # data being plotted and fitted.
        self.manager.setArrays(x, y)

        model_list_gui = self.manager.buildMainPanel(model)
        model_list_gui.setStretchFactor(0, 0)
        model_tree = self.manager.treeWidget

        win = QMainWindow()
        wid = QWidget()
        win.setCentralWidget(wid)
        l = QHBoxLayout()
        l.setSpacing(2)
        l.setContentsMargins(3, 3, 3, 3)
        wid.setLayout(l)

        widget = MplWidget()
        win.addToolBar(GlueToolbar(widget.canvas, win))
        l.addWidget(widget)

        right = QVBoxLayout()
        right.setSpacing(2)
        right.setContentsMargins(2, 0, 2, 0)

        right.addWidget(model_list_gui)

        buttons = QHBoxLayout()
        buttons.setSpacing(2)
        buttons.setContentsMargins(2, 0, 2, 0)

        right.addLayout(buttons)
        add = QPushButton(get_icon('glue_cross'), '')
        add.setToolTip('Add a spectral component')
        remove = QPushButton(get_icon('glue_delete'), '')
        remove.setToolTip('Remove the current spectral component')
        fit = QPushButton('Fit')
        fit.setToolTip("Fit model to spectrum")

        buttons.insertStretch(0, 1)
        buttons.addWidget(fit)
        l.addLayout(right)

        self.canvas = widget.canvas
        self.window = win
        self.model_list_gui = model_list_gui
        self.model_tree = model_tree
        self.remove = remove
        self.add = add
        self.fit = fit
Пример #3
0
    def _mouse_modes(self):
        modes = []
        modes.append(("Rectangle", get_icon('glue_square'),
                      lambda tf: self._set_roi_mode('rectangle', tf)))
        modes.append(("Circle", get_icon('glue_circle'),
                      lambda tf: self._set_roi_mode('circle', tf)))
        modes.append(("Polygon", get_icon('glue_lasso'),
                      lambda tf: self._set_roi_mode('polygon', tf)))

        for tool in self._tools:
            modes += tool._get_modes(self.canvas)
            add_callback(self.client, 'display_data', tool._display_data_hook)

        return modes
Пример #4
0
    def _create_terminal(self):
        if self._terminal is not None:  # already set up
            return

        if hasattr(self, '_terminal_exception'):  # already failed to set up
            return

        self._terminal_button = QtGui.QToolButton(self._ui)
        self._terminal_button.setToolTip("Toggle IPython Prompt")
        i = get_icon('IPythonConsole')
        self._terminal_button.setIcon(i)
        self._terminal_button.setIconSize(QtCore.QSize(25, 25))

        self._ui.layerWidget.button_row.addWidget(self._terminal_button)

        try:
            from glue.qt.widgets.terminal import glue_terminal
            widget = glue_terminal(data_collection=self._data,
                                   dc=self._data,
                                   hub=self._hub,
                                   session=self.session,
                                   application=self,
                                   **vars(env))
            self._terminal_button.clicked.connect(self._toggle_terminal)
        except Exception as e:  # pylint: disable=W0703
            import traceback
            self._terminal_exception = traceback.format_exc()
            self._setup_terminal_error_dialog(e)
            return

        self._terminal = self.add_widget(widget, label='IPython')
        self._hide_terminal()
Пример #5
0
    def make_toolbar(self):
        tb = QtGui.QToolBar(parent=self)
        tb.setIconSize(QtCore.QSize(25, 25))
        tb.layout().setSpacing(1)
        tb.setFocusPolicy(Qt.StrongFocus)

        agroup = QtGui.QActionGroup(tb)
        agroup.setExclusive(True)
        for (mode_text, mode_icon, mode_cb) in self._mouse_modes():
            # TODO: add icons similar to the Matplotlib toolbar
            action = tb.addAction(mode_icon, mode_text)
            action.setCheckable(True)
            action.toggled.connect(mode_cb)
            agroup.addAction(action)

        action = tb.addAction(get_icon('glue_move'), "Pan")
        self.mode_actns['pan'] = action
        action.setCheckable(True)
        action.toggled.connect(lambda tf: self.mode_cb('pan', tf))
        agroup.addAction(action)
        icon = QtGui.QIcon(os.path.join(ginga_icon_dir, 'hand_48.png'))
        action = tb.addAction(icon, "Free Pan")
        self.mode_actns['freepan'] = action
        action.setCheckable(True)
        action.toggled.connect(lambda tf: self.mode_cb('freepan', tf))
        agroup.addAction(action)
        icon = QtGui.QIcon(os.path.join(ginga_icon_dir, 'rotate_48.png'))
        action = tb.addAction(icon, "Rotate")
        self.mode_actns['rotate'] = action
        action.setCheckable(True)
        action.toggled.connect(lambda tf: self.mode_cb('rotate', tf))
        agroup.addAction(action)
        action = tb.addAction(get_icon('glue_contrast'), "Contrast")
        self.mode_actns['contrast'] = action
        action.setCheckable(True)
        action.toggled.connect(lambda tf: self.mode_cb('contrast', tf))
        agroup.addAction(action)
        icon = QtGui.QIcon(os.path.join(ginga_icon_dir, 'cuts_48.png'))
        action = tb.addAction(icon, "Cuts")
        self.mode_actns['cuts'] = action
        action.setCheckable(True)
        action.toggled.connect(lambda tf: self.mode_cb('cuts', tf))
        agroup.addAction(action)

        cmap_w = _colormap_mode(self, self.client.set_cmap)
        tb.addWidget(cmap_w)
        return tb
Пример #6
0
 def __init__(self, axes, **kwargs):
     super(VRangeMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_yrange_select')
     self.mode_id = 'Y range'
     self.action_text = 'Y range'
     self.tool_tip = 'Select a range of y values'
     self._roi_tool = qt_roi.QtYRangeROI(self._axes)
     self.shortcut = 'V'
Пример #7
0
 def __init__(self, axes, **kwargs):
     super(PickMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_yrange_select')
     self.mode_id = 'Pick'
     self.action_text = 'Pick'
     self.tool_tip = 'Select a single item'
     self._roi_tool = roi.MplPickROI(self._axes)
     self.shortcut = 'K'
Пример #8
0
 def __init__(self, axes, **kwargs):
     super(LassoMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_lasso')
     self.mode_id = 'Lasso'
     self.action_text = 'Polygonal ROI'
     self.tool_tip = 'Lasso a region of interest'
     self._roi_tool = qt_roi.QtPolygonalROI(self._axes)
     self.shortcut = 'L'
Пример #9
0
 def __init__(self, axes, **kwargs):
     super(CircleMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_circle')
     self.mode_id = 'Circle'
     self.action_text = 'Circular ROI'
     self.tool_tip = 'Define a circular region of interest'
     self._roi_tool = qt_roi.QtCircularROI(self._axes)
     self.shortcut = 'C'
Пример #10
0
 def __init__(self, axes, **kwargs):
     super(RectangleMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_square')
     self.mode_id = 'Rectangle'
     self.action_text = 'Rectangular ROI'
     self.tool_tip = 'Define a rectangular region of interest'
     self._roi_tool = qt_roi.QtRectangularROI(self._axes)
     self.shortcut = 'R'
Пример #11
0
def act(name, parent, tip='', icon=None, shortcut=None):
    """ Factory for making a new action """
    a = QtGui.QAction(name, parent)
    a.setToolTip(tip)
    if icon:
        a.setIcon(get_icon(icon))
    if shortcut:
        a.setShortcut(shortcut)
    return a
Пример #12
0
    def __init__(self):

        win = QMainWindow()
        wid = QWidget()
        win.setCentralWidget(wid)
        l = QHBoxLayout()
        l.setSpacing(2)
        l.setContentsMargins(3, 3, 3, 3)
        wid.setLayout(l)

        widget = MplWidget()
        win.addToolBar(GlueToolbar(widget.canvas, win))
        l.addWidget(widget)

        right = QVBoxLayout()
        right.setSpacing(2)
        right.setContentsMargins(2, 0, 2, 0)
        model_list = QListWidget()
        right.addWidget(model_list)

        buttons = QHBoxLayout()
        buttons.setSpacing(2)
        buttons.setContentsMargins(2, 0, 2, 0)

        right.addLayout(buttons)
        add = QPushButton(get_icon('glue_cross'), '')
        add.setToolTip('Add a spectral component')
        remove = QPushButton(get_icon('glue_delete'), '')
        remove.setToolTip('Remove the current spectral component')
        fit = QPushButton('Fit')
        fit.setToolTip("Fit model to spectrum")

        buttons.insertStretch(0, 1)
        buttons.addWidget(add)
        buttons.addWidget(remove)
        buttons.addWidget(fit)
        l.addLayout(right)

        self.canvas = widget.canvas
        self.window = win
        self.model_list = model_list
        self.remove = remove
        self.add = add
        self.fit = fit
Пример #13
0
 def __init__(self, axes, **kwargs):
     super(PolyMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_lasso')
     self.mode_id = 'Polygon'
     self.action_text = 'Polygonal ROI'
     self.tool_tip = ('Lasso a region of interest\n'
                      '  ENTER accepts the path\n'
                      '  ESCAPE clears the path')
     self._roi_tool = qt_roi.QtPolygonalROI(self._axes)
     self.shortcut = 'G'
Пример #14
0
 def __init__(self, axes, **kwargs):
     super(SpectrumExtractorMode, self).__init__(axes, **kwargs)
     self.icon = get_icon('glue_spectrum')
     self.mode_id = 'Spectrum'
     self.action_text = 'Spectrum'
     self.tool_tip = 'Extract a spectrum from the selection'
     self._roi_tool = qt_roi.QtRectangularROI(self._axes)
     self._roi_tool.plot_opts.update(edgecolor='#c51b7d',
                                     facecolor=None,
                                     edgewidth=3,
                                     alpha=1.0)
     self.shortcut = 'S'
Пример #15
0
    def _init_toolbar(self):
        self.basedir = os.path.join(matplotlib.rcParams['datapath'], 'images')
        parent = QtGui.QToolBar.parent(self)

        a = QtGui.QAction(get_icon('glue_home'),
                          'Home', parent)
        a.triggered.connect(nonpartial(self.home))
        a.setToolTip('Reset original zoom')
        a.setShortcut('H')
        a.setShortcutContext(Qt.WidgetShortcut)
        parent.addAction(a)
        self.buttons['HOME'] = a
        self.addAction(a)

        a = QtGui.QAction(get_icon('glue_filesave'),
                          'Save', parent)
        a.triggered.connect(nonpartial(self.save_figure))
        a.setToolTip('Save the figure')
        a.setShortcut('Ctrl+Shift+S')
        parent.addAction(a)
        self.buttons['SAVE'] = a
        self.addAction(a)

        a = QtGui.QAction(get_icon('glue_back'),
                          'Back', parent)
        a.triggered.connect(nonpartial(self.back))
        parent.addAction(a)
        self.addAction(a)
        self.buttons['BACK'] = a
        a.setToolTip('Back to previous view')

        a = QtGui.QAction(get_icon('glue_forward'),
                          'Forward', parent)
        a.triggered.connect(nonpartial(self.forward))
        a.setToolTip('Forward to next view')
        parent.addAction(a)
        self.buttons['FORWARD'] = a
        self.addAction(a)

        a = QtGui.QAction(get_icon('glue_move'),
                          'Pan', parent)
        a.triggered.connect(nonpartial(self.pan))
        a.setToolTip('Pan axes with left mouse, zoom with right')
        a.setCheckable(True)
        a.setShortcut('M')
        a.setShortcutContext(Qt.WidgetShortcut)
        parent.addAction(a)
        self.addAction(a)
        self.buttons['PAN'] = a

        a = QtGui.QAction(get_icon('glue_zoom_to_rect'),
                          'Zoom', parent)
        a.triggered.connect(nonpartial(self.zoom))
        a.setToolTip('Zoom to rectangle')
        a.setShortcut('Z')
        a.setShortcutContext(Qt.WidgetShortcut)
        a.setCheckable(True)
        parent.addAction(a)
        self.addAction(a)
        self.buttons['ZOOM'] = a
Пример #16
0
    def menu(self):
        m = QtGui.QMenu()

        a = QtGui.QAction("Or", m)
        a.setIcon(get_icon('glue_or'))
        a.triggered.connect(nonpartial(self._paste, OrMode))
        m.addAction(a)

        a = QtGui.QAction("And", m)
        a.setIcon(get_icon('glue_and'))
        a.triggered.connect(nonpartial(self._paste, AndMode))
        m.addAction(a)

        a = QtGui.QAction("XOR", m)
        a.setIcon(get_icon('glue_xor'))
        a.triggered.connect(nonpartial(self._paste, XorMode))
        m.addAction(a)

        a = QtGui.QAction("Not", m)
        a.setIcon(get_icon('glue_andnot'))
        a.triggered.connect(nonpartial(self._paste, AndNotMode))
        m.addAction(a)
        return m
Пример #17
0
    def __init__(self, axes, **kwargs):
        super(PathMode, self).__init__(axes, **kwargs)
        self.icon = get_icon('glue_slice')
        self.mode_id = 'Slice'
        self.action_text = 'Slice Extraction'
        self.tool_tip = ('Extract a slice from an arbitrary path\n'
                         '  ENTER accepts the path\n'
                         '  ESCAPE clears the path')
        self._roi_tool = qt_roi.QtPathROI(self._axes)
        self.shortcut = 'P'

        self._roi_tool.plot_opts.update(edgecolor='#de2d26',
                                        facecolor=None,
                                        edgewidth=3,
                                        alpha=0.4)
Пример #18
0
 def __init__(self, layer_tree_widget):
     self._parent = layer_tree_widget.layerTree
     super(LayerAction, self).__init__(self._title.title(), self._parent)
     self._layer_tree = layer_tree_widget
     if self._icon:
         self.setIcon(get_icon(self._icon))
     if self._tooltip:
         self.setToolTip(self._tooltip)
     self.setEnabled(self._enabled_on_init)
     if self._shortcut_context is not None:
         self.setShortcutContext(self._shortcut_context)
     if self._shortcut:
         self.setShortcut(self._shortcut)
     self._parent.addAction(self)
     self._connect()
Пример #19
0
    def __init__(self, *args, **kwargs):
        super(ContrastMode, self).__init__(*args, **kwargs)
        self.icon = get_icon('glue_contrast')
        self.mode_id = 'Contrast'
        self.action_text = 'Contrast'
        self.tool_tip = 'Adjust the bias/contrast'
        self.shortcut = 'B'

        self.bias = 0.5
        self.contrast = 1.0

        self._last = None
        self._result = None
        self._percent_lo = 1.
        self._percent_hi = 99.
        self.stretch = 'linear'
        self._vmin = None
        self._vmax = None
Пример #20
0
def _colormap_mode(parent, on_trigger):

    # actions for each colormap
    acts = []
    # for label, cmap in config.colormaps:
    for label in ginga_cmap.get_names():
        cmap = ginga_cmap.get_cmap(label)
        a = ColormapAction(label, cmap, parent)
        a.triggered.connect(nonpartial(on_trigger, cmap))
        acts.append(a)

    # Toolbar button
    tb = QtGui.QToolButton()
    tb.setWhatsThis("Set color scale")
    tb.setToolTip("Set color scale")
    icon = get_icon('glue_rainbow')
    tb.setIcon(icon)
    tb.setPopupMode(QtGui.QToolButton.InstantPopup)
    tb.addActions(acts)

    return tb
Пример #21
0
    def setupUi(self, LayerTree):
        font = QtGui.QFont()
        font.setPointSize(11)

        LayerTree.setObjectName("LayerTree")
        LayerTree.resize(241, 282)

        self.layout = QtGui.QVBoxLayout(LayerTree)
        self.layout.setSpacing(2)
        self.layout.setContentsMargins(5, 5, 5, 0)
        self.layout.setObjectName("layout")

        self.layerTree = DataCollectionView(LayerTree)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(10)
        sizePolicy.setHeightForWidth(self.layerTree.sizePolicy().hasHeightForWidth())
        self.layerTree.setSizePolicy(sizePolicy)
        self.layerTree.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.layerTree.setObjectName("layerTree")
        self.layout.addWidget(self.layerTree)

        self.button_row = QtGui.QHBoxLayout()
        self.button_row.setSpacing(3)
        self.button_row.setObjectName("button_row")

        self.layerAddButton = QtGui.QPushButton(LayerTree)
        self.layerAddButton.setFont(font)
        icon = get_icon('glue_open')
        self.layerAddButton.setIcon(icon)
        self.layerAddButton.setIconSize(QtCore.QSize(18, 18))
        self.layerAddButton.setDefault(False)
        self.layerAddButton.setObjectName("layerAddButton")

        self.button_row.addWidget(self.layerAddButton)
        self.newSubsetButton = GlueActionButton(LayerTree)
        self.newSubsetButton.setIcon(get_icon('glue_subset'))
        self.newSubsetButton.setIconSize(QtCore.QSize(18, 18))
        self.newSubsetButton.setObjectName("newSubsetButton")
        self.button_row.addWidget(self.newSubsetButton)
        self.newSubsetButton.setFont(font)

        self.layerRemoveButton = QtGui.QPushButton(LayerTree)
        self.layerRemoveButton.setEnabled(False)
        self.layerRemoveButton.setIcon(get_icon('glue_delete'))
        self.layerRemoveButton.setIconSize(QtCore.QSize(18, 18))
        self.layerRemoveButton.setObjectName("layerRemoveButton")
        self.layerRemoveButton.setFont(font)
        self.button_row.addWidget(self.layerRemoveButton)

        self.linkButton = GlueActionButton(LayerTree)
        self.linkButton.setEnabled(True)
        self.linkButton.setIcon(get_icon('glue_link'))
        self.linkButton.setObjectName("linkButton")
        self.linkButton.setIconSize(QtCore.QSize(18, 18))
        self.linkButton.setFont(font)
        self.button_row.addWidget(self.linkButton)

        spacerItem = QtGui.QSpacerItem(20, 20,
                                       QtGui.QSizePolicy.Expanding,
                                       QtGui.QSizePolicy.Minimum)
        self.button_row.addItem(spacerItem)
        self.layout.addLayout(self.button_row)

        self.retranslateUi(LayerTree)
        QtCore.QMetaObject.connectSlotsByName(LayerTree)
Пример #22
0
 def __init__(self, *args, **kwargs):
     super(LinkAction, self).__init__(*args, **kwargs)
     self._link_icon = get_icon(self._icon)
     self._unlink_icon = get_icon('glue_unlink')
Пример #23
0
 def _get_modes(self, canvas):
     return [(self.label, get_icon(self.icon), self._set_path_mode)]