示例#1
0
    def __init__(self):
        LoginWindow.QtGui.QDialog.__init__(self)
        LoginWindow.Ui_LoginWIndow.__init__(self)
        self.setupUi(self)

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()

        self.queries = DatabaseQueries(self.app_dir)
        self.setFixedSize(self.size())  # Prevent resizing

        # Hide password entry (show asterisks)
        self.LoginWindowPasswordEdit.setEchoMode(QLineEdit.Password)

        # Disable the OK button at first.
        self.buttonBox.button(
            LoginWindow.QtGui.QDialogButtonBox.Ok).setEnabled(False)

        # Enable the "OK" button once user has entered text into fields
        self.LoginWindowUsernameEdit.textChanged.connect(
            self.line_edit_text_changed)
        self.LoginWindowPasswordEdit.textChanged.connect(
            self.line_edit_text_changed)

        # Handle button clicks
        self.RegisterNewUserButton.clicked.connect(
            self.handle_register_button_clicked)

        ## handle "OK" clicked in buttonbox
        self.buttonBox.button(
            LoginWindow.QtGui.QDialogButtonBox.Ok).clicked.connect(
                self.handle_login)
示例#2
0
    def __init__(self):
        super(AddTaskWindow, self).__init__()
        NewTaskForm.QtGui.QDialog.__init__(self)
        NewTaskForm.Ui_Dialog.__init__(self)
        self.setupUi(self)

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        self.new_task_name = self.TaskLineEdit.text()
        self.all_projects = self.queries.get_all_projects()
        self.all_tasks = self.queries.query_all_tasks(
        )  # For blocker/blockee selection

        for project in self.all_projects:
            self.ProjectComboBox.addItem(project[1])

        # TODO: Allow setting of "None" in blockers & blockees. (Make this the default for each)
        for task in self.all_tasks:  # TODO: prevent crossing blockers and blockees
            self.BlockedByComboBox.addItem(task[1])
            self.BlocksComboBox.addItem(task[1])

        # Handle OK button click
        self.buttonBox.button(NewTaskForm.QtGui.QDialogButtonBox.Ok).clicked. \
            connect(self.create_new_task)
示例#3
0
    def __init__(self):
        ivcs_mainwindow.QtGui.QMainWindow.__init__(self)
        ivcs_mainwindow.Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.image_extensions = []

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        self.setFixedSize(self.size())  # Prevent resizing

        if not os.path.exists(os.path.join(self.app_dir, 'ivcs.ini')):
            logging.warning(
                "Couldn't find configuration file at {}, after it should have been "
                "automatically created.".format(self.app_dir))

            # Disable all GUI elements until a branch is set and scanned
            self.RemoteChangesListView.setEnabled(False)
            self.LocalFileListVIew.setEnabled(False)
            self.RemoteChangesListView.setEnabled(False)
            self.LocalChangesListView.setEnabled(False)

            self.CheckoutButton.setEnabled(False)
            self.ViewRemoteCommitButton.setEnabled(False)
            self.CommitButton.setEnabled(False)
            self.PushButton.setEnabled(False)

        else:

            # Enable multiple selection
            self.RemoteFileListView.setSelectionMode(
                QAbstractItemView.ExtendedSelection)
            self.LocalFileListVIew.setSelectionMode(
                QAbstractItemView.ExtendedSelection)
            # Load current settings
            self.config_file_path = os.path.join(self.app_dir, 'ivcs.ini')
            self.config = configparser.ConfigParser()
            self.config.read(self.config_file_path)

            self.change_detection_method = self.config.get(
                "settings", "changedetectmethod")
            self.username = self.config.get("settings", "username")
            self.image_extensions = ast.literal_eval(
                self.config.get("settings", "imageextensions"))
            self.storage_path = self.config.get("settings", "datapath")

            # Handle main window buttons
            self.CheckoutButton.clicked.connect(
                self.handle_checkout_button_click)
            self.UpdateAllButton.clicked.connect(self.handle_update_all_button)

        # Menu Bar Actions
        self.actionSettings.triggered.connect(self.handle_settings_click)
        self.actionManage_Projects.triggered.connect(
            self.handle_manage_projects_click)

        self.open_database(self.username)
        self.handle_update_all_button()
