Skip to content
Merged
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: 0 additions & 2 deletions examples/compareBackends.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
This script compares the rendering of PlotWidget's matplotlib and OpenGL backends.
"""

from __future__ import annotations

__license__ = "MIT"

import numpy
Expand Down
2 changes: 0 additions & 2 deletions src/silx/app/utils/parseutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# ############################################################################*/
"""Utils related to parsing"""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "28/05/2018"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/app/view/CustomPlotSelectionWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

"""Custom plot selection window for selecting 1D datasets to plot."""

from __future__ import annotations

from silx.gui import qt, plot, icons
import silx.gui
import silx.gui.plot
Expand Down
2 changes: 0 additions & 2 deletions src/silx/app/view/Viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
# ############################################################################*/
"""Browse a data file with a GUI"""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "15/01/2019"
Expand Down
8 changes: 3 additions & 5 deletions src/silx/gui/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""This module provides API to manage colors."""

from __future__ import annotations

__authors__ = ["T. Vincent", "H.Payno"]
__license__ = "MIT"
__date__ = "29/01/2019"
Expand Down Expand Up @@ -255,7 +253,7 @@ class _Colormappable:

def _getColormapAutoscaleRange(
self,
colormap: Colormap | None,
colormap: "Colormap | None",
) -> tuple[float | None, float | None]:
"""Returns the autoscale range for given colormap.

Expand Down Expand Up @@ -396,7 +394,7 @@ def __init__(
self.__warnBadVmin = True
self.__warnBadVmax = True

def setFromColormap(self, other: Colormap):
def setFromColormap(self, other: "Colormap"):
"""Set this colormap using information from the `other` colormap.

:param other: Colormap to use as reference.
Expand Down Expand Up @@ -894,7 +892,7 @@ def _fromDict(dic: dict):
colormap._setFromDict(dic)
return colormap

