Vadus
pretend the impossible
Vadus said:Here is a short tutorial to "Creating a popup and receiving data from it" : http://forums.civfanatics.com/showthread.php?p=3746502#post3746502
Hi all,
I'm trying to popup an EditBox and to receive it's value after pressing the popup ok button ( similar to the popup of city-renaming)
So I used the methods from the original CvEventManager refering to the city renaming. These are
__eventEditCityNameBegin()
Code:
def __eventEditCityNameBegin(self, city, bRename):
popup = PyPopup.PyPopup(CvUtil.EventEditCityName,
EventContextTypes.EVENTCONTEXT_ALL)
popup.setUserData((city.getID(), bRename))
popup.setHeaderString(localText.getText("TXT_KEY_NAME_CITY", ()))
popup.setBodyString(localText.getText("TXT_KEY_SETTLE_NEW_CITY_NAME", ()))
popup.createEditBox(city.getName())
popup.setEditBoxMaxCharCount( 15 )
popup.launch()
and __eventEditCityNameApply()
Code:
def __eventEditCityNameApply(self, playerID, userData, popupReturn):
'Edit City Name Event'
iCityID = userData[0]
bRename = userData[1]
player = gc.getPlayer(playerID)
city = player.getCity(iCityID)
cityName = popupReturn.getEditBoxString(0)
if (len(cityName) > 30):
cityName = cityName[:30]
city.setName(cityName, not bRename)
As you see, the Popup is created with a CvUtil.EventEditCityName
Argument. I think this internal Event manages the dataflow into the popup and back to the aggregating class.
Via a directory
Code:
self.Events={ CvUtil.EventEditCityName :
('EditCityName', self.__eventEditCityNameApply,
self.__eventEditCityNameBegin)
}
But I'm wondering if all this is needed to create just a Popup and receive the data from it. I need only the String of the popups EditBox. Arguments like in this example ( playerID , city , etc .. ) aren't required.
So I tried a little and got the popup to popup by copying this example from the CvEventManager almost 1:1 to my test-mod. But I receive nothing after pressing the Ok-Button of the popup. Not even an error message So I think, that this CvUtil.EventEditCityName is to special for my case. As I said, I only want to receive the popup input in the aggregating class. So instead of a city, I just commit a None Object and so on .. This could be reason, why the CvUtil.EventEditCityName isn't working fine.
So is there an easier way to use a popup. Maybe without this CvUtil.EventEditCityName stuff ?