Search code examples
pythonkivykivy-languageraspberry-pi4

How to rotate the entire kivy application main window?


I have built a kivy application that is designed for use in a touchscreen device in portrait orientation. However the device itself (custom built) is only set up to run applications in landscape.

I need to rotate the entire application window 90° but when i use

Window.rotation = 90

all of my position hints get messed up as the actual width and height are swapped

When I use

canvas.before:
    PushMatrix
    Rotate:
        angle: 90
        origin: self.center
canvas.after:
    PopMatrix

the aspect ratio seems to be correct, but I end up with on_press inputs being rotated by 90° and not lining up with the buttons displayed (i.e. invisible buttons in the original correct locations, and visible buttons now in a new location due to rotated window.

Is there a module that I have not found that rotates the entire application?


Solution

  • You need to change the config.ini file on raspberry pi. it would be in the .kivy folder. In the file you need to find the graphics section and under graphics section find the rotation and change to to 90, 180 or 270

    [kivy]
    keyboard_repeat_delay = 300
    keyboard_repeat_rate = 30
    log_dir = logs
    log_enable = 1
    log_level = info
    log_name = kivy_%y-%m-%d_%_.txt
    window_icon = 
    keyboard_mode = 
    keyboard_layout = qwerty
    desktop = 1
    exit_on_escape = 1
    pause_on_minimize = 0
    kivy_clock = default
    default_font = ['Roboto', 'data/fonts/Roboto-Regular.ttf', 'data/fonts/Roboto-Italic.ttf', 'data/fonts/Roboto-Bold.ttf', 'data/fonts/Roboto-BoldItalic.ttf']
    log_maxfiles = 100
    window_shape = data/images/defaultshape.png
    config_version = 21
    
    [graphics]
    display = -1
    fullscreen = 0
    height = 600
    left = 0
    maxfps = 60
    multisamples = 2
    position = auto
    **rotation = 0**
    show_cursor = 1
    top = 0
    width = 800
    resizable = 1
    borderless = 0
    window_state = visible
    minimum_width = 0
    minimum_height = 0
    min_state_time = .035
    allow_screensaver = 1
    shaped = 0
    vsync = 
    verify_gl_main_thread = 1
    custom_titlebar = 0
    custom_titlebar_border = 5
    
    [input]
    mouse = mouse
    wm_touch = wm_touch
    wm_pen = wm_pen
    
    [postproc]
    double_tap_distance = 20
    double_tap_time = 250
    ignore = []
    jitter_distance = 0
    jitter_ignore_devices = mouse,mactouch,
    retain_distance = 50
    retain_time = 0
    triple_tap_distance = 20
    triple_tap_time = 375
    
    [widgets]
    scroll_timeout = 250
    scroll_distance = 20
    scroll_friction = 1.
    scroll_stoptime = 300
    scroll_moves = 5
    
    [modules]
    
    [network]
    useragent = curl
    

    but I have run into the problem of the touch not flipping correct and that needs to be changed in the pi.