Skip to content

Commit

Permalink
constants: added panel IDs and other global const
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Oct 25, 2023
1 parent 7c577da commit 2897ae4
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
max-line-length=88

[TYPECHECK]
ignored-modules=qtpy.QtWidgets,qtpy.QtCore,qtpy.QtGui,qtpy.QtSvg,qtpy.QtPrintSupport,qtpy.QtDesigner,plotpy._scaler,plotpy.mandelbrot,plotpy.contour2d,plotpy.histogram2d
ignored-modules=qtpy.QtWidgets,qtpy.QtCore,qtpy.QtGui,qtpy.QtSvg,qtpy.QtPrintSupport,qtpy.QtDesigner,plotpy._scaler,plotpy.mandelbrot,plotpy.contour2d,plotpy.histogram2d,PyQt5.QtWidgets

[MESSAGES CONTROL]
disable=wrong-import-order
Expand Down
10 changes: 5 additions & 5 deletions doc/features/panels/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Panels are objects inheriting from the :py:class:`.PanelWidget` class.

The built-in panels are:

* :py:data:`.ID_ITEMLIST`: `item list` panel
* :py:data:`.ID_CONTRAST`: `contrast adjustment` panel
* :py:data:`.ID_XCS`: `X-axis cross section` panel
* :py:data:`.ID_YCS`: `Y-axis cross section` panel
* :py:data:`.ID_OCS`: `oblique cross section` panel
* :py:data:`plotpy.constants.ID_ITEMLIST`: `item list` panel
* :py:data:`plotpy.constants.ID_CONTRAST`: `contrast adjustment` panel
* :py:data:`plotpy.constants.ID_XCS`: `X-axis cross section` panel
* :py:data:`plotpy.constants.ID_YCS`: `Y-axis cross section` panel
* :py:data:`plotpy.constants.ID_OCS`: `oblique cross section` panel
38 changes: 37 additions & 1 deletion plotpy/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

from plotpy.config import _

# TODO: Move here other constants from around the codebase
# ===============================================================================
# Plot types
# ===============================================================================


class PlotType(enum.Enum):
Expand Down Expand Up @@ -44,13 +46,42 @@ class PlotType(enum.Enum):
MANUAL = 4


# ===============================================================================
# Plot parameters
# ===============================================================================

PARAMETERS_TITLE_ICON = {
"grid": (_("Grid..."), "grid.png"),
"axes": (_("Axes style..."), "axes.png"),
"item": (_("Parameters..."), "settings.png"),
}


# ===============================================================================
# Panels
# ===============================================================================

#: ID of the `item list` panel
ID_ITEMLIST = "itemlist"
#: ID of the `contrast adjustment` panel
ID_CONTRAST = "contrast"
#: ID of the `X-axis cross section` panel
ID_XCS = "x_cross_section"
#: ID of the `Y-axis cross section` panel
ID_YCS = "y_cross_section"
#: ID of the `oblique averaged cross section` panel
ID_OCS = "oblique_cross_section"


# ===============================================================================
# Plot items
# ===============================================================================

# Shape Z offset used when adding shapes to the plot
SHAPE_Z_OFFSET = 1000


# Lookup table alpha functions for image items
class LUTAlpha(enum.Enum):
"""LUT Alpha functions"""

Expand Down Expand Up @@ -86,3 +117,8 @@ def get_choices(self):
(LUTAlpha.SIGMOID.value, _("Sigmoid")),
(LUTAlpha.TANH.value, _("Hyperbolic tangent")),
]