def copy(self) -> Colormap:
def copy(self) -> "Colormap":
"""Return a copy of the Colormap."""
colormap = Colormap(
name=self._name,
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/dialog/ColormapDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
:attr:`ColormapDialog.sigColormapChanged`.
""" # noqa

from __future__ import annotations

__authors__ = ["V.A. Sole", "T. Vincent", "H. Payno"]
__license__ = "MIT"
__date__ = "08/12/2020"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/dialog/_ColormapPercentileWidget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from silx.gui import qt
from ..colors import Colormap

Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/dialog/test/test_datafiledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""Test for silx.gui.hdf5 module"""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "08/03/2019"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/dialog/test/test_imagefiledialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""Test for silx.gui.hdf5 module"""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "08/03/2019"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/ImageStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""Image stack view with data prefetch capabilty."""

from __future__ import annotations

__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "04/03/2019"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/PlotInteraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""Implementation of the interaction for the :class:`Plot`."""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "15/02/2019"
Expand Down
11 changes: 4 additions & 7 deletions src/silx/gui/plot/PlotWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
The :class:`PlotWidget` implements the plot API initially provided in PyMca.
"""

from __future__ import annotations

__authors__ = ["V.A. Sole", "T. Vincent"]
__license__ = "MIT"
__date__ = "21/12/2018"
Expand Down Expand Up @@ -68,7 +66,6 @@

from .. import qt
from ._utils.panzoom import ViewConstraints
from ...gui.plot._utils.dtime_ticklayout import timestamp
from ...utils.deprecation import deprecated_warning

from .backends.BackendBase import BackendBase
Expand Down Expand Up @@ -101,7 +98,7 @@ class _PlotWidgetSelection(qt.QObject):
sigSelectedItemsChanged = qt.Signal()
"""Signal emitted whenever the list of selected items changes."""

def __init__(self, parent: PlotWidget):
def __init__(self, parent: "PlotWidget"):
assert isinstance(parent, PlotWidget)
super().__init__(parent=parent)

Expand Down Expand Up @@ -380,7 +377,7 @@ class PlotWidget(qt.QMainWindow):

def __init__(
self,
parent: qt.Qt.Widget | None = None,
parent: qt.QWidget | None = None,
backend: BackendType = None,
):
self._autoreplot = False
Expand Down Expand Up @@ -666,7 +663,7 @@ def _getDirtyPlot(self) -> bool | Literal["overlay"]:

# Default Qt context menu

def contextMenuEvent(self, event: qt.Qt.QContextEvent):
def contextMenuEvent(self, event: qt.QContextMenuEvent):
"""Override QWidget.contextMenuEvent to implement the context menu"""
menu = qt.QMenu(self)
from .actions.control import ZoomBackAction # Avoid cyclic import
Expand Down Expand Up @@ -1240,7 +1237,7 @@ def addCurve(
# tickMode to TickMode.TIME_SERIES and, if necessary, set the axis
# to the correct time zone.
if len(x) > 0 and isinstance(x[0], dt.datetime):
x = [timestamp(d) for d in x]
x = [d.timestamp() for d in x]

curve.setData(x, y, xerror, yerror, baseline=baseline, copy=copy)

Expand Down
47 changes: 1 addition & 46 deletions src/silx/gui/plot/_utils/dtime_ticklayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import annotations


"""This module implements date-time labels layout on graph axes."""

Expand All @@ -35,9 +35,7 @@
import enum
import logging
import math
import time

import dateutil.tz

from dateutil.relativedelta import relativedelta

Expand All @@ -54,49 +52,6 @@
SECONDS_PER_MONTH_AVERAGE = SECONDS_PER_YEAR / 12 # Seconds per average month


# No dt.timezone in Python 2.7 so we use dateutil.tz.tzutc
_EPOCH = dt.datetime(1970, 1, 1, tzinfo=dateutil.tz.tzutc())


def timestamp(dtObj):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp is available on datetime objects since Python 3.3: https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp

"""Returns POSIX timestamp of a datetime objects.

If the dtObj object has a timestamp() method (python 3.3), this is
used. Otherwise (e.g. python 2.7) it is calculated here.

The POSIX timestamp is a floating point value of the number of seconds
since the start of an epoch (typically 1970-01-01). For details see:
https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp

:param datetime.datetime dtObj: date-time representation.
:return: POSIX timestamp
:rtype: float
"""
if hasattr(dtObj, "timestamp"):
return dtObj.timestamp()
else:
# Back ported from Python 3.5
if dtObj.tzinfo is None:
return (
time.mktime(
(
dtObj.year,
dtObj.month,
dtObj.day,
dtObj.hour,
dtObj.minute,
dtObj.second,
-1,
-1,
-1,
)
)
+ dtObj.microsecond / 1e6
)
else:
return (dtObj - _EPOCH).total_seconds()


@enum.unique
class DtUnit(enum.Enum):
YEARS = 0
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/_utils/panzoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""Functions to apply pan and zoom on a Plot"""

from __future__ import annotations

__authors__ = ["T. Vincent", "V. Valls"]
__license__ = "MIT"
__date__ = "08/08/2017"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/backends/BackendBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
This API is a simplified version of PyMca PlotBackend API.
"""

from __future__ import annotations

__authors__ = ["V.A. Sole", "T. Vincent"]
__license__ = "MIT"
__date__ = "21/12/2018"
Expand Down
10 changes: 3 additions & 7 deletions src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@
# ###########################################################################*/
"""Matplotlib Plot backend."""

from __future__ import annotations
from typing import Literal

from .utils import Range, ensureAspectRatio, findDimToKeep

__authors__ = ["V.A. Sole", "T. Vincent, H. Payno"]
__license__ = "MIT"
__date__ = "21/12/2018"


from typing import Literal
import logging
import datetime as dt
import numpy

from .utils import Range, ensureAspectRatio, findDimToKeep
from ... import qt

# First of all init matplotlib and set its backend
Expand Down Expand Up @@ -64,7 +61,6 @@
from .._utils.dtime_ticklayout import (
calcTicks,
formatDatetimes,
timestamp,
)
from ...qt import inspect as qt_inspect
from .... import config
Expand Down Expand Up @@ -205,7 +201,7 @@ def tick_values(self, vmin, vmax):
dtTicks, self._spacing, self._unit = calcTicks(dtMin, dtMax, self.numTicks)

# Convert datetime back to time stamps.
ticks = [timestamp(dtTick) for dtTick in dtTicks]
ticks = [dtTick.timestamp() for dtTick in dtTicks]
return ticks


Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/backends/BackendOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ############################################################################*/
"""OpenGL Plot backend."""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "21/12/2018"
Expand Down
5 changes: 1 addition & 4 deletions src/silx/gui/plot/backends/glutils/GLPlotFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
This modules provides the rendering of plot titles, axes and grid.
"""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "03/04/2017"
Expand Down Expand Up @@ -58,7 +56,6 @@
calcTicksAdaptive,
formatDatetimes,
)
from ..._utils.dtime_ticklayout import timestamp

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -466,7 +463,7 @@ def _ticksGenerator(self):
ticks = formatDatetimes(visibleDatetimes, spacing, unit)

for tickDateTime, text in ticks.items():
dataPos = timestamp(tickDateTime)
dataPos = tickDateTime.timestamp()
xPixel = x0 + (dataPos - dataMin) * xScale
yPixel = y0 + (dataPos - dataMin) * yScale
yield ((xPixel, yPixel), dataPos, text)
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/backends/glutils/GLText.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
It provides Latin-1 (ISO8859-1) characters for one monospace font at one size.
"""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "03/04/2017"
Expand Down
3 changes: 0 additions & 3 deletions src/silx/gui/plot/items/_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import annotations


from collections import OrderedDict


Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/items/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""This module provides the class for axes of the :class:`PlotWidget`."""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "22/11/2018"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/items/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""This module provides the base class for items of the :class:`Plot`."""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "08/12/2020"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/items/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""This module provides the :class:`Curve` item of the :class:`Plot`."""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "24/04/2018"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/items/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
# ###########################################################################*/
"""This module provides markers item of the :class:`Plot`."""

from __future__ import annotations

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "06/03/2017"
Expand Down
2 changes: 0 additions & 2 deletions src/silx/gui/plot/tools/PlotToolButton.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
plot tools for a toolbar.
"""

from __future__ import annotations

__authors__ = ["V. Valls"]
__license__ = "MIT"
__date__ = "20/12/2023"
Expand Down
Loading