示例#1
0
    def __init__(self, mouse_qshortcut):
        '''
        :param _MouseQShortcut mouse_qshortcut:
        '''
        from pyvmmonitor_core.callback import Callback
        self.mouse_qshortcut = mouse_qshortcut

        self.on_call = Callback()
def _init_item(
        item,
        center,
        radius_in_px,
        pen,
        fill_color,
        alpha,
        pixels_displacement=(0, 0),
        graphics_widget=None):
    '''
    :param alpha: 255 means opaque, 0 means transparent.
    '''

    item._center = center
    item._radius_in_px = radius_in_px
    item._pixels_displacement = pixels_displacement

    item._last_radius = None
    item._last_center = None
    item._last_pixels_displacement = None
    item._last_transform = None

    item._custom_hover = False
    item._hover_pen = None
    item._hover_fill_color = None
    item._hover_alpha = None
    item._hover_radius_in_px = None

    item._regular_pen = pen
    item._regular_fill_color = fill_color
    item._regular_alpha = alpha
    item._regular_radius_in_px = radius_in_px

    # May be changed for a function and if True is returned, the mouse press
    # is accepted.
    item.accept_mouse_press = lambda event: False

    item.on_enter_hover = Callback()
    item.on_leave_hover = Callback()

    item.on_mouse_press = Callback()
    item.on_mouse_move = Callback()
    item.on_mouse_release = Callback()

    item._delay_update = 0

    if hasattr(item, 'setPen'):
        set_graphics_item_colors(item, pen, fill_color, alpha)

    assert graphics_widget is not None
    item._graphics_widget = get_weakref(graphics_widget)

    # Needed to set the real position in pixels for the radius and pixels displacement.
    item._update_with_graphics_widget()
示例#3
0
def test_callback3():
    c = Callback()

    called = []

    # When we pass a function we'll create a strong reference!
    def strong_ref_to_method(b):
        called.append(b)

    c.register(strong_ref_to_method)
    assert len(c) == 1

    c(1)
    del strong_ref_to_method
    c(1)
    assert len(c) == 1
    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()
示例#5
0
 def __init__(self):
     self._ep_to_impls = {}
     self._ep_to_instance_impls = {}
     self._ep_to_context_to_instance = {}
     self._name_to_ep = {}
     self.exited = False
     self.on_about_to_exit = Callback()
    def __init__(self, mouse_qshortcut):
        '''
        :param _MouseQShortcut mouse_qshortcut:
        '''
        from pyvmmonitor_core.callback import Callback
        self.mouse_qshortcut = mouse_qshortcut

        self.on_call = Callback()
示例#7
0
class _CustomActivatedSlot(object):
    def __init__(self, mouse_qshortcut):
        '''
        :param _MouseQShortcut mouse_qshortcut:
        '''
        from pyvmmonitor_core.callback import Callback
        self.mouse_qshortcut = mouse_qshortcut

        self.on_call = Callback()

    def __call__(self):
        self.on_call()

    def connect(self, func):
        self.on_call.register(func)

    def disconnect(self, func):
        self.on_call.unregister(func)
    def __init__(self, parent, font=None, lexer=None):
        AdvancedCodeWidget.__init__(self, parent, font=font, lexer=lexer)
        self._filename = ''
        self._file_mtime = -1
        self.code.document().modificationChanged.connect(
            self._on_contents_changed)

        # Called with on_dirty_changed(is_dirty)
        self.on_dirty_changed = Callback()
class _CustomActivatedSlot(object):

    def __init__(self, mouse_qshortcut):
        '''
        :param _MouseQShortcut mouse_qshortcut:
        '''
        from pyvmmonitor_core.callback import Callback
        self.mouse_qshortcut = mouse_qshortcut

        self.on_call = Callback()

    def __call__(self):
        self.on_call()

    def connect(self, func):
        self.on_call.register(func)

    def disconnect(self, func):
        self.on_call.unregister(func)
示例#10
0
def test_callback():
    c = Callback()

    class F(object):
        def __init__(self):
            self.called = None

        def __call__(self, b):
            self.called = b

    f = F()
    c.register(f.__call__)
    assert len(c) == 1

    c(1)
    assert f.called == 1
    f = get_weakref(f)
    assert f() is None
    c(1)
    assert len(c) == 0
