forked from e16/e16
1
0
Fork 0

Add python versions of perl sample-scripts

This commit is contained in:
Kim Woelders 2022-02-13 11:21:16 +01:00
parent 3cb75416a9
commit 9904bdbe66
3 changed files with 218 additions and 0 deletions

95
sample-scripts/bouncingball.py Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/python3
# This is a little script that will create a window that says
# "Follow the Bouncing Ball" and then drops it to the bottom of the
# screen and slowly bounces it around.
# Then when it's done bouncing it gets rid of it.
import os
import re
import subprocess
import time
def EeshExec(cmd):
subprocess.run(["eesh", cmd])
def EeshCall(cmd):
sp = subprocess.run(["eesh", "-e", cmd], capture_output=True, encoding='utf8')
out = sp.stdout.strip()
# print(f'out = "{out}"')
return out
re1 = re.compile(r'.+\s+(\d+)x(\d+)') # Screen 0 size 1920x1080
out = EeshCall('screen size')
match = re1.match(out)
if match:
width = int(match.group(1))
height = int(match.group(2))
EeshExec('dialog_ok "Follow the Bouncing Ball"')
ball = 'Message'
re1 = re.compile(r'.+:\s+(\d+)\s+(\d+)') # window location: 868 498
out = EeshCall(f'win_op {ball} move ?')
match = re1.match(out)
if match:
ballx = int(match.group(1))
bally = int(match.group(2))
re1 = re.compile(r'.+:\s+(\d+)\s+(\d+)') # window location: 868 498
out = EeshCall(f'win_op {ball} size ??')
match = re1.match(out)
if match:
ballw = int(match.group(1))
ballh = int(match.group(2))
#print(f'x,y={ballx},{bally} wxh={ballw} x {ballh}')
# now for the fun part. make that baby bounce up and down.
# we're going to open a big pipe for this one and just shove data
# to it.
fallspeeds = [30, 25, 20, 15, 10, 5, 4, 3, 2]
n = len(fallspeeds)
n1 = n - 1
p = os.popen('eesh', 'w')
for i in range(n):
originalbally = bally
fallspeed = fallspeeds[i]
# print(f'loop {i} x,y {ballx},{bally} fall {fallspeed}')
while bally < height - ballh:
if bally + fallspeed + ballh < height:
bally += fallspeed
else:
bally = height - ballh
# print(f'win_op {ball} move {ballx} {bally}')
p.write(f'win_op {ball} move {ballx} {bally}\n')
p.flush()
time.sleep(.020)
# print('reverse')
if i < n - 1:
fallspeed = fallspeeds[i + 1]
else:
fallspeed = 1
while bally > originalbally + int(originalbally * (1. / n1)):
if bally - fallspeed > originalbally + int(originalbally * (1. / n1)):
bally -= fallspeed
else:
bally = originalbally + int(originalbally * (1. / n1))
# print(f'win_op {ball} move {ballx} {bally}')
p.write(f'win_op {ball} move {ballx} {bally}\n')
p.flush()
time.sleep(.020)
p.write(f'win_op {ball} close\n')
p.close()
# that's all folks.

30
sample-scripts/shade-pagers.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/python3
# This is a hack of mandrake's "testroller.pl" that shades/unshades all your
# pager windows
import os, sys
import subprocess
argv = sys.argv[1:]
shade = ''
if len(argv) > 0:
if argv[0] in ['0', 'off']:
shade = 'off'
elif argv[0] in ['1', 'on']:
shade = 'on'
cmd = f'win_op Pager* shade {shade}'
#print(cmd)
if True:
p = os.popen('eesh', 'w')
p.write(f'{cmd}\n')
p.close()
if False:
subprocess.run(['eesh', '-c', f'{cmd}\n'])
# Alternatively, simply do
#$ eesh wop Pager* shade [on|off]

93
sample-scripts/testroller.py Executable file
View File

@ -0,0 +1,93 @@
#!/usr/bin/python3
# This app will take the parameters "on" and "off", and will basically
# shade or unshade all the windows on the current desktop and area.
import os, sys, re
import subprocess
def EeshExec(cmd):
subprocess.run(["eesh", cmd])
def EeshCall(cmd):
sp = subprocess.run(["eesh", "-e", cmd], capture_output=True, encoding='utf8')
out = sp.stdout.strip()
# print(f'out = "{out}"')
return out
argv = sys.argv[1:]
shade = ''
if len(argv) > 0:
if argv[0] in ['0', 'off']:
shade = 'off'
elif argv[0] in ['1', 'on']:
shade = 'on'
# Get the current desk we're on
out = EeshCall('desk')
re1 = re.compile(r'.+:\s+(\d+)/(\d+)') # Current Desktop: 0/3
match = re1.match(out)
if match:
desk_cur = int(match.group(1))
desk_cnt = int(match.group(2))
#print(f'Desk: {desk_cur} of {desk_cnt}')
# Get the current area we're on
out = EeshCall('area')
re1 = re.compile(r'.+:\s+(\d+)\s+(\d+)') # Current Area: 2 0
match = re1.match(out)
if match:
area_x = int(match.group(1))
area_y = int(match.group(2))
area_cur = f'{area_x} {area_y}'
#print(f'Area: {area_x}, {area_y}: "{area_cur}"')
# Get the old shadespeed so that we can set it back later
# because we want this to happen fairly quickly, we'll set
# the speed to something really high
out = EeshCall('show misc.shading.speed') # misc.shading.speed = 8000
shadespeed = int(out.split('=')[1])
#print(f'shadespeed = {shadespeed}')
# Get the window list
winlist = EeshCall('wl a')
p = os.popen('eesh', 'w')
p.write(f'set misc.shading.speed 10000000\n')
p.flush()
# Now walk through each of the windows and shade/unshade them
for win in winlist.split('\n'):
tok = win.split(':')
tok = [t.strip() for t in tok]
if len(tok) < 6:
continue
window = tok[0]
desk = int(tok[3])
area = tok[4]
name = tok[5]
# print([window, desk, area, name, ':', desk_cur, area_cur])
# Skip pagers, iconboxes, systrays, and epplets
if name.startswith('Pager-') or name.startswith('E-') or \
name.startswith('Iconbox') or name.startswith('Systray'):
continue
if desk != desk_cur:
continue
if area != area_cur:
continue
print(f'win_op {window} shade {shade}')
p.write(f'win_op {window} shade {shade}\n')
# Set the shade speed back to what it was originally
p.write(f'set misc.shading.speed {shadespeed}\n')
#p.flush()
p.close()
# that's it!