Disable Swipe Actions on Kivy Carousel - python

I am using Kivy Carousel to build an App.
However I would like to maintain Manual control of the carousel and disable the swipe action (I will manually call carousel.load_next)
I have looked through the Documentation but cannot see any way to disable the swipe action.
If anyone could help me I would appreciate it.
Many thanks,
Seotha.

You can disable the user swipe by controling the scroll_timeout. If you simply set it to 0 the user will be unable to trigger the scroll event.
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
class CarouselApp(App):
def build(self):
carousel = Carousel(direction='right', scroll_timeout=0)
for i in range(10):
src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i
image = AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
CarouselApp().run()

Thanks Authur, I will mark as Answer.
I also discovered I can subclass Carousel and override on_touch_move with nothing.
class MyCarousel(Carousel): def on_touch_move(self,touch): pass

The following might be helpful:
use
scroll_distance: '<x>dp'

Related

Python Kivy and adding local photos to Carousel

Please forgive me I am in my infancy learning Python and started using Kivy not too long ago.
I am simply trying to add photos from my "carousel/" directory in my project to be each photo that comes up in the carousel app one by one when it loads.
The code runs fine, and I am even able to load Async photos with the link to the photo, but for whatever reason when I try to load photos from my "carousel" folder they don't show up.
I know that these photos return otherwise because I used the "Image" call and it worked, I also looked all over and there were other solutions but I could not make the connection between their solution and what it is I need.
Here is the code and a picture below, like I said the code builds and runs fine but the pictures won't show up. Thank you in advance!
[from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from kivy.core.image import Image
from kivy.factory import Factory
class CarouselApp(App):
def build(self):
carousel = Carousel(direction='right')
for i in range(0,2):
src = "carousel/%s.jpg" % str(i)
image = Factory.AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
CarouselApp().run()][1]
https://i.stack.imgur.com/igyeq.png
You have to store all your pictures in a folder called carousel, and you can remove the Factory.
Example
main.py
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
class CarouselApp(App):
def build(self):
carousel = Carousel(direction='right')
for i in range(0, 6):
src = "carousel/%s.png" % str(i)
image = AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
CarouselApp().run()
Output
You are trying to load 'carousel/0.jpg' and 'carousel/1.jpg' instead of 'carousel_images/00.jpg' and 'carousel_images/01.jpg', Try this:
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
from kivy.core.image import Image
from kivy.factory import Factory
class CarouselApp(App):
def build(self):
carousel = Carousel(direction='right')
for i in range(0,2):
src = "carousel_images/0{}.jpg".format(str(i))
image = Factory.AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
CarouselApp().run()

Issues with changing color of basic Kivy app

I created a simple text-to-speech app with Kivy, using the FloatLayout option but am having trouble changing the color of the GUI without actually creating a .kv file (which I do not wish to do). The code of my app is here:
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
import requests
from threading import Thread
import os
class ButtonApp(App):
def talk(self):
self.info.text = self.text.text
command = "say %s" % (self.text.text)
os.system(command)
def say(self,instance):
t = Thread(target=self.talk)
t.start()
def build(self):
self.b = FloatLayout()
self.info = Label(text="Hello!", pos=(20,400) ,size_hint=(1,0.5), font_size="40sp")
self.text = TextInput(text='Hello!', pos=(20,200), size_hint=(1,0.5))
self.submit = Button(on_press=self.say,text='Submit',pos=(20,100), size_hint=(1,0.5))
self.b.add_widget(self.info)
self.b.add_widget(self.text)
self.b.add_widget(self.submit)
self.b.bind()
return self.b
if __name__ == "__main__":
ButtonApp().run()
Like I mentioned beforehand, all the suggestions I found doing prior research involved either Canvas (which I am not using), or creating a .kv file. Is there a pure python-kivy method of changing the color of a GUI?
You can do anything in pure python, though the reason you see so many kv examples is because it's easier and more concise due to being a more domain specific language, so I don't recommend avoiding it.
What kind of change do you actually want to make? For instance, you can change the background image of the Button with the background_normal or background_down properties (which take a filepath to an image), or tint its colour by setting its background_color to e.g. (1, 0, 0, 1) for red.

What is a root widget and how to implement it in Kivy Python ?

