Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Created January 12, 2011 01:25
Show Gist options
  • Save radiosilence/775512 to your computer and use it in GitHub Desktop.
Save radiosilence/775512 to your computer and use it in GitHub Desktop.
from flask import Flask, request, redirect, url_for, \
abort, render_template, flash
import subprocess, time
import win32con, win32gui, win32process
import os
from SendKeys import SendKeys
DEBUG = True
SECRET_KEY = 'blaahhasdasdasd'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route("/")
def home():
return render_template('home.html')
@app.route("/start/notepad")
def start_notepad():
os.startfile('notepad.exe')
return start_message('notepad.exe')
@app.route("/start/xbmc")
def start_xbmc():
xbmc = subprocess.Popen ([r'C:\\Program Files (x86)\\XBMC\\XBMC.exe'])
time.sleep(3.0)
for hwnd in get_hwnds_for_pid(xbmc.pid):
print hwnd, "=>", win32gui.GetWindowText(hwnd)
win32gui.ShowWindow(hwnd, win32con.SW_SHOW)
win32gui.SendMessage(hwnd, win32con.WM_ACTIVATE)
# win32gui.SetForegroundWindow(hwnd)
return start_message('XBMC')
def start_message(command):
flash("Starting %s" % command)
return redirect(url_for('home'))
def get_hwnds_for_pid(pid):
def callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
_, found_pid = win32process.GetWindowThreadProcessId(hwnd)
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows (callback, hwnds)
return hwnds
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment