Traceback (most recent call last) OSerror and font not found - kivy

enter image description herei will run python script with kivy and kivymd but this problem appears, how to solve it? I already installed the kivy library and kivymd still looks like this...
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
Traceback (most last): File "d:/Python/main python/main.py", line 2, in from kivy.uix.label import Label File "C:\Users\andihasan AppData\Local\Programs\ Python\Python38-32\lib\site-packages\kivy\uix\labe 1.py", line 286, in from kivy.core.text import Label as Corelabel, DEFAULT_FONT File "C:\Users\andihasan AppData \Local\Programs \Python\Python38-32\lib\site-packages\kivy\core\tex t_init_-py", line 1013, in Label.register(DEFAULT_FONT, *default_font_paths) File "C: \Users\ andihasanAppData\Local\Programs \Python\Python38-32\lib\site-packages\kivy\coreltex t_init_-py", line 315, in register raise IOError('File {e} not found'.format(font_type)) OSError: File data/fonts/Roboto-Regular.ttf not found

OSError: File data/fonts/Roboto-Regular.ttf not found.
This line is the cause of your error.
if you're trying to use custom fonts in your kivymd project, you need to have the font file. that is the .ttf file
and to use the font without having to put the full directory, you need to register the font with the following lines.
first import label base
from kivy.core.text import LabelBase
then register the font with an easier name to refer to.
if __name__ == "__main__":
LabelBase.register(name="RobotoReg", fn_regular="{full_path_to}/Roboto-Regular.ttf")
you can then use it in your .kv file like so:
MDLabel:
text: "Text to test if font name works"
size_hint_x: 1
pos_hint: {"center_x":.5, "center_y": .5}
font_name: "RobotoReg"
font_style: "Caption"
halign: "center"

Related

displaying text from .txt file in kivy

I'm trying to make an app that displays text from a .txt file.
Unfortunately when i set a StringProperty, Label binded to it doesn't change. Its possible for me to just print it in the console. Could you give me some advice?
python code:
class notatnik(Screen):
notatnik_plik = open(r"notatnik.txt","r")
#prints the file to the console(works)
print(notatnik_plik.read())
fileoutput = StringProperty(notatnik_plik.read())
notatnik_plik.close()
kv code:
<notatnik>:
name: "screen_notatnik"
FloatLayout:
Label:
text: root.fileoutput
pos_hint: {"top": 1}
result:image
.txt file is a simple hello_world

Getting error "AttributeError: module "ibapi.contract" has no attribute "UnderComp"

Ive tried now for some time to get the following code to work, but I keep getting this error message. What am I doing wrong?
from ib_insync import IB
ib = IB()
ib.connect("127.0.0.1",7497,clientId=1)
stock = Stock("AMD","SMART","USD")
bars = ib.reqHistoricalData(
stock,
endDateTime="",
durationStr="30 D",
barSizeSetting="1 hour",
whatToShow="MIDPOINT",
useRTH="True"
)
print(bars)
Error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:/Users/Ejer/Desktop/TWS/option.py", line 1, in <module>
from ib_insync import IB
File "c:\Users\Ejer\Miniconda3\lib\site-packages\ib_insync\__init__.py", line 21, in <module>
from .objects import *
File "c:\Users\Ejer\Miniconda3\lib\site-packages\ib_insync\objects.py", line 155, in <module>
class UnderComp(Object):
File "c:\Users\Ejer\Miniconda3\lib\site-packages\ib_insync\objects.py", line 156, in UnderComp
defaults = ibapi.contract.UnderComp().__dict__
AttributeError: module 'ibapi.contract' has no attribute 'UnderComp'
>>>
Seems, you are using the old ib-insync package (ver 0.9.11). Try to install the latest version ib-insync 0.9.64, that worked for me.
Also, follow the group for more information: https://groups.io/g/insync

Why am I not getting setting in kivy?

1). Why am I not getting Settings: (i.e. no Kivy core settings displayed) when I click on setting button.
2). Where am I doing wrong? Thanks in advance
KV FILE
<WindowManager>:
Hello:
Setting22:
<Hello>:
name: 'hello'
Button:
text:'setting'
on_press: root.manager.current="setting22"
<Setting22>:
name: 'setting22'
Settings:
Kivy Settings ยป add_kivy_panel()
add_kivy_panel()
Add a panel for configuring Kivy. This panel acts directly on the kivy
configuration. Feel free to include or exclude it in your
configuration.
See use_kivy_settings() for information on enabling/disabling the
automatic kivy panel.
Solution
To display the Kivy core settings in a panel, use Settings.add_kivy_panel()
kv file
Add id: settings for Settings: widget
Add on_pre_enter Screen event to invoke add_kivy_panel() function
Snippets - kv
<Setting22>:
name: 'setting22'
on_pre_enter:
settings.add_kivy_panel()
Settings:
id: settings
Example
In the following example / demo, we are using dynamic classes.
main.py
from kivy.base import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string("""
WindowManager:
<WindowManager#ScreenManager>:
Hello:
Setting22:
<Hello#Screen>:
name: 'hello'
Button:
text:'setting'
on_press: root.manager.current="setting22"
<Setting22#Screen>:
name: 'setting22'
on_pre_enter:
settings.add_kivy_panel()
Settings:
id: settings
"""))
Output

Kivy OSC Windows

Thanks for your quick answer laltin. The code lines are here in the .py file.
kivy 1.9.0
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.widget import Widget
from kivy.lang import Builder
from simpleOSC import initOSCClient, initOSCServer, closeOSC, \
setOSCHandler, sendOSCMsg
class OscShowcase(BoxLayout):
pass
class TestOscApp(App):
def build(self):
return OscShowcase()
def send_Osc(self, *l):
sendOSCMsg('activate', [3.0])
#pass
if name == 'main':
host = '127.0.0.1'
sport = 9000
rport = 9001
# osc
initOSCClient(host, sport)
initOSCServer(host, rport)
TestOscApp().run()
.kv file
:
BoxLayout:
Widget:
Button:
text: 'OSC'
pos: (500, 400)
on_press: app.send_Osc()
sendOSCMsg: ('/%s/press', [])
#on_release: app.send_Osc()
#sendOSCMsg: ('activate', [3.0])
Do you think I can edit the OSC messages directly in the kv.file in order to separate every button with its assigned osc message? This is my main issue from the beginning. In fact i would like to control one of my Max patches on 3 systems, Ipad, MacbookPro and pc at the same time with the OSC protocol. And Kivy is the best on this I think. I already have a graphic plan of what I designed mostly in kv. langage. I can share the code with you if you don't mind. Thanks again for your big help.
stkflwrglator
The line on_press: do_root_action() in your .kv file means that when user presses the button the function do_root_action will be called. But do_root_action is not defined in your application.
Add send_Osc method to your app:
class TestOscApp(App):
...
def send_Osc(self, *l):
sendOSCMsg('/chaine_en_dur/', [2.0])
Call send_Osc method on button press
Button:
text: 'OSC'
pos: (500, 500)
on_press: app.send_Osc()

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