adp001 opened this issue on Dec 27, 2019 ยท 5 posts
adp001 posted Fri, 27 December 2019 at 6:48 AM
import wx
try:
import poser
except ImportError:
raise RuntimeError("Script must run in Poser.")
def generate_names(obj_list):
if hasattr(obj_list, "__iter__"):
for obj in obj_list:
if hasattr(obj, "Name"):
yield obj.Name()
def actor_choice(choicelist=None):
"""
Demonstrates wx.control SingleChoiceDialog
"""
if choicelist is None:
choicelist = poser.Scene().Actors()
choices = list(generate_names(choicelist))
with wx.SingleChoiceDialog(None,
caption="My Actor Dialog",
message="Select one actor",
choices=choices,
style=wx.CHOICEDLG_STYLE
) as dlg:
if dlg.ShowModal() == wx.ID_OK:
return dlg.GetStringSelection()
else:
return None
def actor_choices(choicelist=None):
"""
Demonstrates wx.control MultiChoiceDialog
"""
if choicelist is None:
choicelist = poser.Scene().Actors()
choices = list(generate_names(choicelist))
with wx.MultiChoiceDialog(None,
caption="My Actor Dialog",
message="Select one actor",
choices=choices,
style=wx.CHOICEDLG_STYLE
) as dlg:
if dlg.ShowModal() == wx.ID_OK:
return [choices[i] for i in dlg.GetSelections()]
else:
return None
actorname = actor_choice()
print("Selected Actors:", actorname if actorname is not None else "None")
actornames = actor_choices()
print("Selected Actors:", actornames if actornames is not None else "None")
FVerbaas posted Sat, 28 December 2019 at 9:05 AM Forum Coordinator
Very convenient!
Thanx for sharing.
adp001 posted Sat, 28 December 2019 at 10:19 AM
You are welcome!
For the other thread: I think about clothes. Without MD ;)
maur_2005 posted Wed, 05 February 2020 at 8:13 AM
That very useful, thank you.
one question, how can I add an option that allows me to select all?
adp001 posted Wed, 05 February 2020 at 9:11 AM
This shows "SingleChoiceDialog" and "MultiChoiceDialog" as it is provided by wxPython as a quick solution. If you need it more complicated, you need to create your own dialog.
But I'm sure I also showed a dialog with "select/deselect all" somewhere :).