示例#1
0
def QuestionDialog(title, text, info = None, dontAsk = False):
    msgBox = QMessageBox()

    buttonYes = msgBox.addButton(_("Yes"), QMessageBox.ActionRole)
    buttonNo = msgBox.addButton(_("No"), QMessageBox.ActionRole)

    answers = {buttonYes:"yes",
               buttonNo :"no"}
    if dontAsk:
        buttonDontAsk = msgBox.addButton(_("Don't ask again"), QMessageBox.ActionRole)
        answers[buttonDontAsk] = "dontask"

    msgBox.setText(text)
    if not info:
        info = _("Do you want to continue?")
    msgBox.setInformativeText(info)

    dialog = Dialog(_(title), msgBox, closeButton = False, isDialog = True, icon="question")
    dialog.resize(300,120)
    dialog.exec_()

    ctx.mainScreen.processEvents()
    if msgBox.clickedButton() in answers.keys():
        return answers[msgBox.clickedButton()]
    return "no"
示例#2
0
    def finish_check(self):
        if self.valid_book_ids:
            is_filesize_exceeded = len(self.valid_book_ids) < self.books_count
            is_total_books_exceeded = self.limits[
                'total_books'] and self.books_count > self.limits['total_books']

            if is_filesize_exceeded or is_total_books_exceeded:
                if self.limits['message']:
                    msg_box = QMessageBox(self)
                    msg_box.setWindowTitle('BookFusion Sync')
                    msg_box.addButton(QMessageBox.No)
                    msg_box.addButton(QMessageBox.Yes)
                    msg_box.setText(self.limits['message'])
                    msg_box.setDefaultButton(QMessageBox.Yes)
                    reply = msg_box.exec_()
                    if reply == QMessageBox.Yes:
                        self.start_sync()
                    else:
                        self.in_progress = False
                        self.msg.setText('Canceled.')
                        self.finish_sync()
                else:
                    self.start_sync()
            else:
                self.start_sync()
        else:
            if self.in_progress:
                self.in_progress = False
                self.msg.setText('No supported books selected.')
            self.finish_sync()
示例#3
0
    def __ask_for_continue_if_unsaved_changes(self):
        if not self.__command_handler.can_undo.get():
            # Continue if there are no unsaved changes
            return True
        else:
            # Ask if there are unsaved changes
            box = QMessageBox()
            box.addButton(QCoreApplication.translate("main_window", "Yes"),
                          box.YesRole)
            no_button = box.addButton(QCoreApplication.translate("main_window",
                                                                 "No"),
                                      box.NoRole)
            box.setDefaultButton(no_button)
            box.setWindowTitle(QCoreApplication.translate("main_window",
                                                          "Unsaved changes"))
            box.setText(QCoreApplication.translate(
                                           "main_window",
                                           "Do you really want to continue "
                                           "without saving changes?"))
            box.setIcon(box.Icon.Question)
            response = box.exec()

            if (response == 1):
                # Do not continue because user wants to stop
                return False
            else:
                return True
示例#4
0
def QuestionDialog(title, text, info=None, dontAsk=False):
    msgBox = QMessageBox()

    buttonYes = msgBox.addButton(_("Yes"), QMessageBox.ActionRole)
    buttonNo = msgBox.addButton(_("No"), QMessageBox.ActionRole)

    answers = {buttonYes: "yes", buttonNo: "no"}
    if dontAsk:
        buttonDontAsk = msgBox.addButton(_("Don't ask again"),
                                         QMessageBox.ActionRole)
        answers[buttonDontAsk] = "dontask"

    msgBox.setText(text)
    if not info:
        info = _("Do you want to continue?")
    msgBox.setInformativeText(info)

    dialog = Dialog(_(title),
                    msgBox,
                    closeButton=False,
                    isDialog=True,
                    icon="question")
    dialog.resize(300, 120)
    dialog.exec_()

    ctx.mainScreen.processEvents()
    if msgBox.clickedButton() in answers.keys():
        return answers[msgBox.clickedButton()]
    return "no"
