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

some general code care #6

Merged
merged 10 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions kivy_garden/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

from ._version import __version__

from kivy_garden.matplotlib.backend_kivy import (
from .backend_kivy import (
FigureCanvasKivy,
FigureManagerKivy,
RendererKivy,
GraphicsContextKivy,
NavigationToolbar2Kivy,
MPLKivyApp,
)
from kivy_garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from .backend_kivyagg import FigureCanvasKivyAgg

__all__ = (
FigureCanvasKivy.__name__,
Expand Down
79 changes: 45 additions & 34 deletions kivy_garden/matplotlib/backend_kivy.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
my_mpl_kivy_widget = FigureCanvas(fig)
fig.canvas.mpl_connect('button_press_event', callback_handler)

2. Use pyplot to write the application following matplotlib sintax as can be
2. Use pyplot to write the application following matplotlib syntax as can be
seen in the second example below. In this case a Kivy application will be
created automatically from the matplotlib instructions and a NavigationToolbar
will be added to the main canvas.
Expand Down Expand Up @@ -228,9 +228,13 @@ def close(event):
print_function,
unicode_literals,
)

import six
from packaging.version import Version
import os
import textwrap
import uuid
import six
import numbers
import numpy as np
import matplotlib
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import (
Expand All @@ -243,11 +247,13 @@ def close(event):
)
from matplotlib.figure import Figure
from matplotlib.transforms import Affine2D
from matplotlib.backend_bases import (ShowBase,
Event,
ResizeEvent,
MouseEvent,
KeyEvent)
from matplotlib.backend_bases import (
ShowBase,
Event,
ResizeEvent,
MouseEvent,
KeyEvent,
)
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.mathtext import MathTextParser
from matplotlib import rcParams
Expand All @@ -258,9 +264,27 @@ def close(event):
except ImportError:
raise ImportError("this backend requires Kivy to be installed.")

from kivy.logger import Logger

from kivy.base import EventLoop
from kivy.properties import ObjectProperty
from kivy.app import App
from kivy.graphics import (
Line,
Rectangle,
Color,
Rotate,
Translate,
Mesh,
StencilPush,
StencilPop,
StencilUse,
StencilUnUse,
)
from kivy.graphics.texture import Texture
from kivy.graphics import Rectangle
from kivy.graphics.tesselator import Tesselator
from kivy.graphics.context_instructions import PopMatrix, PushMatrix

from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.behaviors import FocusBehavior
Expand All @@ -273,35 +297,21 @@ def close(event):
ActionOverflow,
ActionSeparator,
)
from kivy.base import EventLoop
from kivy.core.text import Label as CoreLabel
from kivy.core.image import Image
from kivy.graphics import Color, Line
from kivy.graphics import Rotate, Translate
from kivy.graphics.instructions import InstructionGroup
from kivy.graphics.tesselator import Tesselator
from kivy.graphics.context_instructions import PopMatrix, PushMatrix
from kivy.graphics import StencilPush, StencilPop, StencilUse, StencilUnUse
from kivy.logger import Logger
from kivy.graphics import Mesh
from kivy.resources import resource_find
from kivy.uix.stencilview import StencilView
from kivy.core.window import Window
from kivy.uix.popup import Popup
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.clock import Clock
from distutils.version import LooseVersion

_mpl_ge_1_5 = LooseVersion(matplotlib.__version__) >= LooseVersion("1.5.0")
_mpl_ge_2_0 = LooseVersion(matplotlib.__version__) >= LooseVersion("2.0.0")
kivy.require("1.9.1")

import numpy as np
import textwrap
import uuid
import numbers
_mpl_ge_1_5 = Version(matplotlib.__version__) >= Version("1.5.0")
_mpl_ge_2_0 = Version(matplotlib.__version__) >= Version("2.0.0")

kivy.require("1.9.1")

toolbar = None
my_canvas = None
Expand All @@ -317,7 +327,6 @@ class MPLKivyApp(App):
"""Creates the App initializing a FloatLayout with a figure and toolbar
widget.
"""

figure = ObjectProperty(None)
toolbar = ObjectProperty(None)

Expand Down Expand Up @@ -347,7 +356,7 @@ class Show(ShowBase):
"""

@classmethod
def mainloop(self):
def mainloop(cls):
app = App.get_running_app()
if app is None:
app = MPLKivyApp(figure=my_canvas, toolbar=toolbar)
Expand Down Expand Up @@ -989,8 +998,9 @@ def _init_toolbar(self):
"""
basedir = os.path.join(rcParams["datapath"], "images")
actionview = ActionView()
actionprevious = ActionPrevious(title="Navigation",
with_previous=False)
actionprevious = ActionPrevious(
title="Navigation", with_previous=False,
)
actionoverflow = ActionOverflow()
actionview.add_widget(actionprevious)
actionview.add_widget(actionoverflow)
Expand Down Expand Up @@ -1212,13 +1222,14 @@ def on_touch_down(self, touch):
newcoord = self.to_widget(touch.x, touch.y, relative=True)
x = newcoord[0]
y = newcoord[1]

if super(FigureCanvasKivy, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos):
self.motion_notify_event(x, y)
touch.grab(self)
if 'button' in touch.profile and touch.button in ("scrollup",
"scrolldown"):
if ("button" in touch.profile and touch.button in ("scrollup",
"scrolldown")):
self.scroll_event(x, y, 5)
else:
self.button_press_event(x, y, self.get_mouse_button(touch))
Expand Down Expand Up @@ -1269,8 +1280,8 @@ def on_touch_up(self, touch):
x = newcoord[0]
y = newcoord[1]
if touch.grab_current is self:
if 'button' in touch.profile and touch.button in ("scrollup",
"scrolldown"):
if ("button" in touch.profile and touch.button in ("scrollup",
"scrolldown")):
self.scroll_event(x, y, 5)
else:
self.button_release_event(x, y, self.get_mouse_button(touch))
Expand Down
7 changes: 4 additions & 3 deletions kivy_garden/matplotlib/backend_kivyagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def my_callback(event):
unicode_literals,
)

__all__ = "FigureCanvasKivyAgg"
__all__ = (
"FigureCanvasKivyAgg",
)

from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg
Expand Down Expand Up @@ -130,7 +132,6 @@ class MPLKivyApp(App):
"""Creates the App initializing a FloatLayout with a figure and toolbar
widget.
"""

figure = ObjectProperty(None)
toolbar = ObjectProperty(None)

Expand All @@ -152,7 +153,7 @@ class Show(ShowBase):
"""

@classmethod
def mainloop(self):
def mainloop(cls):
global my_canvas
global toolbar
app = App.get_running_app()
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
filterwarnings = ignore::DeprecationWarning:(?!kivy_garden.matplotlib)
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
keywords='Kivy kivy-garden',

packages=find_namespace_packages(include=['kivy_garden.*']),
install_requires=['matplotlib>=3.7.2', 'kivy>=2.1.0'],
install_requires=[
'matplotlib>=3',
'kivy>=1.9.1'
],
extras_require={
'dev': ['pytest>=3.6', 'pytest-cov', 'pytest-asyncio',
'sphinx_rtd_theme'],
Expand Down