mirror of https://github.com/kivy/kivy.git
Page:
Viewport with fixed resolution autofit to window
Pages
A draggable scrollbar using a slider
AdBuddiz Android advertisements integration for Kivy apps
Advanced Graphics: In Progress
An example of background Twisted server running on Android
Android Background Services
Android SDK NDK Information
Android SDK NDK Informations
Android native embedded browser
Android style menu app skeleton
Background Service using P4A android.service
Batch installer for windows(KivyInstaller)
Breaking changes in Kivy
Building Portable Package
Button(s) in settings panel
Buttons in Settings panel
Community Guidelines
Connecting Kivy with Anaconda (OSX)
Contextual Menus
Contextual menus
Control alpha of all the children
Create source distribution release on PyPI
Creating a Release APK
Data driven variables with kivy properties
Debugging widget sizes
Deep Linking with iOS and Android
Delayed Work using Clock
Drag and Drop Widgets
Dragable Widget
Draggable Scalable Button
Editable ComboBox
Editable Label
Embedding a Carousel inside a TabbedPanel
GestureBox
Home
Implementing Android Adaptive Icons
KEP001: Instantiate things other than widgets from kv
Kivy 2.0 api breaks
Kivy Blogs and Blog Posts
Kivy Python 2 Support Timeline
Kivy Technical FAQ
Kv language preprocessing
Linking ScreenManager to a different Widget
List of Kivy Projects
Markup Summary
Menu on long touch
Migration guide from legacy garden packages
Moving kivy.garden.xxx to kivy_garden.xxx and kivy.deps.xxx to kivy_deps.xxx
On touch current widget
On touch on current widget
Packaging Kivy apps written in Python 3, targeting Windows using Nuitka
Pyjnius Vibrator Example
Release Checklist
Release notes for 1.10.0
Release notes for 1.11.0
Sample Gestures
Scaler for Retina screen
Scollable Options in Settings panel
Scrollable Label
Setting Up Kivy with various popular IDE's
Setting up Pycharm on OSX (older versions)
Setting up garden with Mac Ports
Setting up kivy with various popular IDE
Simple slider with value in label
Snippet template
Snippets awaiting moderation
Snippets
Starting Kivy App and Service on bootup on Android
Styling a Spinner and SpinnerOption in KV
Talks and tutorials
Theming Kivy
Tiled Maps & Tile Based Movement
Tiling the background of a widget with an image, pixel perfect
Ubuntu Touch
Updating widget content from a items list
User Snippets
Using Asynchronous programming inside a Kivy application
Using Buildozer on windows 10 using WSL
Viewport with fixed resolution autofit to window
Windows RT
Working with Python threads inside a Kivy application
rand0m app
wiki_proposed
1
Viewport with fixed resolution autofit to window
Mathieu Virbel edited this page 2013-09-27 10:34:33 +02:00
Table of Contents
Summary
- author: hansent
- kivy: >= 1.2
I use this viewport widget as the root widget in many apps that have a fixed resolution. The viewport will automatically fit itself to the window after its been created (including rotating if its a better fit). This makes testing apps for large resolution like 1080p on smaller screens a lot easier.
Usage
#!python
from kivy.app import App
from kivy.factory import Factory
from viewport import Viewport
class ViewportApp(App):
def build(self):
self.root = Viewport(size=(1080,1920))
self.root.add_widget(Factory.Button(text="ViewportApp"))
return self.root
if __name__ == "__main__":
ViewportApp().run()
Files
viewport.py
#!python
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.scatter import ScatterPlane
class Viewport(ScatterPlane):
def __init__(self, **kwargs):
kwargs.setdefault('size', (1920, 1080))
kwargs.setdefault('size_hint', (None, None))
kwargs.setdefault('do_scale', False)
kwargs.setdefault('do_translation', False)
kwargs.setdefault('do_rotation', False)
super(Viewport, self).__init__( **kwargs)
Window.bind(system_size=self.on_window_resize)
Clock.schedule_once(self.fit_to_window, -1)
def on_window_resize(self, window, size):
self.fit_to_window()
def fit_to_window(self, *args):
if self.width < self.height: #portrait
if Window.width < Window.height: #so is window
self.scale = Window.width/float(self.width)
else: #window is landscape..so rotate vieport
self.scale = Window.height/float(self.width)
self.rotation = -90
else: #landscape
if Window.width > Window.height: #so is window
self.scale = Window.width/float(self.width)
else: #window is portrait..so rotate vieport
self.scale = Window.height/float(self.width)
self.rotation = -90
self.center = Window.center
for c in self.children:
c.size = self.size
def add_widget(self, w, *args, **kwargs):
super(Viewport, self).add_widget(w, *args, **kwargs)
w.size = self.size
##Comments Add your comments here...