vdmAPI/VDMAPI/Display/kivyDisplay.py

83 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python
from ..VDM import VDM
import os
import i3
# get screen resolution
import tkinter
root = tkinter.Tk()
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
from kivy.config import Config
Config.set('graphics','fullscreen', 0)
Config.set('graphics','resizable',0)
Config.set('graphics','position', 'custom')
Config.set('graphics','width', 600)
Config.set('graphics','height', 150)
# align bottom and 50 px from right
Config.set('graphics','left', width-Config.getint('graphics', 'width')-45)
Config.set('graphics','top', height-Config.getint('graphics', 'height')-17)
from kivy.core.window import Window
import kivy
from kivy.app import App
from kivy.properties import *
from kivy.uix.gridlayout import GridLayout
class guiApp(GridLayout):
""" display all vdm into kivy interface """
# https://kivy.org/docs/api-kivy.properties.html#kivy.properties.ListProperty
# NumericProperty, StringProperty, ListProperty, ObjectProperty,
# BooleanProperty, BoundedNumericProperty, OptionProperty, ReferenceListProperty, AliasProperty, DictProperty
indice = NumericProperty(0)
vdm = ListProperty([])
def __init__(self, **kwargs):
super(guiApp, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
self._keyboard.bind(on_key_down = self._on_keyboard_down)
self.v = VDM()
self.vdm = self.v.get()
self.render()
i3.msg("command", "floating enable")
def _nextAction(self):
if self.indice == len(self.vdm)-1:
self.vdm = self.v.get()
self.indice = 0
else:
self.indice += 1
self.render()
def _prevAction(self):
if self.indice > 0:
self.indice -= 1
self.render()
def _keyboard_closed(self):
self._keyboard.unbind(on_key_down = self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, *args):
if args[1][1] == 'right':
self._nextAction()
elif args[1][1] == 'left':
self._prevAction()
def render(self):
print(self.indice)
self.ids["Message"].text = self.vdm[self.indice]
class kivyApp(App):
def build(self):
return guiApp(cols=3, pos=(0,0))