# Lookup table size
LUT_SIZE = 1024
LUT_MAX = float(LUT_SIZE - 1)
5 changes: 1 addition & 4 deletions plotpy/items/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_scale_rect,
)
from plotpy.config import _
from plotpy.constants import LUTAlpha
from plotpy.constants import LUT_MAX, LUT_SIZE, LUTAlpha
from plotpy.coords import pixelround
from plotpy.interfaces import (
IBaseImageItem,
Expand Down Expand Up @@ -58,9 +58,6 @@
from plotpy.items import RectangleShape
from plotpy.styles.base import ItemParameters

LUT_SIZE = 1024
LUT_MAX = float(LUT_SIZE - 1)


class BaseImageItem(QwtPlotItem):
"""Base class for image items
Expand Down
2 changes: 1 addition & 1 deletion plotpy/panels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

# pylint: disable=unused-import
from .base import ID_CONTRAST, ID_ITEMLIST, ID_OCS, ID_XCS, ID_YCS, PanelWidget
from .base import PanelWidget
from .contrastadjustment import ContrastAdjustment
from .csection import ObliqueCrossSection, XCrossSection, YCrossSection
from .itemlist import PlotItemList
29 changes: 5 additions & 24 deletions plotpy/panels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class from which all panels must derived from) and identifiers for each kind
of panel.
.. autodata:: ID_ITEMLIST
.. autodata:: ID_CONTRAST
.. autodata:: ID_XCS
.. autodata:: ID_YCS
.. autodata:: ID_OCS
.. autodata:: plotpy.constants.ID_ITEMLIST
.. autodata:: plotpy.constants.ID_CONTRAST
.. autodata:: plotpy.constants.ID_XCS
.. autodata:: plotpy.constants.ID_YCS
.. autodata:: plotpy.constants.ID_OCS
.. autoclass:: PanelWidget
:members:
Expand All @@ -25,25 +25,6 @@ class from which all panels must derived from) and identifiers for each kind
from guidata.widgets.dockable import DockableWidget
from qtpy import QtCore as QC

# ===============================================================================
# Panel IDs
# ===============================================================================

#: ID of the `item list` panel
ID_ITEMLIST = "itemlist"

#: ID of the `contrast adjustment` panel
ID_CONTRAST = "contrast"

#: ID of the `X-axis cross section` panel
ID_XCS = "x_cross_section"

#: ID of the `Y-axis cross section` panel
ID_YCS = "y_cross_section"

#: ID of the `oblique averaged cross section` panel
ID_OCS = "oblique_cross_section"


# ===============================================================================
# Base Panel Widget class
Expand Down
4 changes: 2 additions & 2 deletions plotpy/panels/contrastadjustment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
from qtpy import QtWidgets as QW

from plotpy.config import CONF, _
from plotpy.constants import PlotType
from plotpy.constants import ID_CONTRAST, PlotType
from plotpy.interfaces import IPanel, IVoiImageItemType
from plotpy.items import HistogramItem, XRangeSelection
from plotpy.lutrange import lut_range_threshold
from plotpy.panels.base import ID_CONTRAST, PanelWidget
from plotpy.panels.base import PanelWidget
from plotpy.plot.base import BasePlot, BasePlotOptions
from plotpy.styles import CurveParam, HistogramParam
from plotpy.tools import AntiAliasingTool, BasePlotMenuTool, SelectPointTool, SelectTool
Expand Down
3 changes: 1 addition & 2 deletions plotpy/panels/csection/csplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from qtpy import QtWidgets as QW

from plotpy.config import CONF, _
from plotpy.constants import PlotType
from plotpy.constants import LUT_MAX, PlotType
from plotpy.interfaces import ICSImageItemType
from plotpy.items.image.base import LUT_MAX
from plotpy.panels.csection.csitem import (
ObliqueCrossSectionItem,
XCrossSectionItem,
Expand Down
3 changes: 2 additions & 1 deletion plotpy/panels/csection/cswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from qtpy import QtWidgets as QW

from plotpy.config import _
from plotpy.constants import ID_OCS, ID_XCS, ID_YCS
from plotpy.interfaces import IPanel
from plotpy.panels.base import ID_OCS, ID_XCS, ID_YCS, PanelWidget
from plotpy.panels.base import PanelWidget
from plotpy.panels.csection.csplot import (
CrossSectionPlot,
ObliqueCrossSectionPlot,
Expand Down
3 changes: 2 additions & 1 deletion plotpy/panels/itemlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from qtpy import QtWidgets as QW

from plotpy.config import _
from plotpy.constants import ID_ITEMLIST
from plotpy.interfaces import IPanel
from plotpy.panels.base import ID_ITEMLIST, PanelWidget
from plotpy.panels.base import PanelWidget


class ItemListWidget(QW.QListWidget):
Expand Down
2 changes: 1 addition & 1 deletion plotpy/plot/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from qtpy import QtGui as QG
from qtpy import QtWidgets as QW

from plotpy.constants import ID_CONTRAST, ID_ITEMLIST, ID_XCS, ID_YCS
from plotpy.interfaces import IPlotManager
from plotpy.panels import ID_CONTRAST, ID_ITEMLIST, ID_XCS, ID_YCS
from plotpy.plot import BasePlot
from plotpy.tools import (
AboutTool,
Expand Down
4 changes: 2 additions & 2 deletions plotpy/tools/base.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-

import weakref

from guidata.configtools import get_icon
from qtpy import QtCore as QC
from qtpy import QtWidgets as QW

from plotpy.constants import SHAPE_Z_OFFSET
from plotpy.events import RectangularSelectionHandler, setup_standard_tool_filter
from plotpy.items.shape.rectangle import RectangleShape

SHAPE_Z_OFFSET = 1000


class DefaultToolbarID:
pass
Expand Down
2 changes: 1 addition & 1 deletion plotpy/tools/cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from guidata.configtools import get_icon

from plotpy.config import _
from plotpy.constants import ID_OCS, ID_XCS, ID_YCS
from plotpy.interfaces import IImageItemType
from plotpy.items import AnnotatedObliqueRectangle, AnnotatedPoint, AnnotatedRectangle
from plotpy.panels.base import ID_OCS, ID_XCS, ID_YCS
from plotpy.tools.base import PanelTool
from plotpy.tools.image import update_image_tool_status
from plotpy.tools.shape import RectangularShapeTool
Expand Down
3 changes: 2 additions & 1 deletion plotpy/tools/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from qtpy import QtCore as QC

from plotpy.config import _
from plotpy.constants import SHAPE_Z_OFFSET
from plotpy.events import QtDragHandler, setup_standard_tool_filter
from plotpy.items import Marker, XRangeSelection
from plotpy.tools.base import SHAPE_Z_OFFSET, DefaultToolbarID, InteractiveTool
from plotpy.tools.base import DefaultToolbarID, InteractiveTool


class BaseCursorTool(InteractiveTool):
Expand Down
8 changes: 2 additions & 6 deletions plotpy/tools/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
from qtpy import QtWidgets as QW

from plotpy.config import _
from plotpy.constants import SHAPE_Z_OFFSET
from plotpy.events import QtDragHandler, setup_standard_tool_filter
from plotpy.interfaces import ICurveItemType
from plotpy.items import Marker, XRangeSelection
from plotpy.tools.base import (
SHAPE_Z_OFFSET,
DefaultToolbarID,
InteractiveTool,
ToggleTool,
)
from plotpy.tools.base import DefaultToolbarID, InteractiveTool, ToggleTool
from plotpy.tools.cursor import BaseCursorTool


Expand Down
3 changes: 1 addition & 2 deletions plotpy/tools/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from plotpy import io
from plotpy.config import _
from plotpy.constants import PlotType
from plotpy.constants import ID_CONTRAST, PlotType
from plotpy.events import QtDragHandler, setup_standard_tool_filter
from plotpy.interfaces import (
IColormapImageItemType,
Expand All @@ -31,7 +31,6 @@
get_items_in_rectangle,
)
from plotpy.mathutils.colormap import build_icon_from_cmap_name, get_colormap_list
from plotpy.panels.base import ID_CONTRAST
from plotpy.tools.base import (
CommandTool,
DefaultToolbarID,
Expand Down
2 changes: 1 addition & 1 deletion plotpy/tools/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from qtpy import QtWidgets as QW

from plotpy.config import _
from plotpy.constants import ID_ITEMLIST
from plotpy.interfaces import ICurveItemType
from plotpy.items import (
AnnotatedCircle,
Expand All @@ -14,7 +15,6 @@
RawImageItem,
RectangleShape,
)
from plotpy.panels.base import ID_ITEMLIST
from plotpy.tools.base import CommandTool, DefaultToolbarID, PanelTool
from plotpy.tools.curve import edit_curve_data, export_curve_data
from plotpy.tools.image import edit_image_data, export_image_data
Expand Down
8 changes: 2 additions & 6 deletions plotpy/tools/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from qtpy import QtCore as QC

from plotpy.config import _
from plotpy.constants import SHAPE_Z_OFFSET
from plotpy.events import (
KeyEventMatch,
PointSelectionHandler,
Expand All @@ -15,12 +16,7 @@
PolygonShape,
SegmentShape,
)
from plotpy.tools.base import (
SHAPE_Z_OFFSET,
DefaultToolbarID,
InteractiveTool,
RectangularActionTool,
)
from plotpy.tools.base import DefaultToolbarID, InteractiveTool, RectangularActionTool


class MultiLineTool(InteractiveTool):
Expand Down

0 comments on commit 2897ae4

Please sign in to comment.