How do I turn off fullscreen in Kivy? - python-3.x

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.

Related

How to reliably convince matplotlib to use PySide2 backend when running from Anaconda (Spyder)

I am creating a PySide2 application which uses matplotlib. I am running this application from Spyder in an environment with PySide2 installed. This is causing the application to be run from the iPython console. Somewhere along the line, PyQt5 is imported, which I am attempting to purge in order to convince matplotlib that I really do want to use PySide2, NOT PyQt5. Something like following was working until very recently and I am not really sure why it has stopped, but safe to say this method is unreliable. How can I absolutely convince matplotlib that I am wanting PySide2?
I have tried setting the environment variable QT_API in the operating system (Windows 10), but in this case Spyder itself refuses to open.
import sys
import os
ps = list(filter(lambda x: 'PyQt5' in x, sys.modules))
for p in ps:
print(f"purging module {p}")
sys.modules.pop(p)
# matplotlib.__init__ uses this
os.environ["MPLBACKEND"] = "PySide2"
# matplotlib.backends.qt_compat uses this
os.environ["QT_API"] = "PySide2"
import PySide2.QtCore
assert "PyQt5.QtCore" not in sys.modules
assert "PySide2.QtCore" in sys.modules
# rcParams has the right idea
from matplotlib import rcParams
print(rcParams["backend"])
# qt_compat has the WRONG idea!
import matplotlib.backends.qt_compat as qt_compat
print(qt_compat.QT_API)
# The FigureCanvasWidget is of the wrong (PyQt5) type
from matplotlib.backends.backend_qt5agg import FigureCanvas
import inspect
print(inspect.getmro(FigureCanvas))
To answer this question, the reason that it stopped working was because I had set 'activate support' for Matplotlib graphics in the ipython tab under Spyder settings. After unchecking this, the above works.

QsciScintilla on Pyqt4 for python35 error (unofficial whl)

I want to use pyqt4 on python35. However, the latest official release supports py=<34
So I found this university website https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4
which unofficially extended support for later versions including python35
My problem is that QsciScintilla is not working. I tried to run this code:
import sys
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore, QtGui, Qsci
from PyQt4.Qsci import QsciScintilla
if __name__ == "__main__":
app = QApplication(sys.argv)
editor = QsciScintilla()
editor.show()
sys.exit(app.exec_())
The window becomes unresponsive then crashes:
Process finished with exit code -1073740771 (0xC000041D)
The reason I want to use pyqt4 on python3.5 is that I have a quit big application built on pyqt4
and I want to upgrade python version of the project to 35
I moved to PyQt5. It is always not a good idea to use an unofficial package.

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

Configparser under Kivy

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

Download a file using qwebkit

Good day to all. I started using X. I don't want to surf websites only, but download files too. What should I add to the code, to let it just download the file in a directory without any dialog window.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt4.QtWebKit import *
from PyQt4 import QtGui, QtCore
import os, sys
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
qwv = QWebView()
qwv.load(QtCore.QUrl("http://google.com"))
qwv.show()
app.exec_()
ps. I want that to when you click on the link "download the file" on any sites the file is loading in local folder, but when you click on the "regural" link the qwebkit is opening this page.
To download a file you could use urllib.urlretrieve():
import urllib
urllib.urlretrieve(url, filename)
To download links that QWebView can't show:
qwv.page().setForwardUnsupportedContent(True)
qwv.page().unsupportedContent.connect(save_file_callback)

Resources