borg-qt/borg_qt/main_window.py

49 lines
1.5 KiB
Python
Raw Normal View History

2019-01-23 21:34:08 +01:00
import os
import sys
2019-01-23 21:34:08 +01:00
from PyQt5 import uic
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import QMainWindow
from config import Config
from helper import BorgException, show_error
2019-01-23 21:34:08 +01:00
class MainWindow(QMainWindow):
2019-01-27 14:49:31 +01:00
"""The main window of the application. It provides the various functions to
control BorgBackup."""
2019-01-23 21:34:08 +01:00
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
QCoreApplication.setApplicationName("borg-qt")
2019-01-27 14:49:31 +01:00
# Load the UI file to get the dialogs layout.
2019-01-23 21:34:08 +01:00
dir_path = os.path.dirname(os.path.realpath(__file__))
ui_path = os.path.join(dir_path + '/static/UI/MainWindow.ui')
uic.loadUi(ui_path, self)
2019-01-27 14:49:31 +01:00
# Set the window title after the UI has been loaded. Otherwise it gets
# overwritten.
self.setWindowTitle("Borg-Qt")
2019-01-23 21:34:08 +01:00
2019-01-27 14:49:31 +01:00
# Create a Config object for storing the configuration.
2019-01-23 21:34:08 +01:00
self.config = Config()
2019-01-27 14:49:31 +01:00
# Connecting actions and buttons.
2019-01-23 21:34:08 +01:00
self.action_settings.triggered.connect(self.show_settings)
def start(self):
2019-01-27 14:49:31 +01:00
"""This method is intendet to be used only once at the application
start. It reads the configuration file and sets the required
environment variables."""
try:
self.config.read()
self.config._set_environment_variables()
except BorgException as e:
show_error(e)
sys.exit(1)
2019-01-23 21:34:08 +01:00
def show_settings(self):
2019-01-27 14:49:31 +01:00
"""Display the settings dialog."""
2019-01-23 21:34:08 +01:00
self.config.set_form_values()
self.config.exec_()