How to disable button until check box is checked in pyqt? - python

I am creating an app and I need to disable a button until the user agrees to the terms. I looked online, but couldn't find anything. Any help would be great.
EDIT: I am using pyqt4.

You should use the strategy of signal/slots in Qt. When the checkbox send the checked signal you catch it with the slot defined in your button. Of course you should connect both widgets. For example:
connect(checkbox, SIGNAL(stateChanged(int)), button, SLOT(buttonStateChanged(int)));
This signals and slots maybe don't exists, and you have to create them. It is just the main idea.
I think that is a right way.
Here are some examples of connections in python, using signal/slots. And here is (maybe) what you need.

Related

Background process and tkinter

Looking for help on where to start with this, not too good with Python. What I trying to do is use tkinter for a gui interface but i need to be able to process recieved data and update labels widgets as information changes. I all ready have the communication portion of my program working fine in the shell but when I try to tie it to tkinter it will stop processing as soon as the interface is generated. Anyone have a simple code for me to modify to my needs or point me to a reference example somewhere. Spent days so far trying different options and I still have yet to find something that works.
Thanks for any help
Convert your working program into functions that you can register as callbacks in the tkinter UI (say buttons, or other widgets), that is, make it event-driven, and then, for background processing register some of the functions with the after widget method. The root.mainloop() will never return (only on UI close), use it as the last instruction.
So you can't just write your logic in a top-down structure, and hope that it will work well with the UI. The mainloop will be permanently looping, and will call specific funtions in your code, as appropriate to the received events from the user, or to callbacks you registered to run after some time with after.
See here for the after part
Take a look here for structuring tkinter programs. It should have enough info and links for you to study and learn how to do it in a right way.

Inactivate pyside-generated windows for the duration of background task

I have a simple gui application written in python with pyside. There is a main window and also some modal QDialogs. Depending on the user's actions in some of these dialogs, the application might have to connect to a database and perform corresponding tasks in it.
The problem is: database actions might take a few seconds to complete and my users tend to think that the program is stuck, so they start furiously clicking around and mashing keys. To prevent this erratic behavior I want to deactivate all the windows and display some loading symbol to calm things down.
What I need to create (left - normal state, right - busy state):
This is not the actual app, just an approximate schema of what I want to achieve.
I think some kind of QMovie should do the trick, but I have no idea how to cover a dialog with semi-transparent white and to display the loading symbol on top of it. I am also considering QProgressBar, but I am not sure if it's the right solution for the task.
I would appreciate any advice or a link to similar tasks solved (for some reason I was unable to google anything relevant myself, maybe I am using wrong keywords).
Generally, the way you would do this is with some sort of progress indicator, either a QProgressBar or a QProgressDialog.
With the QProgressDialog, you can launch it modally to prevent users from interacting with the base QDialog or QMainWindow.
Either way, you should still be doing the slow-running task in another thread; otherwise, the GUI is just going to freeze. The user won't be able to move the window or dialog, it won't respond to their clicks, and any progress updates you're making won't be shown in the GUI.

wxPython: Minimize a Frame to tray

I am in the process of writing an app that I want to make a GUI for. I've got a little bit of experience with making GUI's in wxpython already, but one thing I have not had to try yet; is minimizing an application to tray. I have been doing my research and figured out how to make the icon, but what I have gotten stuck in the mud with is minimizing the Frame to the tray. I have found no functions that I can use to hide the frame with (wx.Frame.Hide() is not the answer). Do any of you know of any way that I could accomplish this? Thanks!
You need to look at the wxPython demo's source code. Look for the part which mentions the DemoTaskBarIcon. Then you'll want to bind to wx.EVT_ICONIZE. You do end up using the frame's Hide() method within the "iconize" event handler. How else would you hide it? Then to show it again, you'll want to use the menu from your task bar icon (which is technically a system tray icon on Windows). See also:
http://bytes.com/topic/python/answers/699757-wxpython-how-minimize-taskbar
http://wxpython-users.1045709.n5.nabble.com/minimize-to-try-question-td2359957.html

hook into wndproc of another application?

I have a small question hoping someone will help me.
Is there any way to hook into other applications WNDPROC?
The situation is that I want to insert a menu in the other app menubar and I want to define the commands for every menu item.
I was able to insert the menu with menu items using some Win32 API
functions (user32.dll), but I can't set the commands of that menu item so that it actually does something if clicked.
With some googling, I got some information about wndprocess, and I should intercept the ID Command sent and trigger some function, but I'm stuck.
Can anyone help me?
You are going about this the wrong way. If you think about it, you'll realize that responding to menu events with your custom "actions" must require some code to run in the process that you're targeting. This means you'll need to inject code into the other process in order to achieve what you want.
Since you're going to need to inject code anyway, I strongly suggest you look at DLL-injecting into the other process (search "Dll Injection example"). This will bootstrap your code into the other process, and you can construct your menu there.
This also has the advantage that the foreign app won't be reliant on your app being responsive - it'll all be in-process.

How do I make a dialog box that waits for user response?

When you tkSimpleDialog.askinteger, the program stalls and waits for user input. What are the basics of writing my own method that would have the same effect? I want to make the same kind of dialog box, I just want to be able to request more information.
The problem that I'm having is that when I open the new window using Tk.Toplevel, the program does not wait for user input the way tkSimpleDialog.askinteger does.
First off, if you can use some other widget system like PyGtk or PyQt, you should seriously consider it. Tkinter is ancient, and the newer libraries have a lot more functionality (read: more things you don't have to reinvent). I've used PyGtk and like it a lot more than Tkinter, which I used in the old Python 1.x days.
That said, in Tkinter, you need to do this:
widget.wait_window(window)
This ties up the event loop waiting for the user to dismiss the dialog.
Reference: http://www.pythonware.com/library/tkinter/introduction/dialog-windows.htm

Categories

Resources