নিয়ন্ত্রণ স্ক্রিপ্ট
#!/usr/bin/env python3
import subprocess
import os
import sys
import time
# paths
imagepath = os.path.join(os.environ["HOME"], ".showcase")
wfile = os.path.join(imagepath, "currentwindow")
vpfile = os.path.join(imagepath, "last_vp")
# setup path
if not os.path.exists(imagepath):
os.mkdir(imagepath)
def get(command):
try:
return subprocess.check_output(command).decode("utf-8").strip()
except subprocess.CalledProcessError:
pass
def get_vp():
open(vpfile, "wt").write(get(["wmctrl", "-d"]).split()[5])
def run(command):
subprocess.Popen(command)
def convert_tohex(widxd):
return widxd[:2]+((10-len(widxd))*"0")+widxd[2:]
def check_windowtype(wid):
check = get(["xprop", "-id", wid])
return not any([s in check for s in [
"_NET_WM_WINDOW_TYPE_DOCK",
"_NET_WM_WINDOW_TYPE_DESKTOP"]])
def edit_winprops(wid, convert=True):
run(["xdotool", "windowminimize", wid])
if convert:
widxd = convert_tohex(hex(int(wid)))
else:
widxd = wid
run(["wmctrl", "-i", "-r", widxd, "-b", "add,sticky"])
get_vp()
open(os.path.join(imagepath, "currentwindow"), "wt").write(widxd)
def initiate_min():
# if not, minmize window, write the file
wid = get(["xdotool", "getactivewindow"])
if check_windowtype(wid):
edit_winprops(wid)
else:
pidinfo = [l.split() for l in wlist.splitlines()]
match = [l for l in pidinfo if all([
get(["ps", "-p", l[2], "-o", "comm="]) == "VirtualBox",
not "Manager" in l])]
if match:
edit_winprops(match[0][0], convert=False)
# windowlist
wlist = get(["wmctrl", "-lp"])
if "Window preview" in wlist:
# kill the miniwindow
pid = get(["pgrep", "-f", "showmin"])
run(["kill", pid])
window = open(wfile).read().strip()
viewport = open(vpfile).read().strip()
run(["wmctrl", "-o", viewport])
time.sleep(0.3)
run(["wmctrl", "-i", "-r", window, "-b", "remove,sticky"])
run(["wmctrl", "-ia", window])
os.remove(wfile)
else:
# check if windowfile exists
wfileexists = os.path.exists(wfile)
if wfileexists:
# if file exists, try to run miniwindow
window = open(wfile).read().strip()
if window in wlist:
# if the window exists, run!
run(["showmin", window])
else:
# if not, minmize window, write the file
initiate_min()
else:
# if not, minmize window, write the file
initiate_min()
উইন্ডোটি প্রতিনিধিত্ব করে
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GObject
from PIL import Image
import os
import subprocess
import time
from threading import Thread
import sys
wid = sys.argv[1]
xsize = 300
imagepath = os.path.join(os.environ["HOME"], ".showcase")
if not os.path.exists(imagepath):
os.mkdir(imagepath)
img_in = os.path.join(imagepath, "image.png")
resized = os.path.join(imagepath, "resized.png")
def get_img():
subprocess.Popen([
"import", "-window", wid, "-resize", str(xsize), resized
])
get_img()
class Splash(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Window preview")
maingrid = Gtk.Grid()
self.add(maingrid)
self.image = Gtk.Image()
# set the path to the image below
self.resized = resized
self.image.set_from_file(self.resized)
maingrid.attach(self.image, 0, 0, 1, 1)
maingrid.set_border_width(3)
self.update = Thread(target=self.update_preview)
self.update.setDaemon(True)
self.update.start()
def update_preview(self):
while True:
get_img()
time.sleep(3)
GObject.idle_add(
self.image.set_from_file, self.resized,
priority=GObject.PRIORITY_DEFAULT
)
def miniwindow():
window = Splash()
window.set_decorated(False)
window.set_resizable(False)
window.set_keep_above(True)
window.set_wmclass("ShowCase", "showcase")
window.connect("destroy", Gtk.main_quit)
GObject.threads_init()
window.show_all()
window.move(70, 50)
Gtk.main()
miniwindow()