示例#5
0
 def lataaja(self, tiedosto):
     '''Hoitaa muuttujien lataamisen annetusta tiedostosta'''
     lataus = False 
     try:
         '''Yrittää avata annetun tiedoston. Ilmoittaa jos tulee virhe'''
         file = open(tiedosto, "r")
         rivi = file.readline()
         rivi = rivi.strip()
         if rivi != "Lujuusanalysaattori":
             '''Kerrotaan käyttäjälle, että tiedosto oli virheellinen''' 
             msgBox = QMessageBox()
             msgBox.setText("Tiedoston lukeminen ei onnistu: Virheellinen tiedosto")
             msgBox.setWindowTitle("Virhe")
             msgBox.setMinimumWidth(50)
             msgBox.addButton(QPushButton('OK'), QMessageBox.NoRole)
             msgBox.exec_() 
             return lataus
     except FileNotFoundError:
         return lataus
     
     try:
         '''Ohitetaan päivämäärä'''
         rivi = file.readline()
         '''Luetaan arvot ja tallennetaan ne ominaisuudet luokan avulla'''
         '''Palkin pituus'''
         rivi = file.readline()
         Ominaisuudet.palkin_pituus(self, int(rivi))
         
         '''Palkin pituuden yksikko'''
         rivi = file.readline()
         Ominaisuudet.yksikko(self, int(rivi))
         
         '''Voiman suuruus'''
         rivi = file.readline()
         Ominaisuudet.voima(self, int(rivi)) 
         
         '''Voiman yksikkö'''
         rivi = file.readline()
         Ominaisuudet.yksikko_voima(self, int(rivi)) 
         
         '''Materiaali'''
         rivi = file.readline()
         Ominaisuudet.materiaali(self, int(rivi)) 
         
         '''Tuen tyyppi'''
         rivi = int(file.readline())
         Ominaisuudet.tuki(self, rivi)
         
         '''Onko ulkoinen voima asetettu 0=ei, 1=kyllä'''
         rivi = file.readline()
         Ominaisuudet.ulkoinen_voima(self, int(rivi)) 
         
         return True 
     
     except AttributeError:
         pass     
示例#6
0
 def tallenna_rakenne(self):
     '''Hoitaa rakenteen tallentamisen'''
     tallennus = Tallennin.tallenin(self)
     if tallennus == True:
         '''Kerrotaan käyttäjälle, että tallennus onnistui'''
         msgBox = QMessageBox()
         msgBox.setText("Tallennus onnistui!")
         msgBox.setWindowTitle("Onnistunut Tallennus")
         msgBox.setMinimumWidth(50)
         msgBox.addButton(QPushButton('OK'), QMessageBox.NoRole)
         msgBox.exec_()
示例#7
0
    def lataa_tallennettu_rakenne(self):
        '''Metodi avaa QFileDialog ikkunan, josta käyttäjä valitsee tiedoston, jossa aiemmin tallennettu rakenne sijaitsee. Vain .txt -tiedostot 
        ovat ladattavissa '''
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        tiedosto, _ = QFileDialog.getOpenFileName(self,
                                                  "Valitse tiedosto",
                                                  "",
                                                  "txt Files (*.txt)",
                                                  options=options)
        lataus = Lataaja.lataaja(self, tiedosto)
        if lataus == False:
            return

        if lataus == True:
            self.uusi_rakenne()
            Lataaja.lataaja(self, tiedosto)
            tuen_tyyppi = Ominaisuudet.palauta_tuen_tyyppi(self)
            '''Jos tuki on seinästä, piirretään sitä vastaava grafiikka'''
            if tuen_tyyppi == 0:
                self.nayta_seina_tuki()
                self.gradient_seina_tuki()
            '''Jos tuki on alhaalta, piirretään sitä vastaava grafiikka'''
            if tuen_tyyppi == 1:
                self.nayta_tuki_alhaalta()
                self.gradient_alatuki()

            if tuen_tyyppi != 2:
                self.vaihda_tuki.show()
                self.lisaa_tuki.hide()
            '''Jos ulkoinen voima on asetettu, piirretään se'''
            ulkoinen_voima = int(
                Ominaisuudet.onko_ulkoinen_voima_asetettu(self))
            if ulkoinen_voima == 1:
                self.nayta_ulkoinen_voima()

            self.nayta_palkki()
            Laskin.laskin(self)
            self.paivita_tulos_teksti()
            self.tulos.show()
            self.sp.setValue(float(Ominaisuudet.palauta_palkin_pituus(self)))
            self.uusiAction.setEnabled(True)
            self.simuloi.setEnabled(True)
            '''Kerrotaan käyttäjälle, että kaikki onnistui'''
            msgBox = QMessageBox()
            msgBox.setText("Lataus onnistui!")
            msgBox.setWindowTitle("Onnistunut lataus")
            msgBox.addButton(QPushButton('OK'), QMessageBox.NoRole)
            msgBox.exec_()
