Skip to main content

For development on Android one of the popular modules is Kivy. I had created the countdown pie timer as a way to compare OOP vs Functional programming styles and I wanted to also make it available on Android. 

 

Some thoughts about the migration

  • In Kivy there's a binding that needs to be done between widgets and the window to have them react to the window's changes. That happens naturally if you put a widget in the .kv file. The binding has to be specified if the widgets are added via the python script. 
  • In Tk the window operations like "Keep above" are part of the base system. That's only recently added in Kivy since Feb 2023. 
    • Here's a commit that shows how Window.always_on_top now works https://github.com/AJRepo/pietimer_kivy/commit/9dae3e3cdb38d757203fec7a83d3d11af0307ad7 

      or with just the relevant parts included...

      
      
      from kivy.utils import platform
      from kivy.config import Config
      ...
      if platform == 'linux':
         Config.set("graphics", "always_on_top", 1)  # The app will start with the window on top
      ...
      def __init__(....
         if platform == 'linux':
             Window.always_on_top = True
      
  • In theory it's possible to do it via system calls using xprop and qdbus and I had started that process until I found the Window.always_on_top addition. 

Here is the beginnings of a bash script to find a particular window's id

 

#!/bin/bash
# Search all windowed applications on Linux and find a program's WindowID

PRINT_NONAP_IDS="False"
PRINT_AP_IDS="False"
PROG_NAME="PieTimer"
FOUND=0
PROG_WINID=""

for WINID in $(xprop -root -notype _NET_CLIENT_LIST | sed -e /.*\#/s/// | sed -e /,/s///g); do
 #echo "WINDID=$WINID"
 TYPE=$(xprop -id "$WINID" _NET_WM_WINDOW_TYPE | awk -F '=' '{print $2}')
 CLASS=$(xprop -id "$WINID" WM_CLASS | awk -F '=' '{print $2}')
 NAME=$(xprop -id "$WINID" _NET_WM_NAME | awk -F '=' '{print $2}')
 if [[ $NAME == " \"$PROG_NAME\"" ]]; then
   PROG_WINID=$WINID
   FOUND=1
 fi
 #echo "TYPE=$TYPE"
 if [[ $TYPE == " _NET_WM_WINDOW_TYPE_NORMAL" ]]; then
   #printf "\n%s|%s|%s\n" "$WINID" "$CLASS" "$NAME"
   if [[ $PRINT_AP_IDS == "True" ]]; then
     echo "Application: '$WINID' : '$CLASS' : '$NAME'"
   fi
 elif [[ $PRINT_NONAP_IDS == "True" ]]; then
   echo "NonApplication: $WINID : $CLASS : $NAME"
 fi
done

if [[ $FOUND == "1" ]]; then
 echo "$PROG_WINID"
else
 exit 1
fi
 

Which you can call with 

echo $((16#$(./xprop_list.sh|sed -e /0x/s///)))
 

to get the Decimal value to pass into programs that require it in the non-hex version that xprop returns. 

Tags