예제 #1
0
파일: Popup.py 프로젝트: gonnaflyzhang/HAOC
    def on_tree_item_changed(self, item):
        new_name = item.text()
        if self.__old_name_for_rename is None or self.__old_name_for_rename == new_name:
            return
        if len(new_name) < 3:
            item.setText(self.__old_name_for_rename)
            return
        res = HaocUtils.check_name_ok(new_name)

        if res != '':
            item.setText(self.__old_name_for_rename)
            return

        if self.__old_name_for_rename[-1] == '/':
            if new_name.count('/') > 1:
                item.setText(self.__old_name_for_rename)
                return
            if new_name[-1] != '/':
                new_name = "%s/" % new_name
                item.setText(new_name)
                return
        else:
            if new_name.find('/') != -1:
                item.setText(self.__old_name_for_rename)
                return

        if self.__old_name_for_rename != item.text():
            new_local_name = "%s/%s/%s" % (HaocUtils.get_local_nodes_path(),
                                           self.get_context_name(),
                                           self.get_selected_path(item))
            old_local_name = new_local_name[:-len(item.text(
            ))] + self.__old_name_for_rename
            new_cloud_name = "%s/%s" % (self.get_context_name(),
                                        self.get_selected_path(item))
            old_cloud_name = new_cloud_name[:-len(item.text(
            ))] + self.__old_name_for_rename
            if new_local_name[-1] == "/":
                if os.path.exists(new_local_name):
                    item.setText(self.__old_name_for_rename)
                    return
                else:
                    os.rename(old_local_name, new_local_name)
            else:
                if os.path.exists("%s.nod" % new_local_name):
                    item.setText(self.__old_name_for_rename)
                    return
                else:
                    os.rename("%s.nod" % old_local_name,
                              "%s.nod" % new_local_name)
                    if os.path.exists("%s.hlp" % old_local_name):
                        os.rename("%s.hlp" % old_local_name,
                                  "%s.hlp" % new_local_name)
            com = HaocObjects.CommandItem(3,
                                          old_name=old_cloud_name,
                                          new_name=new_cloud_name)
            t_rename = SCloudUtils.TDoCommands([com])
            t_rename.start()
예제 #2
0
 def on_delete_menu(self):
     if SCloudUtils.is_any_cloud_operation_running():
         print "Please wait for current cloud operation finish"
         return
     selected_path = HaocObjects.get_selected_path(self.get_current_item())
     local_path = "%s/%s" % (HaocUtils.get_local_nodes_path(),
                             selected_path)
     if selected_path[-1] == '/':
         os.rmdir(local_path)
     else:
         os.remove("%s.nod" % local_path)
         if os.path.exists("%s.hlp" % local_path):
             os.remove("%s.hlp" % local_path)
     com = HaocObjects.CommandItem(2, path=selected_path)
     t_delete = SCloudUtils.TDoCommands([com])
     t_delete.start()
     index = self.tree_view.currentIndex()
     self.tree_view.sort_filter.removeRow(index.row(), index.parent())
예제 #3
0
파일: Popup.py 프로젝트: gonnaflyzhang/HAOC
    def save_nodes(self):
        input_name = self.asset_name.text().strip()
        if len(input_name) < 3:
            QtWidgets.QMessageBox.warning(
                hou.qt.mainWindow(), "Input Error",
                "The number of letters of Asset name must at least have 3")
            return
        input_error = HaocUtils.check_name_ok(input_name)
        if input_error != '':
            QtWidgets.QMessageBox.warning(
                hou.qt.mainWindow(), "Input Error",
                "File name is not up to standard,please remove the stuff below from your input:\n%s"
                % input_error)
            return

        selected_path = ""
        index = self.tree_view.currentIndex()
        index = self.sort_filter.mapToSource(index)
        selected_item = self.sort_filter.sourceModel().itemFromIndex(index)
        if selected_item:
            selected_path = PopWidget.get_selected_folder(selected_item)
        asset_upload_path = selected_path + input_name
        parent = hou.selectedItems()[0].parent()
        cat_name = parent.childTypeCategory().name()
        local_path = '%s/data/%s/nodes/%s/%s' % (HaocUtils.get_root_path(),
                                                 HaocUtils.Config.get_ak(),
                                                 cat_name, asset_upload_path)
        cloud_path = '%s/%s' % (cat_name, asset_upload_path)

        if input_name[-1] == "/":
            if not os.path.exists(local_path):
                os.makedirs(local_path)
        else:
            if os.path.exists("%s.nod" % local_path):
                button_code = HaocUtils.show_question_box(
                    self,
                    "This asset is already exist,do you want to replace it?")
                if button_code != QtWidgets.QMessageBox.Yes:
                    return

            # Check for SopNode HardLocked status
            if len(hou.selectedNodes()) > 1:
                locked_nodes = []
                if self.network_editor.pwd().childTypeCategory(
                ) == hou.sopNodeTypeCategory():
                    for node in hou.selectedNodes():
                        if isinstance(node,
                                      hou.SopNode) and node.isHardLocked():
                            locked_nodes.append(node)
                if len(locked_nodes) > 0:
                    text = "Detected these selected nodes have had HardLocked,thus will cause asset become large, " \
                        "do you want to unlock those nodes?\n%s" % "\n".join([x.name() for x in locked_nodes])
                    button_code = HaocUtils.show_question_box(self, text)
                    if button_code == QtWidgets.QMessageBox.Cancel:
                        return
                    if button_code == QtWidgets.QMessageBox.Yes:
                        for node in locked_nodes:
                            node.setHardLocked(False)

            if not os.path.exists(os.path.dirname(local_path)):
                os.makedirs(os.path.dirname(local_path))
            parent.saveItemsToFile(hou.selectedItems(), "%s.nod" % local_path,
                                   self.hda_fall_backs.isChecked())
            if self.comments.toPlainText().strip() != '':
                with codecs.open("%s.hlp" % local_path, 'w',
                                 'utf-8') as comments_file:
                    comments_file.write(self.comments.toPlainText())

        # Put folder or file on cloud
        command = HaocObjects.CommandItem(1, path=cloud_path)
        commands_t = SCloudUtils.TDoCommands([command])
        commands_t.start()