I have a WxPython app that, among other things, has a integrated file-browser.
I want to be able to create a system-default file context menu (e.g. what you get if you right-click on a file in windows explorer) when a user right clicks on one of the items within my application.
Note: I already know how to create my own context menu (e.g. wx.EVT_LIST_ITEM_RIGHT_CLICK), I want the Windows context menu.
To clarify, I do not want, or need to modify the existing system context menu, I want to be able to display it for a specific file within my application.
Basically, I know what was right clicked on, and where the mouse pointer is (if it's needed). I want to create the system context menu there, just like it works in windows explorer.
If you have python win32 installed, then look under the directory <PYTHON>/lib/site-packages/win32comext/shell/demos/servers. This contains a file context_menu.py which has sample code for creating a shell extension.
Update: I think you want the folder_view.py sample.
Related
But I would like for the user, when using a "Save As" function, to also be able to create a new folder in which to put the file.
Is there any way to do this? I've looked through the call reference and the demo programs and don't see anything. FileSaveAs works beautifully for existing folders, but there doesn't seem to be any parameter to get it to make new folders.
Using the sg.SaveAs() chooser button in PySimpleGUI opens a "Save As" dialog box. It has specific options provided for the user to create folders that are not normally shown when browsing for a file to open.
If you wish to create them for the user, you can use os.mkdir prior to showing the dialog.
Ctrl+Escape is a global Windows shortcut for opening main system menu. But I would like my Qt application to use this shortcut without triggering Windows main menu. I know it is probably a bad idea to override system shortcuts in general, but I would like to use this shortcut is a very limited use case.
This usecase is as follows. I have a popup window containing several rows or items. This window is opened by Ctrl+Tab and while the user holds Ctrl and keep pressing Tab, the current rows are cycled through. When the user releases Ctrl, the current row is used for some operation... But sometimes it happens that user presses Ctrl+Tab and then realizes he does not want to continue. He usually presses Escape while still holding Ctrl. And then it triggers Windows system menu and normal user gets confused, choleric user get angry... which is a bad thing. In other words I would like to be able to close the popup window when user presses Ctrl+Escape. How to do that? It is even possible?
If I write the code using this shortcut like any other short, it does not work and it always triggers Windows main menu.
As I understand it, Qt will typically not receive the key event if the underlying window system has intercepted it. For example even QtCreator cannot override system-wide shortcuts.
This question is almost a duplicate of: C++/Qt Global Hotkeys
While that question is asking specifically to capture shortcuts in a hidden/background application, I think the basic concept is the same -- capture shortcuts before the window system processes them.
From that answer, UGlobalHotkey seems pretty good, and the How to use System-Wide Hotkeys in your Qt application blog post could be useful for your limited-use case (but read the comments on that blog post about fixing the example).
Also found:
https://github.com/mitei/qglobalshortcut
https://github.com/Skycoder42/QHotkey (looks like a more detailed version of above)
I am trying to automate a self made GUI in python with pywinauto.
I am starting the application with app = Application().start(...) and get the window with dlg = app.top_window_().
In the next step I want to double-click an item from a list. But I do not know how.
I tried to use the Inspect.exe. By clicking on "navigate to children" I get the list which has no name. Clicking again on "navigate to children" shows the name of the item I want to click.
So, how can I refer to this item?
I thought about something like dlg.itemname.double_click(button='left')? I can only find examples in which they are pressing menu entries.
From what you're describing I can assume you use Application(backend="uia") (or must use) because Inspect.exe uses UI Automation technology which is supported by UIA backend in pywinauto.
And yes, you're almost right about double click. This should look so:
dlg.itemname.double_click_input(button='left')
# or
dlg.itemname.click_input(button='left', double=True)
How would I know? Detecting items as separate controls are typical for UIA backend.
For default Win32 backend (what you can see in Spy++ tool) a list view or a list box always have virtual items that are accessible by wrapper methods only, not as separate controls.
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 want to add a sub-menu to the right-click menu of Windows. Whenever a user right-clicks on a file or a folder, my application name with the sub-menu must appear there.
How to handle this?
You want to edit the Windows Explorer context menu. You can do this in a couple of different ways:
There is a utility at http://www.ghacks.net/2010/08/15/add-custom-items-to-windows-explorer-context-menu/ which provides a bit of hand-holding. It looks like it will also let you add sub-menus directly.
Manually add the appropriate entries in the registry; see http://support.microsoft.com/kb/321379/en-us May be useful for testing, but generally nasty.
Create a .reg file to add the entries automatically. A bit less error-prone, but still hazardous.