예제 #1
0
def setup_tab_paths_save(paths):
    """
    Function to generate or update the database file.
    :param file: tuple with the path file and file format
    :param paths: dict fill with all paths

    :return: return a success or an error
    """

    data = TableProgram()
    data.write_data_path(paths['unreal'], paths['project'], paths['folder'])
    # generate_levels(paths['project'], paths['folder'])
    # data.write_data_levels()

    return 'Data Save'
예제 #2
0
class DialSetupTab(QtWidgets.QDialog, Ui_DialogSetupProject):
    header1, header2 = range(2)

    def __init__(self):
        super(DialSetupTab, self).__init__()
        self.setupUi(self)

        self.settings = Setup()
        self.data = TableProgram()

        # All Tab setup, options are split inside many function
        # Tab Project setup ---------------------------------------------------
        #   Defined data needed -----------------------------------------------
        self.list_levels = QtGui.QStandardItemModel()

        #   Write all Slot and Connect ----------------------------------------
        self.field_setup()
        self.tab_project_setup()

        # Tab Network Setup ---------------------------------------------------
        # self.tab_network()

        # Tab Source Control Setup --------------------------------------------
        self.tab_source_control()

        # Setups Buttons
        box_btn = QtWidgets.QDialogButtonBox
        btn = self.buttonBox.button
        btn(box_btn.RestoreDefaults).clicked.connect(self.btn_restore)
        btn(box_btn.Save).clicked.connect(self.save_tab)
        btn(box_btn.Open).clicked.connect(load_generic)
        btn(box_btn.Close).clicked.connect(self.close)

        # TODO Disable the Network tab settings
        self.tabWidget.setTabEnabled(2, False)

    # Ui Functions ------------------------------------------------------------
    #   Tab Project setup -----------------------------------------------------
    def tab_project_setup(self, index=None, value=str):
        """
        Generate the Tab Setup, include the Paths field and the Tree Levels
        with all editable data.
        It's only a function to add the slot and signal inside the Ui.

        :param index: None by default, this value give a Int to choice the
        field used, Unreal Editor (1) or the Project field (2).
        :param value: String data, it a simple information to send it a field
        :return:
        """
        if index:
            if index == 1:
                self.ue4_path_text.setText(value)
            elif index == 2:
                self.project_file_text.setText(value)
            elif index == 3:
                value = self.sub_folder_text.text()
                self.sub_folder_text.setText(value)
        elif self.settings.last_job_run():
            db = self.data.select_paths()
            self.ue4_path_text.setText(db[0][1])
            self.project_file_text.setText(db[0][2])
            self.sub_folder_text.setText(db[0][3])

        level_path = join(dirname(self.project_file_text.text()),
                          'Content',
                          self.sub_folder_text.text())

        root_model = self.model_base(self)
        self.ProjectTreeLevels.reset()
        self.ProjectTreeLevels.setModel(root_model)
        if self.project_file_text.text():
            data_tree = self.levels_list(level_path)
            self.model_populate(data_tree,
                                root_model.invisibleRootItem())
        self.ProjectTreeLevels.expandAll()
        self.ProjectTreeLevels.setColumnWidth(0, 250)
        self.ProjectTreeLevels.setSortingEnabled(True)
        self.ProjectTreeLevels.sortByColumn(0, Qt.AscendingOrder)
        root_model.itemChanged.connect(self.save_level)

        return self

    def field_setup(self):
        """Generate the fields and signal about all paths"""
        self.ue4_path_edit.clicked.connect(lambda: self.select_file(1))
        self.project_file_edit.clicked.connect(lambda: self.select_file(2))
        self.sub_folder_edit.clicked.connect(
            lambda: self.tab_project_setup(index=3))

    def save_field(self):
        self.data.write_data_path(self.ue4_path_text,
                                  self.project_file_text,
                                  self.sub_folder_text)

    def levels_list(self, path):
        """
        Generate a list with all levels inside a path give than argument
        :param path: specify a path to scan the folder, it's a simple string
        :return: a dict with all levels and folder
        """
        folders = {}
        levels = []
        if isdir(path):
            obj_path = PureWindowsPath(path)
            tree = listdir(str(obj_path))
            tree.sort(key=lambda s: s.find('.umap'))
            for item in tree:
                abs_path = obj_path.joinpath(item)
                if isdir(abs_path):
                    key = obj_path.stem
                    sub_levels = self.levels_list(abs_path)
                    if len(sub_levels) and type(sub_levels) == dict:
                        levels.append(sub_levels)
                        folders[key] = levels
                else:
                    if '.umap' in item:
                        regex = r"^.*Content"
                        relative_path = re.sub(regex, "", str(obj_path))
                        levels.append(join(relative_path, item))
                        key = basename(dirname(abs_path))
                        folders[key] = levels
        else:
            folders = {'No Data': 'Error Path'}

        return folders

    def save_level(self, index_item):
        """
        Function to save or remove the levels from the Data Base
        :param index_item: A string with the level name to save it.
        :return:
        """
        state = index_item.checkState()
        row = index_item.row()
        parent = index_item.parent()
        path_level = parent.child(row, 1)
        if state == Qt.Checked:
            info = [index_item.text(), path_level.text(), 1]
        else:
            info = [index_item.text(), path_level.text(), 0]

        self.data.write_data_levels(state=state, data=info)

    def model_populate(self, children, parent):
        """
        Function to work with the Model.
        You need to give 2 parameter, a dict with your Data you want show,
        and a parent to define the index.
        It's a recursive function, if your Data has a Dict inside a Dict,
        the function generate the Tree with all sub-node.
        :param children: It's only a Dict, included your Data
        :param parent: Define your first level, work with the Invisible Root
        :return: nothing returns.
        """
        for key, values in sorted(children.items()):
            item_object = QStandardItem(key)
            folder_icon = QtGui.QIcon()
            folder_icon.addPixmap(
                QtGui.QPixmap("Resources/Icons/file-submodule.png"))
            item_object.setIcon(folder_icon)
            parent.appendRow(item_object)

            if type(values) == list:
                for value in values:
                    if type(value) == str:
                        level_name = basename(value)
                        check = False
                        if self.settings.last_job_run():
                            if len(self.data.select_levels(name=level_name)):
                                check = 2
                        item_name = QStandardItem(level_name)
                        item_name.setCheckable(True)
                        item_name.setCheckState(check)
                        item_path = QStandardItem(value)
                        item_object.appendRow([item_name, item_path])
                    elif type(value) == dict:
                        self.model_populate(value, item_object)

    def model_base(self, parent):
        """
        Function to work with the Model.
        This function generate the Tree View base, with all header generate.
        :param parent: QTreeView
        :return: give a Model
        """
        model = QStandardItemModel(0, 2, parent)
        model.setHeaderData(self.header1, Qt.Horizontal, 'Names')
        model.setHeaderData(self.header2, Qt.Horizontal, 'Paths')

        return model

    def select_file(self, index):
        """Function to choose a path about the Editor and Project file"""
        select = file_open(self, index)
        self.tab_project_setup(index, select[0])

    # Ui Functions ------------------------------------------------------------
    #   Tab Source Control ----------------------------------------------------
    def tab_source_control(self):
        """
        The Ui about the Source Control panel, all option and slot connect.
        :return:
        """
        soft_work = self.softwares_comboBox
        soft_work.currentIndexChanged.connect(self.sc_software)

        if self.settings.last_job_run():
            data_sc = self.data.select_scv()
            index_cb = self.softwares_comboBox.findText(data_sc[0])
            self.softwares_comboBox.setCurrentIndex(index_cb)
            self.user_text.setText(data_sc[1])
            self.password_text.setText(data_sc[2])

    def sc_software(self):
        """
        Event on the Source control tab, activate or disable all fields about
        the option on this tab.
        Hide the password field.
        :return:
        """
        self.password_text.setEchoMode(QLineEdit.Password)

        type_items = QLineEdit, QLabel, QPushButton
        parent_setup = self.sc_groupBox_setup.findChildren(type_items)
        state = False

        if self.softwares_comboBox.currentText() == 'Disabled':
            state = True

        for item in parent_setup:
            item.setDisabled(state)

    def sc_save(self):
        sc_data = [
            self.softwares_comboBox.currentText(),
            self.user_text.text(),
            self.password_text.text()
        ]

        self.data.write_scv(sc_data)

    # Buttons Box Function ----------------------------------------------------
    @staticmethod
    def btn_restore():
        """
        Function to restore the view.
        :return:
        """
        return print('Restore View')

    def save_tab(self):
        """
        Simple function to save a new project or update the Data Base
        :return:
        """
        if not self.settings.last_job_run():
            file_save_project(self)

        else:
            # TODO Look to save the path field with the function save_field()
            # self.save_field()
            self.sc_save()
            self.data.close()
