Python popups & capturing user response

hooj

Chieftain
Joined
Apr 27, 2006
Messages
5
Location
Idaho
Forgive me if this is an obvious question; I'm new to Civ4 modding and Python, but I'm an experienced C++ coder. I'm trying to make a "modal" popup in python to get a user response. For instance, a popup saying "Are you SURE you want to declare war on Mao?" (for instance, when you alt-click on a score in the main interface), with a "Yes" and a "No" button. I know how to create the popup using PyPopup and PyPopup.addButton(), .launch(), etc. but I cannot figure out how to determine what the user actually clicked. It seems that the PyPopup.launch() displays the popup as "modal", but where does the response get recorded?

I've tried using CyPopupInfo and making a new callback function. I can then properly process the user's selection, but the addPopup(player) command queues the popup. I need it to be displayed NOW! So, if the user is in e.g. the foreign advisor, the popup immediately shows up and the response is immediately processed.

Any code samples, pointers to mods that implement this, etc. would be great. Thanks!
 
Hooj, check out my Great Statesman mod for how to throw-up a popup, let the player choose and get the player's choice from the popup.
 
Also, if you are using a listbox to let the user select a choice, make sure the list isn't empty or it will cause a lockup. That happened to me when I was making my popup awhile back.

Roger Bacon
 
Look, with all respect why couldn't you just post a link or a quick response instead of redirecting people to your mods or back to the forum? I've searched the forum for this problem and what I found was only this kind of one-page thread with people replying without giving any help :((
 
Yeah, a link would've been really nice. But I did manage to find this thread:
http://forums.civfanatics.com/showthread.php?t=160579
which is I think what Belizan was talking about. TheLopez's mod also has some good insights. Basically, you have to define a new event, which takes a little bit more coding than one might expect for just a popup. Still, it's not too hard.

Thanks to everyone for their help!
 
enen said:
Look, with all respect why couldn't you just post a link or a quick response instead of redirecting people to your mods or back to the forum? I've searched the forum for this problem and what I found was only this kind of one-page thread with people replying without giving any help :((

Well, I think putting a link would have been redundant since the link was already in my signature.
 
If you can't be bothered to download a mod with the answer in it, or search the forum for a post which already covers the issue, we can't be bothered to help you. Last I checked, neither TheLopez nor I were paid to provide python support for Civ4. Where does everyone get these unreasonable expectations and feelings of entitlement from, anyway? Next time I just won't even bother to respond.
 
Thanks hooj.

Look Belizan I've been searching the forum for a while, I have downloaded the mod, and _still_ couldn't figure out the callback thing. Given that I'm a sw. engineer I'm quite familiar with programming (not much with python though), I think that neither the mod, nor "find it somewhere" answers were not helpfull. And given that only the main discussion forum has 50+ pages with threads, and the creation and custiomization has 80+ pages, and searching forums returned 4 threads with answers like yours, I don't think that you have to be the one who should whine about people's reaction. And yes, it's better to not respond if you can't (or don't want to) provide real help.

Anyway thanks for all of you, now even I could understand how it's working.
 
enen said:
Thanks hooj.

Look Belizan I've been searching the forum for a while, I have downloaded the mod, and _still_ couldn't figure out the callback thing. Given that I'm a sw. engineer I'm quite familiar with programming (not much with python though), I think that neither the mod, nor "find it somewhere" answers were not helpfull. And given that only the main discussion forum has 50+ pages with threads, and the creation and custiomization has 80+ pages, and searching forums returned 4 threads with answers like yours, I don't think that you have to be the one who should whine about people's reaction. And yes, it's better to not respond if you can't (or don't want to) provide real help.

Anyway thanks for all of you, now even I could understand how it's working.

Unbelievable.
 
I agree Belizan, I agree.

EDIT: Then of course, enen, if you want me to stop working on my mods like the sniper mod and to fully answer a question then I will. If you want to take the initiative and look at a thread or mod I point to and then ask questions if you don't understand something in there, I am also willing to do that as well.
 
Back
Top Bottom