KivyMD TopAppBar - kivy

I'm trying to learn Kivy and KivyMD because I want to make an android app.
But I'm stuck at the first hurdle. I want a toolbar, or as the KivyMD documentation calls it, a TopAppBar.
I'm trying to implement it as per the doc's, but I get an error Unknown Class <MDTopAppBar>
I though maybe that I had mistyped something, so I copied and pasted the entire code example from the docs and the error still persists. As far as I am aware, I am running the latest version of Kivy & KivyMD
Code from docs:
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
MDBoxLayout:
orientation: "vertical"
MDTopAppBar:
title: "MDTopAppBar"
MDLabel:
text: "Content"
halign: "center"
'''
class Test(MDApp):
def build(self):
return Builder.load_string(KV)
Test().run()
My code:
from kivymd.app import MDApp
from kivy.lang import Builder
KV = '''
MDBoxLayout:
MDTopAppBar:
title: "World Pool Rules"
'''
class MyApp(MDApp):
def build(self):
return Builder.load_string(KV)
if __name__ == '__main__':
MyApp().run()
I've also tried from kivymd.uix.topappbar import MDTopAppBar but just get a No module named error.
Any help would be much appreciated
Anyone know how I can fix this?

I recently had the same issue. I was looking through the official documentation and saw, that the documentation was referencing version 1.0.0-dev. However, I had installed via pypi version: 0.104.2 (latest official version - I guess?)
https://pypi.org/project/kivymd/
After changing the documentation to the right version:
https://kivymd.readthedocs.io/en/0.104.2/index.html
I saw that there is no "MDTopBar". You will need to use just "MDToolbar" instead.

According to commentary on this issue thread by the principal developer of KivyMD, the location-specific suite of MD{Bottom,Top}AppBar widgets is a recent addition that has yet to be officially released. Presumably, these widgets will be published with the next stable release (e.g., KivyMD 0.104.3).
To access them now anyway, manually install the live version of KivyMD from its GitHub-hosted git repository. Thanks to the magic of modern pip, this one-liner gets you there and back again: e.g.,
pip install git+https://github.com/kivymd/KivyMD.git
KivyMD's "latest" documentation is, in fact, its unstable documentation. This is why we can't have good things.

Related

Can't access kivy.garden.matplotlib

Everything in installed and has the latest version but when I'm trying to import FigureCanvasKivyAgg :
from kivy.garden.matplotlib import FigureCanvasKivyAgg
it says under matplotlib that: "Cannot find reference 'matplotlib' in 'init.py'"
Thanks for the help!

how to install model_evaluation_utils

I'm trying to model evaluate the performance of our deep learning models. And below is my code. However, I still get
No module named 'model_evaluation_utils'
Is there any pip installation or conda that could solve this problem?
from keras.preprocessing.image import load_img, img_to_array, array_to_img
from keras.models import load_model
import model_evaluation_utils as meu # throws error
Implementation of "model_evaluation_utils" can be found in the following github repository:
link
I think it's not a publicly available library, there must be a model_evaluation_utils.py file which is imported in the code and is used.

kivy+gspread crashes while trying in an android phone, but works fine in my laptop

I am using gspread and oauth2client in a very simple kivy app, I just want to update one cell in my google sheet. The code works just fine in my PC but when I build the apk file using buildozer and upload it to my android phone it crashes. Is there any conflict between gspread and kivy ???? The code is shown below;
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('cl_sec.json', scope)
client = gspread.authorize(creds)
sheet = client.open('project2').sheet1
class bxlayout(BoxLayout):
def __init__(self, **kwargs):
super(bxlayout, self).__init__(**kwargs)
btn1 = Button(text='ON')
btn1.bind(on_press=self.clk1)
self.add_widget(btn1)
btn2 = Button(text='OFF')
btn2.bind(on_press=self.clk2)
self.add_widget(btn2)
def clk1(self, obj):
self.background_color = [0,0,1,1]
sheet.update_cell(2,1, '1')
self.background_color = [1,1,1,1]
def clk2(self, obj):
self.background_color = [0,0,1,1]
sheet.update_cell(2,1, '0')
self.background_color = [1,1,1,1]
class appfile(App):
def build(self):
ml = bxlayout()
return ml
if __name__ == "__main__":
appfile().run()
Without logcat any question like this pretty much tells nothing about the problem because:
the code obviously works (laptop)
the packaging apparently too (you can install and launch the app)
so as Eugene suggested, the problem is most likely with you not including the package either in the buildozer's .spec file - the important part looks like this:
requirements = kivy
and for you to use a third-party library you have to mention its name in that particular line:
requirements = kivy,gspread
or with similar python-for-android console switch.
Depending on if it's pure-python or C-extension it will or will not throw an error during packaging now. If it's an extension, you need to write a recipe for it.

Could not find class 'weka.core.FastVector',

I am using weka for my project. but get the error info"could not find class weka.core.FastVector" on the line below. I have already added weka.jar from the build path of the project by adding external jar file. How should I solve this problem? Thanks a lot for your time on reviewing my question.
import weka.core.Attribute;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;
FastVector atts;
private void setUpARFF(){
atts = new FastVector();}
I know that FastVector was marked as obsolete a while back, perhaps they've finally removed it. Are you using the dev version of weka (or what version are you using)? FastVector can be replaced with ArrayList (in dev version) so use that instead.

How to use alias name in a Kivy Language import?

I am having troubles to assign alias names when importing classes in the Kivy Language. The documentation I am following is here:
To import something from python:
#:import name x.y.z
Is equivalent to:
from x.y import z as name
I created a reduced version of my problem. pieces.py is inside the package pieces (with its respective __init__.py) and the pieces.kv is in my working folder.
pieces/pieces.py
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
class PieceA(Button):
pass
class PieceB(Button):
pass
class PieceC(GridLayout):
pass
pieces.kv
#:import Boo pieces.pieces.PieceA
#:import Foo pieces.pieces.PieceB
#:import Too pieces.pieces.PieceC
<Boo>:
text: "A"
<Foo>:
text: "B"
<Too>:
rows: 2
Boo:
Foo:
The import is as stated in the documentation but the aliases Boo, Foo and Too are not
being recognized. There are also many other versions of this that unexpectedly works if I use the original name of the class but not the alias name:
#:import Boo pieces.pieces
<PieceA>:
text: "A"
<PieceB>:
text: "B"
<PieceC>:
rows: 2
PieceA:
PieceB:
Even if I substitute #:import Boo pieces.pieces for #:import Boo pieces.pieces.PieceA. It continue working as long as I use the original name of the classes but I cannot use alias names. How do I use an alias name when I import a class in the Kivy Language?
I also added here my other 2 files in case you want to test.
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.gridlayout import GridLayout
Builder.load_file('pieces.kv')
class Gallery(GridLayout):
pass
class GalleryApp(App):
def build(self):
return Gallery()
GalleryApp().run()
gallery.kv
<Gallery>:
cols: 3
PieceA:
PieceB:
PieceC:
I'm not sure what you want to do is actually possible, but at the very least this import syntax does not have that purpose and is behaving properly. That is, the #:import syntax applies only to the python parts of the kv file, so for instance you could include code like
#:import Boo pieces.pieces.PieceA
...
...
<SomeWidget>:
Button:
on_press: some_other_widget.add_widget(Boo())
This would do what you expect, with Boo being a standard python alias for PieceA.
However, when the kv file is parsed I'm not aware of a way to alias the names of class rules. I'm also not sure why you'd want or need to (not that this means there isn't a reason!), why not just refer to them as PieceA, PieceB etc.?

Resources