예제 #3
0
class ViewTabSetup(QtWidgets.QTabWidget, Ui_TabWidgetProjects):
    """This widget contains all setup tab"""
    def __init__(self):
        super(ViewTabSetup, self).__init__()
        self.setupUi(self)

        self.data = Setup()
        self.job = self.data.last_job_run()

        if self.job:
            # Project Tab
            self.data = TableProgram()
            data_paths = self.data.select_path(1)

            self.ue4_path = data_paths[0][1]
            self.ue4_project = data_paths[0][2]
            self.dir_project = os.path.dirname(self.ue4_project)
            self.scene = data_paths[0][3]
            self.levels_path = join(self.dir_project, 'content', self.scene)
            self.levels_path = os.path.abspath(self.levels_path)
            self.data_level = self.project_list_level(self.levels_path)

            # CSV Tab
            self.data_csv = self.data.csv_data()
            if self.data_csv[0] == 'False' or self.data_csv is None:
                self.csv_boolean = 0
                self.csv_software = 2
            else:
                self.csv_boolean = 2
                self.csv_software = self.data_csv[0]

        else:
            news_DB = True
            self.ue4_path = self.data.base('editor')
            self.ue4_project = self.data.base('project')
            self.scene = self.data.base('sub folder')
            self.data_level = []
            self.csv_boolean = 0
            self.csv_software = 1

        # Project Panel
        self.levels_list = QtGui.QStandardItemModel()
        self.project_tree_generate(self.levels_list, self.data_level)
        self.treeViewLevels.setModel(self.levels_list)
        self.treeViewLevels.clicked.connect(self.project_update_level)
        self.levels_list.setHorizontalHeaderLabels([self.tr('Level Name')])
        self.pushPathOpenUnreal.clicked.connect(lambda: self.open_save(1))
        self.lineEditUnreal.setText(self.ue4_path)
        self.pushPathOpenProject.clicked.connect(lambda: self.open_save(2))
        self.lineEditProject.setText(self.ue4_project)
        name = project_name(self.lineEditProject.text())
        self.lineEditProjectName.setText(name)
        self.lineEditSubfolder.setText(self.scene)

        # Network Panel
        # TODO Make all network options

        # CSV Panel
        """All option about the CSV options."""
        self.csv_checkBox_enable.setCheckState(self.csv_boolean)
        self.csv_checkBox_enable.clicked.connect(self.csv_enable)
        if self.csv_software:
            self.csv_comboBox.itemText(2)

        # Button Box, Save and Cancel
        btn = QtWidgets.QDialogButtonBox
        #   Restore Default

        #   Save
        self.buttonBoxProjects.button(btn.Save).clicked.connect(self.tab_save)
        self.buttonBoxCSV.button(btn.Save).clicked.connect(self.tab_save)

        #   Close Event
        self.buttonBoxProjects.button(btn.Cancel).clicked.connect(self.close)
        self.buttonBoxNetwork.button(btn.Cancel).clicked.connect(self.close)
        self.buttonBoxCSV.button(btn.Cancel).clicked.connect(self.close)

    def open_save(self, state):
        file_description = ''
        file_select = ''

        if state == 1:
            file_description = 'Open the UE4 Editor'
            file_select = 'UE4Editor.exe'

        elif state == 2:
            file_description = 'Open a Unreal Project File'
            file_select = '*.uproject'

        (filename,
         filter) = QtWidgets.QFileDialog.getOpenFileName(self,
                                                         file_description,
                                                         filter=file_select)

        if state == 1:
            self.lineEditUnreal.setText(filename)

        elif state == 2:
            self.lineEditProject.setText(filename)

        name = project_name(self.lineEditProject.text())
        # self.lineEditProjectName.update()
        self.lineEditProjectName.setText(name)
        self.lineEditProjectName.update()

    def tab_save(self):
        # TODO Update the GUI to show all selected levels
        tab = self.tabBar()
        tab = tab.currentIndex()
        setting = Setup()

        if tab == 1:
            print('Save Network')
        else:
            # Save projects Dataa
            editor = self.lineEditUnreal.text()
            project = self.lineEditProject.text()
            scene = self.lineEditSubfolder.text()

            if not setting.last_job_run():
                self.data_base_save()
            self.data = TableProgram()
            self.data.write_data_path(editor, project, scene)
            self.data.write_data_levels()

            # Save State Data
            csv_state = self.csv_checkBox_enable
            csv_item = 'False'
            if QtWidgets.QAbstractButton.isChecked(csv_state):
                csv_item = self.csv_comboBox.currentText()

            self.data.csv_data(csv_item)

        ViewTabSetup.close(self)

    def data_base_save(self):
        options = QFileDialog.Options()
        directory = join(expanduser('~'), 'BBLUE4')
        database = QFileDialog.getSaveFileName(self,
                                               'Save your projects',
                                               directory=directory,
                                               filter='*.db',
                                               options=options)
        edit = Setup()
        edit.last_job_add(database[0])

    def project_tree_generate(self, parent, elements):
        self.data = TableProgram()
        levels = self.data.select_levels()
        state = i = 0

        for name, path in elements:
            item = QtGui.QStandardItem(name)
            item.setCheckable(True)
            if levels is not None:
                for i in range(0, len(levels)):
                    if name in levels[i]:
                        state = levels[i][3]
                    i = i + 1

            item.setCheckState(state)
            parent.appendRow(item)
            if path:
                self.project_tree_generate(item, path)

    def project_list_level(self, folder_directory):
        levels = []
        for item in os.listdir(folder_directory):
            absolute_path = join(folder_directory, item)
            child = isdir(absolute_path)
            if child:
                sublevel = [(item, self.project_list_level(absolute_path))]
                levels.extend(sublevel)
            else:
                if '.umap' in item:
                    sublevel = [(item, [])]
                    levels.extend(sublevel)

        return levels

    def project_update_level(self, index):
        self.data.write_data_levels(treeview=self, index=index)

    def csv_enable(self):
        csv_enable = self.csv_checkBox_enable
        if QtWidgets.QAbstractButton.isChecked(csv_enable):
            self.csv_label_name.setEnabled(True)
            self.csv_comboBox.setEnabled(True)
            self.csv_label_file.setEnabled(True)
            self.csv_lineEdit_file.setEnabled(True)
            self.csv_pushButton_file.setEnabled(True)
            # self.csv_label_id.setEnabled(True)
            # self.csv_lineEdit_id.setEnabled(True)
            # self.csv_label_password.setEnabled(True)
            # self.csv_lineEdit_password.setEnabled(True)

            # Enable inside the DB.

        else:
            self.csv_label_name.setEnabled(False)
            self.csv_comboBox.setEnabled(False)
            self.csv_label_file.setEnabled(False)
            self.csv_lineEdit_file.setEnabled(False)
            self.csv_pushButton_file.setEnabled(False)