-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
auxiliary_widgets.py
89 lines (70 loc) · 2.38 KB
/
auxiliary_widgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
"""
Spyder API auxiliary widgets.
"""
# Third party imports
from qtpy.QtCore import Signal
from qtpy.QtWidgets import QHBoxLayout, QMainWindow, QWidget
import qdarkstyle
# Local imports
from spyder.api.exceptions import SpyderAPIError
from spyder.config.gui import is_dark_interface
class SpyderWindowWidget(QMainWindow):
"""
MainWindow subclass that contains a Spyder Plugin.
"""
sig_closed = Signal()
"""
This signal is emitted when this widget is closed.
"""
# --- Signals
# ------------------------------------------------------------------------
sig_closed = Signal()
"""This signal is emitted when the close event is fired."""
def __init__(self, widget):
super().__init__()
self.widget = widget
# Setting interface theme
if is_dark_interface():
self.setStyleSheet(qdarkstyle.load_stylesheet())
def closeEvent(self, event):
"""Override Qt method to emit a custom `sig_close` signal."""
super().closeEvent(event)
self.sig_closed.emit()
class MainCornerWidget(QWidget):
"""
Corner widget to hold options menu, spinner and additional options.
"""
def __init__(self, parent, name):
super().__init__(parent)
self._widgets = {}
self.setObjectName(name)
self._layout = QHBoxLayout()
self.setLayout(self._layout)
spacing = 2
self._layout.setSpacing(2)
# left, top, right, bottom
self._layout.setContentsMargins(spacing, 0, spacing, spacing)
self.setContentsMargins(0, 0, 0, 0)
def add_widget(self, widget_id, widget):
"""
Add a widget to the left of the last widget added to the corner.
"""
if widget_id in self._widgets:
raise SpyderAPIError(
'Wigdet with name "{}" already added. Current names are: {}'
''.format(widget_id, list(self._widgets.keys()))
)
widget.ID = widget_id
self._widgets[widget_id] = widget
self._layout.insertWidget(0, widget)
def get_widget(self, widget_id):
"""
Return a widget by unique id..
"""
if widget_id in self._widgets:
return self._widgets[widget_id]