Python: Opening process on a certain screen - python

I wrote a script for myself so when I login to the computer 4 IE windows auto start. I tried to use the webbrowser module but it would load the 4 links into 1 IE window with tabs. I could not get webbrowser to open 4 different windows so I used subprocess.Popen.
I have 4 monitors and I want each instance of IE to automatically start on the appropriate screen. Right now I can only get the 4 windows to load behind eachother on the main screen. How can I accomplish this? I have googled and googled and I cannot find anything about opening the process with certain dimensions or on a certain screen... Here is my script:
import subprocess
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" hxxps://myserver.com/Orion/SummaryView.aspx?viewid=1')
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" hxxp://myserver2.com:8080/WOListView.do')
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" hxxp://myserver3.com:8888/stats/cgi?sid=301960859109&area=stats&action=noc&id=22689236889&page=22&sel=tab_listview_sel_22689236889')
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe" hxxps://mymail.com/owa/')

I doubt you can do this with Python standard cross-platform functions alone. Using Windows API you can specify application window starting position and size with dwX, dwY, dwXSize, dwYSize members of the STARTUPINFO structure passed to the CreateProcess function. There are probably examples out there of using CreateProcess with Python ctypes FFI facility. Multi-monitor setup essentially provides one big virtual desktop with continuous coordinate system, so by setting these parameters you can make each window to appear on a separate monitor. Again, you need Windows API to determine coordinates of each monitor inside this big virtual screen space, namely EnumDisplayMonitors and GetMonitorInfo functions. Or, since you are probably never going to use it on any other machine, you can determine screen offsets experimentally and hardcode them.

Related

Python in OS X: Detect multiple monitors and move application window to specific monitor

Question: Is there a way to have Python detect when running the code in OS X, if there is more than one monitor active? Is it then, possible to move a specific OS X application window to one of those monitors by choosing?
FYI: I have previously been able to utilize Carbon to activate a specific application window as seen in the code below. I'm not aware if it has the capabilities sought above.
from Carbon import AppleEvents
from Carbon import AE
window_target = AE.AECreateDesc(AppleEvents.typeApplicationBundleID, "org.mozilla.FireFox")
window_activate = AE.AECreateAppleEvent('misc', 'actv', window_target, AppleEvents.kAutoGenerateReturnID, AppleEvents.kAnyTransactionID)
window_activate.AESend(AppleEvents.kAEWaitReply, AppleEvents.kAENormalPriority, AppleEvents.kAEDefaultTimeout)
To detect monitors, you can use NSScreen.screens(). You can then probably just position your NSWindow within the destination NSScreen's visibleFrame.
At least that would work with your own application windows -- I'm not sure about how to move a different application's window(s) or if it's even possible via the Cocoa API.
For that particular use case, one possible approach is to use AppleScript instead (e.g., Moving finder window from one display to another or Positioning a window with AppleScript using dual monitors).

Bring terminal to the front in Python

