How to create a file browser in wxpython - python

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

Related

How to programmatically retrieve the equivalent of the "name" field in microsoft's inspect.exe?

I want to retrieve information from a tooltip in the system tray programmatically.
The image shows the tooltip.
Now, I found that by using Microsoft's inspect.exe, which is "a Windows-based tool that enables you select any UI element and view the element's accessibility data", that it is in theory possible to retrieve this value programmatically.
Hovering over the the pandora icon in the toolbar shows me the following properties
It shows one property "name" that contains the exact data I need. I'm unsure how to retrieve this value programmatically using the win32api. I have a hwnd to the pandora icon already.
Additionally, a different ui spy tool, UiSpy.exe calls this same property "helpText" (different song name :p)
I tried using getWindowText(pandoraSystrayIconHwnd) but that returns a different text. Does anyone know what this "name" value is, and how I can retrieve it using the win32api? It should be possible because inspect.exe is an external program that can access the data somehow
I'm doing this in Python, as the target application is written in Python already.
These spy apps are probably using Active Accessibility and/or UI Automation.
You can try calling AccessibleObjectFromWindow on the toolbar HWND or AccessibleObjectFromPoint if you care about the mouse position and then call IAccessible::get_accName.
Keep in mind that the classname and window hierarchy of the tray icon toolbar is undocumented.
If you only care about Pandora and not other applications then I would strongly suggest that you look for other alternatives first. Perhaps they have a hidden window with the title etc.
If you don't mind hacks then you could take a look at TraySaver, it is open source and knows the internal format of the data stored for each icon in the tray toolbar. Keep in mind that it is pretty old and might not work on newer versions of Windows. If you go down this path (and I don't recommend it) then you have to remember that you need to support both 32-bit and 64-bit Explorer.
Maybe GUI automation library pywinauto could help you. It uses Win32 API or UI Automation under the hood (by your choice). Core concept is described in the Getting Started Guide.
Method .window_text() returns exactly the same as Name property shows in Inspect.exe.
To interact with tray area icons you can use this example on StackOverflow.

python show tooltip window on click

There is command In the AutoHotKey that shows tooltip with some message on the top of the screen. I want to do it on python.
In more details I need to make an application, that will work in background, always tracking a keyboard. On the specific hotkey it should show on the top of the screen a message without grabbing focus from other application. And it should remove this message after some conditions (e.g. mouse moving). It should work with full screen apps too.
I couldn't find how to do it on python, or what libraries should I use. Need your help.
Global tooltips are created via WINAPI CreateWindowEx with TOOLTIPS_CLASS for window class. There are some examples which you can adapt. See also the Autohotkey implementation.
Shell tray tooltips are created via Shell_NotifyIcon.
A working example: wontoncc/balloontip.py and the Autohotkey implementation.

wxpython balloonframe overlays all windows

I am using BalloonTip and BalloonFrame from wxpython in order to generate pop up notifications. Unfortunately the generated elements are overlapping all windows: Not only the window of my application but also all windows of the other applications.
I would like to suppress this behavior and display the notification only on top of my own application and not on top of all windows.
Is there any possibility to specify the "z-index" like in CSS or something similar?
You should probably just create your own frame then as I don't believe the Balloon widgets support that behavior. When you do create your own frame, you can tell it to center on parent. If you want it to disappear on it's own, you can use a wx.Timer. You could also look at this:
http://wxpython.org/Phoenix/docs/html/adv.NotificationMessage.html

Using Tkinter to open a webpage

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.

Something like Explorer's icon grid view in a Python GUI

I am making a Python gui project that needs to duplicate the look of a Windows gui environment (ie Explorer). I have my own custom icons to draw but they should be selectable by the same methods as usual; click, ctrl-click, drag box etc. Are any of the gui toolkits going to help with this or will I have to implement it all myself. If there aren't any tools to help with this advice would be greatly appreciated.
edit I am not trying to recreate explorer, that would be madness. I simply want to be able to take icons and lay them out in a scrollable window. Any number of them may be selected at once. It would be great if there was something that could select/deselect them in the same (appearing at least) way that Windows does. Then all I would need is a list of all the selected icons.
Python has extensions for accessing the Win32 API, but good luck trying to re-write explorer in that by yourself. Your best bet is to use a toolkit like Qt, but you'll still have to write the vast majority of the application from scratch.
Is there any way you can re-use explorer itself in your project?
Updated for edited question:
GTK+ has an icon grid widget that you could use. See a reference for PyGTK+: gtk.IconView
In wxPython there's a plethora of ready-made list and tree controls (CustomTreeCtrl, TreeListCtrl, and others), a mixture of which you can use to create a simple explorer in minutes. The wxPython demo even has a few relevant examples (see the demo of MVCTree).
I'll assume you're serious and suggest that you check out the many wonderful GUI libraries available for Python.

Categories