i can't add elevation effect to MDBottomNavigation? - python

am trying to add elevation effect to MDBottomNavigation in kivymd but coldn't get it to work can someone help me ?like in this imageenter image description here
i tried importing from kivy lik this but ddin't work
from kivymd.uix.bottomnavigation import MDBottomNavigation
from kivymd.uix.behaviors import CommonElevationBehavio
class MDBottomNavigation1(MDBottomNavigation,CommonElevationBehavior ):
pass

Related

Displaying a Matplotlib plot in Kivy without using the kivy-garden tools

I am just learning to use Kivy and want to embed some plots from Matplotlib and potentially OpenGL graphics in an app. I was looking at this particular tutorial on how to use kivy-garden to display a Matplotlib plot
However, I was hoping someone might be able to point me to an example of importing a plot into Kivy without using the matplotlib kivy-garden widgets. I want to be a little plotting backend agnostic, and hence I wanted to learn to import plots directly into the Kivy widgets. Matplotlib will export an image from plt.show() so I imagine the corresponding Kivy widget needs to have a property that can receive images? Plotly exports something different, so I was hoping to understand how to directly import these different plots into Kivy.
If anyone knows some good examples of directly plotting into Kivy, it would be appreciated.
You can load an Image. Here is an example hacked out of some code that I use.
kivy file:
#:kivy 2.0.0
<MatPlot>:
Image:
size_hint_x: 12
source: root.matplotlib_image2.source
Image:
size_hint_x: 5
source: root.matplotlib_image1.source
Python:
my method on_start() probably needs to be called from some other code. I think the on_start is only intrinsic with App and not other widgets. I have used this with matplotlib which as you point out can export image files.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from pathlib import Path
from kivy.uix.image import Image
from kivy.uix.boxlayout import BoxLayout
# requires kivy element <MatPlot> from kv_mat_plot.kv
class MatPlot(BoxLayout):
matplotlib_image1 = Image()
matplotlib_image2 = Image()
def __init__(self,
graph_directory: Path,
**kwargs,
):
super().__init__(**kwargs)
self.graph_directory = graph_directory
def load_image1(self, filename: str):
self.matplotlib_image1.source = str(Path(self.graph_directory, filename))
self.matplotlib_image1.reload()
def load_image2(self, filename: str):
self.matplotlib_image2.source = str(Path(self.graph_directory, filename))
self.matplotlib_image2.reload()
def reload_image2(self):
self.matplotlib_image2.reload()
print(f"imag2={self.matplotlib_image2.source}")
def reload_image1(self):
self.matplotlib_image1.reload()
print(f"image1={self.matplotlib_image1.source}")
def reload_images(self):
self.reload_image2()
self.reload_image1()
def on_start(self):
print(f"{self.name} on_start {self}")
self.matplotlib_image2.source = str(Path(self.graph_directory, "one_image.png"))
self.matplotlib_image1.source = str(Path(self.graph_directory, "second_image.png"))

python qpageview - how to draw a rectangle

I am trying to use qpageview library, but the documentation is quite limited and the core developer does not answer any question. This library is intended to make easier the creation of a PDF editor based on Qt and Poppler.
I am able to import a PDF and I am able to display a slection box with the following code:
import qpageview
from qpageview.export import pdf
from qpageview.rubberband import Rubberband
from PyQt5.Qt import *
a = QApplication([])
v = qpageview.View()
v.show()
v.loadPdf("../pdf/Frances_01.pdf")
r = Rubberband()
v.setRubberband(r)
What I would like to do is to draw white rectangle on the selection made with the Rubberband. It is easy to get the selection: r.selection(). But I don't know how to draw on the existing pages.
Any help would be welcomed.

How to import a screen class in another python file?

I am building a kivy application and i am using ScreenManager to go from one window to another. The program is working if i have all the classes used in the screenmanager in the same python file, like this:
sm = ScreenManager()
sm.add_widget(Login(name='login'))
sm.add_widget(Account(name='create_account'))
sm.add_widget(AfterLogin(name='after_login'))
But I want to have for each class a separate python file. How can I import the classes and make the screenmanager worK? i have tried to create "login_after.py" having for now only template:
class AfterLogin(Screen):
pass
And importing the class like this:
import login_after
sm.add_widget(login_after.AfterLogin(name='after_login'))
but this triggers the following error:
AttributeError: module 'login_after' has no attribute 'AfterLogin'
How to solve this?
Maybe this will work?
from login_after import AfterLogin
sm.add_widget(AfterLogin(name='after_login'))

Programmatically controlling a carousel in kivy

I'm new with kivy, but I have decent experience with Python and Tkinter. I'm trying to control a carousel in kivy programmatically. Essentially, I have an external python program which I want to use to automatically switch images in the carousel. To make an example, I have some code in another file:
import time
while True:
time.sleep(1)
#do something to control the carousel
and then I have my kivy app:
import kivy
from kivy.app import App
from kivy.uix.carousel import Carousel
from kivy.uix.image import AsyncImage
class CarouselApp(App):
self.srcs = ["/a/bunch.png", "/of/paths.jpg", "/to/images.png."]
def build(self):
self.carousel = Carousel(direction="right")
for i in range(0, len(self.srcs)):
src = self.srcs[i]
image = AsyncImage(source=src, allow_stretch=True)
self.carousel.add_widget(image)
return self.carousel
if __name__ == "__main__":
CarouselApp().run()
I would like to be able to control which slide is displayed in the carousel using the top code, but I'm not sure how I would go about doing that, since I can't execute anything after App.run()
I have investigated kivy's Clock module, but I'm not sure that would work for me since I want to switch slides when certain conditions are satisfied rather than on a time basis. The time example I gave is simply an example of my line of thinking.
Any help would be greatly appreciated!
I strongly suggest using a Kivy file to handle this situation. Second, AsyncImage is used when you want to use an image that will be downloaded from the Internet, and as I can see you have the images you are going to use are locally stored, so use Image instead.
I think you should implement the method on_start in the class which is extending App (CarouselApp in this case) and schedule a function using Clock as,
def on_start(self):
Clock.schedule_interval(self.my_callback, 1)
Then in the same class (CarouselApp) you should define my_callback:
def my_callback(self, nap):
if condition_is_satisfied: # this is supposed to be your condition
# control carousel

Changing image in widget - Kivy - Python

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.graphics import Color, Rectangle
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
class Imglayout(FloatLayout):
def __init__(self,**args):
super(Imglayout,self).__init__(**args)
with self.canvas.before:
Color(0,0,0,0)
self.rect=Rectangle(size=self.size,pos=self.pos)
self.bind(size=self.updates,pos=self.updates)
def updates(self,instance,value):
self.rect.size=instance.size
self.rect.pos=instance.pos
class MainTApp(App):
im=Image(source='img1.jpg')
def build(self):
root = BoxLayout(orientation='vertical')
c = Imglayout()
root.add_widget(c)
self.im.keep_ratio= False
self.im.allow_stretch = True
cat=Button(text="Categories",size_hint=(1,.07))
cat.bind(on_press=self.callback)
c.add_widget(self.im)
root.add_widget(cat);
return root
def callback(self,value):
self.im=Image(source='img2.jpg')
if __name__ == '__main__':
MainTApp().run()
What i am trying to do here, is change the image first loaded during object creation, which is shown when the app starts, and then change it when the button cat is pressed. I am trying it to do this way but it isnt happening. I would eventually want it to change with a swipe gesture.(with a little bit of swipe animation like it happens in the phone
what i am trying to build is a slideshow, which will change image in t seconds, unless swiped, and then when a new image comes the timer resets.
When the category button is pressed the image will not be there and a list of categories to select from. and when an item from the list is touched the images from that list will be displayed on the screen.
And at the end when everything has been done i would want to make it such that it automatically detects categories(based on directories in a specified location.) and then all the images will be available to it.(that is not telling it explicitly how many images and what images.)
But, i am not able to do the first thing, so i would really like some help on that. And maybe a few pointers on how to achieve the other things as well.
def callback(self,value):
self.im=Image(source='img2.jpg')
Your problem is in the definition of the callback. You create a new image with the new source, but you don't do anything with it, like adding it to your widget tree.
What you really want to do is modify the source of the existing image:
def callback(self, instance, value):
self.im.source = 'img2.jpg'
This will immediately replace the source of the existing image, which will immediately update in your gui. Note that I also added an instance parameter, which will be passed to the callback so you need to catch it or you'll crash with the wrong number of arguments.
Also, I'd define your image inside build rather than as a class level variable. I'm not sure if the current way will actually cause you problems, but it could in some circumstances.

Categories

Resources