Is there a way to bring the Linux terminal to the front of your screen from a python script? Possibly using some kind of os. command
I.e - Your python script opens up a GUI that fills the screen, but if a certain event happens that you want to see printed in the terminal to be viewed, but don't want to / can't show this information on the GUI (so please don't suggest that)
And if possible, hide it back behind your other windows again, if needed.
(Python 2, by the way)
Any suggestions greatly appreciated.
Not in any generally supported way.
Some terminal applications may support the following control sequences. However, these sequences are not standardized, and most terminals do not implement them.
\e[5t - move window to front
\e[6t - move window to back
\e[2t - minimize ("iconify") window
\e[1t - un-minimize window
— from http://rtfm.etla.org/xterm/ctlseq.html
That "bring the Linux terminal to the front of your screen" is likely talking about terminal emulators running in an X Window environment. Ultimately this is accomplished by making a request to the window manager. There is more than one way to do this.
xterm (and some other terminal emulators) implement the Sun control sequences for window manipulation (from the 1980s) which were reimplemented in dtterm during the early 1990s. xterm has done this since 1996 (patch #18).
Python: Xlib — How can I raise(bring to top) windows? mentions wmctl, a command-line tool which allows you to make various requests to the window manager.
xdotool is another command-line tool which performs similar requests.
finally, Can a WM raise or lower windows? points out that you can write your own application (and because python can use shared libraries written in C, you could write a script using the X library).

Duplicate device input events on unix (/dev/input/event)

I'm using linux/ubuntu, and I would like to play a little bit with my touchpad. I'm trying to use python-evdev to read events from /dev/input/events, for now just printing them:
import evdev
dev = evdev.InputDevice('/dev/input/event6')
import time
while True:
try:
for event in dev.read():
print event
except:
print " ~ "
time.sleep(.5)
If I do run that script in with root privilege in a virtual console (outside X, pressing ctrl+alt+F1), the script does print events when I touch the touchpad. Yet, if X is on screen and I run this in a gnome-terminal console, nothing is printed; I somehow guess this is normal, the inputs are intercepted by X. Yet I would like to get them anyway. Is there a way to duplicate whatever comes from /dev/input/event6 so thqt both X and my script can read all events ?
sorry, a bit late on the answer here.
Up until version 1.8, the xorg synaptics driver used the EVIOCGRAB ioctl to prevent events to be delivered to other clients. That's disabled now by default, you can still use the GrabEventDevice option to disable it on your machine for older versions (see man synaptics).
In short, nothing wrong with your script, it's the synaptics driver that's the problem here. You'll find that your script will work on other devices just fine (though the xorg wacom driver did also grab the device until recently).
upstream commit in synaptics:
http://cgit.freedesktop.org/xorg/driver/xf86-input-synaptics/commit/?id=f1948e08ee9894864254a18098e4f4fceb6e322f
So, your idea is, X got the data from your touchpad, so that your python code is blocked from receiving touchpad signal, right? Or, may I repeat your words as: at least for some specific kind of device, an application can't get /dev/input/event*, when another is reading from that device?
Theoritically, since linux make all devices as a file, you are accessing a file as read-only, while X is also read-only accessing the file.
I just did another experiment as: I have a infrared reciver on my archlinux, and I connected to the system in two ssh consoles. I use two ways to access IR, that is, two applications to read the file of /dev/input/event0 (event0 is the SF on my arch):
1, a piece of python code, with evdev;
2, a shell command as: sudo cat /dev/input/event0 | hexdump
You can look on the 2nd as working as your X. If you were reasoning correctly, they both should not receive data from the IR (event0) on the same time, when I sending signal from a IR remote controller, right? But, I really got date on the two ssh consoles(I wish I could post image, but I am new with too low reputation to do so).
So, I think it should not be the reason. I guess it might be because of your touchpad itself. You know, some devices can only work on a single application. e.g., keyboard can only enter characters on the active application, and some input method just make itself as active over other applications, and redirect after it processed. Also, say, if you had a VM running on your system, and you use only one mouse, what would happen if you are moving pointer on the host desktop? Will the pointer in VM move? Or vice versa?
So I need more info about your touchpad. If your TP works only with a single active applicatio, I am afraid you need somethink like a hook to get touchpad signal ahead of X, and redirec it to X and your python code, which might be beyond evdev.
You could create a kernel input handler based on evdev so that the device input is distributed both to the normal /dev/input/eventN and, let's say, /dev/input/copied_eventN
X would read from /dev/input/eventN but you would still be able to read from /dev/input/copied_eventN
Actually you could very easily create a kernel module by copy-pasting the code in drivers/input/evdev.c

Python Curses: Controlling Two Terminals with One Script (Linux)

I would like to make a single Python script to control curses in two seperate terminal windows. Not curses windows within a single terminal, but two different instances of, say, urxvt in my X window manager.
Something like this:
class myprogam():
controlterm1()
controlterm2()
def controlterm1():
Create a new (could be current) urxvt terminal window.
In the urxvt window setup curses with curses.initscr(), etc.
racergame()
def controlterm2():
Create another urxvt terminal window.
Setup curses.initscr, borders, size, etc. in window, leaving the old one alone.
typewriter()
def racecargame():
Racing game in curses
def typwritter()
Boring program for writing
myprogram()
I see that pseudo-terminal windows are given a name when I use the command "tty", and this gives me a reference to /dev/pts/somenumber, where the first terminal emulator is assigned a zero, then 1, 2, etc for new terminals. Can I use this identifier as a basis to do this?
The script does NOT have to actually load a new instance of urxvt, as I am happy if it can just control one that is already open.
In principle there is no problem with opening multiple devices and doing I/O to them from one script. HOWEVER, most curses software that I've seen assumes it does I/O to the one terminal associated with the program. For example, initscr takes no parameters. It looks at your environment variables to determine your terminal characteristics.
Given that, it might be easier to split your program into two, one running on each terminal, which communicate via message-passing.
The ncurses C API has the newterm function that can be used to initialize the screen. According to the newterm man page:
A program that outputs to more than one terminal should use the newterm routine for each terminal instead of initscr.
However, the python curses module does not implement newterm.

Is there a way to move a window to another monitor using Python?

I need to get a handle to a Window and then move it to my secondary monitor. Is this doable with python 2.6, preferably using the standard libraries.
Use the pywin32 module to access the native Win32 API. The functions you'll need to use are:
EnumWindows to enumerate all of the top-level windows in the system; search for the one you want and save off the window handle
EnumDisplayMonitors to enumerate all of the monitors in the system
GetMonitorInfo to get the virtual display coordinates of a monitor and to determine whether or not each monitor is the primary monitor
MoveWindow to move the window to the desired virtual display coordinates, using the window handle you found earlier

Categories

Resources