示例#4
0
class AddTaskWindow(NewTaskForm.QtGui.QDialog, NewTaskForm.Ui_Dialog):
    """New Task Entry"""
    def __init__(self):
        super(AddTaskWindow, self).__init__()
        NewTaskForm.QtGui.QDialog.__init__(self)
        NewTaskForm.Ui_Dialog.__init__(self)
        self.setupUi(self)

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        self.new_task_name = self.TaskLineEdit.text()
        self.all_projects = self.queries.get_all_projects()
        self.all_tasks = self.queries.query_all_tasks(
        )  # For blocker/blockee selection

        for project in self.all_projects:
            self.ProjectComboBox.addItem(project[1])

        # TODO: Allow setting of "None" in blockers & blockees. (Make this the default for each)
        for task in self.all_tasks:  # TODO: prevent crossing blockers and blockees
            self.BlockedByComboBox.addItem(task[1])
            self.BlocksComboBox.addItem(task[1])

        # Handle OK button click
        self.buttonBox.button(NewTaskForm.QtGui.QDialogButtonBox.Ok).clicked. \
            connect(self.create_new_task)

    def create_new_task(self):
        """
        Creates a new task and adds it to the DB.
        :return:
        """
        task_name = self.TaskLineEdit.text()
        project = self.ProjectComboBox.currentText()
        project_id = self.queries.get_project_id_by_name(project)
        blocks = self.BlocksComboBox.currentText()
        blocked_by = self.BlockedByComboBox.currentText()
        input_directory = self.InputDirectoryLineEdit.text()
        output_directory = self.OutputDirectoryLineEdit.text()
        #estimated_completion = self.EstimatedCompletionCalendar.selectedDate()

        if len(task_name) > 0 and len(project) > 0:
            new_task = {
                'task_name': task_name,
                'project': project,
                'project_id': project_id,
                'blocks': blocks,
                'blocked_by': blocked_by,
                'input_directory': input_directory,
                'output_directory': output_directory,
                #'estimated_completion': estimated_completion
            }

            self.queries.add_new_task(new_task)
示例#5
0
    def __init__(self):
        super(AddProjectWindow, self).__init__()
        AddProject.QtGui.QDialog.__init__(self)
        AddProject.Ui_Dialog.__init__(self)
        self.setupUi(self)

        self.setFixedSize(self.size())  # Prevent resizing

        general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = general_functions.get_application_path()

        # Create DB session
        self.db = DatabaseQueries(self.app_dir)

        # handle "OK" clicked in buttonbox
        self.buttonBox.button(AddProject.QtGui.QDialogButtonBox.Ok).clicked.\
            connect(self.create_new_project)
示例#6
0
    def open_database(self, username):
        """
        Opens up the DB
        :return: None
        """
        self.username = username
        logging.info("Querying the database for user projects.")

        queries = DatabaseQueries(self.app_dir)
        projects = queries.query_projects_for_user(self.username)

        if projects is ValueError:  # Could not find any users matching the name
            logging.error(
                "Could not find any rows in Users DB for current username.")
        else:
            for project in projects:
                print("Projects associated with user: {}".format(
                    project))  # TODO: Remove this after testing
示例#7
0
    def __init__(self, image_extensions):
        super(ProjectsWindow, self).__init__()
        self.image_extensions = image_extensions
        ManageProjectsWindow.QtGui.QDialog.__init__(self)
        ManageProjectsWindow.Ui_ManageProjectsWindow.__init__(self)
        self.setupUi(self)

        # Select first item in list by default
        #self.ProjectsList.item(0).setSelected(True)

        self.setFixedSize(self.size())  # Prevent resizing

        # Set the global application path
        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()

        # Get list of projects
        self.queries = DatabaseQueries(self.app_dir)
        db = ImageryDatabase(self.app_dir)
        db_session = db.load_session()

        self.projects = self.queries.get_all_projects()

        # Do something when an item in the projects list is clicked
        self.ProjectsList.itemClicked.connect(self.handle_project_clicked)

        # Handle the various add/remove buttons
        self.AddProjectButton.clicked.connect(self.handle_add_project_clicked)
        self.RemoveProjectButton.clicked.connect(
            self.handle_remove_project_button)
        self.AddProjectDirectoryButton.clicked.connect(
            self.handle_project_add_dir_button)
        self.RemoveDirectoryFromProjectButton.clicked.connect(
            self.handle_delete_project_dir_button)
        self.AddTaskButton.clicked.connect(self.handle_add_task_button)
        self.RemoveTaskButton.clicked.connect(self.handle_delete_task_button)

        self.update_projects_list()
        self.update_tasks_list()