示例#8
0
文件: dgi_qt.py 项目: deavid/pineboo
 def msgbox(cls, typename, text, button0, button1=None, button2=None, title=None, form=None):
     if form:
         logger.warn("MessageBox: Se intentó usar form, y no está implementado.")
     icon = QMessageBox.NoIcon
     if not title:
         title = "Pineboo"
     if typename == "question":
         icon = QMessageBox.Question
         if not title:
             title = "Question"
     elif typename == "information":
         icon = QMessageBox.Information
         if not title:
             title = "Information"
     elif typename == "warning":
         icon = QMessageBox.Warning
         if not title:
             title = "Warning"
     elif typename == "critical":
         icon = QMessageBox.Critical
         if not title:
             title = "Critical"
     # title = unicode(title,"UTF-8")
     # text = unicode(text,"UTF-8")
     msg = QMessageBox(icon, title, text)
     msg.addButton(button0)
     if button1:
         msg.addButton(button1)
     if button2:
         msg.addButton(button2)
     return msg.exec_()
    def on_about_update(self, text):
        self.add_log("Пришло обновление '{}'".format(text))

        mb = QMessageBox()
        mb.setWindowTitle("Доступно обновление")
        mb.setText("Сейчас доступно обновление")
        mb.setDetailedText(text)
        button_ok = mb.addButton("Обновить", QMessageBox.AcceptRole)
        button_cancel = mb.addButton("Отклонить", QMessageBox.RejectRole)

        mb.exec()

        if mb.clickedButton() == button_cancel:
            self.add_log('Пользователь отказался от обновления...')
            return

        self.add_log('Выполняю обновление...')

        # ...
        # Обновляемся
        # ...

        self.add_log('Обновление поставлено успешно...')
示例#10
0
def InfoDialog(text, button=None, title=None, icon="info"):
    if not title:
        title = _("Information")
    if not button:
        button = _("OK")

    msgBox = QMessageBox()

    buttonOk = msgBox.addButton(button, QMessageBox.ActionRole)

    msgBox.setText(text)

    dialog = Dialog(_(title), msgBox, closeButton = False, isDialog = True, icon = icon)
    dialog.resize(300,120)
    dialog.exec_()
    ctx.mainScreen.processEvents()
示例#11
0
    def close_application(self, event):
        """
        Opens a message box to handle program exit properly asking the user if the project should be saved first.

        Args:
            event(`QCloseEvent`):                   A QCloseEvent

        Returns:
            status_code (`int`):                    0 when process finished correctly, otherwise >0
        """
        self.settings.setValue('display_on_startup',
                               self.qi.display_on_startup)

        msg_box = QMessageBox()
        msg_box.setWindowIcon(
            QtGui.QIcon(
                resource_path(
                    os.path.join("ui", "icons", "pyIMD_logo_icon.ico"))))
        msg_box.setWindowTitle('pyIMD :: Quit Program')
        msg_box.setText(
            'Do you want to save changes before quitting the program?')
        save_btn = QPushButton('Save')
        save_btn.setIcon(QApplication.style().standardIcon(
            QStyle.SP_DialogSaveButton))
        msg_box.addButton(save_btn, QMessageBox.YesRole)
        no_save_btn = QPushButton('Don\'t save')
        no_save_btn.setIcon(QApplication.style().standardIcon(
            QStyle.SP_DialogNoButton))
        msg_box.addButton(no_save_btn, QMessageBox.NoRole)
        abort_btn = QPushButton('Cancel')
        abort_btn.setIcon(QApplication.style().standardIcon(
            QStyle.SP_DialogCancelButton))
        msg_box.addButton(abort_btn, QMessageBox.RejectRole)
        ret = msg_box.exec_()

        if ret == 0:
            self.save_project()
            if not event:
                self.close()
            else:
                event.accept()
        elif ret == 1:
            if not event:
                self.close()
            else:
                event.accept()
        else:
            self.print_to_console("Program quit aborted")
            if not event:
                return
            else:
                event.ignore()
示例#12
0
def InfoDialog(text, button=None, title=None, icon="info"):
    if not title:
        title = _("Information")
    if not button:
        button = _("OK")

    msgBox = QMessageBox()

    buttonOk = msgBox.addButton(button, QMessageBox.ActionRole)

    msgBox.setText(text)

    dialog = Dialog(_(title),
                    msgBox,
                    closeButton=False,
                    isDialog=True,
                    icon=icon)
    dialog.resize(300, 120)
    dialog.exec_()
    ctx.mainScreen.processEvents()
