Ejemplo n.º 1
0
class DeleteCards(QDialog, Ui_Dialog):
    """Этот класс будет удалять карточки из базы данных"""
    def __init__(self, parent=None):
        super().__init__()
        self.setupUi(self)
        """подключаем базу данных"""
        self.con = sqlite3.connect("quiz.db")
        self.cur = self.con.cursor()
        self.setWindowTitle("Удаление карточек")
        self.par = parent  # родитель
        self.make_list_of_cards()

        self.rejected.connect(self.open_main)  # если он нажмет cancle
        self.accepted.connect(self.open_delete)  # если он нажмет yes
        self.delete_button.clicked.connect(self.delete_checked)

    def open_main(self):
        self.hide()
        self.par.show()

    def open_delete(self):
        self.delete_checked()

    def make_list_of_cards(self):
        """сначала достаем список с характеристиками, и из них создаем класс с карточкой"""
        self.login = self.par.login
        """вытаскиваем id главного сета"""
        self.id = self.cur.execute(
            """SELECT main_set FROM User WHERE login = ? """,
            (self.login, )).fetchone()
        """Достаем все карточки, принадлежащие этому логину"""
        self.card = self.cur.execute(
            """SELECT * FROM Card WHERE sets LIKE ?""",
            (f'{self.id[0]};%', )).fetchall()
        self.all_card = []
        for i in self.card:
            id = i[0]
            image = i[1]
            trans = i[2]
            word = i[3]
            self.all_card.append(Card(word, trans, image, id, True))

        self.fill_in_scroll()

    def fill_in_scroll(self):
        """Эта функция заполняет scrollarea значениями"""
        if self.all_card:
            self.check_box_group = QButtonGroup()
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            j = 0
            self.check_boxs = []
            for i in self.all_card:
                self.wid = QWidget()
                self.check = QCheckBox("Удалить")
                self.check.setObjectName(f"checkbox{j}")
                self.check_boxs.append(self.check)
                """изменяем размер шрифта чекбокса"""
                f = self.check.font()
                f.setPointSize(25)
                self.check.setFont(f)
                self.check.setStyleSheet("""color: rgb(96, 47, 151)""")

                self.vboxlay = QVBoxLayout(self.wid)
                self.vboxlay.addWidget(i)
                self.vboxlay.addWidget(self.check)
                self.layout_SArea.addWidget(self.wid, stretch=1)
                self.vboxlay.addStretch(0)
            self.layout_SArea.addStretch(0)
        else:
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            self.label = QLabel(
                "Упс, тут пока что пусто \nНо вы можете это исправить")
            self.label.setStyleSheet("font: 18pt 'Helvetica';")
            self.layout_SArea.addWidget(self.label)

    def delete_checked(self):
        """Эта функция удаляет выбранные карточки вообще """
        if self.all_card:
            self.active = []
            if self.open_choice():
                """Цикл по перебору значения в группе, и нахождения индексов выбранных"""
                for i in range(len(self.check_boxs)):
                    if self.check_boxs[i].isChecked():
                        self.active.append(i)
                if self.active:
                    for index in self.active:
                        checkbox = self.all_card[index]
                        id_of_check = checkbox.id
                        self.cur.execute("""DELETE FROM Card WHERE id = ?""",
                                         (id_of_check, ))

                    self.con.commit()

                    self.open_succes_bar()
                else:
                    self.open_empty_bar()

            else:
                self.hide()
                self.par.show()
        else:
            self.open_empty_bar()

    def open_empty_bar(self):
        reply = QMessageBox.question(self, 'Пусто',
                                     f"Упс, вы ничего не выбрали",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.show()

    def open_succes_bar(self):
        """При успешном создании пользователя"""
        reply = QMessageBox.question(self, '',
                                     f"Выбранные карточки успешно удалены",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.par.show()
            self.hide()

    def open_choice(self):
        reply = QMessageBox.question(self, '',
                                     "Вы точно хотите удалить эти карточки?",
                                     QMessageBox.Yes | QMessageBox.No,
                                     QMessageBox.No)

        if reply == QMessageBox.Yes:
            return True
        else:
            return False
Ejemplo n.º 2
0
class PasswordLayout:

    titles = [_("Enter Password"), _("Change Password"), _("Enter Passphrase")]

    def __init__(self, wallet, msg, kind, OK_button, *, permit_empty=True):
        self.wallet = wallet

        self.permit_empty = bool(permit_empty)
        self.pw = QLineEdit()
        self.pw.setEchoMode(QLineEdit.Password)
        self.new_pw = QLineEdit()
        self.new_pw.setEchoMode(QLineEdit.Password)
        self.conf_pw = QLineEdit()
        self.conf_pw.setEchoMode(QLineEdit.Password)
        self.kind = kind
        self.OK_button = OK_button
        self.all_lineedits = (self.pw, self.new_pw, self.conf_pw)
        self.pw_strength = None  # Will be a QLabel if kind != PW_PASSPHRASE

        vbox = QVBoxLayout()
        label = QLabel(msg + "\n")
        label.setWordWrap(True)

        grid = QGridLayout()
        grid.setSpacing(8)
        grid.setColumnStretch(1, 1)

        if kind == PW_PASSPHRASE:
            vbox.addWidget(label)
            msgs = [_('Passphrase:'), _('Confirm Passphrase:')]
        else:
            logo_grid = QGridLayout()
            logo_grid.setSpacing(8)
            logo_grid.setColumnMinimumWidth(0, 70)
            logo_grid.setColumnStretch(1, 1)

            logo = QLabel()
            logo.setAlignment(Qt.AlignCenter)

            logo_grid.addWidget(logo, 0, 0)
            logo_grid.addWidget(label, 0, 1, 1, 2)
            vbox.addLayout(logo_grid)

            m1 = _('New Password:'******'Password:'******'Confirm Password:'******'Current Password:'******'Show'))
        f = self.show_cb.font()
        f.setPointSize(f.pointSize() - 1)
        self.show_cb.setFont(f)  # make font -1
        grid.addWidget(self.show_cb, 3, 2, Qt.AlignRight)

        def toggle_show_pws():
            show = self.show_cb.isChecked()
            for le in self.all_lineedits:
                le.setEchoMode(
                    QLineEdit.Password if not show else QLineEdit.Normal)

        self.show_cb.toggled.connect(toggle_show_pws)

        self.encrypt_cb = QCheckBox(_('Encrypt wallet file'))
        self.encrypt_cb.setEnabled(False)
        grid.addWidget(self.encrypt_cb, 4, 0, 1, -1)
        self.encrypt_cb.setVisible(kind != PW_PASSPHRASE)

        def enable_OK():
            ok = bool(self.new_pw.text() == self.conf_pw.text()
                      and (self.new_pw.text() or self.permit_empty))
            OK_button.setEnabled(ok)
            self.encrypt_cb.setEnabled(bool(ok and self.new_pw.text()))

        self.new_pw.textChanged.connect(enable_OK)
        self.conf_pw.textChanged.connect(enable_OK)

        if not self.permit_empty:
            enable_OK()  # force buttons to OFF state initially.

        self.vbox = vbox

    def title(self):
        return self.titles[self.kind]

    def layout(self):
        return self.vbox

    def pw_changed(self):
        if not self.pw_strength:
            return
        password = self.new_pw.text()
        if password:
            colors = {
                "Weak": "Red",
                "Medium": "Blue",
                "Strong": "Green",
                "Very Strong": "Green"
            }
            strength = check_password_strength(password)
            label = (_("Password Strength") + ": " + "<font color=" +
                     colors[strength] + ">" + strength + "</font>")
        else:
            label = ""
        self.pw_strength.setText(label)

    def old_password(self):
        if self.kind == PW_CHANGE:
            return self.pw.text() or None
        return None

    def new_password(self):
        pw = self.new_pw.text()
        # Empty passphrases are fine and returned empty.
        if pw == "" and self.kind != PW_PASSPHRASE:
            pw = None
        return pw
Ejemplo n.º 3
0
class WelcomeUi(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle(self.tr("Welcome Lime GNU/Linux"))
        self.setFixedSize(700, 475)
        self.setWindowIcon(QIcon(":/images/limelinux-welcome.svg"))
        self.setLayout(QVBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet(
            "QPushButton {border: none; text-align:left; color: black;} QLabel {color:black;}"
        )

        x = (QDesktopWidget().width() - self.width()) // 2
        y = (QDesktopWidget().height() - self.height()) // 2
        self.move(x, y)

        #######################
        self.headerWidget = QWidget()
        self.headerWidget.setFixedHeight(80)
        self.headerWidget.setLayout(QHBoxLayout())
        self.headerWidget.setStyleSheet(
            "background-image: url(:/images/background.png);")
        self.layout().addWidget(self.headerWidget)

        self.logoLabel = QLabel()
        self.logoLabel.setFixedSize(64, 64)
        self.logoLabel.setScaledContents(True)
        self.logoLabel.setPixmap(
            QIcon(":/images/lime-white.svg").pixmap(self.logoLabel.size()))
        self.headerWidget.layout().addWidget(self.logoLabel)

        self.pisiLogoLabel = QLabel()
        self.pisiLogoLabel.setFixedSize(157, 48)
        self.pisiLogoLabel.setScaledContents(True)
        self.pisiLogoLabel.setPixmap(QPixmap(":/images/lime.png"))
        self.headerWidget.layout().addWidget(self.pisiLogoLabel)

        self.headerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.versionLabel = QLabel()
        font = self.versionLabel.font()
        font.setPointSize(12)
        self.versionLabel.setFont(font)
        #self.versionLabel.setText("12313 - 31231")
        self.versionLabel.setText("{} - {}".format(
            QSysInfo.productVersion(), QSysInfo.currentCpuArchitecture()))
        self.versionLabel.setStyleSheet("color: #80ff80; font-weight: bold;")
        self.headerWidget.layout().addWidget(self.versionLabel)

        #######################
        self.contentWidget = QWidget()
        self.contentWidget.setLayout(QVBoxLayout())
        self.contentWidget.setStyleSheet("background-color: white; ")
        self.layout().addWidget(self.contentWidget)

        self.descriptionLabel = QLabel()
        self.descriptionLabel.setText(self.tr("Welcome to Lime Linux! Thank you for joining our community!\n\n"\
                                              "As Lime Linux developers, we hope you enjoy using Lime Linux. "\
                                              "The following links will guide you while using Lime Linux. Please do not "\
                                              "hesitate to inform about your experiences, suggestions and errors you have encountered."))
        self.descriptionLabel.setWordWrap(True)
        font = self.descriptionLabel.font()
        font.setFamily("DejaVu Sans")
        font.setPointSize(10)
        self.descriptionLabel.setFont(font)
        self.descriptionLabel.setStyleSheet("color: black;")
        self.contentWidget.layout().addWidget(self.descriptionLabel)

        self.mainLayout = QHBoxLayout()
        self.contentWidget.layout().addLayout(self.mainLayout)

        vlayoutI = QVBoxLayout()

        self.docLabel = QLabel()
        font = self.docLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.docLabel.setFont(font)
        self.docLabel.setAlignment(Qt.AlignHCenter)
        self.docLabel.setText(self.tr("Documents"))
        vlayoutI.addWidget(self.docLabel)

        self.installDocButton = QPushButton()
        self.installDocButton.setFixedWidth(185)
        self.installDocButton.setCursor(Qt.PointingHandCursor)
        self.installDocButton.setText(self.tr("Installation Guide"))
        self.installDocButton.setIcon(QIcon(":/images/guide.svg"))
        self.installDocButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.installDocButton)

        self.releaseButton = QPushButton()
        self.releaseButton.setFixedWidth(185)
        self.releaseButton.setCursor(Qt.PointingHandCursor)
        self.releaseButton.setText(self.tr("Release Notes"))
        self.releaseButton.setIcon(QIcon(":/images/info.svg"))
        self.releaseButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.releaseButton)

        self.wikiButton = QPushButton()
        self.wikiButton.setFixedWidth(185)
        self.wikiButton.setCursor(Qt.PointingHandCursor)
        self.wikiButton.setText(self.tr("Wiki"))
        self.wikiButton.setIcon(QIcon(":/images/wiki.svg"))
        self.wikiButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.wikiButton)

        vlayoutII = QVBoxLayout()

        self.supportLabel = QLabel()
        font = self.supportLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.supportLabel.setFont(font)
        self.supportLabel.setAlignment(Qt.AlignHCenter)
        self.supportLabel.setText(self.tr("Support"))
        vlayoutII.addWidget(self.supportLabel)

        self.forumButton = QPushButton()
        self.forumButton.setFixedWidth(185)
        self.forumButton.setCursor(Qt.PointingHandCursor)
        self.forumButton.setText(self.tr("Forum"))
        self.forumButton.setIconSize(QSize(32, 32))
        self.forumButton.setIcon(QIcon(":/images/forum.svg"))
        vlayoutII.addWidget(self.forumButton)

        self.chatButton = QPushButton()
        self.chatButton.setFixedWidth(185)
        self.chatButton.setCursor(Qt.PointingHandCursor)
        self.chatButton.setText(self.tr("Chat Rooms"))
        self.chatButton.setIcon(QIcon(":/images/chat.svg"))
        self.chatButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.chatButton)

        self.bugsButton = QPushButton()
        self.bugsButton.setFixedWidth(185)
        self.bugsButton.setCursor(Qt.PointingHandCursor)
        self.bugsButton.setText(self.tr("Bug Report"))
        self.bugsButton.setIcon(QIcon(":/images/bocuk.svg"))
        self.bugsButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.bugsButton)

        vlayoutIII = QVBoxLayout()

        self.installLabel = QLabel()
        font = self.installLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.installLabel.setFont(font)
        self.installLabel.setAlignment(Qt.AlignHCenter)
        self.installLabel.setText(self.tr("Installation"))
        vlayoutIII.addWidget(self.installLabel)

        self.useLiliiButton = QPushButton()
        self.useLiliiButton.setFixedWidth(185)
        self.useLiliiButton.setCursor(Qt.PointingHandCursor)
        self.useLiliiButton.setText(self.tr("Start Installation"))
        self.useLiliiButton.setIcon(QIcon.fromTheme("lilii-logo"))
        self.useLiliiButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.useLiliiButton)

        self.getInvolvedButton = QPushButton()
        self.getInvolvedButton.setFixedWidth(185)
        self.getInvolvedButton.setCursor(Qt.PointingHandCursor)
        self.getInvolvedButton.setText(self.tr("Join Us"))
        self.getInvolvedButton.setIcon(QIcon(":/images/joinus.svg"))
        self.getInvolvedButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.getInvolvedButton)

        self.donateButton = QPushButton()
        self.donateButton.setFixedWidth(185)
        self.donateButton.setCursor(Qt.PointingHandCursor)
        self.donateButton.setText(self.tr("Donate"))
        self.donateButton.setIcon(QIcon(":/images/donate.svg"))
        self.donateButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.donateButton)

        self.mainLayout.addLayout(vlayoutI)
        self.mainLayout.addLayout(vlayoutII)
        self.mainLayout.addLayout(vlayoutIII)

        self.noteLabel = QLabel()
        font = self.noteLabel.font()
        font.setPointSize(12)
        font.setBold(True)
        self.noteLabel.setFont(font)
        self.noteLabel.setText(self.tr("Note: The password is \"live\"."))
        self.noteLabel.setAlignment(Qt.AlignHCenter)
        self.contentWidget.layout().addWidget(self.noteLabel)

        #######################
        self.footerWidget = QWidget()
        self.footerWidget.setFixedHeight(50)
        self.footerWidget.setLayout(QHBoxLayout())
        self.footerWidget.setStyleSheet(
            "background-image: url(:/images/background.png);")
        self.layout().addWidget(self.footerWidget)

        self.facebookButton = QPushButton()
        self.facebookButton.setFixedSize(36, 36)
        self.facebookButton.setIconSize(QSize(36, 36))
        self.facebookButton.setIcon(QIcon(":/images/facebook.png"))
        self.facebookButton.setCursor(Qt.PointingHandCursor)
        self.facebookButton.setToolTip(self.tr("Facebook Page"))
        self.footerWidget.layout().addWidget(self.facebookButton)

        self.twitterButton = QPushButton()
        self.twitterButton.setFixedSize(36, 36)
        self.twitterButton.setIconSize(QSize(36, 36))
        self.twitterButton.setIcon(QIcon(":/images/twitter.png"))
        self.twitterButton.setCursor(Qt.PointingHandCursor)
        self.twitterButton.setToolTip(self.tr("Twitter Page"))
        self.footerWidget.layout().addWidget(self.twitterButton)

        self.youtubeButton = QPushButton()
        self.youtubeButton.setFixedSize(36, 36)
        self.youtubeButton.setIconSize(QSize(36, 36))
        self.youtubeButton.setIcon(QIcon(":/images/youtube.png"))
        self.youtubeButton.setCursor(Qt.PointingHandCursor)
        self.youtubeButton.setToolTip(self.tr("Youtube Channel"))
        self.footerWidget.layout().addWidget(self.youtubeButton)

        self.githubButton = QPushButton()
        self.githubButton.setFixedSize(36, 36)
        self.githubButton.setIconSize(QSize(36, 36))
        self.githubButton.setIcon(QIcon(":/images/git.svg"))
        self.githubButton.setCursor(Qt.PointingHandCursor)
        self.githubButton.setToolTip(self.tr("GitHub Page"))
        self.footerWidget.layout().addWidget(self.githubButton)

        self.footerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.openCheckBox = QCheckBox()
        self.openCheckBox.setChecked(
            os.path.exists(
                os.path.join(os.environ["HOME"], ".config", "autostart",
                             "limelinux-welcome.desktop")))
        font = self.openCheckBox.font()
        font.setBold(True)
        self.openCheckBox.setFont(font)
        self.openCheckBox.setText(self.tr("Show on startup"))
        self.openCheckBox.setStyleSheet("color: #80ff80;")
        self.footerWidget.layout().addWidget(self.openCheckBox)

        self.facebookButton.clicked.connect(self.facebookPage)
        self.youtubeButton.clicked.connect(self.youtubePage)
        self.twitterButton.clicked.connect(self.twitterPage)
        self.githubButton.clicked.connect(self.githubPage)

        self.installDocButton.clicked.connect(self.installedDoc)
        self.releaseButton.clicked.connect(self.releaseNote)
        self.wikiButton.clicked.connect(self.wikiPage)
        self.forumButton.clicked.connect(self.forumPage)
        self.chatButton.clicked.connect(self.chatPages)
        self.getInvolvedButton.clicked.connect(self.involvedPage)
        self.donateButton.clicked.connect(self.donatePage)
        self.openCheckBox.clicked.connect(self.openState)
        self.bugsButton.clicked.connect(self.issuePage)

    def setSystem(self, type):
        if type == "live":
            self.useLiliiButton.clicked.connect(self.liliiExec)

        else:
            self.useLiliiButton.setText(self.tr("Start Driver Manager"))
            self.useLiliiButton.setIcon(QIcon(":/images/limelinux-dm.svg"))
            self.useLiliiButton.clicked.connect(self.driverManagerExec)
            self.installLabel.setText(self.tr("Project"))
            self.noteLabel.hide()
            self.contentWidget.layout().addItem(
                QSpacerItem(20, 50, QSizePolicy.Expanding,
                            QSizePolicy.Minimum))

    def facebookPage(self):
        QDesktopServices.openUrl(QUrl("https://www.facebook.com/LimeLinux/"))

    def twitterPage(self):
        QDesktopServices.openUrl(QUrl("https://twitter.com/limelinux"))

    def githubPage(self):
        QDesktopServices.openUrl(QUrl("https://github.com/limelinux"))

    def youtubePage(self):
        QDesktopServices.openUrl(
            QUrl("https://www.youtube.com/channel/UCCYADWqop8p9wH6UbKWFFgg"))

    def installedDoc(self):
        QProcess.startDetached(
            "xdg-open /usr/share/limelinux-welcome/data/limelinux-install-doc.pdf"
        )

    def releaseNote(self):
        pass

    def wikiPage(self):
        QDesktopServices.openUrl(QUrl("http://wiki.limelinux.com"))

    def forumPage(self):
        QDesktopServices.openUrl(QUrl("http://forum.limelinux.com"))

    def chatPages(self):
        QDesktopServices.openUrl(
            QUrl("https://kiwiirc.com/client/irc.freenode.net/#limelinux"))

    def liliiExec(self):
        QProcess.startDetached("sudo lilii &")

    def driverManagerExec(self):
        QProcess.startDetached("limelinux-dm &")

    def involvedPage(self):
        QDesktopServices.openUrl(QUrl("http://www.limelinux.com/iletisim/"))

    def donatePage(self):
        QDesktopServices.openUrl(QUrl("https://www.patreon.com/limelinux"))

    def issuePage(self):
        QDesktopServices.openUrl(
            QUrl("https://github.com/limelinux/packages/issues/new"))

    def openState(self):
        if self.openCheckBox.isChecked():
            try:
                shutil.copy(
                    "/usr/share/limelinux-welcome/data/limelinux-welcome.desktop",
                    os.path.join(os.environ["HOME"], ".config", "autostart"))

            except FileNotFoundError as err:
                print(err)

        else:
            try:
                os.remove(
                    os.path.join(os.environ["HOME"], ".config", "autostart",
                                 "limelinux-welcome.desktop"))

            except OSError as err:
                print(err)