示例#8
0
    def __init__(self):
        super(NewUserWindow, self).__init__()
        NewUserRegistrationWindow.QtGui.QDialog.__init__(self)
        NewUserRegistrationWindow.Ui_NewUserWindow.__init__(self)
        self.setupUi(self)

        # Hide password entry (show asterisks)
        self.NewUserPasswordEntry.setEchoMode(QLineEdit.Password)

        self.setFixedSize(self.size())  # Prevent resizing

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        # Enable OK button if all fields contain text
        self.NewUserNameEntry.textChanged.connect(self.line_edit_text_changed)
        self.NewUserUsernameEntry.textChanged.connect(
            self.line_edit_text_changed)
        self.NewUserPasswordEntry.textChanged.connect(
            self.line_edit_text_changed)
        self.NewUserEmailEntry.textChanged.connect(self.line_edit_text_changed)

        # User variables
        self.name = None
        self.username = None
        self.password = None
        self.email = None

        # handle "OK" clicked in buttonbox
        self.buttonBox.button(NewUserRegistrationWindow.QtGui.QDialogButtonBox.Ok).clicked.\
            connect(self.create_new_user)

        # Disable OK button at first
        self.buttonBox.button(NewUserRegistrationWindow.QtGui.QDialogButtonBox.Ok). \
            setEnabled(False)
示例#9
0
    def create_new_project(self):
        """
        Adds the project name from the Add Project window to the db
        :return: None
        """

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        project_name = self.ProjectNameEntryEdit.text()
        result = self.db.add_new_project(project_name)
        self.queries = DatabaseQueries(self.app_dir)

        if result == 1:  # User tried to enter a project that already exists
            # Bring up error message
            text = "Error: Project already exists in database."
            error_window = ErrorMessagePopup(text)
            error_window.show()
            error_window.exec_()
示例#10
0
class AddProjectWindow(AddProject.QtGui.QDialog, AddProject.Ui_Dialog):
    """
    New Project Name Entry
    """
    def __init__(self):
        super(AddProjectWindow, self).__init__()
        AddProject.QtGui.QDialog.__init__(self)
        AddProject.Ui_Dialog.__init__(self)
        self.setupUi(self)

        self.setFixedSize(self.size())  # Prevent resizing

        general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = general_functions.get_application_path()

        # Create DB session
        self.db = DatabaseQueries(self.app_dir)

        # handle "OK" clicked in buttonbox
        self.buttonBox.button(AddProject.QtGui.QDialogButtonBox.Ok).clicked.\
            connect(self.create_new_project)

    def create_new_project(self):
        """
        Adds the project name from the Add Project window to the db
        :return: None
        """

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        project_name = self.ProjectNameEntryEdit.text()
        result = self.db.add_new_project(project_name)
        self.queries = DatabaseQueries(self.app_dir)

        if result == 1:  # User tried to enter a project that already exists
            # Bring up error message
            text = "Error: Project already exists in database."
            error_window = ErrorMessagePopup(text)
            error_window.show()
            error_window.exec_()
