def symbol_icon(symbol, color=None): bm = QtGui.QBitmap(icon_path(POINT_ICONS.get(symbol, 'glue_circle'))) if color is not None: return QtGui.QIcon(tint_pixmap(bm, color)) return QtGui.QIcon(bm)
def _update_icons(self): self.setIconSize(QtCore.QSize(self.width(), 15)) for index in range(self.count()): cmap = self.itemData(index) icon = QtGui.QIcon( cmap2pixmap(cmap, size=(self.width(), 15), steps=200)) self.setItemIcon(index, icon)
def __init__(self, collect, default=None, parent=None): """Create a new dialog for subset faceting :param collect: The :class:`~glue.core.data_collection.DataCollection` to use :param default: The default dataset in the collection (optional) """ super(SubsetFacet, self).__init__(parent=parent) self.ui = load_ui('subset_facet.ui', self, directory=os.path.dirname(__file__)) self.ui.setWindowTitle("Subset Facet") self._collect = collect self.ui.component_selector.setup(self._collect) if default is not None: self.ui.component_selector.data = default val = QtGui.QDoubleValidator(-1e100, 1e100, 4, None) self.ui.component_selector.component_changed.connect(self._set_limits) combo = self.ui.color_scale for cmap in [cm.cool, cm.RdYlBu, cm.RdYlGn, cm.RdBu, cm.Purples]: combo.addItem(QtGui.QIcon(cmap2pixmap(cmap)), cmap.name, cmap)
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
def toggle_record(self): if self.record_action.isChecked(): # pop up a window for file saving outfile, file_filter = getsavefilename( caption='Save Animation', filters='GIF Files (*.gif);;') # This indicates that the user cancelled if not outfile: self.record_action.blockSignals(True) self.record_action.setChecked(False) self.record_action.blockSignals(False) return self.record_action.setIcon(QtGui.QIcon(RECORD_STOP_ICON)) self.writer = imageio.get_writer(outfile) self.record_timer.start(0.1) else: self.record_timer.stop() self.record_action.setIcon(QtGui.QIcon(RECORD_START_ICON)) self.writer.close()
def __init__(self, *args, **kwargs): super(ContourMode, self).__init__(*args, **kwargs) self.icon = QtGui.QIcon(os.path.join(ROOT, "glue_contour.png")) self.mode_id = 'Contour' self.action_text = 'Contour' self.tool_tip = 'Define a region of intrest via contours' self.shortcut = 'N'
def __init__(self, *args, **kwargs): super(FloodfillMode, self).__init__(*args, **kwargs) self.icon = QtGui.QIcon(os.path.join(ROOT, "glue_floodfill.png")) self.mode_id = 'Flood fill' self.action_text = 'Flood fill' self.tool_tip = ('Define a region of interest with the flood fill ' 'algorithm. Click to define the starting pixel and ' 'drag (keeping the mouse clicked) to grow the ' 'selection.') self._start_event = None self._end_event = None
def get_icon(icon_name): """ Build a QtGui.QIcon from an image name Parameters ---------- icon_name : str Name of image file. Assumed to be a png file in glue/qt/icons Do not include the extension Returns ------- A QtGui.QIcon object """ return QtGui.QIcon(icon_path(icon_name))
def layer_icon(layer): """Create a QtGui.QIcon for a Data or Subset instance :type layer: :class:`~glue.core.data.Data`, :class:`~glue.core.subset.Subset`, or object with a .style attribute :rtype: QtGui.QIcon """ icon = POINT_ICONS.get(layer.style.marker, 'circle_point') bm = QtGui.QBitmap(icon_path(icon)) color = mpl_to_qt4_color(layer.style.color) pm = tint_pixmap(bm, color) pm = pm.scaledToHeight(15, Qt.SmoothTransformation) return QtGui.QIcon(pm)
def test_glue_action_button(): a = QtGui.QAction(None) a.setToolTip("testtooltip") a.setWhatsThis("testwhatsthis") a.setIcon(QtGui.QIcon("dummy_file")) a.setText('testtext') b = GlueActionButton() b.set_action(a) # assert b.icon() == a.icon() icons are copied, apparently assert b.text() == a.text() assert b.toolTip() == a.toolTip() assert b.whatsThis() == a.whatsThis() #stays in sync a.setText('test2') assert b.text() == 'test2'
def __init__(self, data_collection=None, session=None): self.app = get_qapp() QtGui.QMainWindow.__init__(self) Application.__init__(self, data_collection=data_collection, session=session) self.app.setQuitOnLastWindowClosed(True) pth = os.path.abspath(os.path.dirname(__file__)) pth = os.path.join(pth, 'icons', 'app_icon.png') self.app.setWindowIcon(QtGui.QIcon(pth)) # Even though we loaded the plugins in start_glue, we re-load them here # in case glue was started directly by initializing this class. load_plugins() self.setWindowIcon(self.app.windowIcon()) self.setAttribute(Qt.WA_DeleteOnClose) self._actions = {} self._terminal = None self._setup_ui() self.tab_widget.setMovable(True) self.tab_widget.setTabsClosable(True) # The following is a counter that never goes down, even if tabs are # deleted (this is by design, to avoid having two tabs called the # same if a tab is removed then a new one added again) self._total_tab_count = 0 lwidget = self._ui.layerWidget a = PlotAction(lwidget, self) lwidget.layerTree.addAction(a) lwidget.bind_selection_to_edit_subset() self._tweak_geometry() self._create_actions() self._create_menu() self._connect() self.new_tab() self._update_plot_dashboard(None) self._load_settings()
def layer_artist_icon(artist): """Create a QtGui.QIcon for a LayerArtist instance""" # TODO: need a test for this from glue.viewers.image.layer_artist import ImageLayerArtist if not artist.enabled: bm = QtGui.QBitmap(icon_path('glue_delete')) elif isinstance(artist, ImageLayerArtist): bm = QtGui.QBitmap(icon_path('glue_image')) else: bm = QtGui.QBitmap( icon_path( POINT_ICONS.get(artist.layer.style.marker, 'glue_circle_point'))) color = mpl_to_qt4_color(artist.layer.style.color) pm = tint_pixmap(bm, color) return QtGui.QIcon(pm)
def __init__(self, vispy_widget=None, parent=None): super(VispyDataViewerToolbar, self).__init__(parent=parent) # Keep a reference to the Vispy Widget and the Vispy Data Viewer self._vispy_widget = vispy_widget self._vispy_data_viewer = parent self._data_collection = parent._data # Set visual preferences self.setIconSize(QtCore.QSize(25, 25)) # Initialize drawing visual self.line_pos = [] self.line = scene.visuals.Line(color=settings.FOREGROUND_COLOR, width=2, method='agg', parent=self._vispy_widget.canvas.scene) # Selection defaults self._scatter = None self.mode = None self.selection_origin = (0, 0) self.selected = [] # Add a timer to control the view rotate self.timer = app.Timer(connect=self.rotate) self.record_timer = app.Timer(connect=self.record) self.writer = None a = QtWidgets.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.addAction(a) self.save_action = a if IMAGEIO_INSTALLED: a = QtWidgets.QAction(QtGui.QIcon(RECORD_START_ICON), 'Record', parent) a.triggered.connect(nonpartial(self.toggle_record)) a.setToolTip('Start/Stop the record') a.setCheckable(True) parent.addAction(a) self.addAction(a) self.record_action = a a = QtWidgets.QAction(QtGui.QIcon(ROTATE_ICON), 'Rotate View', parent) a.triggered.connect(nonpartial(self.toggle_rotate)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.rotate_action = a # Set up selection actions a = QtWidgets.QAction(get_icon('glue_lasso'), 'Lasso Selection', parent) a.triggered.connect(nonpartial(self.toggle_lasso)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.lasso_action = a a = QtWidgets.QAction(get_icon('glue_square'), 'Rectangle Selection', parent) a.triggered.connect(nonpartial(self.toggle_rectangle)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.rectangle_action = a a = QtWidgets.QAction(get_icon('glue_circle'), 'Ellipse Selection', parent) a.triggered.connect(nonpartial(self.toggle_ellipse)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.ellipse_action = a # TODO: change path to icon once it's in a released version of glue a = QtWidgets.QAction(QtGui.QIcon(POINT_ICON), 'Point Selection', parent) a.triggered.connect(nonpartial(self.toggle_point)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.point_action = a # Connect callback functions to VisPy Canvas self._vispy_widget.canvas.events.mouse_press.connect( self.on_mouse_press) self._vispy_widget.canvas.events.mouse_release.connect( self.on_mouse_release) self._vispy_widget.canvas.events.mouse_move.connect(self.on_mouse_move)
def setupUi(self, LayerTree): LayerTree.setObjectName("LayerTree") LayerTree.resize(241, 282) self.verticalLayout_2 = QtGui.QVBoxLayout(LayerTree) self.verticalLayout_2.setSpacing(5) self.verticalLayout_2.setContentsMargins(5, 5, 5, 0) self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setSpacing(2) self.verticalLayout.setContentsMargins(-1, -1, -1, 0) self.verticalLayout.setObjectName("verticalLayout") 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.setMinimumSize(QtCore.QSize(0, 0)) self.layerTree.setMaximumSize(QtCore.QSize(16777215, 16777215)) self.layerTree.setBaseSize(QtCore.QSize(0, 0)) self.layerTree.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) self.layerTree.setObjectName("layerTree") self.verticalLayout.addWidget(self.layerTree) self.button_row = QtGui.QHBoxLayout() self.button_row.setSpacing(3) self.button_row.setObjectName("button_row") self.layerAddButton = QtGui.QPushButton(LayerTree) font = QtGui.QFont() font.setPointSize(11) self.layerAddButton.setFont(font) self.layerAddButton.setStatusTip("") self.layerAddButton.setWhatsThis("") self.layerAddButton.setText("") icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/icons/glue_open.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.layerAddButton.setIcon(icon) self.layerAddButton.setIconSize(QtCore.QSize(18, 18)) self.layerAddButton.setDefault(False) self.layerAddButton.setFlat(False) self.layerAddButton.setObjectName("layerAddButton") self.button_row.addWidget(self.layerAddButton) self.newSubsetButton = GlueActionButton(LayerTree) font = QtGui.QFont() font.setPointSize(11) self.newSubsetButton.setFont(font) self.newSubsetButton.setText("") icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/icons/glue_subset.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.newSubsetButton.setIcon(icon1) self.newSubsetButton.setIconSize(QtCore.QSize(19, 19)) self.newSubsetButton.setObjectName("newSubsetButton") self.button_row.addWidget(self.newSubsetButton) self.layerRemoveButton = QtGui.QPushButton(LayerTree) self.layerRemoveButton.setEnabled(False) font = QtGui.QFont() font.setPointSize(11) self.layerRemoveButton.setFont(font) self.layerRemoveButton.setText("") icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/icons/glue_delete.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.layerRemoveButton.setIcon(icon2) self.layerRemoveButton.setObjectName("layerRemoveButton") self.button_row.addWidget(self.layerRemoveButton) self.linkButton = GlueActionButton(LayerTree) self.linkButton.setEnabled(True) font = QtGui.QFont() font.setPointSize(11) self.linkButton.setFont(font) self.linkButton.setText("") icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/icons/glue_link.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.linkButton.setIcon(icon3) self.linkButton.setObjectName("linkButton") self.button_row.addWidget(self.linkButton) spacerItem = QtGui.QSpacerItem(20, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.button_row.addItem(spacerItem) self.verticalLayout.addLayout(self.button_row) self.verticalLayout_2.addLayout(self.verticalLayout) self.retranslateUi(LayerTree) QtCore.QMetaObject.connectSlotsByName(LayerTree)
def __init__(self, label, cmap, parent): super(ColormapAction, self).__init__(label, parent) self.cmap = cmap pm = cmap2pixmap(cmap) self.setIcon(QtGui.QIcon(pm))
def __init__(self, vispy_widget=None, parent=None): super(VispyDataViewerToolbar, self).__init__(parent=parent) # Keep a reference to the Vispy Widget and the Vispy Data Viewer self._vispy_widget = vispy_widget self._vispy_data_viewer = parent self._data_collection = parent._data # Set visual preferences self.setIconSize(QtCore.QSize(25, 25)) # Initialize drawing visual self.line_pos = [] self.line = scene.visuals.Line(color='white', method='gl', parent=self._vispy_widget.canvas.scene) # Selection defaults self._scatter = None self.mode = None self.selection_origin = (0, 0) self.selected = [] # Set up selection actions a = QtGui.QAction(get_icon('glue_lasso'), 'Lasso Selection', parent) a.triggered.connect(nonpartial(self.toggle_lasso)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.lasso_action = a a = QtGui.QAction(get_icon('glue_square'), 'Rectangle Selection', parent) a.triggered.connect(nonpartial(self.toggle_rectangle)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.rectangle_action = a a = QtGui.QAction(get_icon('glue_circle'), 'Ellipse Selection', parent) a.triggered.connect(nonpartial(self.toggle_ellipse)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.ellipse_action = a # TODO: change path to icon once it's in a released version of glue a = QtGui.QAction(QtGui.QIcon(POINT_ICON), 'Point Selection', parent) a.triggered.connect(nonpartial(self.toggle_point)) a.setCheckable(True) parent.addAction(a) self.addAction(a) self.point_action = a # Connect callback functions to VisPy Canvas self._vispy_widget.canvas.events.mouse_press.connect( self.on_mouse_press) self._vispy_widget.canvas.events.mouse_release.connect( self.on_mouse_release) self._vispy_widget.canvas.events.mouse_move.connect(self.on_mouse_move)