Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Opening dialog twice in a row doesn't work[SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 259 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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)

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 24/05/2016 at 20:14, xxxxxxxx wrote:

        Don't you need to create a unique class instance for each dialog you open?

        s = SubmitSummaryDialog()
        s.put("hello")
        s.Open()

        s2 = SubmitSummaryDialog()
        s2.put("hello")
        s2.Open()

        -ScottA

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 25/05/2016 at 01:57, xxxxxxxx wrote:

          Hey Scott,

          You're right, that works! And I actually tried that already (that's why there is a copy() method in the
          class)! But when I did, the function that was opening the dialog was still referencing the original dialog
          instance (not the second, new instance). After I sorted that out, it works. 🙂

          Thanks for the hint!

          Cheers,
          -Niklas

          1 Reply Last reply Reply Quote 0
          • First post
            Last post