示例#11
0
class NewUserWindow(NewUserRegistrationWindow.QtGui.QDialog,
                    NewUserRegistrationWindow.Ui_NewUserWindow):
    """
    Window for registering new users
    """
    def __init__(self):
        super(NewUserWindow, self).__init__()
        NewUserRegistrationWindow.QtGui.QDialog.__init__(self)
        NewUserRegistrationWindow.Ui_NewUserWindow.__init__(self)
        self.setupUi(self)

        # Hide password entry (show asterisks)
        self.NewUserPasswordEntry.setEchoMode(QLineEdit.Password)

        self.setFixedSize(self.size())  # Prevent resizing

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        # Enable OK button if all fields contain text
        self.NewUserNameEntry.textChanged.connect(self.line_edit_text_changed)
        self.NewUserUsernameEntry.textChanged.connect(
            self.line_edit_text_changed)
        self.NewUserPasswordEntry.textChanged.connect(
            self.line_edit_text_changed)
        self.NewUserEmailEntry.textChanged.connect(self.line_edit_text_changed)

        # User variables
        self.name = None
        self.username = None
        self.password = None
        self.email = None

        # handle "OK" clicked in buttonbox
        self.buttonBox.button(NewUserRegistrationWindow.QtGui.QDialogButtonBox.Ok).clicked.\
            connect(self.create_new_user)

        # Disable OK button at first
        self.buttonBox.button(NewUserRegistrationWindow.QtGui.QDialogButtonBox.Ok). \
            setEnabled(False)

    def line_edit_text_changed(self):
        """
        Enable the OK button when all fields contain data
        :return: None
        """

        if len(self.NewUserNameEntry.text()) > 3 and  len(self.NewUserUsernameEntry.text()) > 4 \
                and len(self.NewUserPasswordEntry.text()) > 4 \
                and len(self.NewUserEmailEntry.text()) > 5:
            self.buttonBox.button(NewUserRegistrationWindow.QtGui.QDialogButtonBox.Ok).\
                setEnabled(True)

    def create_new_user(self):
        """
        Tries to create a new user when the OK button is clicked
        :return: None
        """

        valid_name = False
        valid_username = False
        valid_password = False
        valid_email = False

        self.name = self.NewUserNameEntry.text()
        self.username = self.NewUserUsernameEntry.text()
        password = self.NewUserPasswordEntry.text()
        self.email = self.NewUserEmailEntry.text()

        if len(self.name) <= 5:
            raise_error_window(
                "You must enter a name longer than 5 characers.")
        else:
            valid_name = True

        if len(self.username) <= 3:
            raise_error_window(
                "You must enter a username longer than 3 characters.")
        else:
            valid_username = True

        if len(password) < 4:
            raise_error_window(
                "You must enter a password longer than 3 characters.")
        else:
            valid_password = True

        if len(self.email) < 5:
            raise_error_window(
                "You must enter an email address longer than 4 characters.")
        else:
            valid_email = True

        if valid_name and valid_username and valid_password and valid_email:

            # Hash the password
            #self.password = PasswordHash.new(password, 12)
            self.password = (sha1(password.encode('utf-8'))).hexdigest()

            # Create a dict to pass to new user creator
            new_user = {
                'name': self.name,
                'username': self.username,
                'password': self.password,
                'email': self.email
            }

            # Write to database
            result = self.queries.add_new_user(new_user)

            if result == -1:
                # Username already exists
                raise_error_window("Username {} already exists in DB.".format(
                    self.username))
            elif result == -2:
                # Email already exists
                raise_error_window(
                    "Email address {} already exists in DB.".format(
                        self.email))

        else:
            raise_new_user_window()
