def __init__(self, parent, text, model):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt_utils import add_expanding_spacer_to_layout
        from pyvmmonitor_qt.qt.QtWidgets import QLineEdit
        QWidget.__init__(self, parent)
        self._in_expected_ui_change = 0
        self._in_expected_data_change = 0
        self._model = model

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._line_edit = QLineEdit(self)
        self._line_edit.textChanged.connect(self._on_line_edit_changed)
        self._line_edit.setFixedWidth(WIDTH_VALUE)

        self._layout.addWidget(self._label)
        add_expanding_spacer_to_layout(self._layout)
        self._layout.addWidget(self._line_edit)
        self._model.register_modified(self._on_model_changed)
        self._update_line_edit()
Example #2
0
    def __init__(self, parent, title, message, detailed_message, icon):
        from pyvmmonitor_qt.qt.QtGui import QCursor
        CustomMessageDialog.__init__(self, parent)

        title = compat.as_unicode(title)
        message = compat.as_unicode(message)
        detailed_message = compat.as_unicode(detailed_message)

        cp = [title, message]
        if detailed_message:
            cp.append(detailed_message)
        self._copy_text = u'\n---------------------\n'.join(cp)
        self._initial_pos = QCursor.pos()
        self._use_initial_pos = True
        self.setWindowTitle(title)

        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt.QtWidgets import QLabel

        self._hor_layout = QHBoxLayout()
        if icon is not None:
            self._label_icon = QLabel(self)
            self._label_icon.setPixmap(icon.pixmap(32, 32))
            self._label_icon.setFixedSize(40, 40)
            self._hor_layout.addWidget(self._label_icon)

        message = message.replace('\n', '<br/>')
        label = self.create_label(message, layout=self._hor_layout)
        self._layout.addLayout(self._hor_layout)

        label.setTextFormat(Qt.RichText)
        label.setTextInteractionFlags(Qt.TextBrowserInteraction)
        label.setOpenExternalLinks(True)

        from pyvmmonitor_qt.qt.QtWidgets import QDialogButtonBox
        self.bbox = bbox = QDialogButtonBox()
        if detailed_message:
            self.bt_copy = bbox.addButton(u'Copy to clipboard', QDialogButtonBox.ApplyRole)
        else:
            self.bt_copy = None

        self.bt_close = bbox.addButton(u'Ok', QDialogButtonBox.RejectRole)
        if detailed_message:
            self.bt_show_details = bbox.addButton(u'Show Details...', QDialogButtonBox.AcceptRole)
        else:
            self.bt_show_details = None

        bbox.clicked.connect(self._clicked_button)

        self._layout.addWidget(bbox)
        if detailed_message:
            self.tx_details = self.create_text(
                detailed_message, read_only=True, line_wrap=False, is_html=False)

            self.tx_details.setVisible(False)

        self.adjustSize()
class _LabelAndHex(QWidget):

    def __init__(self, parent, text, model):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt_utils import add_expanding_spacer_to_layout
        from pyvmmonitor_qt.qt.QtWidgets import QLineEdit
        QWidget.__init__(self, parent)
        self._in_expected_ui_change = 0
        self._in_expected_data_change = 0
        self._model = model

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._line_edit = QLineEdit(self)
        self._line_edit.textChanged.connect(self._on_line_edit_changed)
        self._line_edit.setFixedWidth(WIDTH_VALUE)

        self._layout.addWidget(self._label)
        add_expanding_spacer_to_layout(self._layout)
        self._layout.addWidget(self._line_edit)
        self._model.register_modified(self._on_model_changed)
        self._update_line_edit()

    def _on_model_changed(self, obj, attrs):
        if 'color' in attrs:
            self._update_line_edit()

    @does_expected_ui_change
    @skip_on_expected_data_change
    def _update_line_edit(self):
        color = self._model.color
        self._line_edit.setText(color.name())
        self._line_edit.setStyleSheet("")

    @skip_on_expected_ui_change
    @does_expected_data_change
    def _on_line_edit_changed(self, value):
        color = QColor()
        color.setNamedColor(value)
        if not color.isValid():
            color.setNamedColor('#' + value)
        if color.isValid():
            self._model.color = color
            self._line_edit.setStyleSheet("")
        else:
            self._line_edit.setStyleSheet("QLineEdit { background: #D30000; color: white;}")
