Animating an image with FuncAnimation - python

So, I'm trying to animate some pixels moving around a static image using FuncAnimation. The static image itself is 256x256 and the objects moving around are essentially a brightly colored pixel. In the end i'd like for the animation to go indefinitely or until I stop it but thats besides the point. Right now I'd like to get things moving first.
The static image in question is this one (for this example anyways).
The code below is a simple class consisting of a location and color. When i spawn it or move it i make sure to record the previous pixel color so the object doesnt leave 'tracks' sort of speak.
class Prey:
def __init__(self, color = [255, 0, 255]) -> None:
self.color = color
self.x = None
self.y = None
def set_spawn(self, world):
self.x = random.randint(0, 256)
self.y = random.randint(0, 256)
while np.array_equal(world[self.x][self.y], [65, 105, 225]):
self.x = random.randint(0, 256)
self.y = random.randint(0, 256)
prev_pix = world[self.x, self.y]
return prev_pix
def move(self, world, x, y):
if not np.array_equal(world[x][y], [65, 105, 225]):
prev_pix = ((self.x, self.y), world[x][y])
self.x = x
self.y = y
return prev_pix
And below here I actually try to animate the damn thing.
def load_map(wname):
bgr_world = cv2.imread(wname)
rgb_world = cv2.cvtColor(bgr_world, cv2.COLOR_BGR2RGB)
return rgb_world
world = load_map('m3.png')
fig = plt.figure('lifesim')
im = plt.imshow(world, animated=True)
p1 = Prey()
def movement(*args):
x1, y1, prev_pix1 = p1.move(world, p1.x+1, p1.y) #i'm trying to get it to move down (when it actually works ill make sure it doesnt go OOB)
ppxy, pp = prev_pix1
ppx, ppy = ppxy
world[ppx][ppy] = pp
world[x1][y1] = p1.color
im.set_array(world)
return world,
def init_game(world):
x0, y0, prev_pix0 = p1.set_spawn(world) #The spawn is random, so i just overwrote it here so i can test
prev_pix0 = world[110, 100]
x0, y0 = (110, 100)
p1.x = 110
p1.y = 100
world[x0][y0] = p1.color
ani = animation.FuncAnimation(fig, movement, blit=True)
plt.show()
def main():
init_game(world)
if __name__ == "__main__":
main()
And when the code gets eventually executed, i get the following error
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Python39\lib\site-packages\matplotlib\backends\_backend_tk.py", line 241, in resize
self.resize_event()
File "C:\Python39\lib\site-packages\matplotlib\backend_bases.py", line 1767, in resize_event
self.callbacks.process(s, event)
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 229, in process
self.exception_handler(exc)
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 81, in _exception_printer
raise exc
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 224, in process
func(*args, **kwargs)
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1275, in _on_resize
self._init_draw()
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1719, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1747, in _draw_frame
self._drawn_artists = sorted(self._drawn_artists,
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1748, in <lambda>
key=lambda x: x.get_zorder())
AttributeError: 'numpy.ndarray' object has no attribute 'get_zorder'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python39\lib\tkinter\__init__.py", line 1892, in __call__
return self.func(*args)
File "C:\Python39\lib\tkinter\__init__.py", line 814, in callit
func(*args)
File "C:\Python39\lib\site-packages\matplotlib\backends\_backend_tk.py", line 253, in idle_draw
self.draw()
File "C:\Python39\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 9, in draw
super(FigureCanvasTkAgg, self).draw()
File "C:\Python39\lib\site-packages\matplotlib\backends\backend_agg.py", line 407, in draw
self.figure.draw(self.renderer)
File "C:\Python39\lib\site-packages\matplotlib\artist.py", line 41, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "C:\Python39\lib\site-packages\matplotlib\figure.py", line 1870, in draw
self.canvas.draw_event(renderer)
File "C:\Python39\lib\site-packages\matplotlib\backend_bases.py", line 1759, in draw_event
self.callbacks.process(s, event)
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 229, in process
self.exception_handler(exc)
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 81, in _exception_printer
raise exc
File "C:\Python39\lib\site-packages\matplotlib\cbook\__init__.py", line 224, in process
func(*args, **kwargs)
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 975, in _start
self._init_draw()
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1719, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1747, in _draw_frame
self._drawn_artists = sorted(self._drawn_artists,
File "C:\Python39\lib\site-packages\matplotlib\animation.py", line 1748, in <lambda>
key=lambda x: x.get_zorder())
AttributeError: 'numpy.ndarray' object has no attribute 'get_zorder'
I'm not sure what I'm doing wrong here since I'm completely new to matplotlibs animation modules... The mistake is probably blisteringly obvious but I just can't see it.