Ejemplo n.º 4
0
class welcomeui(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle(self.tr("Welcome Pisi GNU/Linux"))
        self.setFixedSize(700, 475)
        self.setWindowIcon(QIcon(":/images/pisilinux-welcome.svg"))
        self.setLayout(QVBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet("QPushButton {border: none; text-align: left; color:black;} QLabel {color:black;}")

        x = (QDesktopWidget().width() - self.width()) // 2
        y = (QDesktopWidget().height() - self.height()) // 2
        self.move(x, y)

        # The header code:

        self.headerWidget = QWidget()
        self.headerWidget.setFixedHeight(80)
        self.headerWidget.setLayout(QHBoxLayout())
        self.headerWidget.setStyleSheet("background-image:url(:/images/background.png);")
        self.layout().addWidget(self.headerWidget)

        self.pisiWhiteLogo = QLabel()
        self.pisiWhiteLogo.setFixedSize(64, 64)
        self.pisiWhiteLogo.setScaledContents(True)
        self.pisiWhiteLogo.setPixmap(
            QIcon(":/images/pisi-white.svg").pixmap(self.pisiWhiteLogo.size()))
        self.headerWidget.layout().addWidget(self.pisiWhiteLogo)

        self.pisiTextLabel = QLabel()
        self.pisiTextLabel.setFixedSize(157, 48)
        self.pisiTextLabel.setScaledContents(True)
        self.pisiTextLabel.setPixmap(QPixmap(":/images/pisi-text.png"))
        self.headerWidget.layout().addWidget(self.pisiTextLabel)

        self.headerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.versionLabel = QLabel()
        font = self.versionLabel.font()
        font.setPointSize(12)
        self.versionLabel.setFont(font)
        self.versionLabel.setText(
            "{} - {}".format(
                QSysInfo.productVersion(), QSysInfo.currentCpuArchitecture()))
        self.versionLabel.setStyleSheet("color: white; font-weight: bold;")
        self.headerWidget.layout().addWidget(self.versionLabel)

        # The middle area code:

        self.contentWidget = QWidget()
        self.contentWidget.setLayout(QVBoxLayout())
        self.contentWidget.setStyleSheet("background-color: white;")
        self.layout().addWidget(self.contentWidget)

        self.meetingLabel = QLabel()
        self.meetingLabel.setText(
            self.tr("Welcome to Pisi GNU/Linux!"
                    " Thank you for joining our community!\n\n"
                    "As Pisi GNU/Linux developers,"
                    " we hope you enjoy using Pisi GNU/Linux."
                    " The following links will guide you while"
                    " using Pisi GNU/Linux. Please do not"
                    " hesitate to inform about your experiences,"
                    " suggestions and errors you have encountered."))

        self.meetingLabel.setWordWrap(True)
        font = self.meetingLabel.font()
        font.setPointSize(10)
        self.meetingLabel.setFont(font)
        self.meetingLabel.setAlignment(Qt.AlignHCenter)
        self.meetingLabel.setStyleSheet("color: black;")
        self.contentWidget.layout().addWidget(self.meetingLabel)

        self.mainLayout = QHBoxLayout()
        self.contentWidget.layout().addLayout(self.mainLayout)

        vlayoutI = QVBoxLayout()

        self.docsHeader = QLabel()
        font = self.docsHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.docsHeader.setFont(font)
        self.docsHeader.setAlignment(Qt.AlignHCenter)
        self.docsHeader.setText(self.tr("Documents"))
        vlayoutI.addWidget(self.docsHeader)

        self.installationDocButton = QPushButton()
        self.installationDocButton.setFixedWidth(160)
        self.installationDocButton.setCursor(Qt.PointingHandCursor)
        self.installationDocButton.setText(self.tr("Installation Guide"))
        self.installationDocButton.setIcon(QIcon(':/images/guide.svg'))
        self.installationDocButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.installationDocButton)

        self.releaseNotesButton = QPushButton()
        self.releaseNotesButton.setFixedWidth(160)
        self.releaseNotesButton.setCursor(Qt.PointingHandCursor)
        self.releaseNotesButton.setText(self.tr("Release Notes"))
        self.releaseNotesButton.setIcon(QIcon(':/images/info.svg'))
        self.releaseNotesButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.releaseNotesButton)

        self.wikiButton = QPushButton()
        self.wikiButton.setFixedWidth(160)
        self.wikiButton.setCursor(Qt.PointingHandCursor)
        self.wikiButton.setText(self.tr("Pisi GNU/Linux Wiki"))
        self.wikiButton.setIcon(QIcon(':/images/wikipedia-logo.svg'))
        self.wikiButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.wikiButton)

        vlayoutII = QVBoxLayout()

        self.supportHeader = QLabel()
        font = self.supportHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.supportHeader.setFont(font)
        self.supportHeader.setAlignment(Qt.AlignHCenter)
        self.supportHeader.setText(self.tr("Support"))
        vlayoutII.addWidget(self.supportHeader)

        self.forumButton = QPushButton()
        self.forumButton.setFixedWidth(160)
        self.forumButton.setCursor(Qt.PointingHandCursor)
        self.forumButton.setText(self.tr("Forum"))
        self.forumButton.setIconSize(QSize(32, 32))
        self.forumButton.setIcon(QIcon(':/images/forum.svg'))
        vlayoutII.addWidget(self.forumButton)

        self.chatButton = QPushButton()
        self.chatButton.setFixedWidth(160)
        self.chatButton.setCursor(Qt.PointingHandCursor)
        self.chatButton.setText(self.tr("Chat Rooms"))
        self.chatButton.setIcon(QIcon(':/images/chat.svg'))
        self.chatButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.chatButton)

        self.bugsButton = QPushButton()
        self.bugsButton.setFixedWidth(160)
        self.bugsButton.setCursor(Qt.PointingHandCursor)
        self.bugsButton.setText(self.tr("Bug Report"))
        self.bugsButton.setIcon(QIcon(':/images/bug.svg'))
        self.bugsButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.bugsButton)

        vlayoutIII = QVBoxLayout()

        self.installationHeader = QLabel()
        font = self.installationHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.installationHeader.setFont(font)
        self.installationHeader.setAlignment(Qt.AlignHCenter)
        self.installationHeader.setText(self.tr("Installation"))
        vlayoutIII.addWidget(self.installationHeader)

        # TODO: Also for YALI
        self.calamaresButton = QPushButton()
        self.calamaresButton.setFixedWidth(160)
        self.calamaresButton.setCursor(Qt.PointingHandCursor)
        self.calamaresButton.setText(self.tr("Start Installation"))
        self.calamaresButton.setIcon(QIcon(':/images/calamares.svg'))
        self.calamaresButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.calamaresButton)

        self.joinUsButton = QPushButton()
        self.joinUsButton.setFixedWidth(160)
        self.joinUsButton.setCursor(Qt.PointingHandCursor)
        self.joinUsButton.setText(self.tr("Join Us"))
        self.joinUsButton.setIcon(QIcon(':/images/joinus.svg'))
        self.joinUsButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.joinUsButton)

        self.donateButton = QPushButton()
        self.donateButton.setFixedWidth(160)
        self.donateButton.setCursor(Qt.PointingHandCursor)
        self.donateButton.setText(self.tr("Ev"))
        self.donateButton.setIcon(QIcon(':/images/ev.svg'))
        self.donateButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.donateButton)

        self.mainLayout.addLayout(vlayoutI)
        self.mainLayout.addLayout(vlayoutII)
        self.mainLayout.addLayout(vlayoutIII)

        self.noteLabel = QLabel()
        font = self.noteLabel.font()
        font.setPointSize(12)
        font.setBold(True)
        self.noteLabel.setFont(font)
        self.noteLabel.setText(self.tr("Note: The password is \"live\"."))
        self.noteLabel.setAlignment(Qt.AlignHCenter)
        self.noteLabel.setMinimumSize(250, 50)
        self.noteLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
        self.contentWidget.layout().addWidget(self.noteLabel)

        # The footer code:

        self.footerWidget = QWidget()
        self.footerWidget.setFixedHeight(50)
        self.footerWidget.setLayout(QHBoxLayout())
        self.footerWidget.setStyleSheet(
            "background-image: url(:/images//background.png);")
        self.layout().addWidget(self.footerWidget)

        self.facebookButton = QPushButton()
        self.facebookButton.setFixedSize(36, 36)
        self.facebookButton.setIconSize(QSize(36, 36))
        self.facebookButton.setIcon(QIcon(':/images/facebook.svg'))
        self.facebookButton.setCursor(Qt.PointingHandCursor)
        self.facebookButton.setToolTip(self.tr("Facebook Page"))
        self.footerWidget.layout().addWidget(self.facebookButton)

        self.twitterButton = QPushButton()
        self.twitterButton.setFixedSize(36, 36)
        self.twitterButton.setIconSize(QSize(36, 36))
        self.twitterButton.setIcon(QIcon(':/images/twitter.svg'))
        self.twitterButton.setCursor(Qt.PointingHandCursor)
        self.twitterButton.setToolTip(self.tr("Twitter Page"))
        self.footerWidget.layout().addWidget(self.twitterButton)

        self.googleButton = QPushButton()
        self.googleButton.setFixedSize(36, 36)
        self.googleButton.setIconSize(QSize(36, 36))
        self.googleButton.setIcon(QIcon(':/images/google-plus.svg'))
        self.googleButton.setCursor(Qt.PointingHandCursor)
        self.googleButton.setToolTip(self.tr("Google+ Page"))
        self.footerWidget.layout().addWidget(self.googleButton)

        self.instagramButton = QPushButton()
        self.instagramButton.setFixedSize(36, 36)
        self.instagramButton.setIconSize(QSize(36, 36))
        self.instagramButton.setIcon(QIcon(':/images/instagram.svg'))
        self.instagramButton.setCursor(Qt.PointingHandCursor)
        self.instagramButton.setToolTip(self.tr("Instagram Page"))
        self.footerWidget.layout().addWidget(self.instagramButton)

        self.githubButton = QPushButton()
        self.githubButton.setFixedSize(36, 36)
        self.githubButton.setIconSize(QSize(36, 36))
        self.githubButton.setIcon(QIcon(':/images/github-logo.svg'))
        self.githubButton.setCursor(Qt.PointingHandCursor)
        self.githubButton.setToolTip(self.tr("GitHub Page"))
        self.footerWidget.layout().addWidget(self.githubButton)

        self.footerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.startupCheckBox = QCheckBox()
        self.startupCheckBox.setChecked(
            os.path.exists(os.path.join(os.environ["HOME"],
                                        ".config",
                                        "autostart",
                                        "pisilinux-welcome.desktop")))
        font = self.startupCheckBox.font()
        font.setBold(True)
        self.startupCheckBox.setFont(font)
        self.startupCheckBox.setText(self.tr("Show on startup"))
        self.startupCheckBox.setStyleSheet("color: white;")
        self.footerWidget.layout().addWidget(self.startupCheckBox)

        self.facebookButton.clicked.connect(self.facebookPage)
        self.twitterButton.clicked.connect(self.twitterPage)
        self.googleButton.clicked.connect(self.googlePage)
        self.instagramButton.clicked.connect(self.instagramPage)
        self.githubButton.clicked.connect(self.githubPage)

        self.releaseNotesButton.clicked.connect(self.releaseNotes)
        self.wikiButton.clicked.connect(self.wikiPage)
        self.forumButton.clicked.connect(self.forumPage)
        self.chatButton.clicked.connect(self.chatPages)
        self.joinUsButton.clicked.connect(self.joinUsPage)
        self.donateButton.clicked.connect(self.homePage)
        self.startupCheckBox.clicked.connect(self.startupState)
        self.bugsButton.clicked.connect(self.issuesPage)

    def setSystem(self, type):
        if type == "live":
            self.installationDocButton.clicked.connect(self.installationDocument)

            # TODO: Also for YALI
            self.calamaresButton.clicked.connect(self.calamaresExec)

        else:
            self.installationDocButton.setText(self.tr("Pisi Guide"))
            self.installationDocButton.clicked.connect(self.installationDocument)

            self.installationHeader.setText(self.tr("Project"))

            # TODO: Also for YALI
            self.calamaresButton.setText(self.tr("Start Kaptan"))
            self.calamaresButton.setIcon(QIcon(':/images/kaptan.svg'))
            self.calamaresButton.clicked.connect(self.kaptanExec)

            self.noteLabel.hide()
            self.contentWidget.layout().addItem(
                QSpacerItem(20, 50, QSizePolicy.Expanding, QSizePolicy.Minimum))

    def open_url(self, url):
        webbrowser.get('firefox').open(url)

    def facebookPage(self):
        self.open_url("https://www.facebook.com/Pisilinux/")

    def twitterPage(self):
        self.open_url("https://twitter.com/pisilinux")

    def googlePage(self):
        self.open_url("https://plus.google.com/communities/113565681602860915332")

    def instagramPage(self):
        self.open_url("https://www.instagram.com/pisilinux/")

    def githubPage(self):
        self.open_url("https://github.com/pisilinux")

    def installationDocument(self):
        self.open_url("https://pisilinux.org/wiki/cont/53-pisi-linux-kurulum.html")

    def releaseNotes(self):
        self.open_url("/usr/share/welcome/data/media-content/index.html")

    def wikiPage(self):
        self.open_url("https://pisilinux.org/wiki")

    def forumPage(self):
        self.open_url("https://pisilinux.org/forum")

    def chatPages(self):
        self.open_url("https://gitter.im/Pisi-GNU-Linux/Lobby")

    def joinUsPage(self):
        self.open_url("http://www.pisilinux.org/iletisim/")

    def homePage(self):
        self.open_url("http://www.pisilinux.org")

    # TODO: Also for YALI
    def calamaresExec(self):
        QProcess.startDetached("sudo LC_ALL=en_US calamares &")

    def kaptanExec(self):
        QProcess.startDetached("kaptan &")

    def issuesPage(self):
        self.open_url("https://github.com/pisilinux/main/issues/new")

    def startupState(self):
        if self.startupCheckBox.isChecked():
            try:
                shutil.copy("/usr/share/applications/pisilinux-welcome.desktop",
                            os.path.join(os.environ["HOME"],
                                         ".config", "autostart"))

            except OSError as err:
                print(err)

        else:
            try:
                os.remove(
                    os.path.join(
                        os.environ["HOME"], ".config", "autostart",
                        "pisilinux-welcome.desktop"))

            except OSError as err:
                print(err)