示例#13
0
class MessageWindow:
    def __init__(self, title, text, type="ok", default=None, customButtons =None, customIcon=None, run=True, destroyAfterRun=True, detailed=False, longText=""):
        self.rc = None
        self.dialog = None
        self.msgBox = QMessageBox()
        self.doCustom = False
        self.customButtons = customButtons

        icon  = None
        buttons = None

        if type == 'ok':
            buttons = QMessageBox.Ok
            icon = "question"
        elif type == 'error':
            icon = "error"
            buttons =  QMessageBox.Ok
        elif type == 'warning':
            icon = "warning"
            buttons =  QMessageBox.Ok
        elif type == 'okcancel':
            icon = "question"
            buttons = QMessageBox.Ok | QMessageBox.Cancel
        elif type == 'question':
            icon = "question"
            buttons = QMessageBox.Ok | QMessageBox.Cancel
        elif type == 'yesno':
            icon = "question"
            buttons = QMessageBox.Yes | QMessageBox.No
        elif type == 'custom':
            self.doCustom = True
            if customIcon:
                icon = customIcon
            else:
                icon = "question"

        text = "<qt>%s</qt>" % text.replace("\n", " ")
        self.msgBox.setText(text)
        if detailed:
            self.msgBox.setDetailedText(unicode(longText))

        if self.doCustom:
            button = None
            for index, text in enumerate(self.customButtons):
                button = self.msgBox.addButton(text, QMessageBox.ActionRole)
                if default is not None and default == index:
                    self.msgBox.setDefaultButton(button)
        else:
            self.msgBox.setStandardButtons(buttons)

            if default == "no":
                default = QMessageBox.No
            elif default == "yes":
                default = QMessageBox.Yes
            elif default == "ok":
                default = QMessageBox.Ok
            else:
                default = None

        self.msgBox.setDefaultButton(default)

        self.dialog = Dialog(_(title), self.msgBox, closeButton=False, isDialog=True, icon=icon)
        self.dialog.resize(QSize(0,0))
        if run:
            self.run(destroyAfterRun)

    def run(self, destroyAfterRun=True):
        self.rc = self.dialog.exec_()
        if self.msgBox.clickedButton():
            if not self.doCustom:
                if self.msgBox.clickedButton().text() in [_("Ok"), _("Yes")]:
                    self.rc = 1
                elif self.msgBox.clickedButton().text() in [_("Cancel"), _("No")]:
                    self.rc = 0
            else:
                if self.msgBox.clickedButton().text() in self.customButtons:
                    self.rc = self.customButtons.index(self.msgBox.clickedButton().text())

        if destroyAfterRun:
            self.dialog = None

        return self.rc
示例#14
0
class MessageWindow:
    def __init__(self,
                 title,
                 text,
                 type="ok",
                 default=None,
                 customButtons=None,
                 customIcon=None,
                 run=True,
                 destroyAfterRun=True,
                 detailed=False,
                 longText=""):
        self.rc = None
        self.dialog = None
        self.msgBox = QMessageBox()
        self.doCustom = False
        self.customButtons = customButtons

        icon = None
        buttons = None

        if type == 'ok':
            buttons = QMessageBox.Ok
            icon = "question"
        elif type == 'error':
            icon = "error"
            buttons = QMessageBox.Ok
        elif type == 'warning':
            icon = "warning"
            buttons = QMessageBox.Ok
        elif type == 'okcancel':
            icon = "question"
            buttons = QMessageBox.Ok | QMessageBox.Cancel
        elif type == 'question':
            icon = "question"
            buttons = QMessageBox.Ok | QMessageBox.Cancel
        elif type == 'yesno':
            icon = "question"
            buttons = QMessageBox.Yes | QMessageBox.No
        elif type == 'custom':
            self.doCustom = True
            if customIcon:
                icon = customIcon
            else:
                icon = "question"

        text = "<qt>%s</qt>" % text.replace("\n", " ")
        self.msgBox.setText(text)
        if detailed:
            self.msgBox.setDetailedText(unicode(longText))

        if self.doCustom:
            button = None
            for index, text in enumerate(self.customButtons):
                button = self.msgBox.addButton(text, QMessageBox.ActionRole)
                if default is not None and default == index:
                    self.msgBox.setDefaultButton(button)
        else:
            self.msgBox.setStandardButtons(buttons)

            if default == "no":
                default = QMessageBox.No
            elif default == "yes":
                default = QMessageBox.Yes
            elif default == "ok":
                default = QMessageBox.Ok
            else:
                default = None

        self.msgBox.setDefaultButton(default)

        self.dialog = Dialog(_(title),
                             self.msgBox,
                             closeButton=False,
                             isDialog=True,
                             icon=icon)
        self.dialog.resize(QSize(0, 0))
        if run:
            self.run(destroyAfterRun)

    def run(self, destroyAfterRun=True):
        self.rc = self.dialog.exec_()
        if self.msgBox.clickedButton():
            if not self.doCustom:
                if self.msgBox.clickedButton().text() in [_("Ok"), _("Yes")]:
                    self.rc = 1
                elif self.msgBox.clickedButton().text() in [
                        _("Cancel"), _("No")
                ]:
                    self.rc = 0
            else:
                if self.msgBox.clickedButton().text() in self.customButtons:
                    self.rc = self.customButtons.index(
                        self.msgBox.clickedButton().text())

        if destroyAfterRun:
            self.dialog = None

        return self.rc
