#!/usr/bin/env python3 """ project: Backuppy version: 0.9 file: install_gui.py summary: python installer-script in GUI-mode (needs PySide2) """ # Standard library imports import os # Third party imports from PySide2 import QtWidgets # local imports from install import EXCLUDE_FILE, EMAIL from utils import set_language, get_lang_text, LANG_EN, LANG_DE class BackuppyWizard(QtWidgets.QWizard): def __init__(self, parent=None, mydir=os.getcwd(), exclude_file=EXCLUDE_FILE): super().__init__(parent) # init instance variables self.mydir = mydir self.exclude_file = exclude_file self.exclude = None self.sourcedir = None self.targetdir = None self.rsync_cmd = None self.setWindowTitle(get_lang_text("intromsg1")) self.addPage(Page01(self)) self.addPage(Page02(self)) self.addPage(Page03(self)) self.addPage(Page04(self)) self.addPage(Page05(self)) self.addPage(Page06(self)) self.addPage(Page07(self)) self.addPage(Page08(self)) self.addPage(Page09(self)) self.addPage(Page10(self)) self.resize(640, 480) class Page01(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.label = QtWidgets.QLabel(get_lang_text("welcome")) self.comboBox = QtWidgets.QComboBox(self) self.comboBox.addItem(LANG_EN) self.comboBox.addItem(LANG_DE) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) layout.addWidget(self.comboBox) self.setLayout(layout) def validatePage(self): set_language(self.comboBox.currentText()) return True class Page02(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) self.setLayout(layout) def initializePage(self): self.setWindowTitle(get_lang_text("intromsg1")) self.label1.setText(get_lang_text("languagepack")) self.label2.setText(get_lang_text("intromsg2")) class Page03(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label = QtWidgets.QLabel() self.groupbox = QtWidgets.QGroupBox() self.groupbox.setFlat(True) self.radio1 = QtWidgets.QRadioButton() self.radio2 = QtWidgets.QRadioButton() vbox = QtWidgets.QVBoxLayout() vbox.addWidget(self.radio1) vbox.addWidget(self.radio2) vbox.addStretch(1) self.groupbox.setLayout(vbox) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) layout.addWidget(self.groupbox) self.setLayout(layout) def initializePage(self): self.label.setText(get_lang_text("excludefile1")) self.radio1.setText(get_lang_text("Yes")) self.radio2.setText(get_lang_text("No")) self.radio1.setChecked(True) def validatePage(self): if self.radio1.isChecked(): self.parent.exclude = True else: self.parent.exclude = False return True class Page04(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label) self.setLayout(layout) def initializePage(self): if self.parent.exclude: self.label.setText(get_lang_text("excludefile2")) else: self.label.setText(get_lang_text("excludefile3")) class Page05(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() self.efSourceDir = QtWidgets.QLineEdit() self.pbBrowse = QtWidgets.QPushButton("Browse") self.pbBrowse.clicked.connect(self.on_pbBrowse_clicked) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) hLayout = QtWidgets.QHBoxLayout() hLayout.addWidget(self.efSourceDir) hLayout.addWidget(self.pbBrowse) layout.addLayout(hLayout) self.setLayout(layout) def initializePage(self): self.label1.setText(get_lang_text("srcdir1")) self.label2.setText(get_lang_text("srcdir2")) def on_pbBrowse_clicked(self): options = QtWidgets.QFileDialog.Options() | QtWidgets.QFileDialog.ShowDirsOnly dirName = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory", None, options) self.efSourceDir.setText(dirName) def validatePage(self): self.parent.sourcedir = self.efSourceDir.text() return True class Page06(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() self.label3 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) layout.addWidget(self.label3) self.setLayout(layout) def initializePage(self): self.label1.setText(get_lang_text("srcdir3_1")) bold_text = f"

{self.parent.sourcedir}

" self.label2.setText(bold_text) self.label3.setText(get_lang_text("srcdir3_2")) class Page07(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label1 = QtWidgets.QLabel() self.efTargetDir = QtWidgets.QLineEdit() self.pbBrowse = QtWidgets.QPushButton("Browse") self.pbBrowse.clicked.connect(self.on_pbBrowse_clicked) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) hLayout = QtWidgets.QHBoxLayout() hLayout.addWidget(self.efTargetDir) hLayout.addWidget(self.pbBrowse) layout.addLayout(hLayout) self.setLayout(layout) def initializePage(self): self.label1.setText(get_lang_text("targetdir1")) def on_pbBrowse_clicked(self): options = QtWidgets.QFileDialog.Options() | QtWidgets.QFileDialog.ShowDirsOnly dirName = QtWidgets.QFileDialog.getExistingDirectory(self, "Select Directory", None, options) self.efTargetDir.setText(dirName) def validatePage(self): self.parent.targetdir = self.efTargetDir.text() return True class Page08(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() self.label3 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) layout.addWidget(self.label3) self.setLayout(layout) def initializePage(self): self.label1.setText(get_lang_text("targetdir2_1")) bold_text = f"

{self.parent.targetdir}

" self.label2.setText(bold_text) self.label3.setText(get_lang_text("targetdir2_2")) def validatePage(self): exclude_file = os.path.join(self.parent.mydir, self.parent.exclude_file) self.parent.rsync_cmd = f"rsync -aqp --exclude-from={exclude_file} {self.parent.sourcedir} {self.parent.targetdir}" return True class Page09(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.parent = parent self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) self.setLayout(layout) def initializePage(self): self.label1.setText(get_lang_text("collect")) bold_text = f"

{self.parent.rsync_cmd}

" self.label2.setText(bold_text) class Page10(QtWidgets.QWizardPage): def __init__(self, parent=None): super().__init__(parent) self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() self.label3 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) layout.addWidget(self.label3) self.setLayout(layout) self.setFinalPage(True) def initializePage(self): self.label1.setText(get_lang_text("outro1")) self.label2.setText(get_lang_text("outro2")) global EMAIL urlLink = f"{EMAIL}" self.label3.setText(urlLink) self.label3.setOpenExternalLinks(True) def validatePage(self): return True def main_install_gui(mydir, exclude_file): app = QtWidgets.QApplication() wizard = BackuppyWizard(parent=None, mydir=mydir, exclude_file=exclude_file) wizard.show() app.exec_() return True, wizard.exclude, wizard.rsync_cmd if __name__ == '__main__': is_finalized, is_exclude, rsync_cmd = main_install_gui(mydir=os.getcwd(), exclude_file=EXCLUDE_FILE)