Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: remove widget classes inheritance from enum, as preperation for qt6 enum support #1154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydm/tests/widgets/test_timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_timeplotcurveitem_receive_value(qtbot, signals, async_update, new_data)
pydm_timeplot_curve_item.setUpdatesAsynchronously(async_update)
if async_update:
assert (
pydm_timeplot_curve_item._update_mode == PyDMTimePlot.AtFixedRated
pydm_timeplot_curve_item._update_mode == PyDMTimePlot.AtFixedRate
if async_update
else pydm_timeplot_curve_item._update_mode == PyDMTimePlot.OnValueChange
)
Expand Down
14 changes: 12 additions & 2 deletions pydm/widgets/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ class TimeBase(object):
Seconds = 1


class PyDMDateTimeEdit(QtWidgets.QDateTimeEdit, PyDMWritableWidget, TimeBase):
class PyDMDateTimeEdit(QtWidgets.QDateTimeEdit, PyDMWritableWidget):
QtCore.Q_ENUMS(TimeBase)

# Make enum definitions known to this class
Milliseconds = TimeBase.Milliseconds
Seconds = TimeBase.Seconds

returnPressed = QtCore.Signal()
"""
A QDateTimeEdit with support for setting the text via a PyDM Channel, or
Expand Down Expand Up @@ -107,8 +112,13 @@ def value_changed(self, new_val):
self.setDateTime(val)


class PyDMDateTimeLabel(QtWidgets.QLabel, PyDMWidget, TimeBase):
class PyDMDateTimeLabel(QtWidgets.QLabel, PyDMWidget):
QtCore.Q_ENUMS(TimeBase)

# Make enum definitions known to this class
Milliseconds = TimeBase.Milliseconds
Seconds = TimeBase.Seconds

"""
A QLabel with support for setting the text via a PyDM Channel, or
through the PyDM Rules system.
Expand Down
1 change: 0 additions & 1 deletion pydm/widgets/display_format.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import math
import numpy as np
from typing import Any

import logging
import warnings

Expand Down
6 changes: 5 additions & 1 deletion pydm/widgets/enum_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WidgetType(object):
logger = logging.getLogger(__name__)


class PyDMEnumButton(QWidget, PyDMWritableWidget, WidgetType):
class PyDMEnumButton(QWidget, PyDMWritableWidget):
"""
A QWidget that renders buttons for every option of Enum Items.
For now, two types of buttons can be rendered:
Expand All @@ -41,6 +41,10 @@ class PyDMEnumButton(QWidget, PyDMWritableWidget, WidgetType):
Q_ENUMS(WidgetType)
WidgetType = WidgetType

# Make enum definitions known to this class
PushButton = WidgetType.PushButton
RadioButton = WidgetType.RadioButton

def __init__(self, parent=None, init_channel=None):
QWidget.__init__(self, parent)
PyDMWritableWidget.__init__(self, init_channel=init_channel)
Expand Down
17 changes: 16 additions & 1 deletion pydm/widgets/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run(self):
self.image_view.needs_redraw = False


class PyDMImageView(ImageView, PyDMWidget, PyDMColorMap, ReadingOrder, DimensionOrder):
class PyDMImageView(ImageView, PyDMWidget):
"""
A PyQtGraph ImageView with support for Channels and more from PyDM.

