On 24/05/2016 at 16:42, xxxxxxxx wrote:
Hi! I've got a strange issue with modal dialogs and I can't find a workaround. Paste the following code into the Script Manager and run it. The dialog should pop up twice.
import c4d
class SubmitSummaryDialog(c4d.gui.GeDialog) :
def __init__(self, job_id=None, title=None, kind='ok') :
super(SubmitSummaryDialog, self).__init__()
assert kind in ('ok', 'cancel', 'confirm')
self.AddGadget(c4d.DIALOG_NOMENUBAR, 0)
self.job_id = job_id
self.title = title
self.kind = kind; assert kind in ('ok', 'confirm')
self.result = None
self.messages = []
self.update_gui = False
def put(self, message, kind='message') :
assert kind in ('message', 'section', 'close-section')
if kind == 'message':
message = '' + str(message)
self.messages.append({'msg': str(message), 'kind': kind})
self.update_gui = True
def section(self, header) :
self.put(header, kind='section')
def close_section(self) :
self.put('', kind='close-section')
def copy(self) :
obj = SubmitSummaryDialog(self.job_id, self.title, self.kind)
obj.result = self.result
obj.messages = self.messages
obj.update_gui = False
return obj
def update(self) :
# Helper function to start a new group.
def group_begin(title=None, cols=1) :
self.GroupBegin(0, c4d.BFH_SCALEFIT, cols=cols, title=title)
self.GroupBorderSpace(10, 6, 10, 6)
if title:
self.GroupBorder(c4d.BORDER_WITH_TITLE_BOLD | c4d.BORDER_THIN_IN)
self.LayoutFlushGroup(1000)
group_begin(cols=3)
in_section = False
for data in self.messages:
border = c4d.BORDER_NONE
if data['kind'] == 'section':
in_section = True
self.GroupEnd()
group_begin(data['msg'])
elif data['kind'] == 'close-section':
in_section = False
self.GroupEnd()
group_begin(cols=3)
else:
if in_section:
self.AddStaticText(0, c4d.BFH_SCALEFIT | c4d.BFV_CENTER, name=data['msg'])
else:
# Without an item that scales completely, we can't use
# BFH_CENTER correctly, it'll just be aligned to the left.
self.AddStaticText(0, c4d.BFH_SCALEFIT)
self.AddStaticText(0, c4d.BFH_CENTER | c4d.BFV_CENTER, name=data['msg'])
self.AddStaticText(0, c4d.BFH_SCALEFIT)
self.GroupEnd()
self.LayoutChanged(1000)
self.update_gui = False
def CreateLayout(self) :
self.SetTitle(self.title or self.job_id)
self.GroupBorderSpace(4, 4, 4, 4)
self.ScrollGroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, c4d.SCROLLGROUP_VERT | c4d.SCROLLGROUP_AUTOVERT, inith=150)
self.GroupBegin(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, cols=1)
self.GroupSpace(0, 6)
self.update()
self.GroupEnd()
self.GroupEnd()
self.GroupBegin(0, c4d.BFH_CENTER, rows=1)
if self.kind == 'confirm':
self.AddButton(c4d.DLG_OK, 0, name='Submit')
self.AddButton(c4d.DLG_CANCEL, 0, name='Cancel')
elif self.kind == 'ok':
self.AddButton(c4d.DLG_OK, 0, name='OK')
elif self.kind == 'cancel':
self.AddButton(c4d.DLG_CANCEL, 0, name='Cancel')
else:
raise ValueError('invalid kind: {0!r}'.format(self.kind))
self.GroupEnd()
return True
def Command(self, wid, bc) :
if wid == c4d.DLG_OK:
self.result = 'ok'
self.Close()
elif wid == c4d.DLG_CANCEL:
self.result = 'cancel'
self.Close()
return True
def CoreMessage(self, mid, bc) :
if mid == c4d.EVMSG_CHANGE:
if self.update_gui:
self.update()
return super(SubmitSummaryDialog, self).CoreMessage(mid, bc)
def Open(self, dlgtype=c4d.DLG_TYPE_MODAL, **kwargs) :
print(">>> SubmitSummaryDialog.Open()")
# Only open if we have stuff to show.
self.update_gui = True
kwargs.setdefault('xpos', -1)
kwargs.setdefault('ypos', -1)
if self.messages:
return super(SubmitSummaryDialog, self).Open(dlgtype, **kwargs)
return True
s = SubmitSummaryDialog()
s.put("hello")
s.Open()
s.Open()
It does, but the second one has no content!
First: Second:
How can I fix this?
Thanks! (PS: R16.050)