Ejemplo n.º 5
0
class WelcomeUi(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle(self.tr("Welcome Pisi Linux"))
        self.setFixedSize(700, 475)
        self.setWindowIcon(QIcon(":/images/pisilinux-welcome.svg"))
        self.setLayout(QVBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet(
            "QPushButton {border: none; text-align:left; color: black;} QLabel {color:black;}"
        )

        x = (QDesktopWidget().width() - self.width()) // 2
        y = (QDesktopWidget().height() - self.height()) // 2
        self.move(x, y)

        #######################
        self.headerWidget = QWidget()
        self.headerWidget.setFixedHeight(80)
        self.headerWidget.setLayout(QHBoxLayout())
        self.headerWidget.setStyleSheet(
            "background-image: url(:/images/background.png);")
        self.layout().addWidget(self.headerWidget)

        self.logoLabel = QLabel()
        self.logoLabel.setFixedSize(64, 64)
        self.logoLabel.setScaledContents(True)
        self.logoLabel.setPixmap(
            QIcon(":/images/pisi-white.svg").pixmap(self.logoLabel.size()))
        self.headerWidget.layout().addWidget(self.logoLabel)

        self.pisiLogoLabel = QLabel()
        self.pisiLogoLabel.setFixedSize(157, 48)
        self.pisiLogoLabel.setScaledContents(True)
        self.pisiLogoLabel.setPixmap(QPixmap(":/images/pisi.png"))
        self.headerWidget.layout().addWidget(self.pisiLogoLabel)

        self.headerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.versionLabel = QLabel()
        font = self.versionLabel.font()
        font.setPointSize(12)
        self.versionLabel.setFont(font)
        self.versionLabel.setText("{} - {}".format(
            QSysInfo.productVersion(), QSysInfo.currentCpuArchitecture()))
        self.versionLabel.setStyleSheet("color: white; font-weight: bold;")
        self.headerWidget.layout().addWidget(self.versionLabel)

        #######################
        self.contentWidget = QWidget()
        self.contentWidget.setLayout(QVBoxLayout())
        self.contentWidget.setStyleSheet("background-color: white; ")
        self.layout().addWidget(self.contentWidget)

        self.descriptionLabel = QLabel()
        self.descriptionLabel.setText(self.tr("Welcome to Pisi Linux! Thank you for joining our community!\n\n"\
                                              "As Pisi Linux developers, we hope you enjoy using Pisi Linux. "\
                                              "The following links will guide you while using Pisi Linux. Please do not "\
                                              "hesitate to inform about your experiences, suggestions and errors you have encountered."))
        self.descriptionLabel.setWordWrap(True)
        font = self.descriptionLabel.font()
        font.setFamily("DejaVu Sans")
        font.setPointSize(10)
        self.descriptionLabel.setFont(font)
        self.descriptionLabel.setStyleSheet("color: black;")
        self.contentWidget.layout().addWidget(self.descriptionLabel)

        self.mainLayout = QHBoxLayout()
        self.contentWidget.layout().addLayout(self.mainLayout)

        vlayoutI = QVBoxLayout()

        self.docLabel = QLabel()
        font = self.docLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.docLabel.setFont(font)
        self.docLabel.setAlignment(Qt.AlignHCenter)
        self.docLabel.setText(self.tr("Documents"))
        vlayoutI.addWidget(self.docLabel)

        self.installDocButton = QPushButton()
        self.installDocButton.setFixedWidth(150)
        self.installDocButton.setCursor(Qt.PointingHandCursor)
        self.installDocButton.setText(self.tr("Installation Guide"))
        self.installDocButton.setIcon(QIcon(":/images/guide.svg"))
        self.installDocButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.installDocButton)

        self.releaseButton = QPushButton()
        self.releaseButton.setFixedWidth(135)
        self.releaseButton.setCursor(Qt.PointingHandCursor)
        self.releaseButton.setText(self.tr("Release Notes"))
        self.releaseButton.setIcon(QIcon(":/images/info.svg"))
        self.releaseButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.releaseButton)

        self.wikiButton = QPushButton()
        self.wikiButton.setFixedWidth(150)
        self.wikiButton.setCursor(Qt.PointingHandCursor)
        self.wikiButton.setText(self.tr("Pisi Linux Wiki"))
        self.wikiButton.setIcon(QIcon(":/images/wiki.svg"))
        self.wikiButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.wikiButton)

        vlayoutII = QVBoxLayout()

        self.supportLabel = QLabel()
        font = self.supportLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.supportLabel.setFont(font)
        self.supportLabel.setAlignment(Qt.AlignHCenter)
        self.supportLabel.setText(self.tr("Support"))
        vlayoutII.addWidget(self.supportLabel)

        self.forumButton = QPushButton()
        self.forumButton.setFixedWidth(150)
        self.forumButton.setCursor(Qt.PointingHandCursor)
        self.forumButton.setText(self.tr("Forum"))
        self.forumButton.setIconSize(QSize(32, 32))
        self.forumButton.setIcon(QIcon(":/images/forum.svg"))
        vlayoutII.addWidget(self.forumButton)

        self.chatButton = QPushButton()
        self.chatButton.setFixedWidth(150)
        self.chatButton.setCursor(Qt.PointingHandCursor)
        self.chatButton.setText(self.tr("Chat Rooms"))
        self.chatButton.setIcon(QIcon(":/images/chat.svg"))
        self.chatButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.chatButton)

        self.bugsButton = QPushButton()
        self.bugsButton.setFixedWidth(150)
        self.bugsButton.setCursor(Qt.PointingHandCursor)
        self.bugsButton.setText(self.tr("Bug Report"))
        self.bugsButton.setIcon(QIcon(":/images/bocuk.svg"))
        self.bugsButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.bugsButton)

        vlayoutIII = QVBoxLayout()

        self.installLabel = QLabel()
        font = self.installLabel.font()
        font.setPointSize(14)
        font.setBold(True)
        self.installLabel.setFont(font)
        self.installLabel.setAlignment(Qt.AlignHCenter)
        self.installLabel.setText(self.tr("Installation"))
        vlayoutIII.addWidget(self.installLabel)

        self.useKalamarButton = QPushButton()
        self.useKalamarButton.setFixedWidth(150)
        self.useKalamarButton.setCursor(Qt.PointingHandCursor)
        self.useKalamarButton.setText(self.tr("Start Installation"))
        self.useKalamarButton.setIcon(QIcon(":/images/calamares.svg"))
        self.useKalamarButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.useKalamarButton)

        self.getInvolvedButton = QPushButton()
        self.getInvolvedButton.setFixedWidth(150)
        self.getInvolvedButton.setCursor(Qt.PointingHandCursor)
        self.getInvolvedButton.setText(self.tr("Join Us"))
        self.getInvolvedButton.setIcon(QIcon(":/images/joinus.svg"))
        self.getInvolvedButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.getInvolvedButton)

        self.donateButton = QPushButton()
        self.donateButton.setFixedWidth(150)
        self.donateButton.setCursor(Qt.PointingHandCursor)
        self.donateButton.setText(self.tr("Donate"))
        self.donateButton.setIcon(QIcon(":/images/donate.svg"))
        self.donateButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.donateButton)

        self.mainLayout.addLayout(vlayoutI)
        self.mainLayout.addLayout(vlayoutII)
        self.mainLayout.addLayout(vlayoutIII)

        self.noteLabel = QLabel()
        font = self.noteLabel.font()
        font.setPointSize(12)
        font.setBold(True)
        self.noteLabel.setFont(font)
        self.noteLabel.setText(self.tr("Note: The password is \"live\"."))
        self.noteLabel.setAlignment(Qt.AlignHCenter)
        self.contentWidget.layout().addWidget(self.noteLabel)

        #######################
        self.footerWidget = QWidget()
        self.footerWidget.setFixedHeight(50)
        self.footerWidget.setLayout(QHBoxLayout())
        self.footerWidget.setStyleSheet(
            "background-image: url(:/images/background.png);")
        self.layout().addWidget(self.footerWidget)

        self.facebookButton = QPushButton()
        self.facebookButton.setFixedSize(36, 36)
        self.facebookButton.setIconSize(QSize(36, 36))
        self.facebookButton.setIcon(QIcon(":/images/facebook.png"))
        self.facebookButton.setCursor(Qt.PointingHandCursor)
        self.facebookButton.setToolTip(self.tr("Facebook Page"))
        self.footerWidget.layout().addWidget(self.facebookButton)

        self.googleButton = QPushButton()
        self.googleButton.setFixedSize(36, 36)
        self.googleButton.setIconSize(QSize(36, 36))
        self.googleButton.setIcon(QIcon(":/images/google.png"))
        self.googleButton.setCursor(Qt.PointingHandCursor)
        self.googleButton.setToolTip(self.tr("Google+ Page"))
        self.footerWidget.layout().addWidget(self.googleButton)

        self.twitterButton = QPushButton()
        self.twitterButton.setFixedSize(36, 36)
        self.twitterButton.setIconSize(QSize(36, 36))
        self.twitterButton.setIcon(QIcon(":/images/twitter.png"))
        self.twitterButton.setCursor(Qt.PointingHandCursor)
        self.twitterButton.setToolTip(self.tr("Twitter Page"))
        self.footerWidget.layout().addWidget(self.twitterButton)

        self.githubButton = QPushButton()
        self.githubButton.setFixedSize(36, 36)
        self.githubButton.setIconSize(QSize(36, 36))
        self.githubButton.setIcon(QIcon(":/images/git.svg"))
        self.githubButton.setCursor(Qt.PointingHandCursor)
        self.githubButton.setToolTip(self.tr("GitHub Page"))
        self.footerWidget.layout().addWidget(self.githubButton)

        self.footerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.openCheckBox = QCheckBox()
        self.openCheckBox.setChecked(
            os.path.exists(
                os.path.join(os.environ["HOME"], ".config", "autostart",
                             "pisilinux-welcome.desktop")))
        font = self.openCheckBox.font()
        font.setBold(True)
        self.openCheckBox.setFont(font)
        self.openCheckBox.setText(self.tr("Show on startup"))
        self.openCheckBox.setStyleSheet("color: white;")
        self.footerWidget.layout().addWidget(self.openCheckBox)

        self.facebookButton.clicked.connect(self.facebookPage)
        self.googleButton.clicked.connect(self.googlePage)
        self.twitterButton.clicked.connect(self.twitterPage)
        self.githubButton.clicked.connect(self.githubPage)

        self.installDocButton.clicked.connect(self.installedDoc)
        self.releaseButton.clicked.connect(self.releaseNote)
        self.wikiButton.clicked.connect(self.wikiPage)
        self.forumButton.clicked.connect(self.forumPage)
        self.chatButton.clicked.connect(self.chatPages)
        self.getInvolvedButton.clicked.connect(self.involvedPage)
        self.donateButton.clicked.connect(self.donatePage)
        self.openCheckBox.clicked.connect(self.openState)
        self.bugsButton.clicked.connect(self.issuePage)

    def setSystem(self, type):
        if type == "live":
            self.useKalamarButton.clicked.connect(self.calamaresExec)

        else:
            self.useKalamarButton.setText(self.tr("Start Kaptan"))
            self.useKalamarButton.setIcon(QIcon(":/images/kaptan.svg"))
            self.useKalamarButton.clicked.connect(self.kaptanExec)
            self.installLabel.setText(self.tr("Project"))
            self.noteLabel.hide()
            self.contentWidget.layout().addItem(
                QSpacerItem(20, 50, QSizePolicy.Expanding,
                            QSizePolicy.Minimum))

    def facebookPage(self):
        QDesktopServices.openUrl(QUrl("https://www.facebook.com/Pisilinux/"))

    def googlePage(self):
        QDesktopServices.openUrl(
            QUrl("https://plus.google.com/communities/113565681602860915332"))

    def twitterPage(self):
        QDesktopServices.openUrl(QUrl("https://twitter.com/pisilinux"))

    def githubPage(self):
        QDesktopServices.openUrl(QUrl("https://github.com/pisilinux"))

    def installedDoc(self):
        QProcess.startDetached(
            "xdg-open /usr/share/welcome/data/pisilinux-2-0-kurulum-belgesi.pdf"
        )

    def releaseNote(self):
        pass

    def wikiPage(self):
        QDesktopServices.openUrl(QUrl("http://wiki.pisilinux.org"))

    def forumPage(self):
        QDesktopServices.openUrl(QUrl("http://forum.pisilinux.org"))

    def chatPages(self):
        QDesktopServices.openUrl(QUrl("http://pisi.slack.com"))
        QDesktopServices.openUrl(QUrl("http://www.pisilinux.org/irc-2/"))

    def calamaresExec(self):
        QProcess.startDetached("sudo LC_ALL=en_US calamares &")

    def kaptanExec(self):
        QProcess.startDetached("kaptan &")

    def involvedPage(self):
        QDesktopServices.openUrl(QUrl("http://www.pisilinux.org/iletisim/"))

    def donatePage(self):
        QDesktopServices.openUrl(
            QUrl(
                "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AS4PKA7HH38PE"
            ))

    def issuePage(self):
        QDesktopServices.openUrl(
            QUrl("https://github.com/pisilinux/main/issues/new"))

    def openState(self):
        if self.openCheckBox.isChecked():
            try:
                shutil.copy(
                    "/usr/share/welcome/data/pisilinux-welcome.desktop",
                    os.path.join(os.environ["HOME"], ".config", "autostart"))

            except FileNotFoundError as err:
                print(err)

        else:
            try:
                os.remove(
                    os.path.join(os.environ["HOME"], ".config", "autostart",
                                 "pisilinux-welcome.desktop"))

            except OSError as err:
                print(err)
