code: def qteReplaceAppletInLayout(self, newApplet: (QtmacsApplet, str),
                                   oldApplet: (QtmacsApplet, str)=None,
                                   windowObj: QtmacsWindow=None):
          if isinstance(oldApplet, str):
              oldAppObj = self.qteGetAppletHandle(oldApplet)
          else:
              oldAppObj = oldApplet
          if isinstance(newApplet, str):
              newAppObj = self.qteGetAppletHandle(newApplet)
          else:
              newAppObj = newApplet
          if windowObj is None:
              windowObj = self.qteActiveWindow()
              if windowObj is None:
                  msg = 'Cannot determine the currently active window.'
                  self.qteLogger.warning(msg, stack_info=True)
                  return
          if windowObj.qteAppletSplitter.count() == 0:
              windowObj.qteAppletSplitter.qteAddWidget(newAppObj)
              return
          if oldAppObj is None:
              oldAppObj = self.qteNextApplet(numSkip=0, windowObj=windowObj)
          if oldAppObj is None:
              msg = 'Applet to replace does not exist.'
              self.qteLogger.error(msg, stack_info=True)
              return
          if newAppObj is oldAppObj:
              return
          if oldAppObj.qteIsVisible() and newAppObj.qteIsVisible():
              return
          split = self._qteFindAppletInSplitter(
              oldAppObj, windowObj.qteAppletSplitter)
          if split is None:
              msg = ('Applet <b>{}</b> not replaced because it is not'
                     'in the layout.'.format(oldAppObj.qteAppletID()))
              self.qteLogger.warning(msg)
              return
          oldAppIdx = split.indexOf(oldAppObj)
          sizes = split.sizes()
          split.qteInsertWidget(oldAppIdx, newAppObj)
          oldAppObj.hide(True)
          split.setSizes(sizes)