Skip to content

Commit

Permalink
Merge e5b2a0e into e9ac091
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Feb 2, 2021
2 parents e9ac091 + e5b2a0e commit f70ff47
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 170 deletions.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args: ["--in-place", "--remove-all-unused-imports"]
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.4
rev: v2.9.0
hooks:
- id: pyupgrade
- repo: https://github.com/psf/black
Expand Down
2 changes: 0 additions & 2 deletions examples/self_reference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from enum import auto

from magicgui import magicgui


Expand Down
2 changes: 1 addition & 1 deletion examples/table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Demonstrating a few ways to input tables."""
import numpy as np

from magicgui.widgets import PushButton, Slider, Table
from magicgui.widgets import Table

# all of these are valid data types
dict_of_lists = {"col_1": [1, 4], "col_2": [2, 5], "col_3": [3, 6]}
Expand Down
12 changes: 6 additions & 6 deletions magicgui/_magicgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import inspect
from functools import partial
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from typing import TYPE_CHECKING, Any, Callable

from magicgui.widgets import FunctionGui, MainFunctionGui

Expand All @@ -13,12 +13,12 @@


def magicgui(
function: Optional[Callable] = None,
function: Callable | None = None,
*,
layout: str = "vertical",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: bool = False,
Expand Down Expand Up @@ -83,12 +83,12 @@ def magicgui(


def magic_factory(
function: Optional[Callable] = None,
function: Callable | None = None,
*,
layout: str = "vertical",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: bool = False,
Expand Down Expand Up @@ -192,7 +192,7 @@ def _magicgui(function=None, factory=False, main_window=False, **kwargs):
Otherwise, this will return a FunctionGui instance directly.
"""

def inner_func(func: Callable) -> Union[FunctionGui, MagicFactory]:
def inner_func(func: Callable) -> FunctionGui | MagicFactory:
if not callable(func):
raise TypeError("the first argument must be callable")

Expand Down
18 changes: 9 additions & 9 deletions magicgui/_magicgui.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import partial
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, Union, overload
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, overload

from typing_extensions import Literal