示例#11
0
    def __init__(self, *args, **kwargs):
        from pyvmmonitor_core.callback import Callback
        from pyvmmonitor_qt.qt.QtGui import QColor
        from pyvmmonitor_qt.qt.QtCore import Qt
        QPixmapWidget.__init__(self, *args, **kwargs)
        self._props = _QGradientSliderProps()
        self._props.register_modified(self._on_modified)
        self._triangle_path = None
        self._triangle_size = None
        # Called with on_value(self, value)
        self.on_value = Callback()

        gradient_stops = [
            (0, QColor(Qt.black)),
            (1, QColor(Qt.red)),
        ]
        self.set_gradient_stops(gradient_stops)
示例#12
0
    def __init__(self):
        QWidget.__init__(self)

        self._layout = QVBoxLayout(self)
        self._layout.setSpacing(0)

        self._tabbar = QTabBar(self)
        self._tabbar.currentChanged.connect(self._tab_changed)
        self._layout.addWidget(self._tabbar)

        self._stack = QStackedWidget(self)
        self._layout.addWidget(self._stack)

        self._widgets = []
        self._buttons = []
        self.setLayout(self._layout)
        # Called with: on_remove_requested(index)
        self.on_remove_requested = Callback()
    def __init__(self, *args, **kwargs):
        from pyvmmonitor_qt.qt.QtWidgets import QGraphicsScene
        from pyvmmonitor_core.callback import Callback
        self.on_zoom = Callback()
        self._old_size = None

        scene = QGraphicsScene()
        QGraphicsView.__init__(self, scene, *args, **kwargs)
        self._scene = scene

        qglwidget = None
        from pyvmmonitor_qt.qt.QtOpenGL import is_good_opengl_version, create_gl_widget
        if is_good_opengl_version():
            qglwidget = create_gl_widget()
            self.setViewport(qglwidget)

        from pyvmmonitor_qt.qt_utils import set_painter_antialiased
        set_painter_antialiased(self, True, qglwidget)

        self._background_painter = BackgroundPainter(self.BACKGROUND_MODE)
    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)
示例#15
0
    def __init__(self,
                 tree,
                 editable=False,
                 has_children=None,
                 create_children=None):
        '''
        :param QTreeView tree:
        :param bool editable:
            Determines if the tree items should be editable.
        '''

        self.tree = tree
        if has_children and create_children:
            self._has_children = has_children
            self._create_children = create_children
            model = self._model = _VirtualModel(tree, self)
        else:
            model = self._model = _CustomModel(tree)
        from pyvmmonitor_qt.qt.QtWidgets import QAbstractItemView

        tree.setSelectionMode(QAbstractItemView.ExtendedSelection)
        tree.setSelectionBehavior(QAbstractItemView.SelectRows)

        self._sort_model = FilterProxyModelCheckingChildren()
        self._sort_model.setSourceModel(model)

        self._fast = {}
        self._root_items = _RootItems()

        if not editable:
            # Set all items not editable
            # Otherwise, it could be set individually with:
            # QStandardItem.setEditable(False)
            tree.setEditTriggers(QAbstractItemView.NoEditTriggers)

        # Called with on_clicked(TreeNode, column)
        self.on_clicked = Callback()
        tree.clicked.connect(self._on_clicked)

        tree.setModel(self._sort_model)
 def __init__(self):
     self.on_add = Callback()  # Called as on_add(obj_id, obj)
     self.on_remove = Callback()  # Called as on_remove(obj_id, obj)
示例#17
0
 def __init__(self, **kwargs):
     self._props = {}
     self._original_on_modified_callback = self._on_modified_callback = Callback(
     )
     for key, val in compat.iteritems(kwargs):
         setattr(self, key, val)
 def __init__(self):
     self.on_selection_changed = Callback(
     )  # Called as on_selection_changed(source, selection)
示例#19
0
 def __init__(self):
     self.exited = Callback()
示例#20
0
# License: LGPL
#
# Copyright: Brainwy Software
from pyvmmonitor_core.callback import Callback
from pyvmmonitor_core.weak_utils import WeakSet
from pyvmmonitor_qt import compat

_applied_stylesheet = False

THEMES = ['DARK', 'NATIVE', 'DARK_ORANGE']
_USE_THEME = 'DARK'

on_stylesheet_changed = Callback()


def set_default_stylesheet(theme):
    global _USE_THEME
    _USE_THEME = theme.strip().upper()


def get_app_stylesheet():
    if _USE_THEME == 'DARK':
        from pyvmmonitor_qt.stylesheet.dark import AppStylesheet
    elif _USE_THEME == 'DARK_ORANGE':
        from pyvmmonitor_qt.stylesheet.dark import AppStylesheetDarkOrange as AppStylesheet
    else:
        from pyvmmonitor_qt.stylesheet.light import AppStylesheet

    return AppStylesheet()

 def __init__(self):
     self._props = {}
     self._on_modified_callback = Callback()