def __init__(self, item: QListWidgetItem, parent: QWidget = None): super().__init__(parent) self.item = item self.opacity = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.opacity) layout = QHBoxLayout() self.setLayout(layout) self.position_label = QLabel() self.update_position_label() self.setToolTip(trans._("Click and drag to change call order")) self.plugin_name_label = QElidingLabel() self.plugin_name_label.setObjectName('small_text') self.plugin_name_label.setText(item.hook_implementation.plugin_name) plugin_name_size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) plugin_name_size_policy.setHorizontalStretch(2) self.plugin_name_label.setSizePolicy(plugin_name_size_policy) self.function_name_label = QLabel( item.hook_implementation.function.__name__) self.enabled_checkbox = QCheckBox(self) self.enabled_checkbox.setToolTip( trans._("Uncheck to disable this plugin")) self.enabled_checkbox.stateChanged.connect(self._set_enabled) self.enabled_checkbox.setChecked( getattr(item.hook_implementation, 'enabled', True)) layout.addWidget(self.position_label) layout.addWidget(self.enabled_checkbox) layout.addWidget(self.function_name_label) layout.addWidget(self.plugin_name_label) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0)
def disable_with_opacity(obj, widget_list, disabled): for wdg in widget_list: widget = getattr(obj, wdg) widget.setEnabled(obj.layer.editable) op = QGraphicsOpacityEffect(obj) op.setOpacity(1 if obj.layer.editable else 0.5) widget.setGraphicsEffect(op)
class SplashScreen(QSplashScreen): """Splash screen for the main window.""" def __init__(self, *args, **kwargs): """Splash screen for the main window.""" super(SplashScreen, self).__init__(*args, **kwargs) self._effect = QGraphicsOpacityEffect() self._font = self.font() self._pixmap = QPixmap(ANACONDA_ICON_256_PATH) self._message = '' # Setup self._font.setPixelSize(10) self._effect.setOpacity(0.9) self.setFont(self._font) self.setGraphicsEffect(self._effect) self.setPixmap(self._pixmap) self.setWindowFlags(Qt.FramelessWindowHint | Qt.SplashScreen | Qt.WindowStaysOnTopHint) def get_message(self): """Return currently displayed message.""" return self._message def show_message(self, message): """Show message in the screen.""" self._message = message message += '\n' self.show() self.showMessage(message, Qt.AlignBottom | Qt.AlignCenter | Qt.AlignAbsolute, QColor(Qt.white)) QApplication.processEvents()
def disable_with_opacity(obj, widget_list, disabled): """Set enabled state on a list of widgets. If disabled, decrease opacity""" for wdg in widget_list: widget = getattr(obj, wdg) widget.setEnabled(obj.layer.editable) op = QGraphicsOpacityEffect(obj) op.setOpacity(1 if obj.layer.editable else 0.5) widget.setGraphicsEffect(op)
def disable_with_opacity(obj, widget_list, enabled): """Set enabled state on a list of widgets. If not enabled, decrease opacity.""" for widget_name in widget_list: widget = getattr(obj, widget_name) widget.setEnabled(enabled) op = QGraphicsOpacityEffect(obj) op.setOpacity(1 if enabled else 0.5) widget.setGraphicsEffect(op)
def __init__(self, parent=None, toggle_button=None): super().__init__(parent) self._toggleButton = toggle_button self.setObjectName('Activity') self.setMinimumWidth(self.MIN_WIDTH) self.setMinimumHeight(self.MIN_HEIGHT) self.setMaximumHeight(self.MIN_HEIGHT) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.setWindowFlags(Qt.SubWindow | Qt.WindowStaysOnTopHint) self.setModal(False) opacityEffect = QGraphicsOpacityEffect(self) opacityEffect.setOpacity(0.8) self.setGraphicsEffect(opacityEffect) self._baseWidget = QWidget() self._activityLayout = QVBoxLayout() self._activityLayout.addStretch() self._baseWidget.setLayout(self._activityLayout) self._baseWidget.layout().setContentsMargins(0, 0, 0, 0) self._scrollArea = QScrollArea() self._scrollArea.setWidgetResizable(True) self._scrollArea.setWidget(self._baseWidget) self._titleBar = QLabel() title = QLabel('activity', self) title.setObjectName('QtCustomTitleLabel') title.setSizePolicy( QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Maximum) ) line = QFrame(self) line.setObjectName("QtCustomTitleBarLine") titleLayout = QHBoxLayout() titleLayout.setSpacing(4) titleLayout.setContentsMargins(8, 1, 8, 0) line.setFixedHeight(1) titleLayout.addWidget(line) titleLayout.addWidget(title) self._titleBar.setLayout(titleLayout) self._baseLayout = QVBoxLayout() self._baseLayout.addWidget(self._titleBar) self._baseLayout.addWidget(self._scrollArea) self.setLayout(self._baseLayout) self.resize(520, self.MIN_HEIGHT) self.move_to_bottom_right() # TODO: what do we do with any existing progress objects in action? # connect callback to handle new progress objects being added/removed progress._all_instances.events.changed.connect( self.handle_progress_change )
def __init__(self, *args, **kwargs): super(SplashScreen, self).__init__(*args, **kwargs) self._effect = QGraphicsOpacityEffect() self._font = self.font() self._pixmap = QPixmap(ANACONDA_ICON_256_PATH) # Setup self._font.setPixelSize(10) self._effect.setOpacity(0.9) self.setFont(self._font) self.setGraphicsEffect(self._effect) self.setPixmap(self._pixmap) self.setWindowFlags(Qt.SplashScreen | Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
def __init__(self, parent=None, toggle_button=None): super().__init__(parent) self._toggleButton = toggle_button self.setObjectName('Activity') self.setMinimumWidth(self.MIN_WIDTH) self.setMinimumHeight(self.MIN_HEIGHT) self.setMaximumHeight(self.MIN_HEIGHT) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed) self.setWindowFlags(Qt.SubWindow | Qt.WindowStaysOnTopHint) self.setModal(False) opacityEffect = QGraphicsOpacityEffect(self) opacityEffect.setOpacity(0.8) self.setGraphicsEffect(opacityEffect) self._baseWidget = QWidget() self._activityLayout = QVBoxLayout() self._activityLayout.addStretch() self._baseWidget.setLayout(self._activityLayout) self._baseWidget.layout().setContentsMargins(0, 0, 0, 0) self._scrollArea = QScrollArea() self._scrollArea.setWidgetResizable(True) self._scrollArea.setWidget(self._baseWidget) self._titleBar = QLabel() title = QLabel('activity', self) title.setObjectName('QtCustomTitleLabel') title.setSizePolicy( QSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Maximum) ) line = QFrame(self) line.setObjectName("QtCustomTitleBarLine") titleLayout = QHBoxLayout() titleLayout.setSpacing(4) titleLayout.setContentsMargins(8, 1, 8, 0) line.setFixedHeight(1) titleLayout.addWidget(line) titleLayout.addWidget(title) self._titleBar.setLayout(titleLayout) self._baseLayout = QVBoxLayout() self._baseLayout.addWidget(self._titleBar) self._baseLayout.addWidget(self._scrollArea) self.setLayout(self._baseLayout)
def fadeOut(self, callback, distance=-20): duration = 200 self._effects = [] for action in self.actions(): for widget in action.associatedWidgets(): if widget is not self: a = QPropertyAnimation(widget, b"pos", widget) a.setStartValue(widget.pos()) a.setEndValue(widget.pos() + QPoint(0, distance)) self._effects.append(a) a.setDuration(duration) a.setEasingCurve(QEasingCurve.OutBack) a.start(QPropertyAnimation.DeleteWhenStopped) effect = QGraphicsOpacityEffect(self) widget.setGraphicsEffect(effect) self._effects.append(effect) b = QPropertyAnimation(effect, b"opacity") self._effects.append(b) b.setDuration(duration) b.setStartValue(1) b.setEndValue(0) b.setEasingCurve(QEasingCurve.OutBack) b.start(QPropertyAnimation.DeleteWhenStopped) b.finished.connect(partial(self.removeAction, action)) b.finished.connect(callback) if not self.actions(): callback()
def _fade_setup(self): """ """ self._fade_running = True self.effect = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.effect) self.anim = QPropertyAnimation(self.effect, to_binary_string("opacity"))
def set_opacity(self, val): """ Float value between 0 and 1 representing the opacity of the widget where 0 means transparent. Parameters ---------- val : float The new value for the opacity """ op = QGraphicsOpacityEffect(self) if val > 1: val = 1 elif val < 0: val = 0 self._opacity = val op.setOpacity(val) # 0 to 1 will cause the fade effect to kick in self.setGraphicsEffect(op) self.setAutoFillBackground(True)
def __init__(self, item: QListWidgetItem, parent: QWidget = None): super().__init__(parent) self.setToolTip("Click and drag to change call order") self.item = item self.opacity = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.opacity) layout = QHBoxLayout() self.setLayout(layout) self.position_label = QLabel() self.update_position_label() self.plugin_name_label = QLabel(item.hook_implementation.plugin_name) self.enabled_checkbox = QCheckBox(self) self.enabled_checkbox.setToolTip("Uncheck to disable this plugin") self.enabled_checkbox.stateChanged.connect(self._set_enabled) self.enabled_checkbox.setChecked( getattr(item.hook_implementation, 'enabled', True)) layout.addWidget(self.position_label) layout.addWidget(self.enabled_checkbox) layout.addWidget(self.plugin_name_label) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0)
def fadeIn(self): self._effects = [] for action in self.actions(): effect = QGraphicsOpacityEffect(self) self._effects.append(effect) for widget in action.associatedWidgets(): if widget is not self: widget.setGraphicsEffect(effect) a = QPropertyAnimation(effect, b"opacity") self._effects.append(a) a.setDuration(1000) a.setStartValue(0) a.setEndValue(1) a.setEasingCurve(QEasingCurve.OutBack) a.start(QPropertyAnimation.DeleteWhenStopped)
def __init__( self, message: str, severity: Union[ str, NotificationSeverity ] = NotificationSeverity.WARNING, source: Optional[str] = None, actions: ActionSequence = (), ): """[summary] """ super().__init__(None) # FIXME: this does not work with multiple viewers. # we need a way to detect the viewer in which the error occured. for wdg in QApplication.topLevelWidgets(): if isinstance(wdg, QMainWindow): try: # TODO: making the canvas the parent makes it easier to # move/resize, but also means that the notification can get # clipped on the left if the canvas is too small. canvas = wdg.centralWidget().children()[1].canvas.native self.setParent(canvas) canvas.resized.connect(self.move_to_bottom_right) break except Exception: pass self.setupUi() self.setAttribute(Qt.WA_DeleteOnClose) self.setup_buttons(actions) self.setMouseTracking(True) self.severity_icon.setText(NotificationSeverity(severity).as_icon()) self.message.setText(message) if source: self.source_label.setText(f'Source: {source}') self.close_button.clicked.connect(self.close) self.expand_button.clicked.connect(self.toggle_expansion) self.timer = None self.opacity = QGraphicsOpacityEffect() self.setGraphicsEffect(self.opacity) self.opacity_anim = QPropertyAnimation(self.opacity, b"opacity", self) self.geom_anim = QPropertyAnimation(self, b"geometry", self) self.move_to_bottom_right()
def __init__(self): super(TourTestWindow, self).__init__() self.setGeometry(300, 100, 400, 600) self.setWindowTitle('Exploring QMainWindow') self.exit = QAction('Exit', self) self.exit.setStatusTip('Exit program') # create the menu bar menubar = self.menuBar() file_ = menubar.addMenu('&File') file_.addAction(self.exit) # create the status bar self.statusBar() # QWidget or its instance needed for box layout self.widget = QWidget(self) self.button = QPushButton('test') self.button1 = QPushButton('1') self.button2 = QPushButton('2') effect = QGraphicsOpacityEffect(self.button2) self.button2.setGraphicsEffect(effect) self.anim = QPropertyAnimation(effect, to_binary_string("opacity")) self.anim.setStartValue(0.01) self.anim.setEndValue(1.0) self.anim.setDuration(500) lay = QVBoxLayout() lay.addWidget(self.button) lay.addStretch() lay.addWidget(self.button1) lay.addWidget(self.button2) self.widget.setLayout(lay) self.setCentralWidget(self.widget) self.button.clicked.connect(self.action1) self.button1.clicked.connect(self.action2) self.tour = AnimatedTour(self)
def __init__( self, message: str, severity: Union[str, NotificationSeverity] = 'WARNING', source: Optional[str] = None, actions: ActionSequence = (), ): super().__init__() from ..qt_main_window import _QtMainWindow current_window = _QtMainWindow.current() if current_window is not None: canvas = current_window.qt_viewer._canvas_overlay self.setParent(canvas) canvas.resized.connect(self.move_to_bottom_right) self.setupUi() self.setAttribute(Qt.WA_DeleteOnClose) self.setup_buttons(actions) self.setMouseTracking(True) self.severity_icon.setText(NotificationSeverity(severity).as_icon()) self.message.setText(message) if source: self.source_label.setText( trans._('Source: {source}', source=source) ) self.close_button.clicked.connect(self.close) self.expand_button.clicked.connect(self.toggle_expansion) self.timer = QTimer() self.opacity = QGraphicsOpacityEffect() self.setGraphicsEffect(self.opacity) self.opacity_anim = QPropertyAnimation(self.opacity, b"opacity", self) self.geom_anim = QPropertyAnimation(self, b"geometry", self) self.move_to_bottom_right()
class ImplementationListItem(QFrame): """A Widget to render each hook implementation item in a ListWidget. Parameters ---------- item : QListWidgetItem An item instance from a QListWidget. This will most likely come from :meth:`QtHookImplementationListWidget.add_hook_implementation_to_list`. parent : QWidget, optional The parent widget, by default None Attributes ---------- plugin_name_label : QLabel The name of the plugin providing the hook implementation. enabled_checkbox : QCheckBox Checkbox to set the ``enabled`` status of the corresponding hook implementation. opacity : QGraphicsOpacityEffect The opacity of the whole widget. When self.enabled_checkbox is unchecked, the opacity of the item is decreased. """ on_changed = Signal() # when user changes whether plugin is enabled. def __init__(self, item: QListWidgetItem, parent: QWidget = None): super().__init__(parent) self.item = item self.opacity = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.opacity) layout = QHBoxLayout() self.setLayout(layout) self.position_label = QLabel() self.update_position_label() self.setToolTip(trans._("Click and drag to change call order")) self.plugin_name_label = QElidingLabel() self.plugin_name_label.setObjectName('small_text') self.plugin_name_label.setText(item.hook_implementation.plugin_name) plugin_name_size_policy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Preferred) plugin_name_size_policy.setHorizontalStretch(2) self.plugin_name_label.setSizePolicy(plugin_name_size_policy) self.function_name_label = QLabel( item.hook_implementation.function.__name__) self.enabled_checkbox = QCheckBox(self) self.enabled_checkbox.setToolTip( trans._("Uncheck to disable this plugin")) self.enabled_checkbox.stateChanged.connect(self._set_enabled) self.enabled_checkbox.setChecked( getattr(item.hook_implementation, 'enabled', True)) layout.addWidget(self.position_label) layout.addWidget(self.enabled_checkbox) layout.addWidget(self.function_name_label) layout.addWidget(self.plugin_name_label) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0) def _set_enabled(self, state: Union[bool, int]): """Set the enabled state of this hook implementation to ``state``.""" self.item.hook_implementation.enabled = bool(state) self.opacity.setOpacity(1 if state else 0.5) self.on_changed.emit() def update_position_label(self, order=None): """Update the label showing the position of this item in the list. Parameters ---------- order : list, optional A HookOrderType list ... unused by this function, but here for ease of signal connection, by default None. """ position = self.item.listWidget().indexFromItem(self.item).row() + 1 self.position_label.setText(str(position))
class ImplementationListItem(QFrame): """A Widget to render each hook implementation item in a ListWidget. Parameters ---------- item : QListWidgetItem An item instance from a QListWidget. This will most likely come from :meth:`QtHookImplementationListWidget.add_hook_implementation_to_list`. parent : QWidget, optional The parent widget, by default None Attributes ---------- plugin_name_label : QLabel The name of the plugin providing the hook implementation. enabled_checkbox : QCheckBox Checkbox to set the ``enabled`` status of the corresponding hook implementation. opacity : QGraphicsOpacityEffect The opacity of the whole widget. When self.enabled_checkbox is unchecked, the opacity of the item is decreased. """ def __init__(self, item: QListWidgetItem, parent: QWidget = None): super().__init__(parent) self.setToolTip("Click and drag to change call order") self.item = item self.opacity = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.opacity) layout = QHBoxLayout() self.setLayout(layout) self.position_label = QLabel() self.update_position_label() self.plugin_name_label = QLabel(item.hook_implementation.plugin_name) self.enabled_checkbox = QCheckBox(self) self.enabled_checkbox.setToolTip("Uncheck to disable this plugin") self.enabled_checkbox.stateChanged.connect(self._set_enabled) self.enabled_checkbox.setChecked( getattr(item.hook_implementation, 'enabled', True)) layout.addWidget(self.position_label) layout.addWidget(self.enabled_checkbox) layout.addWidget(self.plugin_name_label) layout.setStretch(2, 1) layout.setContentsMargins(0, 0, 0, 0) def _set_enabled(self, state: Union[bool, int]): """Set the enabled state of this hook implementation to ``state``.""" # "hook_implementation.enabled" is NOT a pluggy attribute... # we are adding that to allow skipping of hook_implementations. # see plugins.io.read_data_with_plugins() for an example self.item.hook_implementation.enabled = bool(state) self.opacity.setOpacity(1 if state else 0.5) def update_position_label(self, order=None): """Update the label showing the position of this item in the list. Parameters ---------- order : list, optional A HookOrderType list ... unused by this function, but here for ease of signal connection, by default None. """ position = self.item.listWidget().indexFromItem(self.item).row() + 1 self.position_label.setText(str(position))