Change wxpython program's default title and icon in dialog box - python

I want to change the title of my program from its default "Python" to lets say "MyProgram". Also, if I choose "About" from this menu, the dialog box comes up with a picture of the Python logo. How can I change that image?
Pictures for reference:
http://i.imgur.com/iop5f0q.jpg
http://i.imgur.com/XjagYBA.jpg

I'm pretty sure you have to create an app bundle with py2app to get that changed. Otherwise it just defaults to Python.
See the following answer:
Changing WxPython app Mac menu bar title?
According to that, you will have to also make sure that the plist file is filled out correctly.

Related

wxPython Menu Open Location

I'm going through this tutorial here http://zetcode.com/wxpython/menustoolbars/ under the section Submenus and Separators. I get the menu items and submenu to display, but my menu opens "to the left" like so:
instead of "to the right" like the reference image and all other menu examples I've seen which open like so:
Why is my menu opening the way it is? The window/frame size doesn't seem to matter as far as I can tell. I know the tutorial is Linux based while mine is Windows based, but other Windows based examples also show like the tutorial. Any ideas?
For reference, I'm using VS Code for editing (not that I think that matters), and a standard system install of Python 3.7 and wxPython 4.0.3.

Python GTK: make about dialog without logo

GNOME Developer Center website shows About Dialog without an icon. On Ubuntu 16.04 LTS however, it seems that GTK now requires for icon to be present, as without explicitly declaring icon name, that very same example form the website it shows error icon.
Thus the question: how do I get around this issue ? I want the About dialog for my program only have simple text and no icon/logo.
I know I'm a little late to the party but I just stumbled upon your question because I was too searching for an answer to this. What worked for me was this:
about = Gtk.AboutDialog() # Create your about dialog object
about.set_logo_icon_name(None)
By passing None to set_logo_icon_name the default window icon set with the gtk.window_set_default_icon_list() function will be used. If you haven't specifically specified a default window icon then no icon/logo will be rendered.

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.

How to create a file browser in wxpython

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

How to change the OSX menubar in wxPython without any opened window?

I am writing a wxPython application that remains open after closing all of its windows - so you can still drag & drop new files onto the OSX dock icon (I do this with myApp.SetExitOnFrameDelete(False)).
Unfortunately if I close all the windows, the OSX menubar will only contain a "Help" menu. I would like to add at least a File/Open menu item, or just keep the menubar of the main window. Is this somehow possible in wxPython?
In fact, I would be happy with a non-wxPython hack as well (for example, setting the menu in pyobjc, but running the rest of the GUI in wxPython). wxPython development in OSX is such a hack anyway ;)
UPDATE: I managed to solve this problem using the tip from Lyndsey Ferguson. Here's what I have done:
On startup I create a window which I show and hide immediately. I set its position to (-10000,-10000) so that it does not flicker on the screen (aargh, what a dirty hack!)
I create an empty EVT_CLOSE event handler in that window so that it cannot be closed.
It seems that destroying a window resets the OSX menu, but hiding does not... So when the last window is closed, I need to show and hide this window again (hiding is necessary so that the user cannot switch to this window using the Window menu or Cmd-`)
Yeah, this is really ugly... I will be very grateful if someone comes up with a prettier solution.
UPDATE 2: Actually it can be solved in a much easier way: if we do not close the last window, only hide it. And ensure that it does not respond to menu events anymore.
Nowadays you can use wx.MenuBar.MacSetCommonMenuBar() to set the menu bar (which you have to create) that should be used when no windows are open.
If you just want a default macOS menu bar to be used (with the application and Window menus already there), this appears to be the minimal code:
menubar = wx.MenuBar()
wx.MenuBar.MacSetCommonMenuBar(menubar)
This will let your app respond to Command+Q out-of-the-box, too.
The wx.MenuItem IDs wx.ID_ABOUT and wx.ID_EXIT are special as menu items with those IDs are moved to the macOS Application menu. The docs actually refer to the application menu as the "Apple" menu (e.g. the menu described in the wx.MenuBar.OSXGetAppleMenu() function's docs is the application menu), possibly for historical reasons.
Can you create a hidden window that is offscreen somewhere? It is a hack, but I remember having to do a lot of hacks to make my wxPython-based application work correctly on Mac OS X.
Note:You'll have to disable the close button and set up that hidden window so that it doesn't show up in the Window menu.
Aside:Have you considered factoring out your GUI portion of your Python application and using PyObjC on Mac OS X? You'll get more native behaviours...

Categories