示例#12
0
class UserLoginWindow(LoginWindow.QtGui.QDialog, LoginWindow.Ui_LoginWIndow):
    """Login window"""
    def __init__(self):
        LoginWindow.QtGui.QDialog.__init__(self)
        LoginWindow.Ui_LoginWIndow.__init__(self)
        self.setupUi(self)

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()

        self.queries = DatabaseQueries(self.app_dir)
        self.setFixedSize(self.size())  # Prevent resizing

        # Hide password entry (show asterisks)
        self.LoginWindowPasswordEdit.setEchoMode(QLineEdit.Password)

        # Disable the OK button at first.
        self.buttonBox.button(
            LoginWindow.QtGui.QDialogButtonBox.Ok).setEnabled(False)

        # Enable the "OK" button once user has entered text into fields
        self.LoginWindowUsernameEdit.textChanged.connect(
            self.line_edit_text_changed)
        self.LoginWindowPasswordEdit.textChanged.connect(
            self.line_edit_text_changed)

        # Handle button clicks
        self.RegisterNewUserButton.clicked.connect(
            self.handle_register_button_clicked)

        ## handle "OK" clicked in buttonbox
        self.buttonBox.button(
            LoginWindow.QtGui.QDialogButtonBox.Ok).clicked.connect(
                self.handle_login)

    def line_edit_text_changed(self):
        """
        Enable the OK button when all fields contain data
        :return: None
        """

        if len(self.LoginWindowUsernameEdit.text()) > 3 and \
                        len(self.LoginWindowPasswordEdit.text()) > 4:
            self.buttonBox.button(
                LoginWindow.QtGui.QDialogButtonBox.Ok).setEnabled(True)

    def handle_register_button_clicked(self):
        """
        Calls ths the NewUserWindow GUI class when user clicks the "Register" button.
        :return: None
        """
        new_user_window = NewUserWindow()
        new_user_window.show()
        new_user_window.exec_()

    def handle_login(self):
        """
        Handles an existing user logging in.
        :return: None
        """

        # TODO: Go back to login window if no data entered
        entered_username = self.LoginWindowUsernameEdit.text()
        entered_password = (self.LoginWindowPasswordEdit.text())
        userdata = self.queries.query_users(entered_username)

        password_verified = self.queries.validate_password_input(
            userdata.username, entered_password)

        if password_verified:
            print("Passwords match!")
        else:
            text = "Incorrect password"
            raise_error_window(text)
            logging.warning(text)

        if userdata != ValueError and password_verified:
            raise_main_window()