Here is my code:
from kivy.app import App
from kivy.uix.button import Button
from kivy.core.image import Image as CoreImage
class WeaselApp(App):
def __init__(self, image):
self.image = image
def coreimage(self, load_image):
self.load_image = load_image
load_image = CoreImage("psychTREE.jpg")
#return load_image
def built(self):
return coreimage(self, load_image)
if __name__== "__main__":
WeaselApp(App).run()
When I run it, it says " WeaselApp has no attribute 'root' ". Why is this the case? Any hints or suggestions are greatly appreciated.
You don't return any widget from your build method, for two reasons:
As Joran Beasley said, you need a build method, not built.
CoreImage is not a widget that can be displayed on screen, it's a low level tool to load image data. You should use a kivy.uix.image.Image widget.
Edit: Following the comments, replace your code with this:
from kivy.app import App
from kivy.uix.image import Image
class YourApp(App):
def build(self):
return Image(source='psychTREE.jpg')
YourApp().run() # edited this in after

Kivy: Hide mouse cursor on desktop

I have a fullscreen app and I'm trying to hide the mouse cursor. The setup is Kivy 1.9.0 on Python 3.4.1 for Windows, using the prepared packages.
I have tried the following approaches, with no success:
1- Using Config object:
from kivy.config import Config
Config.set("graphics", "show_cursor", 0)
2- Editing .kivy\config.ini:
[graphics]
.
.
.
show_cursor = 0
3- Using pygame:
import pygame
pygame.init()
pygame.mouse.set_visible(False)
4- Moving the mouse off-screen:
def move_mouse_away(etype, motionevent):
# this one doesn't get called at all
Window.mouse_pos = [1400, 1000]
Window.bind(on_motion=move_mouse_away)
5- Using Clock for a similar effect:
Clock.schedule_interval(self._reset_mouse, 0.05)
def _reset_mouse(self, time):
Window.mouse_pos = [1400, 1400]
I'm a little out of ideas now.
You can use Window.show_cursor
It was added in kivy version 1.9.1
from kivy.core.window import Window
Window.show_cursor = False
I just read the documentation, tried it and fixed it (version 1.9.0). To hide the cursor from the application window permanently (even if you are using a touchscreen) :
>>> from kivy.config import Config
>>> Config.set('graphics','show_cursor','0')
>>> Config.write()
>>> quit()
I use a touch screen (LG 19MB15T) which works 'out_of_the_box'.
I'm having the same kind of problem: I need to hide or change my mouse cursor in a kivy app.
I don't have a perfect solution only a partial one:
from kivy.uix.widget import Widget
from kivy.core.window import Window
import win32api
class NoCursorWindow(Widget):
def __init__(self, **kwargs):
super(NoCursorWindow, self).__init__(**kwargs)
Window.bind(mouse_pos=self.on_mouse_pos)
def on_mouse_pos(self, *args):
win32api.SetCursor(None)
if __name__ == '__main__':
from kivy.base import runTouchApp
runTouchApp(NoCursorWindow())
It works only partially:
The problem when you use win32api.SetCursor() is that when the mouse moves, the window gets a WM_SETCURSOR Message which changes the cursor back to default. This is why the win32api.SetCursor() must be triggered for each change of the mouse_pos.
But even like that sometimes we can see the default cursor blinking.
If anyone knows how to hook the WM_SETCURSOR, to prevent the call back of the default cursor, it could solve this...

How to make a carousel in Kivy?

I made a little Kivy application as an interface. The carousel seems to be working, but I would like to make the carousel start by itself (that means without using a mouse). In fact, the app will be deployed on a little robot that does not have any mouse or keybord, thus that is why I need the carousel passing the images by itself.
As you can see in my code, the carousel does work, but I just can't figure out how to make it start without clicking on it with a mouse.
class Logo(App):
def build(self):
carousel = Carousel(direction='right')
for i in range(2):
src = "image.png"
image = Factory.AsyncImage(source=src, allow_stretch=True)
carousel.add_widget(image)
return carousel
if __name__ == '__main__':
Logo().run()
Any ideas ? Thanks.
You want an event to trigger the movement, i think the easiest way would be to use a Clock.
from kivy.clock import Clock
then in your build, you could schedule incrementing the position of the carousel at some interval, carousel has a convenient function for that load_next, but if you just do that, it'll get stuck on the last frame pretty fast, so you'll probably want to pass loop=True to the Carousel instantiation.
from kivy.app import App
from kivy.factory import Factory
from kivy.uix.carousel import Carousel
from kivy.clock import Clock
class Logo(App):
def build(self):
carousel = Carousel(direction='right', loop=True)
for i in range(2):
image = Factory.Label(text=str(i))
carousel.add_widget(image)
Clock.schedule_interval(carousel.load_next, 1)
return carousel
if __name__ == '__main__':
Logo().run()
(i changed the images by labels to see the difference more easily)

Categories

Resources