Ejemplo n.º 1
0
 def unpack(self, package):
     """Unpack the given lilypond .sh archive."""
     fileName = os.path.basename(package)
     ver = version(fileName) or 'unknown' # should not happen
     self.prefix = os.path.join(self.installDest.url().path(), ver)
     self.lilypond = os.path.join(self.prefix, "bin", "lilypond")
     if not os.path.exists(self.prefix):
         os.makedirs(self.prefix)
     elif os.path.exists(self.lilypond):
         result = KMessageBox.questionYesNoCancel(self, i18n(
             "LilyPond %1 seems already to be installed in %2.\n\n"
             "Do you want to use it or to remove and re-install?",
             ver, self.prefix), None,
             KGuiItem(i18n("Use existing LilyPond")),
             KGuiItem(i18n("Remove and re-install")))
         if result == KMessageBox.Yes:
             self.info.lilypond.setText(self.lilypond)
             self.enableButtonOk(True)
             KDialog.done(self, KDialog.Accepted)
             return
         elif result == KMessageBox.No:
             shutil.rmtree(self.prefix, True)
         else: # Cancel
             self.progress.reset()
             self.enableButtonOk(True)
             return
     self.status.setText(i18n("Unpacking %1...", fileName))
     self.progress.setRange(0, 0)
     unpack = self.unpackJob = QProcess()
     unpack.setProcessChannelMode(QProcess.MergedChannels)
     unpack.setWorkingDirectory(self.prefix)
     unpack.finished.connect(self.unpackFinished)
     unpack.error.connect(self.unpackError)
     unpack.start("sh", [package, "--batch", "--prefix", self.prefix])
 def __kdeQuestion(parent, title, text, 
                   buttons = QMessageBox.Ok, defaultButton = QMessageBox.NoButton):
     """
     Function to show a modal critical message box.
     
     @param parent parent widget of the message box
     @param title caption of the message box
     @param text text to be shown by the message box
     @param buttons flags indicating which buttons to show 
         (QMessageBox.StandardButtons)
     @param defaultButton flag indicating the default button
         (QMessageBox.StandardButton)
     @return button pressed by the user (QMessageBox.StandardButton)
     """
     if __nrButtons(buttons) == 1:
         if defaultButton == QMessageBox.NoButton:
             defaultButton = __getLowestFlag(buttons)
         yesButton = defaultButton
         yesItem = __getGuiItem(yesButton)
         KMessageBox.questionYesNo(parent, text, title, yesItem, KGuiItem())
         return yesButton
     
     if __nrButtons(buttons) == 2:
         if defaultButton == QMessageBox.NoButton:
             defaultButton = __getLowestFlag(buttons)
         yesButton = defaultButton
         yesItem = __getGuiItem(yesButton)
         noButton = int(buttons & ~yesButton)
         noItem = __getGuiItem(noButton)
         res = KMessageBox.questionYesNo(parent, text, title, yesItem, noItem)
         if res == KMessageBox.Yes:
             return yesButton
         else:
             return noButton
     
     if __nrButtons(buttons) == 3:
         if defaultButton == QMessageBox.NoButton:
             defaultButton = __getLowestFlag(buttons)
         yesButton = defaultButton
         yesItem = __getGuiItem(yesButton)
         buttons = buttons & ~yesButton
         noButton = __getLowestFlag(buttons)
         noItem = __getGuiItem(noButton)
         cancelButton = int(buttons & ~noButton)
         cancelItem = __getGuiItem(cancelButton)
         res = KMessageBox.questionYesNoCancel(parent, text, title, 
             yesItem, noItem, cancelItem)
         if res == KMessageBox.Yes:
             return yesButton
         elif res == KMessageBox.No:
             return noButton
         else:
             return cancelButton
     
     raise RuntimeError("More than three buttons are not supported.")