Related

Python "EPSG code is unknown" when plotting a base map?

I am trying to add a base map to my plot through Contextily, but am getting this error when trying to see the plot.
Traceback (most recent call last):
File "rasterio/_crs.pyx", line 322, in rasterio._crs._CRS.from_epsg
File "rasterio/_err.pyx", line 192, in rasterio._err.exc_wrap_int
rasterio._err.CPLE_AppDefinedError: PROJ: proj_create_from_database: /opt/anaconda3/share/proj/proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/cbook/__init__.py", line 196, in process
func(*args, **kwargs)
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1051, in _clicked
self.set_active(closest)
File "/opt/anaconda3/lib/python3.8/site-packages/matplotlib/widgets.py", line 1077, in set_active
func(self.labels[index].get_text())
File "vis.py", line 1109, in draw_basemap
ctx.add_basemap(ax, crs=properties_geo.crs.to_string())
File "/opt/anaconda3/lib/python3.8/site-packages/contextily/plotting.py", line 139, in add_basemap
left, right, bottom, top = _reproj_bb(
File "/opt/anaconda3/lib/python3.8/site-packages/contextily/plotting.py", line 229, in _reproj_bb
n_l, n_b, n_r, n_t = transform_bounds(s_crs, t_crs, left, bottom, right, top)
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/warp.py", line 180, in transform_bounds
xs, ys = transform(src_crs, dst_crs, in_xs, in_ys)
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/env.py", line 387, in wrapper
return f(*args, **kwds)
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/warp.py", line 65, in transform
return _transform(src_crs, dst_crs, xs, ys, zs)
File "rasterio/_base.pyx", line 1398, in rasterio._base._transform
File "rasterio/_base.pyx", line 1444, in rasterio._base._osr_from_crs
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 496, in from_user_input
return cls.from_string(value, morph_from_esri_dialect=morph_from_esri_dialect)
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 384, in from_string
return cls.from_epsg(val)
File "/opt/anaconda3/lib/python3.8/site-packages/rasterio/crs.py", line 333, in from_epsg
obj._crs = _CRS.from_epsg(code)
File "rasterio/_crs.pyx", line 324, in rasterio._crs._CRS.from_epsg
rasterio.errors.CRSError: The EPSG code is unknown. PROJ: proj_create_from_database: /opt/anaconda3/share/proj/proj.db lacks DATABASE.LAYOUT.VERSION.MAJOR / DATABASE.LAYOUT.VERSION.MINOR metadata. It comes from another PROJ installation.
Here is what I am doing in my code:
route = pd.read_excel("0002_D1_0_fixed_out_points_15ft.xls")
geometry = [Point(xy) for xy in zip(route.x_dd, route.y_dd)]
gdf = GeoDataFrame(route, geometry=geometry, crs='EPSG:3857')
fig,ax = plt.subplots()
ax.plot(route['x_dd'], route['y_dd'], 'o', markersize=1)
ctx.add_basemap(ax, crs=gdf.crs.to_string())
plt.show()
I'm assuming this is an issue with how my installations are set up and not the code itself. I've tried doing conda activate base which is the environment I'm in but am still getting the same error. I am on macOS as well

How to animate movement to a text artist in matplotlib?

I'm trying to animate a piece of text in matplotlib, in order to make some educational videos. However, I'm having trouble with setting text in motion.
I've tried to use FuncAnimation (as I did for animating lines), and defining the anchor of that text as a pair of moving coordinates. Here's what I've tried:
def data_gen(): #Data generator. Gives me the anchor.
counter = 0
x0 = data_gen.x0
while counter < 1000:
counter+=1
x0-=0.09
yield x0,(1-counter*0.05)
data_gen.x0=1
def animate_text(data): #Here is where I try to tell my code to refresh
#only the coordinates of the text.
x0,y0 = data
text_sample = ax.text(x0,y0,'text here',transform=ax.transAxes,
fontsize=12, color='black',fontstyle='oblique',family='serif')
return text_sample
#animation part:
ani = animation.FuncAnimation(fig,animate_text,data_gen,blit=True,
interval=50,repeat = False)
plt.show()
However, I get this:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\matplotlib\cbook\__init__.py", line 387,
in process
proxy(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\cbook\__init__.py", line 227,
in __call__
return mtd(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1026, in
_start
self._init_draw()
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1750, in
_init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1777, in
_draw_frame
for a in self._drawn_artists:
TypeError: 'Text' object is not iterable
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\matplotlib\cbook\__init__.py", line 387,
in process
proxy(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\cbook\__init__.py", line 227,
in __call__
return mtd(*args, **kwargs)
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1308, in
_handle_resize
self._init_draw()
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1750, in
_init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Python27\lib\site-packages\matplotlib\animation.py", line 1777, in
_draw_frame
for a in self._drawn_artists:
TypeError: 'Text' object is not iterable
Does anybody know how can I solve that?
In FuncAnimation documentation you can read:
func must return an iterable of all artists that were modified or
created
"iterable" means that animate_text() has to return list or tuple with elements - even if you have only one element:
return (text_sample,)

auto07p IndexError when uses matplotlib 2.0 instead of matplotlib 1.5

I am recently working on making auto07p work with matplotlib 2.0.
The source code can be found here:
https://sourceforge.net/projects/auto-07p/files/auto07p/0.9/
When using matplotlib 2.0 (or any version greater than 1.5), IndexError: invalid index to scalar variable. appears:
/home/ngb/auto/07p/python/Points.py:1086: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`.
r = rank(array_temp)
Created plot
<graphics.windowPlotter.WindowPlotter2D object at 0x7f9e42007710>
AUTO> Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1562, in __call__
return self.func(*args)
File "/usr/lib/python3.5/tkinter/__init__.py", line 608, in callit
func(*args)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 370, in idle_draw
self.draw()
File "/home/ngb/auto/07p/python/graphics/grapher_mpl.py", line 92, in draw
self.redraw()
File "/home/ngb/auto/07p/python/graphics/grapher_mpl.py", line 65, in redraw
FigureCanvasTkAgg.draw(self)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py", line 351, in draw
FigureCanvasAgg.draw(self)
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_agg.py", line 464, in draw
self.figure.draw(self.renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 2409, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "/usr/lib/python3/dist-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 1136, in draw
ticks_to_draw = self._update_ticks(renderer)
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 969, in _update_ticks
tick_tups = [t for t in self.iter_ticks()]
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 969, in <listcomp>
tick_tups = [t for t in self.iter_ticks()]
File "/usr/lib/python3/dist-packages/matplotlib/axis.py", line 912, in iter_ticks
majorLocs = self.major.locator()
File "/usr/lib/python3/dist-packages/matplotlib/ticker.py", line 1794, in __call__
return self.tick_values(vmin, vmax)
File "/usr/lib/python3/dist-packages/matplotlib/ticker.py", line 1802, in tick_values
locs = self._raw_ticks(vmin, vmax)
File "/usr/lib/python3/dist-packages/matplotlib/ticker.py", line 1761, in _raw_ticks
istep = np.nonzero(steps >= raw_step)[0][0]
IndexError: invalid index to scalar variable.
It appears that there are only two lines involved. They are from the file /auto/07p/python/graphics/grapher_mpl.py.
The two methods involved are:
def redraw(self):
# recalculate label positions
self.grapher.plotlabels()
FigureCanvasTkAgg.draw(self)
And
def draw(self):
ax = self.grapher.ax
d = {}
if ax is self.grapher.ax3d:
[d["minx"], d["maxx"]] = ax.get_xlim3d()
[d["miny"], d["maxy"]] = ax.get_ylim3d()
[d["minz"], d["maxz"]] = ax.get_zlim3d()
d["azimuth"] = ax.azim
d["elevation"] = ax.elev
d["cur_lims"] = Axes.get_xlim(ax), Axes.get_ylim(ax)
else:
[d["minx"], d["maxx"]] = ax.get_xlim()
[d["miny"], d["maxy"]] = ax.get_ylim()
for k in list(d):
# don't adjust any unchanged settings
if k == "cur_lims":
if map(list, d[k]) == map(list, self.grapher._cur_lims):
del d[k]
elif d[k] == self.grapher.cget(k):
del d[k]
if d != {}:
if "cur_lims" in d:
del d["cur_lims"]
if d != {}:
self.grapher._configNoDraw(**d)
self.redraw()
return
FigureCanvasTkAgg.draw(self)
I would appreciate if anyone can assist me with the error, without changing the matlibplot code but only the auto code. I have read through the code but did not find anything suspicious.
I ran into this error using a given equation and auto file. But if you use matplotlib 2.0 and auto07p to plot most graphs in general, you are very likely to get this error if you zoom on the graph.
I used the files as the following:
https://1drv.ms/f/s!ArJqyyCr1FQOhkITst8JdVK_mIFV
Put them in auto folder.
Run auto.
and type:
auto("couple2.auto")
Thanks.

Issues with passing variables inside a class - python

I am facing issues with the implementation of the method animation from the class wave bellow. The animation method aims to create an animation of a wave propagation. I do not want that the animation method modify the state instance variable u of the Wave object, and because of that I am trying to create a local variable u inside the method animation. Nevertheless, I do not know how to pass the local variable u from the animation method for the animate function that is defined inside the animation method. In the way that I tried to implement, from my conception, the local variable u of the method animation should be a king of global variable for the animate method (that is defined inside the animation method). But, this assumption is cleary wrong, otherwise I would not get an error. As a complementary information the error I am getting is: UnboundLocalError: local variable 'u' referenced before assignment.
I will be glad if someone indicate to me the way for the implementation that I want.
thanks in advance
class Wave(object):
def __init__(self, phenomenon):
'''
nx: Number of spatial grid points
dx: Distance between any pair of adjacent grid points
nt: Number of steps in time
nu: Diffusion coefficient
dt: Value of the step in time
c: wave velocity
u: grid vector of the wave
'''
if phenomenon == 'convection':
self.phenomenon = phenomenon
self.nx = 81
self.dx = 2.0/(self.nx - 1) # Distance between any pair of adjacent grid
self.nt = 100
self.dt = 0.002
self.c = 3
self.x = numpy.linspace(0,4,self.nx)
self.u = numpy.ones(self.nx)
self.lbound = numpy.where(self.x >= 0.5)
self.ubound = numpy.where(self.x <= 1.0)
self.bounds = numpy.intersect1d(self.lbound[0], self.ubound[0])
self.u[self.bounds] = 2
if phenomenon == 'diffusion':
...
if phenomenon == 'burgers':
...
def _convection(self, u):
un = u.copy()
u[1:] = un[1:] - self.c*self.dt/self.dx*(un[1:] - un[:-1])
u[0] = 1.0
return u
def integration(self):
if self.phenomenon == 'convection':
for n in range(1,self.nt):
self.u = self._convection(u=self.u)
if self.phenomenon == 'diffusion':
...
if self.phenomenon == 'burgers':
...
def animation(self):
fig = plt.figure()
ax = plt.axes(xlim=(0,4), ylim=(0,3))
ax.grid()
line, = ax.plot([], [], 'o-', lw=2)
time_template = 'time = %.2fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
def init():
line.set_data([], [])
time_text.set_text('')
return line, time_text
x = self.x
u = self.u.copy()
def animate(i):
if self.phenomenon == 'convection':
u = self._convection(u=u)
if self.phenomenon == 'diffusion':
...
if self.phenomenon == 'burgers':
...
line.set_data(x,u)
time_text.set_text(time_template % (i*self.dt))
return line, time_text
anim = animation.FuncAnimation(fig, animate, frames=500, init_func=init, interval=10, blit=True)
plt.show()
EDIT
Complete trace error:
Exception in Tkinter callback Traceback (most
recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line
1489, in call
return self.func(*args) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 536, in callit
func(*args) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py",
line 141, in _on_timer
TimerBase._on_timer(self) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1203,
in _on_timer
ret = func(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 876, in
_step
still_going = Animation._step(self, *args) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 735, in
_step
self._draw_next_frame(framedata, self._blit) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 754, in
_draw_next_frame
self._draw_frame(framedata) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 1049, in
_draw_frame
self._drawn_artists = self._func(framedata, *self._args) File "wave.py", line 201, in animate
un = u.copy() UnboundLocalError: local variable 'u' referenced before assignment Exception in Tkinter callback Traceback (most recent
call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1489,
in call
return self.func(*args) File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 536, in callit
func(*args) File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py",
line 141, in _on_timer
TimerBase._on_timer(self) File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1203,
in _on_timer
ret = func(*args, **kwargs) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 876, in
_step
still_going = Animation._step(self, *args) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 735, in
_step
self._draw_next_frame(framedata, self._blit) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 754, in
_draw_next_frame
self._draw_frame(framedata) File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 1049, in
_draw_frame
self._drawn_artists = self._func(framedata, *self._args) File "wave.py", line 201, in animate
un = u.copy() UnboundLocalError: local variable 'u' referenced before assignment
When you capture a variable with a closure in Python, you are not allowed to assign to it. If Python sees you assign to it, then it isn't allowed to be captured from the enclosing scope; it must be a new function-local variable (local to your animate function). But since you're trying to use the captured u to initialize it, you need that u's value, but in this context Python has decided that u must be local to animate, so it isn't looking at animate's enclosing scope. That's why you're getting that error.
A simple way to get around that in your case is just to define animate as
def animate(i, u=u):
...
This explicitly passes a copy of u into animate.

Kivy Scatter Image - Bounding Box - NoneType

I'm having some issues using the bounding box feature of the Scatter (FloatView). My build code is;
MapPopup = Popup(title='Map')
def openMap(self):
box = BoxLayout(orientation='vertical')
stack = StackLayout(orientation='tb-lr', padding=0, spacing=1)
grid = GridLayout(orientation='vertical', cols=1)
button = Button(markup=True,bold=True,text='B\nA\nC\nK',width=40,size_hint_x=None)
button.bind(on_press=partial(self.backButton))
stack.add_widget(button)
source = os.path.join(os.getcwd(), 'Games', str(CURRENT_GAME[0]), 'map.png')
if os.path.isfile(source):
img = PILImage.open(source)
width, height = img.size
scatter = Scatter(size_hint=(None, None), size=(width,height), auto_bring_to_front=False, bbox=((10,10),(10,10)))
image = Image(source=source, size=(width,height))
scatter.add_widget(image)
grid.add_widget(scatter)
else:
label = Label(text="Please Start/Load a Game")
grid.add_widget(label)
stack.add_widget(grid)
box.add_widget(stack)
Container.MapPopup.content = box
Container.MapPopup.open()
It doesn't matter what values I put in at bbox=((?,?),(?,?)) I get the error;
TypeError: 'NoneType' object is not callable
Removing the bbox and all works normally, but the image I'm housing is spilling outside of the popup box. I don't want to resize the image using scale=.
From the docs:
bbox Added in 1.0.0
Bounding box of the widget in parent space:
((x, y), (w, h))
I think my issue is that it's scatter.scatter.bbox instead of scatter.bbox due to the ScatterLayout implementing FloatLayout, and Scatter implementing ScatterLayout, or something daft like that - can anyone help?
Many thanks!
Full Traceback;
Traceback (most recent call last):
File "main.py", line 1069, in <module>
TextGameTopiaApp().run()
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 792, in run
runTouchApp()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 481, in runTouchApp
EventLoop.window.mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 381, in mainloop
self._mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_pygame.py", line 287, in _mainloop
EventLoop.idle()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 324, in idle
self.dispatch_input()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 309, in dispatch_input
post_dispatch_input(*pop(0))
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 275, in post_dispatch_input
wid.dispatch('on_touch_up', me)
File "_event.pyx", line 316, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4550)
File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors.py", line 110, in on_touch_up
self.dispatch('on_release')
File "_event.pyx", line 312, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:4504)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1299, in custom_callback
exec(__kvlang__.co_value, idmap)
File "./textgametopia.kv", line 258, in <module>
on_release: root.openMap()
File "main.py", line 311, in openMap
scatter = Scatter(size_hint=(None, None), size=(width,height), auto_bring_to_front=False, bbox=((10,10),(10,10)))
File "/usr/lib/python2.7/dist-packages/kivy/uix/scatter.py", line 363, in __init__
super(Scatter, self).__init__(**kwargs)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 163, in __init__
super(Widget, self).__init__(**kwargs)
File "_event.pyx", line 156, in kivy._event.EventDispatcher.__init__ (kivy/_event.c:3184)
File "properties.pyx", line 345, in kivy.properties.Property.__set__ (kivy/properties.c:3589)
File "properties.pyx", line 1219, in kivy.properties.AliasProperty.set (kivy/properties.c:19329)
TypeError: 'NoneType' object is not callable

Categories

Resources