Ejemplo n.º 6
0
class welcomeui(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.setWindowTitle(self.tr("Welcome Pisi GNU/Linux"))
        self.setFixedSize(700, 475)
        self.setWindowIcon(QIcon(":/images/pisilinux-welcome.svg"))
        self.setLayout(QVBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet(
            "QPushButton {border: none; text-align: left; color:black;} QLabel {color:black;}"
        )

        x = (QDesktopWidget().width() - self.width()) // 2
        y = (QDesktopWidget().height() - self.height()) // 2
        self.move(x, y)

        # The header code:

        self.headerWidget = QWidget()
        self.headerWidget.setFixedHeight(80)
        self.headerWidget.setLayout(QHBoxLayout())
        self.headerWidget.setStyleSheet(
            "background-image:url(:/images/background.png);")
        self.layout().addWidget(self.headerWidget)

        self.pisiWhiteLogo = QLabel()
        self.pisiWhiteLogo.setFixedSize(64, 64)
        self.pisiWhiteLogo.setScaledContents(True)
        self.pisiWhiteLogo.setPixmap(
            QIcon(":/images/pisi-white.svg").pixmap(self.pisiWhiteLogo.size()))
        self.headerWidget.layout().addWidget(self.pisiWhiteLogo)

        self.pisiTextLabel = QLabel()
        self.pisiTextLabel.setFixedSize(157, 48)
        self.pisiTextLabel.setScaledContents(True)
        self.pisiTextLabel.setPixmap(QPixmap(":/images/pisi-text.png"))
        self.headerWidget.layout().addWidget(self.pisiTextLabel)

        self.headerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.versionLabel = QLabel()
        font = self.versionLabel.font()
        font.setPointSize(12)
        self.versionLabel.setFont(font)
        self.versionLabel.setText("{} - {}".format(
            QSysInfo.productVersion(), QSysInfo.currentCpuArchitecture()))
        self.versionLabel.setStyleSheet("color: white; font-weight: bold;")
        self.headerWidget.layout().addWidget(self.versionLabel)

        # The middle area code:

        self.contentWidget = QWidget()
        self.contentWidget.setLayout(QVBoxLayout())
        self.contentWidget.setStyleSheet("background-color: white;")
        self.layout().addWidget(self.contentWidget)

        self.meetingLabel = QLabel()
        self.meetingLabel.setText(
            self.tr("Welcome to Pisi GNU/Linux!"
                    " Thank you for joining our community!\n\n"
                    "As Pisi GNU/Linux developers,"
                    " we hope you enjoy using Pisi GNU/Linux."
                    " The following links will guide you while"
                    " using Pisi GNU/Linux. Please do not"
                    " hesitate to inform about your experiences,"
                    " suggestions and errors you have encountered."))

        self.meetingLabel.setWordWrap(True)
        font = self.meetingLabel.font()
        font.setPointSize(10)
        self.meetingLabel.setFont(font)
        self.meetingLabel.setAlignment(Qt.AlignHCenter)
        self.meetingLabel.setStyleSheet("color: black;")
        self.contentWidget.layout().addWidget(self.meetingLabel)

        self.mainLayout = QHBoxLayout()
        self.contentWidget.layout().addLayout(self.mainLayout)

        vlayoutI = QVBoxLayout()

        self.docsHeader = QLabel()
        font = self.docsHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.docsHeader.setFont(font)
        self.docsHeader.setAlignment(Qt.AlignHCenter)
        self.docsHeader.setText(self.tr("Documents"))
        vlayoutI.addWidget(self.docsHeader)

        self.installationDocButton = QPushButton()
        self.installationDocButton.setFixedWidth(160)
        self.installationDocButton.setCursor(Qt.PointingHandCursor)
        self.installationDocButton.setText(self.tr("Installation Guide"))
        self.installationDocButton.setIcon(QIcon(':/images/guide.svg'))
        self.installationDocButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.installationDocButton)

        self.releaseNotesButton = QPushButton()
        self.releaseNotesButton.setFixedWidth(160)
        self.releaseNotesButton.setCursor(Qt.PointingHandCursor)
        self.releaseNotesButton.setText(self.tr("Release Notes"))
        self.releaseNotesButton.setIcon(QIcon(':/images/info.svg'))
        self.releaseNotesButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.releaseNotesButton)

        self.wikiButton = QPushButton()
        self.wikiButton.setFixedWidth(160)
        self.wikiButton.setCursor(Qt.PointingHandCursor)
        self.wikiButton.setText(self.tr("Pisi GNU/Linux Wiki"))
        self.wikiButton.setIcon(QIcon(':/images/wikipedia-logo.svg'))
        self.wikiButton.setIconSize(QSize(32, 32))
        vlayoutI.addWidget(self.wikiButton)

        vlayoutII = QVBoxLayout()

        self.supportHeader = QLabel()
        font = self.supportHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.supportHeader.setFont(font)
        self.supportHeader.setAlignment(Qt.AlignHCenter)
        self.supportHeader.setText(self.tr("Support"))
        vlayoutII.addWidget(self.supportHeader)

        self.forumButton = QPushButton()
        self.forumButton.setFixedWidth(160)
        self.forumButton.setCursor(Qt.PointingHandCursor)
        self.forumButton.setText(self.tr("Forum"))
        self.forumButton.setIconSize(QSize(32, 32))
        self.forumButton.setIcon(QIcon(':/images/forum.svg'))
        vlayoutII.addWidget(self.forumButton)

        self.chatButton = QPushButton()
        self.chatButton.setFixedWidth(160)
        self.chatButton.setCursor(Qt.PointingHandCursor)
        self.chatButton.setText(self.tr("Chat Rooms"))
        self.chatButton.setIcon(QIcon(':/images/chat.svg'))
        self.chatButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.chatButton)

        self.bugsButton = QPushButton()
        self.bugsButton.setFixedWidth(160)
        self.bugsButton.setCursor(Qt.PointingHandCursor)
        self.bugsButton.setText(self.tr("Bug Report"))
        self.bugsButton.setIcon(QIcon(':/images/bug.svg'))
        self.bugsButton.setIconSize(QSize(32, 32))
        vlayoutII.addWidget(self.bugsButton)

        vlayoutIII = QVBoxLayout()

        self.installationHeader = QLabel()
        font = self.installationHeader.font()
        font.setPointSize(14)
        font.setBold(True)
        self.installationHeader.setFont(font)
        self.installationHeader.setAlignment(Qt.AlignHCenter)
        self.installationHeader.setText(self.tr("Installation"))
        vlayoutIII.addWidget(self.installationHeader)

        # TODO: Also for YALI
        self.calamaresButton = QPushButton()
        self.calamaresButton.setFixedWidth(160)
        self.calamaresButton.setCursor(Qt.PointingHandCursor)
        self.calamaresButton.setText(self.tr("Start Installation"))
        self.calamaresButton.setIcon(QIcon(':/images/calamares.svg'))
        self.calamaresButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.calamaresButton)

        self.joinUsButton = QPushButton()
        self.joinUsButton.setFixedWidth(160)
        self.joinUsButton.setCursor(Qt.PointingHandCursor)
        self.joinUsButton.setText(self.tr("Join Us"))
        self.joinUsButton.setIcon(QIcon(':/images/joinus.svg'))
        self.joinUsButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.joinUsButton)

        self.donateButton = QPushButton()
        self.donateButton.setFixedWidth(160)
        self.donateButton.setCursor(Qt.PointingHandCursor)
        self.donateButton.setText(self.tr("Ev"))
        self.donateButton.setIcon(QIcon(':/images/ev.svg'))
        self.donateButton.setIconSize(QSize(32, 32))
        vlayoutIII.addWidget(self.donateButton)

        self.mainLayout.addLayout(vlayoutI)
        self.mainLayout.addLayout(vlayoutII)
        self.mainLayout.addLayout(vlayoutIII)

        self.noteLabel = QLabel()
        font = self.noteLabel.font()
        font.setPointSize(12)
        font.setBold(True)
        self.noteLabel.setFont(font)
        self.noteLabel.setText(self.tr("Note: The password is \"live\"."))
        self.noteLabel.setAlignment(Qt.AlignHCenter)
        self.noteLabel.setMinimumSize(250, 50)
        self.noteLabel.setSizePolicy(QSizePolicy.Expanding,
                                     QSizePolicy.Maximum)
        self.contentWidget.layout().addWidget(self.noteLabel)

        # The footer code:

        self.footerWidget = QWidget()
        self.footerWidget.setFixedHeight(50)
        self.footerWidget.setLayout(QHBoxLayout())
        self.footerWidget.setStyleSheet(
            "background-image: url(:/images//background.png);")
        self.layout().addWidget(self.footerWidget)

        self.facebookButton = QPushButton()
        self.facebookButton.setFixedSize(36, 36)
        self.facebookButton.setIconSize(QSize(36, 36))
        self.facebookButton.setIcon(QIcon(':/images/facebook.svg'))
        self.facebookButton.setCursor(Qt.PointingHandCursor)
        self.facebookButton.setToolTip(self.tr("Facebook Page"))
        self.footerWidget.layout().addWidget(self.facebookButton)

        self.twitterButton = QPushButton()
        self.twitterButton.setFixedSize(36, 36)
        self.twitterButton.setIconSize(QSize(36, 36))
        self.twitterButton.setIcon(QIcon(':/images/twitter.svg'))
        self.twitterButton.setCursor(Qt.PointingHandCursor)
        self.twitterButton.setToolTip(self.tr("Twitter Page"))
        self.footerWidget.layout().addWidget(self.twitterButton)

        self.googleButton = QPushButton()
        self.googleButton.setFixedSize(36, 36)
        self.googleButton.setIconSize(QSize(36, 36))
        self.googleButton.setIcon(QIcon(':/images/google-plus.svg'))
        self.googleButton.setCursor(Qt.PointingHandCursor)
        self.googleButton.setToolTip(self.tr("Google+ Page"))
        self.footerWidget.layout().addWidget(self.googleButton)

        self.instagramButton = QPushButton()
        self.instagramButton.setFixedSize(36, 36)
        self.instagramButton.setIconSize(QSize(36, 36))
        self.instagramButton.setIcon(QIcon(':/images/instagram.svg'))
        self.instagramButton.setCursor(Qt.PointingHandCursor)
        self.instagramButton.setToolTip(self.tr("Instagram Page"))
        self.footerWidget.layout().addWidget(self.instagramButton)

        self.githubButton = QPushButton()
        self.githubButton.setFixedSize(36, 36)
        self.githubButton.setIconSize(QSize(36, 36))
        self.githubButton.setIcon(QIcon(':/images/github-logo.svg'))
        self.githubButton.setCursor(Qt.PointingHandCursor)
        self.githubButton.setToolTip(self.tr("GitHub Page"))
        self.footerWidget.layout().addWidget(self.githubButton)

        self.footerWidget.layout().addItem(
            QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))

        self.startupCheckBox = QCheckBox()
        self.startupCheckBox.setChecked(
            os.path.exists(
                os.path.join(os.environ["HOME"], ".config", "autostart",
                             "pisilinux-welcome.desktop")))
        font = self.startupCheckBox.font()
        font.setBold(True)
        self.startupCheckBox.setFont(font)
        self.startupCheckBox.setText(self.tr("Show on startup"))
        self.startupCheckBox.setStyleSheet("color: white;")
        self.footerWidget.layout().addWidget(self.startupCheckBox)

        self.facebookButton.clicked.connect(self.facebookPage)
        self.twitterButton.clicked.connect(self.twitterPage)
        self.googleButton.clicked.connect(self.googlePage)
        self.instagramButton.clicked.connect(self.instagramPage)
        self.githubButton.clicked.connect(self.githubPage)

        self.releaseNotesButton.clicked.connect(self.releaseNotes)
        self.wikiButton.clicked.connect(self.wikiPage)
        self.forumButton.clicked.connect(self.forumPage)
        self.chatButton.clicked.connect(self.chatPages)
        self.joinUsButton.clicked.connect(self.joinUsPage)
        self.donateButton.clicked.connect(self.homePage)
        self.startupCheckBox.clicked.connect(self.startupState)
        self.bugsButton.clicked.connect(self.issuesPage)

    def setSystem(self, type):
        if type == "live":
            self.installationDocButton.clicked.connect(
                self.installationDocument)

            # TODO: Also for YALI
            self.calamaresButton.clicked.connect(self.calamaresExec)

        else:
            self.installationDocButton.setText(self.tr("Pisi Guide"))
            self.installationDocButton.clicked.connect(
                self.installationDocument)

            self.installationHeader.setText(self.tr("Project"))

            # TODO: Also for YALI
            self.calamaresButton.setText(self.tr("Start Kaptan"))
            self.calamaresButton.setIcon(QIcon(':/images/kaptan.svg'))
            self.calamaresButton.clicked.connect(self.kaptanExec)

            self.noteLabel.hide()
            self.contentWidget.layout().addItem(
                QSpacerItem(20, 50, QSizePolicy.Expanding,
                            QSizePolicy.Minimum))

    def open_url(self, url):
        webbrowser.get('firefox').open(url)

    def facebookPage(self):
        self.open_url("https://www.facebook.com/Pisilinux/")

    def twitterPage(self):
        self.open_url("https://twitter.com/pisilinux")

    def googlePage(self):
        self.open_url(
            "https://plus.google.com/communities/113565681602860915332")

    def instagramPage(self):
        self.open_url("https://www.instagram.com/pisilinux/")

    def githubPage(self):
        self.open_url("https://github.com/pisilinux")

    def installationDocument(self):
        self.open_url(
            "https://pisilinux.org/wiki/cont/53-pisi-linux-kurulum.html")

    def releaseNotes(self):
        self.open_url("/usr/share/welcome/data/media-content/index.html")

    def wikiPage(self):
        self.open_url("https://pisilinux.org/wiki")

    def forumPage(self):
        self.open_url("https://pisilinux.org/forum")

    def chatPages(self):
        self.open_url("https://gitter.im/Pisi-GNU-Linux/Lobby")

    def joinUsPage(self):
        self.open_url("http://www.pisilinux.org/iletisim/")

    def homePage(self):
        self.open_url("http://www.pisilinux.org")

    # TODO: Also for YALI
    def calamaresExec(self):
        QProcess.startDetached("sudo LC_ALL=en_US calamares &")

    def kaptanExec(self):
        QProcess.startDetached("kaptan &")

    def issuesPage(self):
        self.open_url("https://github.com/pisilinux/main/issues/new")

    def startupState(self):
        if self.startupCheckBox.isChecked():
            try:
                shutil.copy(
                    "/usr/share/applications/pisilinux-welcome.desktop",
                    os.path.join(os.environ["HOME"], ".config", "autostart"))

            except OSError as err:
                print(err)

        else:
            try:
                os.remove(
                    os.path.join(os.environ["HOME"], ".config", "autostart",
                                 "pisilinux-welcome.desktop"))

            except OSError as err:
                print(err)