class _LabelAndHex(QWidget):
    def __init__(self, parent, text, model):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt_utils import add_expanding_spacer_to_layout
        from pyvmmonitor_qt.qt.QtWidgets import QLineEdit
        QWidget.__init__(self, parent)
        self._in_expected_ui_change = 0
        self._in_expected_data_change = 0
        self._model = model

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._line_edit = QLineEdit(self)
        self._line_edit.textChanged.connect(self._on_line_edit_changed)
        self._line_edit.setFixedWidth(WIDTH_VALUE)

        self._layout.addWidget(self._label)
        add_expanding_spacer_to_layout(self._layout)
        self._layout.addWidget(self._line_edit)
        self._model.register_modified(self._on_model_changed)
        self._update_line_edit()

    def _on_model_changed(self, obj, attrs):
        if 'color' in attrs:
            self._update_line_edit()

    @does_expected_ui_change
    @skip_on_expected_data_change
    def _update_line_edit(self):
        color = self._model.color
        self._line_edit.setText(color.name())
        self._line_edit.setStyleSheet("")

    @skip_on_expected_ui_change
    @does_expected_data_change
    def _on_line_edit_changed(self, value):
        color = QColor()
        color.setNamedColor(value)
        if not color.isValid():
            color.setNamedColor('#' + value)
        if color.isValid():
            self._model.color = color
            self._line_edit.setStyleSheet("")
        else:
            self._line_edit.setStyleSheet(
                "QLineEdit { background: #D30000; color: white;}")
    def __init__(self, parent, text, model):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt_utils import add_expanding_spacer_to_layout
        from pyvmmonitor_qt.qt.QtWidgets import QLineEdit
        QWidget.__init__(self, parent)
        self._in_expected_ui_change = 0
        self._in_expected_data_change = 0
        self._model = model

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._line_edit = QLineEdit(self)
        self._line_edit.textChanged.connect(self._on_line_edit_changed)
        self._line_edit.setFixedWidth(WIDTH_VALUE)

        self._layout.addWidget(self._label)
        add_expanding_spacer_to_layout(self._layout)
        self._layout.addWidget(self._line_edit)
        self._model.register_modified(self._on_model_changed)
        self._update_line_edit()
