Ejemplo n.º 1
0
    def edit_label(self, index):
        if not (self._model.flags(index) & Qt.ItemIsEditable):
            return
        self.edit(index)

    def _edit(self, index):
        item = self._model.data(index, role=Qt.UserRole)
        if item is None or item.edit_factory is None:
            return

        rect = self.visualRect(index)
        pos = self.mapToGlobal(rect.bottomLeft())
        pos.setY(pos.y() + 1)
        item.edit_factory(pos)

CUSTOM_QWIDGETS.append(DataCollectionView)


class LabeledDelegate(QtGui.QStyledItemDelegate):

    """ Add placeholder text to default delegate """

    def setEditorData(self, editor, index):
        super(LabeledDelegate, self).setEditorData(editor, index)
        label = index.model().data(index, role=Qt.DisplayRole)
        editor.selectAll()
        editor.setText(label)


if __name__ == "__main__":
Ejemplo n.º 2
0
class GlueActionButton(QtWidgets.QPushButton):
    def set_action(self, action, text=True):
        self._text = text
        self._action = action
        self.clicked.connect(action.trigger)
        action.changed.connect(self._sync_to_action)
        self._sync_to_action()

    def _sync_to_action(self):
        self.setIcon(self._action.icon())
        if self._text:
            self.setText(self._action.text())
        self.setToolTip(self._action.toolTip())
        self.setWhatsThis(self._action.whatsThis())
        self.setEnabled(self._action.isEnabled())


CUSTOM_QWIDGETS.append(GlueActionButton)


def action(name, parent, tip='', icon=None, shortcut=None):
    """ Factory for making a new action """
    a = QtWidgets.QAction(name, parent)
    a.setToolTip(tip)
    if icon:
        a.setIcon(get_icon(icon))
    if shortcut:
        a.setShortcut(shortcut)
    return a
Ejemplo n.º 3
0
        if not (self._model.flags(index) & Qt.ItemIsEditable):
            return
        self.edit(index)

    def _edit(self, index):
        item = self._model.data(index, role=Qt.UserRole)
        if item is None or item.edit_factory is None:
            return

        rect = self.visualRect(index)
        pos = self.mapToGlobal(rect.bottomLeft())
        pos.setY(pos.y() + 1)
        item.edit_factory(pos)


CUSTOM_QWIDGETS.append(DataCollectionView)


class LabeledDelegate(QtGui.QStyledItemDelegate):
    """ Add placeholder text to default delegate """
    def setEditorData(self, editor, index):
        super(LabeledDelegate, self).setEditorData(editor, index)
        label = index.model().data(index, role=Qt.DisplayRole)
        editor.selectAll()
        editor.setText(label)


if __name__ == "__main__":

    from glue.external.qt import get_qapp
    from glue.external.qt import QtGui
Ejemplo n.º 4
0
class GlueActionButton(QtGui.QPushButton):
    def set_action(self, action, text=True):
        self._text = text
        self._action = action
        self.clicked.connect(action.trigger)
        action.changed.connect(self._sync_to_action)
        self._sync_to_action()

    def _sync_to_action(self):
        self.setIcon(self._action.icon())
        if self._text:
            self.setText(self._action.text())
        self.setToolTip(self._action.toolTip())
        self.setWhatsThis(self._action.whatsThis())
        self.setEnabled(self._action.isEnabled())


CUSTOM_QWIDGETS.append(GlueActionButton)


def action(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
Ejemplo n.º 5
0
    def color(self):
        return self._color

    def on_color_change(self):
        self._qcolor = mpl_to_qt4_color(self.color())
        image = QtGui.QImage(70, 22, QtGui.QImage.Format_RGB32)
        try:
            image.fill(self._qcolor)
        except TypeError:
            # PySide and old versions of PyQt require a RGBA integer
            image.fill(self._qcolor.rgba())
        pixmap = QtGui.QPixmap.fromImage(image)
        self.setPixmap(pixmap)

CUSTOM_QWIDGETS.append(QColorBox)


class QColormapCombo(QtGui.QComboBox):

    def __init__(self, *args, **kwargs):
        super(QColormapCombo, self).__init__(*args, **kwargs)
        for label, cmap in config.colormaps:
            self.addItem("", userData=cmap)
        self._update_icons()

    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))
Ejemplo n.º 6
0
        tc = self.textCursor()
        pos = tc.position()

        self.setHtml(html)

        # Sometimes the HTML gets rid of double spaces so we have to make
        # sure the position isn't greater than the text length.
        text = self.toPlainText()
        pos = min(pos, len(text))

        tc.setPosition(pos)
        self.setTextCursor(tc)
        self.setAlignment(Qt.AlignCenter)


CUSTOM_QWIDGETS.append(ColorizedCompletionTextEdit)


class CustomComponentWidget(QtGui.QDialog):
    """
    Dialog to add derived components to data via parsed commands.
    """
    def __init__(self, collection, parent=None):

        super(CustomComponentWidget, self).__init__(parent=parent)

        # Load in ui file to set up widget
        self.ui = load_ui('widget.ui',
                          self,
                          directory=os.path.dirname(__file__))
Ejemplo n.º 7
0
    def color(self):
        return self._color

    def on_color_change(self):
        self._qcolor = mpl_to_qt4_color(self.color())
        image = QtGui.QImage(70, 22, QtGui.QImage.Format_RGB32)
        try:
            image.fill(self._qcolor)
        except TypeError:
            # PySide and old versions of PyQt require a RGBA integer
            image.fill(self._qcolor.rgba())
        pixmap = QtGui.QPixmap.fromImage(image)
        self.setPixmap(pixmap)


CUSTOM_QWIDGETS.append(QColorBox)


class QColormapCombo(QtWidgets.QComboBox):
    def __init__(self, *args, **kwargs):
        super(QColormapCombo, self).__init__(*args, **kwargs)
        for label, cmap in config.colormaps:
            self.addItem("", userData=cmap)
        self._update_icons()

    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))
Ejemplo n.º 8
0
        tc = self.textCursor()
        pos = tc.position()

        self.setHtml(html)

        # Sometimes the HTML gets rid of double spaces so we have to make
        # sure the position isn't greater than the text length.
        text = self.toPlainText()
        pos = min(pos, len(text))

        tc.setPosition(pos)
        self.setTextCursor(tc)
        self.setAlignment(Qt.AlignCenter)

CUSTOM_QWIDGETS.append(ColorizedCompletionTextEdit)


class CustomComponentWidget(QtGui.QDialog):
    """
    Dialog to add derived components to data via parsed commands.
    """

    def __init__(self, collection, parent=None):

        super(CustomComponentWidget, self).__init__(parent=parent)

        # Load in ui file to set up widget
        self.ui = load_ui('widget.ui', self,
                          directory=os.path.dirname(__file__))