Expand All @@ -28,7 +28,7 @@ def magicgui( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[False] = False,
Expand All @@ -42,7 +42,7 @@ def magicgui( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[False] = False,
Expand All @@ -56,7 +56,7 @@ def magicgui( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[True],
Expand All @@ -70,7 +70,7 @@ def magicgui( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[True],
Expand All @@ -84,7 +84,7 @@ def magic_factory( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[False] = False,
Expand All @@ -98,7 +98,7 @@ def magic_factory( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[False] = False,
Expand All @@ -112,7 +112,7 @@ def magic_factory( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[True],
Expand All @@ -126,7 +126,7 @@ def magic_factory( # noqa
layout: str = "horizontal",
labels: bool = True,
tooltips: bool = True,
call_button: Union[bool, str] = False,
call_button: bool | str = False,
auto_call: bool = False,
result_widget: bool = False,
main_window: Literal[True],
Expand Down
8 changes: 4 additions & 4 deletions magicgui/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from contextlib import contextmanager
from importlib import import_module
from types import ModuleType
from typing import TYPE_CHECKING, Callable, Iterator, Optional, Union
from typing import TYPE_CHECKING, Callable, Iterator, Union

from magicgui.backends import BACKENDS

Expand All @@ -31,9 +31,9 @@ class Application:

_backend_module: ModuleType
_backend: "BaseApplicationBackend"
_instance: Optional[Application] = None
_instance: Application | None = None

def __init__(self, backend_name: Optional[str] = None):
def __init__(self, backend_name: str | None = None):
self._use(backend_name)

@property
Expand Down Expand Up @@ -117,7 +117,7 @@ def __exit__(self, *exc_details):
def start_timer(
self,
interval: int = 1000,
on_timeout: Optional[Callable[[], None]] = None,
on_timeout: Callable[[], None] | None = None,
single_shot: bool = False,
):
"""Start a timer with a given interval, optional callback, and single_shot."""
Expand Down
27 changes: 14 additions & 13 deletions magicgui/backends/_qtpy/widgets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Widget implementations (adaptors) for the Qt backend."""
from typing import Any, Dict, Iterable, Optional, Sequence, Tuple, Union
from __future__ import annotations

from typing import Any, Iterable, Sequence

import qtpy
from qtpy import QtWidgets as QtW
Expand Down Expand Up @@ -109,7 +111,7 @@ def _mgui_set_max_height(self, value: int) -> None:
def _mgui_get_tooltip(self) -> str:
return self._qwidget.toolTip()

def _mgui_set_tooltip(self, value: Optional[str]) -> None:
def _mgui_set_tooltip(self, value: str | None) -> None:
self._qwidget.setToolTip(str(value) if value else None)

def _mgui_bind_parent_change_callback(self, callback):
Expand Down Expand Up @@ -178,7 +180,7 @@ def _mgui_bind_change_callback(self, callback):


class QBaseStringWidget(QBaseValueWidget):
_qwidget: Union[QtW.QLineEdit, QtW.QTextEdit]
_qwidget: QtW.QLineEdit | QtW.QTextEdit

def _mgui_set_value(self, value) -> None:
super()._mgui_set_value(str(value))
Expand Down Expand Up @@ -221,7 +223,7 @@ def _mgui_get_read_only(self) -> bool:
class QBaseRangedWidget(QBaseValueWidget, _protocols.RangedWidgetProtocol):
"""Provides min/max/step implementations."""

_qwidget: Union[QtW.QDoubleSpinBox, QtW.QSpinBox, QtW.QSlider]
_qwidget: QtW.QDoubleSpinBox | QtW.QSpinBox | QtW.QSlider

def __init__(self, qwidg):
super().__init__(qwidg, "value", "setValue", "valueChanged")
Expand Down Expand Up @@ -255,7 +257,7 @@ def _mgui_set_step(self, value: float):


class QBaseButtonWidget(QBaseValueWidget, _protocols.SupportsText):
_qwidget: Union[QtW.QCheckBox, QtW.QPushButton, QtW.QRadioButton, QtW.QToolButton]
_qwidget: QtW.QCheckBox | QtW.QPushButton | QtW.QRadioButton | QtW.QToolButton

def __init__(self, qwidg):
super().__init__(qwidg, "isChecked", "setChecked", "toggled")
Expand Down Expand Up @@ -309,11 +311,11 @@ def _mgui_remove_widget(self, widget: Widget):
self._layout.removeWidget(widget.native)
widget.native.setParent(None)

def _mgui_get_margins(self) -> Tuple[int, int, int, int]:
def _mgui_get_margins(self) -> tuple[int, int, int, int]:
m = self._layout.contentsMargins()
return m.left(), m.top(), m.right(), m.bottom()

def _mgui_set_margins(self, margins: Tuple[int, int, int, int]) -> None:
def _mgui_set_margins(self, margins: tuple[int, int, int, int]) -> None:
self._layout.setContentsMargins(*margins)

def _mgui_set_orientation(self, value) -> None:
Expand All @@ -337,7 +339,7 @@ def __init__(self, layout="vertical"):
self._main_window = QtW.QMainWindow()
self._main_window.setCentralWidget(self._qwidget)
self._main_menu = self._main_window.menuBar()
self._menus: Dict[str, QtW.QMenu] = {}
self._menus: dict[str, QtW.QMenu] = {}

def _mgui_get_visible(self):
return self._main_window.isVisible()
Expand Down Expand Up @@ -409,7 +411,6 @@ def _mgui_get_step(self) -> float:

def _mgui_set_step(self, value: float):
"""Set the step size."""
pass


class ComboBox(QBaseValueWidget, _protocols.CategoricalWidgetProtocol):
Expand Down Expand Up @@ -463,14 +464,14 @@ def _mgui_del_choice(self, choice_name: str) -> None:
if item_index >= 0:
self._qwidget.removeItem(item_index)

def _mgui_get_choices(self) -> Tuple[Tuple[str, Any]]:
def _mgui_get_choices(self) -> tuple[tuple[str, Any]]:
"""Show the widget."""
return tuple( # type: ignore
(self._qwidget.itemText(i), self._qwidget.itemData(i))
for i in range(self._qwidget.count())
)

def _mgui_set_choices(self, choices: Iterable[Tuple[str, Any]]) -> None:
def _mgui_set_choices(self, choices: Iterable[tuple[str, Any]]) -> None:
"""Set current items in categorical type ``widget`` to ``choices``."""
choices_ = list(choices)
if not choices_:
Expand Down Expand Up @@ -537,12 +538,12 @@ def _mgui_get_value(self):


def show_file_dialog(
mode: Union[str, FileDialogMode] = FileDialogMode.EXISTING_FILE,
mode: str | FileDialogMode = FileDialogMode.EXISTING_FILE,
caption: str = None,
start_path: str = None,
filter: str = None,
parent=None,
) -> Optional[str]:
) -> str | None:
show_dialog = QFILE_DIALOG_MODES[FileDialogMode(mode)]
args = (parent, caption, start_path, filter)
if mode is FileDialogMode.EXISTING_DIRECTORY:
Expand Down
8 changes: 4 additions & 4 deletions magicgui/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import inspect
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Callable, Dict, Mapping, Sequence, Tuple, cast
from typing import TYPE_CHECKING, Any, Callable, Mapping, Sequence, cast

from typing_extensions import Annotated, _AnnotatedAlias

Expand Down Expand Up @@ -60,7 +60,7 @@ def make_annotated(annotation=Any, options: dict = None) -> _AnnotatedAlias:
return Annotated[annotation, _options]


def split_annotated_type(annotation: _AnnotatedAlias) -> Tuple[Any, WidgetOptions]:
def split_annotated_type(annotation: _AnnotatedAlias) -> tuple[Any, WidgetOptions]:
"""Split an Annotated type into its base type and options dict."""
if not isinstance(annotation, _AnnotatedAlias):
raise TypeError("Type hint must be an 'Annotated' type.")
Expand Down Expand Up @@ -190,7 +190,7 @@ def __init__(
parameters: Sequence[inspect.Parameter] = None,
*,
return_annotation=inspect.Signature.empty,
gui_options: Dict[str, dict] = None,
gui_options: dict[str, dict] = None,
):
params = [
MagicParameter.from_parameter(p, (gui_options or {}).get(p.name))
Expand Down Expand Up @@ -229,7 +229,7 @@ def to_container(self, **kwargs) -> Container:


def magic_signature(
obj: Callable, *, gui_options: Dict[str, dict] = None, follow_wrapped: bool = True
obj: Callable, *, gui_options: dict[str, dict] = None, follow_wrapped: bool = True
) -> MagicSignature:
"""Create a MagicSignature from a callable object.
Expand Down
Loading

0 comments on commit f70ff47

Please sign in to comment.