示例#13
0
class ProjectsWindow(ManageProjectsWindow.QtGui.QDialog,
                     ManageProjectsWindow.Ui_ManageProjectsWindow):
    def __init__(self, image_extensions):
        super(ProjectsWindow, self).__init__()
        self.image_extensions = image_extensions
        ManageProjectsWindow.QtGui.QDialog.__init__(self)
        ManageProjectsWindow.Ui_ManageProjectsWindow.__init__(self)
        self.setupUi(self)

        # Select first item in list by default
        #self.ProjectsList.item(0).setSelected(True)

        self.setFixedSize(self.size())  # Prevent resizing

        # Set the global application path
        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()

        # Get list of projects
        self.queries = DatabaseQueries(self.app_dir)
        db = ImageryDatabase(self.app_dir)
        db_session = db.load_session()

        self.projects = self.queries.get_all_projects()

        # Do something when an item in the projects list is clicked
        self.ProjectsList.itemClicked.connect(self.handle_project_clicked)

        # Handle the various add/remove buttons
        self.AddProjectButton.clicked.connect(self.handle_add_project_clicked)
        self.RemoveProjectButton.clicked.connect(
            self.handle_remove_project_button)
        self.AddProjectDirectoryButton.clicked.connect(
            self.handle_project_add_dir_button)
        self.RemoveDirectoryFromProjectButton.clicked.connect(
            self.handle_delete_project_dir_button)
        self.AddTaskButton.clicked.connect(self.handle_add_task_button)
        self.RemoveTaskButton.clicked.connect(self.handle_delete_task_button)

        self.update_projects_list()
        self.update_tasks_list()

    def update_projects_list(self):
        """
        Update the list of projects
        :return: None
        """

        self.ProjectsList.clear()
        self.projects = self.queries.get_all_projects()

        for project in self.projects:
            project_id = project[0]
            project_name = project[1]
            self.ProjectsList.addItem(project_name)

    def update_directories_list(self, project_id):
        """
        Update the list of directories
        :return: None
        """

        self.ProjectDirectoriesList.clear()

        project_directories = self.queries.get_directories_for_project(
            project_id)
        for row in project_directories:
            project_id = row[0]
            directory = row[1]
            if len(directory) > 0:
                self.ProjectDirectoriesList.addItem(directory)

    def update_tasks_list(self):
        """
        Update the list of projects
        :return: None
        """

        self.TasksList.clear()
        self.tasks = self.queries.query_all_tasks()

        for task in self.tasks:
            task_id = task[0]
            task_name = task[1]
            self.TasksList.addItem(task_name)

    def handle_remove_project_button(self):
        """
        Handles user clicking the remove project button
        :return: None
        """

        project = self.ProjectsList.currentItem().text()

        for item in self.ProjectsList.selectedItems():
            self.queries.delete_project(item.text())

        self.update_projects_list()

    def handle_project_add_dir_button(self):
        """
        Handle user clicking the add project directory button
        :return: None
        """
        project = self.ProjectsList.currentItem().text()
        project_id = self.queries.get_project_id_by_name(project)
        directory = str(
            QFileDialog.getExistingDirectory(self, "Select Directory"))

        new_directory_id = self.queries.add_project_directory(
            project, directory)
        """Get a list of images in directory with correct extensions. The function returns a tuple
        that looks like this:

        (image_path, image_extension, image_size, image_hash, image_modification_time,
        image_first_seen, image_last_scanned, image_on_disk)

        """
        images = self.general_functions.search_for_images(
            self.image_extensions, directory)

        for image in images:
            image_path = image[0]
            image_extension = image[1]
            image_size = image[2]
            image_hash = image[3]
            image_modification_time = image[4]
            image_first_seen = image[5]
            image_last_scanned = image[6]
            image_on_disk = image[7]

            image_metadata = {
                'project_id': project_id,
                'directory_id': new_directory_id,
                'image_path': image_path,
                'image_extension': image_extension,
                'image_size': image_size,
                'image_hash': image_hash,
                'image_modification_time': image_modification_time,
                'image_first_seen': image_first_seen,
                'image_last_scanned': image_last_scanned,
                'image_on_disk': image_on_disk
            }

            self.queries.add_file_to_database(image_metadata)

        self.update_directories_list(project_id)

    def handle_project_clicked(self):
        """
        Updates the users and directories lists when a project is clicked
        :return: None
        """

        # First, clear the user list so that they don't stack up
        self.UsersList.clear()
        self.ProjectDirectoriesList.clear()

        project_id = None
        project_name = self.ProjectsList.currentItem().text()
        project_id = self.queries.get_project_id_by_name(project_name)
        project_users = self.queries.get_users_for_project(project_name)

        for item in project_users:
            project_id = item[0]
            project_name = item[1]
            username = item[2]

            self.UsersList.addItem(username)

        project_directories = self.queries.get_directories_for_project(
            project_id)

        for row in project_directories:
            project_id = row[0]
            directory = row[1]
            if len(directory) > 0:
                self.ProjectDirectoriesList.addItem(directory)

    def handle_add_project_clicked(self):
        """
        Handles user clicking the add project button
        :return: None
        """

        add_project_window = AddProjectWindow()
        add_project_window.show()
        add_project_window.exec_()

        self.update_projects_list()

    def handle_delete_project_dir_button(self):
        """
        Handles user clicking the delete dir button
        :return: None
        """
        selected_project = self.ProjectsList.currentItem().text()
        project_id = self.queries.get_project_id_by_name(selected_project)
        selected_directory = self.ProjectDirectoriesList.currentItem().text()

        self.queries.delete_project_directory(selected_project,
                                              selected_directory)

        self.update_directories_list(project_id)

    def handle_add_task_button(self):
        """Opens the new task window"""
        new_task_window = AddTaskWindow()
        new_task_window.show()
        new_task_window.exec_()

        self.update_tasks_list()

    def handle_delete_task_button(self):
        """Deletes the task selected"""

        task_name = self.TasksList.currentItem().text()
        self.queries.delete_task(task_name)

        self.update_tasks_list()
