Forum Moderators: Staff
Poser Python Scripting F.A.Q (Last Updated: 2025 Feb 05 6:41 am)
you could try
def askmenu( foundfilelist ) :
return poser.DialogSimple.AskMenu("Multiple 'SmartPlusData.txt' files found","Select which to use:",foundfilelist) else False
if askmenu( filelist ):
do something
***UNTESTED***
or an alternative
import wx
class dialogs:
def choose( self, title = "", prompt = "", OptionList = [], parent = None ):
dialog = wx.SingleChoiceDialog( parent, prompt, title, OptionList )
if not OptionList == []:
return dialog.GetStringSelection() if dialog.ShowModal() == wx.ID_OK else False
you can choose to return anything if the cancel button is pressed ,
e.g.
return dialog.GetStringSelection() if dialog.ShowModal() == wx.ID_OK else "NOTHING"
Locked Out
Yes indeed, there are many ways to get round it, but you shouldn't need to as it's supposed to return a StringType.
Hence 'bug'.
This looks like sloppy coding of AskMenu() to me - trust me, I'm an expert on sloppy coding... ;o)
The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.
*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).
However, I like your alternative workarounds better than my own, and this seems to get round the bug nicely for me:
action = ""
while action == "":
action = poser.DialogSimple.AskMenu("Multiple 'SmartPlusData.txt' files found","Select which to use:",foundfilelist)
# Handle NoneType return value if Cancel button pressed
if action:
locatedfile = action
else:
locatedfile = "CANCEL"
print "TEST RESULT = "+locatedfile
P.S. I don't use wxPython - far too complicated for my decaying brain ! So I'm stuck with PoserPython's built in dialogues
The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.
*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).
Returning None is the correct Python way if nothing is selected (canceled). Returning nothing is different than returning an empty string.
result = poser.DialogSimple.AskMenu(...)
if result:
do_something()
else:
forget_it()
In Python None is assumed as False.
for item in emptylist or listwithcontent:
print(item_from_listwithcontent)
In that case it's probably not a bug then, just my lack of understanding of Python :)
So AskMenu() returns nothing (NoneType) if you click 'Cancel', but returns an empty/null string (StringType, "") if you click 'OK' with the AskMenu dialogue's default 'None' option, as shown below.
Thanks - that makes some sort of sense now.
The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.
*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).
It's also worth noting that BOTH None and '' (empty string) evaluate to False in a boolean expression. That provides a simple way to distinguish between a useful returned string to be parsed (any non-empty string will evaluate as True) and a non-selection ('' OK) or cancellation (None). Python design has its own logic, and it takes some getting used to when coming from other languages.
Similarly with lots of other Poser Python API methods which can return None instead of an empty list. As in adp's second example, if a method could return None instead of an empty list, make use of None evaluating as False, and iterate over a list conditional like:
for item in ListMethodThatMayReturnNone() or []: # The " or []" CAN be iterated over without error, while None cannot
pass
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.
According to the Poser 11 PoserPython manual AskMenu returns a StringType.
This is correct, EXCEPT if you click the 'Cancel' button on the dialogue, when it returns a NoneType.
To catch that I found I had to cast (if that's the correct Pythonspeak) the return value as a string, which appears to convert NoneType to "None".
I don't recall having this problem with PP2014, although it's possible I never tested clicking the Cancel button from an AskMenu
(N.B. this darn forum s**tware removed anything between (and including) less-than and greater-than symbols, so the types in my code extract disappeared, despite being within a triple backtick block )`
The 3Dcheapskate* occasionally posts sensible stuff. Usually by accident.
And it usually uses Poser 11, with units set to inches. Except when it's using Poser 6 or PP2014, or when its units are set to PNU.
*also available in ShareCG, DAZ, and HiveWire3D flavours (the DeviantArt and CGBytes flavour have been discontinued).