Expand Down Expand Up @@ -130,6 +130,21 @@ class PyDMImageView(ImageView, PyDMWidget, PyDMColorMap, ReadingOrder, Dimension
Q_ENUMS(DimensionOrder)
Q_ENUMS(PyDMColorMap)

# Make enum definitions known to this class
Fortranlike = ReadingOrder.Fortranlike
Clike = ReadingOrder.Clike

HeightFirst = DimensionOrder.HeightFirst
WidthFirst = DimensionOrder.WidthFirst

Magma = PyDMColorMap.Magma
Inferno = PyDMColorMap.Inferno
Plasma = PyDMColorMap.Plasma
Viridis = PyDMColorMap.Viridis
Jet = PyDMColorMap.Jet
Monochrome = PyDMColorMap.Monochrome
Hot = PyDMColorMap.Hot

color_maps = cmaps

def __init__(self, parent=None, image_channel=None, width_channel=None):
Expand Down
9 changes: 8 additions & 1 deletion pydm/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_labelRuleProperties = {"Text": ["value_changed", str]}


class PyDMLabel(QLabel, TextFormatter, PyDMWidget, DisplayFormat, new_properties=_labelRuleProperties):
class PyDMLabel(QLabel, TextFormatter, PyDMWidget, new_properties=_labelRuleProperties):
"""
A QLabel with support for setting the text via a PyDM Channel, or
through the PyDM Rules system.
Expand All @@ -27,6 +27,13 @@ class PyDMLabel(QLabel, TextFormatter, PyDMWidget, DisplayFormat, new_properties
The channel to be used by the widget.
"""

Default = DisplayFormat.Default
String = DisplayFormat.String
Decimal = DisplayFormat.Decimal
Exponential = DisplayFormat.Exponential
Hex = DisplayFormat.Hex
Binary = DisplayFormat.Binary

Q_ENUMS(DisplayFormat)
DisplayFormat = DisplayFormat

Expand Down
10 changes: 9 additions & 1 deletion pydm/widgets/line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger(__name__)


class PyDMLineEdit(QLineEdit, TextFormatter, PyDMWritableWidget, DisplayFormat):
class PyDMLineEdit(QLineEdit, TextFormatter, PyDMWritableWidget):
"""
A QLineEdit (writable text field) with support for Channels and more
from PyDM.
Expand All @@ -32,6 +32,14 @@ class PyDMLineEdit(QLineEdit, TextFormatter, PyDMWritableWidget, DisplayFormat):
Q_ENUMS(DisplayFormat)
DisplayFormat = DisplayFormat

# Make enum definitions known to this class
Default = DisplayFormat.Default
String = DisplayFormat.String
Decimal = DisplayFormat.Decimal
Exponential = DisplayFormat.Exponential
Hex = DisplayFormat.Hex
Binary = DisplayFormat.Binary

def __init__(self, parent=None, init_channel=None):
QLineEdit.__init__(self, parent)
PyDMWritableWidget.__init__(self, init_channel=init_channel)
Expand Down
11 changes: 10 additions & 1 deletion pydm/widgets/logdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def as_dict():
return OrderedDict(sorted(entries, key=lambda x: x[1], reverse=False))


class PyDMLogDisplay(QWidget, LogLevels):
class PyDMLogDisplay(QWidget):
"""
Standard display for Log Output

Expand All @@ -131,6 +131,15 @@ class PyDMLogDisplay(QWidget, LogLevels):

Q_ENUMS(LogLevels)
LogLevels = LogLevels

# Make enum definitions known to this class
NOTSET = LogLevels.NOTSET
DEBUG = LogLevels.DEBUG
INFO = LogLevels.INFO
WARNING = LogLevels.WARNING
ERROR = LogLevels.ERROR
CRITICAL = LogLevels.CRITICAL

terminator = "\n"
default_format = "%(asctime)s %(message)s"
default_level = logging.INFO
Expand Down
7 changes: 6 additions & 1 deletion pydm/widgets/template_repeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class LayoutType(object):
layout_class_for_type = (QVBoxLayout, QHBoxLayout, FlowLayout)


class PyDMTemplateRepeater(QFrame, PyDMPrimitiveWidget, LayoutType):
class PyDMTemplateRepeater(QFrame, PyDMPrimitiveWidget):
"""
PyDMTemplateRepeater takes a .ui file with macro variables as a template, and a JSON
file (or a list of dictionaries) with a list of values to use to fill in
Expand All @@ -143,6 +143,11 @@ class PyDMTemplateRepeater(QFrame, PyDMPrimitiveWidget, LayoutType):
Q_ENUMS(LayoutType)
LayoutType = LayoutType

# Make enum definitions known to this class
Vertical = LayoutType.Vertical
Horizontal = LayoutType.Horizontal
Flow = LayoutType.Flow

def __init__(self, parent=None):
pydm.data_plugins.initialize_plugins_if_needed()
QFrame.__init__(self, parent)
Expand Down
15 changes: 8 additions & 7 deletions pydm/widgets/timeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def receiveNewValue(self, new_value):
if self.points_accumulated < self._bufferSize:
self.points_accumulated += 1
self.data_changed.emit()
elif self._update_mode == PyDMTimePlot.AtFixedRated:
elif self._update_mode == PyDMTimePlot.AtFixedRate:
self.latest_value = new_value

@Slot()
Expand All @@ -234,7 +234,7 @@ def asyncUpdate(self):
buffer, together with the timestamp when this happens. Also increments
the accumulated point counter.
"""
if self._update_mode != PyDMTimePlot.AtFixedRated:
if self._update_mode != PyDMTimePlot.AtFixedRate:
return
self.data_buffer = np.roll(self.data_buffer, -1)
self.data_buffer[0, self._bufferSize - 1] = time.time()
Expand Down Expand Up @@ -412,7 +412,7 @@ def channels(self):
return [self.channel]


class PyDMTimePlot(BasePlot, updateMode):
class PyDMTimePlot(BasePlot):
"""
PyDMTimePlot is a widget to plot one or more channels vs. time.

Expand All @@ -437,12 +437,13 @@ class PyDMTimePlot(BasePlot, updateMode):
to either a TimeAxisItem if plot_by_timestamps is true, or a regular AxisItem otherwise
"""

OnValueChange = 1
AtFixedRated = 2

Q_ENUMS(updateMode)
updateMode = updateMode

# Make enum definitions known to this class
OnValueChange = updateMode.OnValueChange
AtFixedRate = updateMode.AtFixedRate

plot_redrawn_signal = Signal(TimePlotCurveItem)

def __init__(
Expand Down Expand Up @@ -918,7 +919,7 @@ def resetBufferSize(self):
bufferSize = Property("int", getBufferSize, setBufferSize, resetBufferSize)

def getUpdatesAsynchronously(self):
return self._update_mode == PyDMTimePlot.AtFixedRated
return self._update_mode == PyDMTimePlot.AtFixedRate

def setUpdatesAsynchronously(self, value):
for curve in self._curves:
Expand Down
Loading