I have a frame which I use as the main form (mainFrame), it inherits from mainFrameBase, which inherits from wxFrame.
It has a "close" system button. When it is pressed the app shuts down. All very much to my liking.
I inherit another frame from mainFrameBase (progScreen). When a button is pressed, the progScreen is shown. When I click its system close button, the form does not close.
What I want to achieve with this setup is that you can click a button on the main frame and a slightly different view of the main frame is shown to allow the user to "progam" certain buttons.
By the way, I'm using WXFormBuilder (excellent program) to create the screens.
What I would do is create two panels with the controls you want, one for the regular screen and one for the programming screen. Then when you want to switch, you hide one panel and show the other. That way, both screens are contained in one frame that when closed, exits the program. I actually have a tutorial that is similar to this here:
http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/
Hope that helps!
Related
So I have a script running inside another program (The Foundry's Hiero) and I'm just making a new QWidget object, and calling self.show()
Now, I can set it to self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint), so my window will stay on top of the main window, even if you click on something in the main window.
The problem is, this is a sort of popup window that you configure settings in, and it triggers other QWidget popups. If I set my window to WindowStaysOnTopHint, those subdialogs that my widget triggers end up beneath my widget.
Is there a way in PySide/PyQt to make a window stay on top/keep focus from the main application window in particular, but not everything?
You can use the QApplication.focusChanged signal to raise your widget up when Hiero's main window is selected. Then you would just need to remove the WindowStaysOnTopHint flag.
I'm not familiar with Hiero's API, but I'm guessing you could try something like:
def raiseMyWidget(old, new):
if new == hiero.ui.mainWindow():
myWidget.raise_()
QtWidgets.QApplication.instance().focusChanged.connect(raiseMyWidget)
Hope this helps! You can take advantage of the old parameter or some other means to make sure that your widget isn't raised above the others as well.
I am trying to make a custom window that acts like a popup window and closes as it loses its focus (click outside of popup).
I have a frame with several clickable images. If you click one of the images a frame appears. This frame is a base class and its contents (text controls, grids, buttons e.t.c) are replaced depending on what image you clicked. My problem is where and what event I should capture.
I will try to simplify with sample/pseudo code.
class MainFrame(MainFrameDefinition):
# unimportant code
custom_frame_holder = CustomFrame()
for child_panel in self.lots_of_panels:
# add a panel to a map and set
custom_frame_holder.panel = child_panel
class CustomFrame(wx.Frame):
def __init__(self, parent):
# unimportant code
self.panel = # a panel that changes
self.Bind(wx.EVT_KILL_FOCUS, self.lost_focus)
def lost_focus(self, event):
self.Hide()
So what seems to be the officer problem? Well as soon as I click on a control in the CustomFrame, the frame loses its focus and the window will hide.
I have tried to capture EVT_CHILD_FOCUS and then set the focus back to the frame, but then, since the frame has the focus I am unable to write in say a text control.
I have looked at the wxPopup and wxTransientPopup, but they apparently have a bug that doesn't allow radio buttons, which makes them useless to me.
Let me know if I make no sense and I will try to explain better.
Use wxEVT_ACTIVATE for this purpose (probably wx.EVT_ACTIVATE in wxPython).
I think the radio button issue in popup windows was fixed in the trunk.
I am currently working on a project using Python and tkinter.
The problem is that I don't know what's the proper way to display multiple windows, or screens, I don't know how to call them. Let me explain better.
When the application starts the login screen appears. After that, if I click register, I want to go to the register screen, but I don't want it to be a separate window (I don't want to have 2 windows displayed at the same time), but rather another window with different content ?!
How should I handle properly this situation? Create a second window using Toplevel and hiding the first (can I do that?) or changing the widgets of the first?
Code I've written so far
You can do that- just call window.withdraw() on the Toplevel you need to hide after creating a new Toplevel. Changing the widgets in the first is also an option- if you like, you could always try a Notebook widget and disable manual flipping or just put each "screen" in a frame and grid_ or pack_forget them to remove them from the window.
I don't know How structure the GUI of my program...
I don't have big experience with GUI programming, i know all the widgets, the
geometry managers, the "object-oriented" method in Tkinter, but i don't understand
how combine all this things...
I want to create a program with an image in background where there is a button and if i press this button i switch in another page and the button disappears
Like this : https://moqups.com/iampirla#gmail.com/wyM7CyET/p:a80e8d902
How i can structure my code to do this?
You could use pack_forget() this removes the widget although allows you to use it later if you wish. You could do the first page and then use some code like below. To clear the page. This could then reference the next thing you wish to do using in this example question().
def answred():
nameLabel.pack_forget()
nameEntry.pack_forget()
nameButton.pack_forget()
classQuestion.pack_forget()
button1.pack_forget()
button2.pack_forget()
button3.pack_forget()
question()
You could this but not remove the background widgets
I have two windows in my application and one of these windows has no frame for design purposes.
The frame with the window has the usual toolbar with the minimize, restore, maximize and close buttons.
Is there a way i can close the window with no frame, with the framed windows close button?
Yes. You just need to save a reference to the 2nd frame. Something like this should suffice:
self.secondFrame = MySecondFrame()
Then in the first frame's close method, you can just do something like this:
self.secondFrame.Close()
However, I should note that creating a frame without the usual toolbar goes against most OS GUI guidelines and users will likely be irritated by that design decision.
EDIT: Yes, you can catch the event that occurs when the user presses the "X" button on the window via wx.EVT_CLOSE. When you do that, you need to call the main frame's Destroy() method instead of its Close method or you'll end up in an infinite loop since calling Close() fires EVT_CLOSE. You can still use Close() for the second frame though.