Configparser under Kivy - python-3.x

I have a problem deploying a Kivy application using configparser
import kivy
from kivy.app import App
from kivy.uix.screenmanager import Screen
import configparser
class MainFrame(Screen):
def __init__(self, **kwargs):
super(MainFrame, self).__init__(**kwargs)
pass
def on_quit_button_click(self):
quit()
class BasicApp(App):
def build(self):
return MainFrame()
pass
if __name__ == '__main__':
BasicApp().run()
with the following basic.kv
<MainFrame>:
BoxLayout:
Button:
text: 'Click to quit ... test'
on_press: root.on_quit_button_click()
It works perfectly on the pc and I can build and deploy on Android using buildozer provided I comment out the line
import configparser
With that line in the app closes as soon as the splash screen is displayed
my buildozer.spec file is here
and a copy of the logcat is here
[Update 2018.04.26:08:16]
I have done some debugging and when run on the android device it return an 'import error' at the point that it attempts to load configparser.
[Update 2018.04.26:08:41]
It loads if I use ConfigParser (i.e. the Python 2 version). Is this a bug in configparser (Python 3)?

kivy comes with its own configparser. It appears this is based on the standard python configparser.
Use:
from kivy.config import ConfigParser

Related

cx_Freeze .app crashes when external import is used (mac OS monterey)

I have a problem freezing my tkinter application. As long as I don't import an external library the frozen app works. If I import a module like pandas the app crashes with no error messages. My OS is macOS monterey, I also tried on a windows machine and the same problem happens. Here's an example code:
from tkinter import *
import pandas as pd # it only works after building if this line is ommited
class MyApp(Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title("Welcome to My_App")
self.geometry('350x200')
app = MyApp()
app.mainloop()```
It seems there is a problem with the conda environment and there is somehow a clash between the conda env and cx_Freeze. It was solved when I created a pyenv.

How to change the source of python used by atom runner or script in Atom?

I want to run python code with Kivy by atom-runner or script, but when I run the simple any codes with Kivy, I got ModuleNotFoundError. I checked python path by
import sys
print(sys.prefix)
which prints ''/Library/Frameworks/Python.framework/Versions/3.7''
I guess I need to use Anaconda's python because I can run Kivy app on terminal and terminal uses python3.7 showing Anaconda.inc things.
But I can not find where to write path of python in Atom.
I tried pip install Kivy and it worked but nothing changed in Atom. And Kivy3 is in Application folder.
Just in case, my Kivy codes is this
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
class IntroKivy(App):
def build(self):
return Button(text="Hello, World!")
if __name__ == "__main__":
IntroKivy().run()
It will be perfect if I can run this codes without using terminal as it is faster and quick.
Best

Can't exit PyQt application on 3.7.4 and Spyder

Running on Windows 10 64 bit and Python 3.7.4 (no Anaconda), the basic script from Terminate PyQt Application
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtCore import QSize
class HelloWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(640, 480))
self.setWindowTitle("Hello world")
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)
gridLayout = QGridLayout(self)
centralWidget.setLayout(gridLayout)
title = QLabel("Hello World from PyQt", self)
title.setAlignment(QtCore.Qt.AlignCenter)
gridLayout.addWidget(title, 0, 0)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = HelloWindow()
mainWin.show()
sys.exit( app.exec_() )
does not exit when starting from Spyder.
The IPython console simply "idles", but never returns. Running the script from the command prompt (i.e. 'python script.py') works OK.
Switching back to a fresh install of Python 3.7.2, everthing works as expected. The IPython version is in both cases 7.7.0.
In both cases (3.7.2 and 3.7.4) all modules including Spyder had been installed via pip.
Any idea why that is? Is it a Spyder related issue?
Keeping the Graphics Backend as not "Inline" is creating this problem.
Either change the graphics backend as,
Tools -> Preferences --> IPython Console -> Graphics --> Graphics Backend as Inline
Or Restore the default settings of the Spyder Environment. Which can be done by,
Tools -> Preference --> Reset to Defaults.

PyQt5 howto load UI file in bundle

I'm trying to load a Qt5 file in a bundle on a Mac.
#!/usr/bin/env python
from PyQt5.QtWidgets import (QApplication, QMainWindow)
from PyQt5 import uic
import sys
import os
MainUI = os.path.dirname(os.path.realpath(__file__)) + "/data/MainUI.ui"
Ui_MainWindow, QtBaseClass = uic.loadUiType(MainUI)
class MyForm(QMainWindow,Ui_MainWindow):
def __init__(self):
QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
This works fine in the commandline but when I bundle this with pyinstaller the program aborts because it can't find the file mainUI.ui. I found this solution but I can't get it working (resource_path function not found).
I've made another and that worked fine but this one (a one file program) I can't get working.
Edit:
I stopped trying to fix this and went for the multiple file solution: 1 file to startup and one for the PyQt functions. That works 100%.

How do I turn off fullscreen in Kivy?

All Kivy (1.8.0) applications run fullscreen on my PC by default. I need to turn fullscreen off for only one (not for each) Kivy application. Strange, but I haven't found the answer for this simple question. Probably, that's not Kivy, but Pygame, but anyway I don't know how to trun it off. Kivy and Pygame were taken from here.
I know this is an old question but if anyone runs in to this problem again and you want to set the config options as default.
In a terminal.
from kivy.config import Config
Config.set('graphics', 'fullscreen', '0')
Config.write()
You can configure the way window will be displayed using kivy.config.Config before importing any Kivy module. For example, to have fullscreen application (this shouldn't be enabled by default):
from kivy.config import Config
Config.set('graphics', 'fullscreen', 'auto')
In your case you can try to set it explicitly:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from kivy.config import Config
Config.set('graphics', 'fullscreen', '0')
from kivy.app import App
class TestApp(App):
pass
if __name__ == '__main__':
TestApp().run()
You can find details about graphics:fullscreen option in documentation.

Resources