I have a pygame window that I want to know when a file has been dragged and dropped onto it. I only need to be able to fetch the name of the file. How can this be accomplished?
Here's a forum thread that might be what you're looking for.
And another forum.
And a link to the msdn page. You'll probably want the pythoncom library.
one option for a similar effect is is to use pygame's scrap module so you can copy-paste into the window, your program would just need to look for ctr-V events.
On this XFCE desktop I'm using
If I hit ctrl-C with a file selected, the file name shows up when I type
pygame.scrap.init()
types= pygame.scrap.get_types()
print dict(
[type,pygame.scrap.get(type)]
for type intypes
)
Related
I am developing the GUI for my application using wxpython and have most of the features down, except in the main frame/window I want to have a box for choosing a file (in this case, the input will have to be an excel file). Something similar to the standard filebrowser that is accessed whenever you choose "open" from a menu.
Below is an image to show exactly what I want...
You probably want a wx.FileDialog. It provides access to the default file dialog of the OS your app is running in. You can see an example of how it's used in the wxPython demo package. This tutorial also has some screenshots and sample code:
http://www.blog.pythonlibrary.org/2010/06/26/the-dialogs-of-wxpython-part-1-of-2/
The screenshot you show appears to be an interface to actually open the dialog. You can easily create that using sizers and basic widgets. Then just bind the open button to a handler that will show the dialog.
You might also want to take a look at the FileBrowseButton from wx.lib.filebrowsebutton (also in the demo).
There are a few other related widgets which you might be interested in too: wx.DirDialog, MultiDirDialog or wx.GenericDirDialog.
Assuming you know the basics of wxPython you can use wx.GenericDirCtrl and wx.ListCtrl to make nice browser
I'm trying to write a program than will detect when my mouse pointer will change icon and automatically send out a mouse click. Is there a better way to do this than to take screenshots and parse the image for the mouse icon?
EDIT:
I'm running my program on windows 7.
I'm trying to learn some image processing and make a simple flash game i made automated.
Rules: when the curses changes shape, click to get a point.
Also what imaging modules for python will allow you to take a specific size screenshot not just the whole screen? This question has moved to a new thread: "Taking Screen shots of specific size"
The way to do this in Windows is to install either a global message hook with SetWindowsHookEx or SetWinEventHook. (Alternatively, you could build a DLL that embeds Python and hooks into the browser or its Flash wrapper app and do it less intrusively from within the app, but that's much more work.)
The message you want is WM_SETCURSOR. Note that this is the message sent by Windows to the app to ask whether it wants to change the cursor, not a message sent when the cursor changes. So, IIRC, you will want to put a WH_CALLWNDPROC and a WH_CALLWNDPROCRET and check GetCursorInfo before and after to see if the app has done so.
So, how do you do this from Python? Honestly, if you don't already know both win32api and friends from the pywin32 package, and how to write Windows message procs in some language, you probably don't want to. If you do want to, I'd start off with the (abandoned) pyHook project from UNC Assist. Even if you can't get it working, it's full of useful source code.
You should also search SO for [python] SetWinEventHook and [python] SetWindowsHookEx, and google around a bit; there are some examples out there (I even wrote one here somewhere…)
You can look at higher-level wrapper frameworks like pywinauto and winGuiAuto, but as far as I know, none of them has much help for capturing events.
I believe there are other tools, maybe AutoIt, that have all the functionality you need, but not in Python module. (AutoIt, for example, has its own VB-like scripting language instead.)
So my App needs to be able to open a single webpage(and it must be from the internet and not saved) in it, and specifically I'd like to use the Tkinter GUI toolkit since it's the one i'm most comfortable with. On top of that though, I'd like to be able to generate events in the window(say a mouse click) but without actually using the mouse. What's a good method to go about this?
EDIT: I suppose to clarify this a bit, I need a way to load a webpage, or maybe even a specific java applet into a tkinter widget or window. Or if not that perhaps another method to do this where I can generate mouse and keyboard events without using either the mouse of the keyboard.
If you want it to be opened inside your GUI use Bryans suggestion, if you just want to open a webpage you can use:
import webbrowser
webbrowser.open("page.html")
Tkinter does not have a widget that can render a web page.
So i found this module named pywebview
pip install pywebview
sample code:-
import webview
webview.create_window('duckduckgo', 'https://www.duckduckgo.com')
webview.start() #this will open the webpage in a new window
You should use pywebview it is very easy only code three lines .
I used it but in my case it didn't work everywhere. Comment and let me know if it works for you.
The best option that works everywhere is PyQt's QtWebview module. You might run into one problem that is to rename the window, so here is the solution
web.setWindowTitle(title)
You can use all the functions as it is but just replace window or self with web like the above code.
I saw here a solution, but i don't want wait until the key is pressed. I want to get the last key pressed.
The related question may help you, as #S.Lott mentioned: Detect in python which keys are pressed
I am writting in, though to give yu advice: don't worry about that.
What kind of program are you trying to produce?
Programas running on a terminal usually don't have an interface in which getting "live" keystrokes is interesting. Not nowadays. For programs running in the terminal, you should worry about a usefull command line User Interfase, using the optparse or other modules.
For interative programs, you should use a GUI library and create a decent UI for your users, instead of reinventing the wheel.Which wouldb eb etter for what you ar trying to do? Theuser click on an icon,a window opens on the screen, witha couple of buttons on it, and half a dozen or so menu options packed under a "File" menu as all the otehr windws on the screen - or - a black terminal opens up, with an 80's looking text interface with some blue-highlighted menu options and so on?. You can use Tkinter for simple windowed applications, as it comes pre-installed with Python + Windows, so that yoru users don't have to worry about installign aditional libraries.
Rephrasing it just to be clear: Any program that requires a user interface should either se a GUI library, or have a WEB interface. It is a waste of your time, and that of your users, to try and create a UI operating over the terminal - we are not in 1989 any more.
If you absolutely need a text interface, you should look at the ncurses library then. Better than trying to reinvent the wheel.
http://code.activestate.com/recipes/134892/
i think it's what you need
ps ooops, i didn't see it's the same solution you rejected...why, btw?
edit:
do you know:
from msvcrt import getch
it works only in windows, however...
(and it is generalised in the above link)
from here: http://www.daniweb.com/forums/thread115282.html
I'm not familiar with PowerBuilder but I have a task to create Automatic UI Test Application for PB. We've decided to do it in Python with pywinauto and iaccesible libraries. The problem is that some UI elements like newly added lists record can not be accesed from it (even inspect32 can't get it).
Any ideas how to reach this elements and make them testable?
I'm experimenting with code for a tool for automating PowerBuilder-based GUIs as well. From what I can see, your best bet would be to use the PowerBuilder Native Interface (PBNI), and call PowerScript code from within your NVO.
If you like, feel free to send me an email (see my profile for my email address), I'd be interested in exchanging ideas about how to do this.
I didn't use PowerBuilder for a while but I guess that the problem that you are trying to solve is similar to the one I am trying to address for people making projects with SCADA systems like Wonderware Intouch.
The problem with such an application is that there is no API to get or set the value of a control. So a pywinauto approach can't work.
I've made a small tool to simulate the user events and to get the results from a screencapture. I am usig PIL and pytesser ORM for the analysis of the screen captures. It is not the easiest way but it works OK.
The tool is open-source and free of charge and can be downloaded from my website (Sorry in french). You just need an account but it's free as well. Just ask.
If you can read french, here is one article about testing Intouch-based applications
Sorry for the self promotion, but I was facing a similar problem with no solution so I've written my own. Anyway, that's free and open-source...
I've seen in AutomatedQa support that they a recipe recommending using msaa and setting some properties on the controls. I do not know if it works.
If you are testing DataWindows (the class is pbdwxxx, e.g. pbdw110) you will have to use a combination of clicking at specific coordinates and sending Tab keys to get to the control you want. Of course you can also send up and down arrow keys to move among rows. The easiest thing to do is to start with a normal control like an SLE and tab into the DataWindow. The problem is that the DataWindow is essentially just an image. There is no control for a given field until you move the focus there by clicking or tabbing. I've also found that the DataWindow's iAccessible interface is a bit strange. If you ask the DataWindow for the object with focus, you don't get the right answer. If you enumerate through all of the children you can find the one that has focus. If you can modify the source I also advise that you set AccessibleName for your DataWindow controls, otherwise you probably won't be able to identify the controls except by position (by DataWindow controls I mean the ones inside the DataWindow, not the DataWindow itself). If it's an MDI application, you may also find it useful to locate the MicroHelp window (class fnhelpxxx, e.g. fnhelp110, find from the main application window) to help determine your current context.
Edited to add:
Sikuli looks very promising for testing PowerBuilder. It works by recognizing objects on the screen from a saved fragment of screenshot. That is, you take a screenshot of the part of the screen you want it to find.