Example #6
0
    def __init__(self, parent, title, message, detailed_message, icon):
        from pyvmmonitor_qt.qt.QtGui import QCursor
        CustomMessageDialog.__init__(self, parent)

        title = compat.as_unicode(title)
        message = compat.as_unicode(message)
        detailed_message = compat.as_unicode(detailed_message)

        cp = [title, message]
        if detailed_message:
            cp.append(detailed_message)
        self._copy_text = u'\n---------------------\n'.join(cp)
        self._initial_pos = QCursor.pos()
        self._use_initial_pos = True
        self.setWindowTitle(title)

        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        from pyvmmonitor_qt.qt.QtWidgets import QLabel

        self._hor_layout = QHBoxLayout()
        if icon is not None:
            self._label_icon = QLabel(self)
            self._label_icon.setPixmap(icon.pixmap(32, 32))
            self._label_icon.setFixedSize(40, 40)
            self._hor_layout.addWidget(self._label_icon)

        message = message.replace('\n', '<br/>')
        label = self.create_label(message, layout=self._hor_layout)
        self._layout.addLayout(self._hor_layout)

        label.setTextFormat(Qt.RichText)
        label.setTextInteractionFlags(Qt.TextBrowserInteraction)
        label.setOpenExternalLinks(True)

        from pyvmmonitor_qt.qt.QtWidgets import QDialogButtonBox
        self.bbox = bbox = QDialogButtonBox()
        if detailed_message:
            self.bt_copy = bbox.addButton(u'Copy to clipboard', QDialogButtonBox.ApplyRole)
        else:
            self.bt_copy = None

        self.bt_close = bbox.addButton(u'Ok', QDialogButtonBox.RejectRole)
        if detailed_message:
            self.bt_show_details = bbox.addButton(u'Show Details...', QDialogButtonBox.AcceptRole)
        else:
            self.bt_show_details = None

        bbox.clicked.connect(self._clicked_button)

        self._layout.addWidget(bbox)
        if detailed_message:
            self.tx_details = self.create_text(
                detailed_message, read_only=True, line_wrap=False, is_html=False)

            self.tx_details.setVisible(False)

        self.adjustSize()
    def __init__(self, parent, text, gradient_stops=None, limits=(0, 100)):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt_gradient_slider import QGradientSlider
        from pyvmmonitor_qt.qt.QtWidgets import QSpinBox
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        QWidget.__init__(self, parent)

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._limits = limits

        self._slider = QGradientSlider(self)
        self._slider.min_value = limits[0]
        self._slider.max_value = limits[1]
        self._slider.on_value.register(self._on_gradient_value_changed)

        self._slider.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        self._slider.setFixedHeight(20)

        self._spin_box = QSpinBox(self)
        self._spin_box.setFixedWidth(WIDTH_VALUE)
        self._spin_box.setMinimum(limits[0])
        self._spin_box.setMaximum(limits[1])
        self._spin_box.valueChanged.connect(self._on_spin_value_changed)

        self._layout.addWidget(self._label)
        self._layout.addWidget(self._slider)
        self._layout.addWidget(self._spin_box)

        self.set_gradient_stops(gradient_stops)
    def __init__(self, parent, text, gradient_stops=None, limits=(0, 100)):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt_gradient_slider import QGradientSlider
        from pyvmmonitor_qt.qt.QtWidgets import QSpinBox
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        QWidget.__init__(self, parent)

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._limits = limits

        self._slider = QGradientSlider(self)
        self._slider.min_value = limits[0]
        self._slider.max_value = limits[1]
        self._slider.on_value.register(self._on_gradient_value_changed)

        self._slider.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self._slider.setFixedHeight(20)

        self._spin_box = QSpinBox(self)
        self._spin_box.setFixedWidth(WIDTH_VALUE)
        self._spin_box.setMinimum(limits[0])
        self._spin_box.setMaximum(limits[1])
        self._spin_box.valueChanged.connect(self._on_spin_value_changed)

        self._layout.addWidget(self._label)
        self._layout.addWidget(self._slider)
        self._layout.addWidget(self._spin_box)

        self.set_gradient_stops(gradient_stops)
class _LabelGradientAndInt(QWidget):

    def __init__(self, parent, text, gradient_stops=None, limits=(0, 100)):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt_gradient_slider import QGradientSlider
        from pyvmmonitor_qt.qt.QtWidgets import QSpinBox
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        QWidget.__init__(self, parent)

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._limits = limits

        self._slider = QGradientSlider(self)
        self._slider.min_value = limits[0]
        self._slider.max_value = limits[1]
        self._slider.on_value.register(self._on_gradient_value_changed)

        self._slider.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self._slider.setFixedHeight(20)

        self._spin_box = QSpinBox(self)
        self._spin_box.setFixedWidth(WIDTH_VALUE)
        self._spin_box.setMinimum(limits[0])
        self._spin_box.setMaximum(limits[1])
        self._spin_box.valueChanged.connect(self._on_spin_value_changed)

        self._layout.addWidget(self._label)
        self._layout.addWidget(self._slider)
        self._layout.addWidget(self._spin_box)

        self.set_gradient_stops(gradient_stops)

    @property
    def slider(self):
        return self._slider

    def set_gradient_stops(self, gradient_stops):
        if gradient_stops is not None:
            self._slider.set_gradient_stops(gradient_stops)

    def set_normalized_value(self, v):
        self._slider.normalized_value = v
        not_normalized = round(self._slider.value)  # Round to nearest int
        self._spin_box.setValue(not_normalized)

    def _on_gradient_value_changed(self, slider, value):
        self.on_value_changed(self._normalize(value))

    def _on_spin_value_changed(self, value):
        self.on_value_changed(self._normalize(value))

    def _normalize(self, value):
        limits = self._limits
        return (value - limits[0]) / float(limits[1] - limits[0])
