I am writing python app and need to run another program in specific (not the current one) desktop in openbox (I have 4 desktops). There is freedesktop _NET_CURRENT_DESKTOP param, but I don't know how to change it under python and gi.repository (Wnck, Gdk?). Or maybe use Xlib? I can't find what is best method to do it...
With PyGTK, you would create a gio.AppInfo instance representing the application you want to launch, then provide a gtk.gdk.AppLaunchContext to its launch() method.
When you create the launch context, you would call its set_desktop() method to specify the index of the desktop the launched application will run on.
Related
Does anyone know the trick to pywinauto's find_window function? I am building an application with kivy, and trying to use pywinauto to bring an .exe to the foreground, using the following code:
SetForegroundWindow(find_window(title='program.exe'))
I simply want to identify a currently open .exe, and bring it to the foreground. I have looked here https://pywinauto.github.io/docs/code/pywinauto.findwindows.html and it seems "title=" is what I want.
Does anyone know how to point to the .exe with pywinauto?
I think title is for window title (i.e. "python - Cannot find..." in case of this tab), are you sure it not more like "process='program.exe'" ?
if it needs to be and int then its pid (process id) and you can use this to get process id by title:
import win32gui,win32process
def get_window_pid(title):
hwnd = win32gui.FindWindow(None, title)
threadid,pid = win32process.GetWindowThreadProcessId(hwnd)
return pid
Eventually have at this answer as it contains really nice class for getting windows Python Window Activation, i dont want to copy paste, but use it and then you can do:
w = WindowMgr()
w.find_window_wildcard(".*Hello.*")
w.set_foreground()
find_window is low level function I wouldn’t recommend to use.
The right thing is Application object connected to the target process. It can be used so:
from pywinauto import Application
app = Application(backend=“uia”).connect(path=“program.exe”)
app.WindowTitle.set_focus()
If you have several app instances, there is a Desktop object to walk all the windows in the system:
from pywinauto import Desktop
Desktop(backend=“win32”).window(title=“Window Title”, found_index=0).set_focus()
You referred to the old docs for version 0.5.4, the latest one is 0.6.4 with two backends available and many bug fixes. The Getting Started Guide link on the main page is a good source to learn the main concept.
I would like to create a GUI that pops up asking where to download a file using python. I would like it to be similar to the interface that Google Chrome uses when downloading a file as that looks pretty standard. Is there a default module or add on that I can use to create thus GUI? or will I have to create myself? any help would be appreciated.
If You mean the dialog window, in which You chose where to put file, it's tkinter.filedialog (https://docs.python.org/3/library/tkinter.html), which would give the most native look and feel.
But if You mean the dialog, in which You chose whether to save file in default location or specify another one, there's no such widget, but You may build it on Your own. For that case You probably should dig into Chromium sources, to determine how exactly it acts(https://chromium.googlesource.com/)
There are a number of GUI toolkits you could use, including:
Kivy (modern touch-enabled)
Tkinter (bundled with Python)
These have file chooser widgets, which you could use that would provide standard-looking interfaces to your file system.
How do you want to run this program?
I am currently using the Python Webkit DOM Bindings to interact with a website programmatically and that's working for me.
The only problem is that it insists on opening a GTK window to display the page. Has somebody figured out a way to prevent it from opening a window? I.e. to use it in a headless way?
I'm initializing the view like this:
wv = pywebkitgtk.WebView(1024, 768, url=url)
which implicitly opens the GTK window and then I have an onload event-handler to manipulate the DOM.
I first thought of subclassing WebView, but that's not possible because it is a compiled class.
Any other ideas?
I'm the developer responsible for pythonwebkit, and I have a great deal of expertise covering these areas across several platforms. Realistically, you really, really want a completely "headless" WebKit port. In pythonwebkit that actually shouldn't be too hard to do, as there are only three "entry point" functions (one for window, one for document, and one for XMLHTTPRequest).
Really, somebody should do a proper "completely headless" port of WebKit. There already is an example program which is pretty close in WebKit's source tree, maybe that will get you started.
I've been using PyQT. PyQTWebView runs on Webkit and works great. Check out Ghost.py to get started, or use PyQT's API directly. Runs fully headless, and supports a decently recent build of Webkit.
You could try using Xvfb. I like using the command line and setting my display manually, but if you don't like that you could use this: http://cgoldberg.github.io/xvfbwrapper/
Can you get a handle to the GTK window and then call window.hide()? Otherwise, you might just have to use the full Webkit library.
Create a window and add the webview there, and never show the window..
I have webviews running without showing them, and can call a show_all if I need to show them.
web_view = pywebkitgtk.WebView()
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
sw = gtk.ScrolledWindow(hadjustment=None, vadjustment=None)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
sw.add(web_view)
window.add(sw)
#window.show_all()
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.
I am planning to do the folliwing:
Create a PyGtk GUI (hardcoded, no Glade) with some widgets, and at the bottom of the screen put some sort of VTE (Virtual Terminal Emulator) from where I could manipulate the widgets, for example changing their attributes and calling their methods from the commandline.
The result would be similar to using AutoCAD's commands, only that I would be acting upon the GUI objects.
I have already found very few things about gtk.VteTerminal widget, but not only could not find a working example or make one myself, it also seem to be a system terminal, not a "current session" python terminal where I could run python commands and access GUI objects.
Any suggestion?
Thanks for reading
What you want exists already: GtkParasite. It's meant for debugging, but I'm sure if you wanted it to actually be a part of your application, you could adapt it.
I'm late to the party, but I had a similar problem.
Look here
Virtual Terminal Question
It's an option if you decide to do something different than what you might have already done.