示例#15
0
    def valitse_tuki(self):
        '''Tuen valinta.
        Jos tuki on seinästä (tyyppi = 0), kysytään halutaanko vaihtaa.
        Jos haluaa muutetaan tuen grafiikka ja arvo'''

        if Ominaisuudet.palauta_tuen_tyyppi(self) == 0:
            msgBox = QMessageBox()
            msgBox.setText("Haluatko vaihtaa tuen tyyppiä?")
            msgBox.addButton(QPushButton('En'), QMessageBox.NoRole)
            msgBox.addButton(QPushButton('Kyllä'), QMessageBox.YesRole)
            vastaus = msgBox.exec_()
            self.rect.setBrush(QBrush(4))

            if vastaus == 1:
                self.viiva_1.hide()
                self.viiva_2.hide()
                self.viiva_3.hide()
                self.viiva_4.hide()
                self.nayta_tuki_alhaalta()

                if int(Ominaisuudet.onko_ulkoinen_voima_asetettu(self)) == 1:
                    self.viiva.hide()
                    self.nuoli_3.hide()
                    self.viiva_5.show()
                    self.nuoli_6.show()

                Ominaisuudet.tuki(self, 1)
            return
        '''Jos tuki on alhaalta (tyyppi = 1), kysytään halutaanko vaihtaa.
        Jos haluaa muutetaan tuen grafiikka ja arvo'''
        if Ominaisuudet.palauta_tuen_tyyppi(self) == 1:
            msgBox = QMessageBox()
            msgBox.setText("Haluatko vaihtaa tuen tyyppiä?")
            msgBox.addButton(QPushButton('Kyllä'), QMessageBox.YesRole)
            msgBox.addButton(QPushButton('En'), QMessageBox.NoRole)
            vastaus = msgBox.exec_()
            self.rect.setBrush(QBrush(4))

            if vastaus == 0:
                Ominaisuudet.tuki(self, 0)
                self.nuoli_4.hide()
                self.nuoli_5.hide()
                self.nayta_seina_tuki()

                if int(Ominaisuudet.onko_ulkoinen_voima_asetettu(self)) == 1:
                    self.viiva.show()
                    self.nuoli_3.show()
                    self.viiva_5.hide()
                    self.nuoli_6.hide()

            if vastaus == 1:
                pass
        '''Jos tukea ei ole (tyyppi = 2). Tuen tyypin valinta'''
        if Ominaisuudet.palauta_tuen_tyyppi(self) == 2:
            msgBox = QMessageBox()
            msgBox.setText("Valitse tuen tyyppi")
            msgBox.addButton(QPushButton('Seinätuki'), QMessageBox.YesRole)
            msgBox.addButton(QPushButton('Tuki alhaalta'), QMessageBox.NoRole)
            vastaus = msgBox.exec_()
            self.vaihda_tuki.show()
            self.lisaa_tuki.hide()

            if vastaus == 0:
                self.nayta_seina_tuki()
                Ominaisuudet.tuki(self, 0)

            if vastaus == 1:
                self.nayta_tuki_alhaalta()
                Ominaisuudet.tuki(self, 1)
        '''Joka tapauksessa asetetaan ulkoisen voiman lisääminen mahdolliseksi
        sekä maalataan palkki normaaliksi'''
        self.lisaa_ulkoinen_voima.setEnabled(True)
        self.simuloi.setEnabled(True)