Ejemplo n.º 7
0
class EditSet(QDialog, Ui_Dialog):
    """Этот класс изменяет сет"""
    def __init__(self, parent=None):
        super().__init__()
        self.setupUi(self)
        """подключаем базу данных"""
        self.con = sqlite3.connect("quiz.db")
        self.cur = self.con.cursor()
        self.setWindowTitle("Редактирование сета")
        self.par = parent  # родитель
        self.head_label.setText(f"Редактирование сета: {self.par.name}")
        self.rejected.connect(self.open_parent)  # если он нажмет cancle
        self.accepted.connect(self.open_parent)  # если он нажмет yes
        self.make_list_of_cards()
        self.choose_all_button.clicked.connect(
            self.choose_all)  # подключаем кнопку выбора всех карточек
        self.delete_set_button.clicked.connect(
            self.before_the_deliion)  # подключаем кнопку удаления сета
        self.save_editions_button.clicked.connect(self.count)

    def count(self):
        """Считает количество активированных"""

        count = 0
        for i in self.check_boxs:
            if i.isChecked():
                count += 1
        if count > 0:
            self.change()
        elif count == 0:
            self.before_the_deliion()

    def choose_all(self):
        """Делает все чекбоксы нажатыми"""
        for i in self.check_boxs:
            i.setChecked(True)

    def delete_set(self):
        """Удаляет данный сет целиком"""
        self.cur.execute("""DELETE FROM Sets WHERE id = ?""",
                         (self.par.id_of_set, ))
        self.con.commit()
        self.par.fill_in()
        self.open_succes_bar()

    def change(self):
        """Эта функция уже меняет сам сет"""
        num = 0
        for i in self.check_boxs:
            id_of_card = self.all_card[num].id
            self.sets = self.cur.execute(
                """SELECT sets FROM Card WHERE id = ?""",
                (id_of_card, )).fetchone()[0]
            if i.isChecked():
                """Если чекбокс активен"""
                """Дальше есть два варианта, был ли он изначально там, либо нет"""
                if not f"{self.par.id_of_set};" in self.sets:
                    self.sets += f"{self.par.id_of_set};"

            else:
                """Если она не была выбрана"""
                if f"{self.par.id_of_set};" in self.sets:
                    self.sets = self.sets.split(";")
                    self.sets = [
                        i for i in self.sets if i != str(self.par.id_of_set)
                    ]
                    self.sets = ";".join(self.sets)

            num += 1
            """Вносим изменения и созраняем их"""
            self.cur.execute(
                """UPDATE Card
                                               SET sets = ?
                                               WHERE id = ?""",
                (self.sets, id_of_card))

            self.con.commit()
        self.open_succes_bar_after_changing()

    def make_list_of_cards(self):
        """сначала достаем список с характеристиками, и из них создаем класс с карточкой"""
        self.login = self.par.login
        """вытаскиваем id главного сета"""
        self.id = self.cur.execute(
            """SELECT main_set FROM User WHERE login = ? """,
            (self.login, )).fetchone()
        """Достаем все карточки, принадлежащие этому логину"""
        self.card = self.cur.execute(
            """SELECT * FROM Card WHERE sets LIKE ?""",
            (f'{self.id[0]};%', )).fetchall()
        self.all_card = []
        for i in self.card:
            id = i[0]
            image = i[1]
            trans = i[2]
            word = i[3]
            self.all_card.append(Card(word, trans, image, id, True))

        self.fill_in_scroll()

    def fill_in_scroll(self):
        """Эта функция заполняет scrollarea значениями"""
        if self.all_card:
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            j = 0
            self.check_boxs = []
            for i in self.all_card:
                self.wid = QWidget()
                self.check = QCheckBox("Выбрать")
                self.check.setObjectName(f"checkbox{j}")
                self.check.setStyleSheet("""color: rgb(96, 47, 151)""")
                self.check_boxs.append(self.check)
                self.sets_of_this_card = self.cur.execute(
                    """SELECT sets FROM Card WHERE id = ?""",
                    (i.id, )).fetchone()
                self.sets_of_this_card = self.sets_of_this_card[
                    0]  # все сеты, к которым принадлежит карточкаданная
                if f"{self.par.id_of_set}" in self.sets_of_this_card:
                    """Если она изначально была в этом сете, то надо будет сделать чекбокс сразу активным"""
                    self.check.setChecked(True)
                """изменяем размер шрифта чекбокса"""
                f = self.check.font()
                f.setPointSize(25)
                self.check.setFont(f)

                self.vboxlay = QVBoxLayout(self.wid)
                self.vboxlay.addWidget(i)
                self.vboxlay.addWidget(self.check)
                self.layout_SArea.addWidget(self.wid, stretch=1)
                self.vboxlay.addStretch(0)
            self.layout_SArea.addStretch(0)
        else:
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            self.layout_SArea.addWidget(
                QLabel("Упс, тут пока что пусто, но вы можете это исправить"))

    def before_the_deliion(self):
        reply = QMessageBox.question(self, '',
                                     "Вы точно хотите удалить этот набор?",
                                     QMessageBox.Yes | QMessageBox.No,
                                     QMessageBox.No)

        if reply == QMessageBox.Yes:
            self.delete_set()

    def open_succes_bar(self):
        """При успешномудалении сета"""
        reply = QMessageBox.question(self, '', f"Сет успешно удален",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.par.show()
            self.hide()

    def open_succes_bar_after_changing(self):
        """после успешного обновления сета"""
        reply = QMessageBox.question(self, '', f"Сет успешно обновлен",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            pass

    def open_parent(self):
        self.hide()
        self.par.show()
Ejemplo n.º 8
0
class CreateNewSet(QDialog, Ui_Dialog):
    """Этот класс будет создавать новый сет из карточек с уникальным названием"""
    def __init__(self, parent=None):
        super().__init__()
        self.setupUi(self)
        """подключаем базу данных"""
        self.con = sqlite3.connect("quiz.db")
        self.cur = self.con.cursor()
        self.setWindowTitle("Создание нового набора карточек")
        self.par = parent  # родитель

        self.rejected.connect(self.open_main)  # если он нажмет cancle
        self.accepted.connect(self.open_main)  # если он нажмет yes
        self.create_button.clicked.connect(self.create_set)
        self.make_list_of_cards()

    def open_main(self):
        self.hide()
        self.par.show()

    def make_list_of_cards(self):
        """сначала достаем список с характеристиками, и из них создаем класс с карточкой"""
        self.login = self.par.login
        """вытаскиваем id главного сета"""
        self.id = self.cur.execute(
            """SELECT main_set FROM User WHERE login = ? """,
            (self.login, )).fetchone()
        """Достаем все карточки, принадлежащие этому логину"""
        self.card = self.cur.execute(
            """SELECT * FROM Card WHERE sets LIKE ?""",
            (f'{self.id[0]};%', )).fetchall()
        self.all_card = []
        for i in self.card:
            id = i[0]
            image = i[1]
            trans = i[2]
            word = i[3]
            self.all_card.append(Card(word, trans, image, id, True))

        self.fill_in_scroll()

    def fill_in_scroll(self):
        """Эта функция заполняет scrollarea значениями"""
        if self.all_card:
            self.check_box_group = QButtonGroup()
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            j = 0
            self.check_boxs = []
            for i in self.all_card:
                self.wid = QWidget()
                self.check = QCheckBox("Выбрать")
                self.check.setObjectName(f"checkbox{j}")
                self.check_boxs.append(self.check)
                """изменяем размер шрифта чекбокса"""
                f = self.check.font()
                f.setPointSize(25)
                self.check.setFont(f)

                self.check.setStyleSheet("""color: rgb(96, 47, 151)""")

                self.vboxlay = QVBoxLayout(self.wid)
                self.vboxlay.addWidget(i)
                self.vboxlay.addWidget(self.check)
                self.layout_SArea.addWidget(self.wid, stretch=1)
                self.vboxlay.addStretch(0)
            self.layout_SArea.addStretch(0)
        else:
            self.widget = QWidget()

            self.all_cards.setWidget(self.widget)
            self.layout_SArea = QHBoxLayout(self.widget)
            self.label = QLabel(
                "Упс, тут пока что пусто \nНо вы можете это исправить")
            self.label.setStyleSheet("font: 18pt 'Helvetica';")
            self.layout_SArea.addWidget(self.label)

    def take_activated_checkbox(self):
        """Эта функция добывает классы тех карточек, которые были выбраны"""
        if self.all_card:
            self.active = []
            if self.open_choice():
                """Цикл по перебору значения в группе, и нахождения индексов выбранных"""
                for i in range(len(self.check_boxs)):
                    if self.check_boxs[i].isChecked():
                        self.active.append(i)
                if self.active:
                    self.active_cards = [
                    ]  # в нем будут хранится экземпляры выбранных классов
                    for i in self.active:
                        self.active_cards.append(self.all_card[i])
                    """Тут будет функция создания, куда будут помещены нужные карточки из списка, искать их будем по id"""
                else:
                    self.open_empty_bar()

            else:
                self.hide()
                self.par.show()
        else:
            self.open_empty_bar()

    def not_unique(self):
        """Вызывает окошко, что имя сета не является уникальным и нужно придумать другое имя"""
        reply = QMessageBox.question(
            self, 'Ошибка',
            f"Сет с таким именем уже имеется, придумайте другое",
            QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.title_of_sets()

    def title_of_sets(self):
        """Запрашиваект название сета, и если оно уникальное, продолжает"""
        self.name, ok_pressed = QInputDialog.getText(
            self, "Новая карточка", "Введите название набора")
        if ok_pressed and self.name:
            names = self.cur.execute(
                """SELECT id FROM Sets WHERE login = ? AND title = ?""",
                (self.par.login, self.name)).fetchall()
            if names:
                self.not_unique()
        else:
            reply = QMessageBox.question(
                self, 'М',
                "Вы не ввели название, хотите вернуться к выбору карточек?",
                QMessageBox.Yes | QMessageBox.No)

            if reply == QMessageBox.Yes:
                pass
            else:
                self.title_of_sets()

    def add_set_in_db(self):
        """Добавляем новый сет в БД и возвращаем его новый id"""
        self.cur.execute("""INSERT INTO Sets(title, login) VALUES (?, ?)""",
                         (self.name, self.par.login))
        return self.cur.execute(
            """SELECT id FROM Sets WHERE login = ? and title = ?""",
            (self.par.login, self.name)).fetchone()[0]

    def create_set(self):
        """Тут все сливается и содается новый сет"""
        self.take_activated_checkbox()

        if self.all_card and self.active:
            self.title_of_sets()
            self.id_of_set = self.add_set_in_db()
            """Добавляем каждому выбранному элементу принадлежность к этому сету"""
            for i in self.active_cards:
                id_of_card = i.id
                self.sets_of_card = \
                    self.cur.execute("""SELECT sets FROM Card WHERE id = ?""", (id_of_card,)).fetchone()[0]
                self.sets_of_card += f"{self.id_of_set};"
                self.cur.execute(
                    """UPDATE Card
                                            SET sets = ?
                                            WHERE id = ?""",
                    (self.sets_of_card, id_of_card))

                self.con.commit()
            self.open_succes_bar()

    def open_empty_bar(self):
        reply = QMessageBox.question(self, '', f"Упс, вы ничего не выбрали",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.show()

    def open_succes_bar(self):
        """При успешном создании нового сета"""
        reply = QMessageBox.question(self, '',
                                     f"Сет {self.name} успешно создан",
                                     QMessageBox.Yes)

        if reply == QMessageBox.Yes:
            self.par.fill_in()
            self.par.show()
            self.hide()

    def open_choice(self):
        """Тут будет выбор картчек"""
        return True