示例#14
0
class MainWindow(ivcs_mainwindow.QtGui.QMainWindow,
                 ivcs_mainwindow.Ui_MainWindow):
    def __init__(self):
        ivcs_mainwindow.QtGui.QMainWindow.__init__(self)
        ivcs_mainwindow.Ui_MainWindow.__init__(self)
        self.setupUi(self)
        self.image_extensions = []

        self.general_functions = filesystem_utils.GeneralFunctions()
        self.app_dir = self.general_functions.get_application_path()
        self.queries = DatabaseQueries(self.app_dir)

        self.setFixedSize(self.size())  # Prevent resizing

        if not os.path.exists(os.path.join(self.app_dir, 'ivcs.ini')):
            logging.warning(
                "Couldn't find configuration file at {}, after it should have been "
                "automatically created.".format(self.app_dir))

            # Disable all GUI elements until a branch is set and scanned
            self.RemoteChangesListView.setEnabled(False)
            self.LocalFileListVIew.setEnabled(False)
            self.RemoteChangesListView.setEnabled(False)
            self.LocalChangesListView.setEnabled(False)

            self.CheckoutButton.setEnabled(False)
            self.ViewRemoteCommitButton.setEnabled(False)
            self.CommitButton.setEnabled(False)
            self.PushButton.setEnabled(False)

        else:

            # Enable multiple selection
            self.RemoteFileListView.setSelectionMode(
                QAbstractItemView.ExtendedSelection)
            self.LocalFileListVIew.setSelectionMode(
                QAbstractItemView.ExtendedSelection)
            # Load current settings
            self.config_file_path = os.path.join(self.app_dir, 'ivcs.ini')
            self.config = configparser.ConfigParser()
            self.config.read(self.config_file_path)

            self.change_detection_method = self.config.get(
                "settings", "changedetectmethod")
            self.username = self.config.get("settings", "username")
            self.image_extensions = ast.literal_eval(
                self.config.get("settings", "imageextensions"))
            self.storage_path = self.config.get("settings", "datapath")

            # Handle main window buttons
            self.CheckoutButton.clicked.connect(
                self.handle_checkout_button_click)
            self.UpdateAllButton.clicked.connect(self.handle_update_all_button)

        # Menu Bar Actions
        self.actionSettings.triggered.connect(self.handle_settings_click)
        self.actionManage_Projects.triggered.connect(
            self.handle_manage_projects_click)

        self.open_database(self.username)
        self.handle_update_all_button()

    def handle_update_all_button(self):
        """
        Updates lists in main window
        :return: None
        """

        self.update_remote_files()
        self.update_local_files()

        projects = self.queries.get_all_projects()

        for project in projects:
            project_id = project[0]
            project = project[1]
            self.ProjectSelection.addItem(project)

            tasks = self.queries.get_task_by_project(project_id)

            for task in tasks:
                self.TaskSelection.addItem(task)

    def update_local_files(self):
        """
        Updates the list of local files
        :return: None
        """
        pass  # TODO: FInish this

    def update_remote_files(self):
        """
        Updates the list of remote files.
        :return: None
        """
        self.RemoteFileListView.clear()
        files = self.queries.get_all_remote_files()
        hash_list = []

        list_widget_index = 0
        for file in files:
            self.RemoteFileListView.addItem(file[0])

            # Change text color of changed files to red
            if not self.general_functions.get_file_hash(file):
                self.RemoteFileListView.item(list_widget_index).setSelected(
                    True)

                for item in self.RemoteFileListView.selectedItems():
                    item.setForeground(QBrush(Qt.red, Qt.SolidPattern))

        list_widget_index += 1

    def handle_checkout_button_click(self):
        """
        Opens the checkout status window and initiates file transfer from network
        :return: None
        """

        checkout_status = CheckoutStatusWindow()
        checkout_status.show()
        checkout_status.exec_()

    def handle_settings_click(self):
        """
        Handles user clicking the settings button in the menu bar
        :return: None
        """

        settings = SettingsWindow()
        settings.show()
        settings.exec_()

    def handle_new_branch_click(self):
        """
        Handles user clicking the new branch button in the menu bar
        :return: None
        """

        pass

    def open_database(self, username):
        """
        Opens up the DB
        :return: None
        """
        self.username = username
        logging.info("Querying the database for user projects.")

        queries = DatabaseQueries(self.app_dir)
        projects = queries.query_projects_for_user(self.username)

        if projects is ValueError:  # Could not find any users matching the name
            logging.error(
                "Could not find any rows in Users DB for current username.")
        else:
            for project in projects:
                print("Projects associated with user: {}".format(
                    project))  # TODO: Remove this after testing

        #self.fs_walker = filesystem_utils.FileSystemWalker(self.storage_path, self.image_extensions)
        #self.files = self.fs_walker

    def handle_manage_projects_click(self):
        """
        Handle user clicking manage projects
        :return: None
        """

        proj_window = ProjectsWindow(self.image_extensions)
        proj_window.show()
        proj_window.exec_()

        self.update_remote_files()