class _LabelGradientAndInt(QWidget):
    def __init__(self, parent, text, gradient_stops=None, limits=(0, 100)):
        from pyvmmonitor_qt.qt.QtWidgets import QLabel
        from pyvmmonitor_qt.qt_gradient_slider import QGradientSlider
        from pyvmmonitor_qt.qt.QtWidgets import QSpinBox
        from pyvmmonitor_qt.qt.QtWidgets import QHBoxLayout
        QWidget.__init__(self, parent)

        self.on_value_changed = Callback()

        self._layout = QHBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self.setLayout(self._layout)

        self._label = QLabel(self)
        self._label.setText(text)
        self._label.setFixedWidth(WIDTH_LABEL)

        self._limits = limits

        self._slider = QGradientSlider(self)
        self._slider.min_value = limits[0]
        self._slider.max_value = limits[1]
        self._slider.on_value.register(self._on_gradient_value_changed)

        self._slider.setSizePolicy(QSizePolicy.Expanding,
                                   QSizePolicy.Expanding)
        self._slider.setFixedHeight(20)

        self._spin_box = QSpinBox(self)
        self._spin_box.setFixedWidth(WIDTH_VALUE)
        self._spin_box.setMinimum(limits[0])
        self._spin_box.setMaximum(limits[1])
        self._spin_box.valueChanged.connect(self._on_spin_value_changed)

        self._layout.addWidget(self._label)
        self._layout.addWidget(self._slider)
        self._layout.addWidget(self._spin_box)

        self.set_gradient_stops(gradient_stops)

    @property
    def slider(self):
        return self._slider

    def set_gradient_stops(self, gradient_stops):
        if gradient_stops is not None:
            self._slider.set_gradient_stops(gradient_stops)

    def set_normalized_value(self, v):
        self._slider.normalized_value = v
        not_normalized = round(self._slider.value)  # Round to nearest int
        self._spin_box.setValue(not_normalized)

    def _on_gradient_value_changed(self, slider, value):
        self.on_value_changed(self._normalize(value))

    def _on_spin_value_changed(self, value):
        self.on_value_changed(self._normalize(value))

    def _normalize(self, value):
        limits = self._limits
        return (value - limits[0]) / float(limits[1] - limits[0])
def test_custom_close_tab_widget(qtapi):

    custom = CustomCloseTabWidget()
    qtapi.add_widget(custom)

    label = QLabel(custom._stack)
    label.setText('Label 1')
    custom.addTab(label, 't1', closeable=False)

    label = QLabel(custom._stack)
    label.setText('Label 2')
    custom.addTab(label, 't2', True)

    label = QLabel(custom._stack)
    label.setText('Label 3')
    custom.addTab(label, 't3', False)

    label = QLabel(custom._stack)
    label.setText('Label 4')
    custom.addTab(label, 't4', True)

    assert custom.tabText(3) == 't4'

    def on_remove(i):
        custom.removeTab(i)

    custom.on_remove_requested.register(on_remove)

    #     qtapi.d()
    while custom.count() > 0:
        custom.removeTab(0)
def test_custom_close_tab_widget(qtapi):

    custom = CustomCloseTabWidget()
    qtapi.add_widget(custom)

    label = QLabel(custom._stack)
    label.setText('Label 1')
    custom.addTab(label, 't1', closeable=False)

    label = QLabel(custom._stack)
    label.setText('Label 2')
    custom.addTab(label, 't2', True)

    label = QLabel(custom._stack)
    label.setText('Label 3')
    custom.addTab(label, 't3', False)

    label = QLabel(custom._stack)
    label.setText('Label 4')
    custom.addTab(label, 't4', True)

    assert custom.tabText(3) == 't4'

    def on_remove(i):
        custom.removeTab(i)
    custom.on_remove_requested.register(on_remove)


#     qtapi.d()
    while custom.count() > 0:
        custom.removeTab(0)
 def create_label(self, txt='', layout=None):
     from pyvmmonitor_qt.qt.QtWidgets import QLabel
     widget = QLabel(self._widget)
     widget.setText(txt)
     return self.add_widget(widget, layout=layout)
 def create_label(self, txt='', layout=None):
     from pyvmmonitor_qt.qt.QtWidgets import QLabel
     widget = QLabel(self._widget)
     widget.setText(txt)
     return self.add_widget(widget, layout=layout)