def removeRow(self, position, parent=QtCore.QModelIndex()): parentItem = self.getItem(parent) parentID = parentItem._dbId dbid = parentItem.child(position)._dbId # 获取要删除项的ID # 获取并更新父级 childrenID 数据 childrenID = self.getChildrenIdList(parent) if parent != QtCore.QModelIndex(): childrenID.remove(dbid) # 删除id 从childrenID childrenIdStr = str(childrenID)[1:-1] # list转为文字并去掉首尾字符([]) # 更新父级item 数据 parentItem._itemData[3] = childrenIdStr # 更新父级数据库数据 DB.updateData(configure.getProjectPath(), 'table_taskInfo', 'id=%d' % (parentID), 'childrenID="%s"' % childrenIdStr) # 从数据库删除项 DB.deleteData(configure.getProjectPath(), 'table_taskInfo', 'id=%d' % (dbid)) # 从树删除 self.removeRows(position, 1, parent) filePath = configure.getProjectPath() + '/data/%s' % dbid shutil.rmtree(filePath, True) #递归删除文件夹,True参数表示ignore_errors(忽略错误)。
def openFile(self, path): if path == os.path.abspath('./UI/img_loss.png') or os.path.isfile(): filePath = configure.getProjectPath() + '/data/Content/%s'%(self.datas[0]) if not os.path.exists(filePath): os.makedirs(filePath) # 创建路径 # 选择缩略图 imgPath = QtWidgets.QFileDialog.getOpenFileName(None, "Find Img", \ filePath, "Image Files(*.jpg *.png *.jpge *.tga *.gif)") # 设置缩略图 if imgPath[1]: imgName = os.path.split(imgPath[0])[1] # 分离文件名 if not os.path.exists(filePath+'/$PMF_SystemFiles'): os.makedirs(filePath+'/$PMF_SystemFiles') # 创建系统文件路径 if 'Windows' in platform.system(): win32api.SetFileAttributes(filePath+'/$PMF_SystemFiles', win32con.FILE_ATTRIBUTE_HIDDEN) # 隐藏文件夹 if os.path.exists(filePath+'/$PMF_SystemFiles'+imgName): os.remove(filePath+'/$PMF_SystemFiles'+imgName) shutil.copy(imgPath[0], filePath+'/$PMF_SystemFiles') # 复制文件到指定目录 imgRelativePath = '/data/Content/%s'%(self.datas[0]) + '/$PMF_SystemFiles/' + imgName # 重组路径,相对路径 self.imgPath = configure.getProjectPath() + imgRelativePath self.setDetail_Img(self.imgPath) # set 任务树item的缩略图 self.dataChanged(u'缩略图', imgRelativePath) else: openFile(path)
def insertRow(self, position, parent=QtCore.QModelIndex(), data=None): parentItem = self.getItem(parent) parentID = parentItem._dbId if data == None: data = configure.get_DB_Struct( 'empty_taskInfo') # 从配置文件获取插入的空内容(list) data[0] = parentID # print(data) # 数据库插入项并获取其id dbid = DB.insertData(configure.getProjectPath(), 'table_taskInfo', configure.struct_taskInfo(), data) # 获取并更新父级 childrenID 数据 childrenID = self.getChildrenIdList(parent) if parent != QtCore.QModelIndex(): childrenID.insert(position, dbid) # 插入id到childrenID childrenIdStr = str(childrenID)[1:-1] # list转为文字并去掉首尾字符([]) # 更新父级item 数据 parentItem._itemData[3] = childrenIdStr # 更新父级数据库数据 DB.updateData(configure.getProjectPath(), 'table_taskInfo', 'id=%d' % (parentID), 'childrenID="%s"' % childrenIdStr) data.insert(0, dbid) # 将ID添加到插入数据中 # print(data) item = BaseTreeItem(data) self.insertRows(position, 1, parent, [item]) filePath = configure.getProjectPath() + '/data/Content/%s' % dbid if not os.path.exists(filePath): os.makedirs(filePath) # 创建路径 return self.index(position, 0, parent) # 返回插入项的index
def processtrigger(self, q): # 输出那个Qmenu对象被点击 if q.text().encode("utf-8") == "设置缩略图": filePath = configure.getProjectPath() + '/data/Content/%s'%(self.datas[0]) if not os.path.exists(filePath): os.makedirs(filePath) # 创建路径 # 选择缩略图 imgPath = QtWidgets.QFileDialog.getOpenFileName(None, "Find Img", \ filePath, "Image Files(*.jpg *.png *.jpge *.tga *.gif)") # 设置缩略图 if imgPath[1]: imgName = os.path.split(imgPath[0])[1] # 分离文件名 if not os.path.exists(filePath+'/$PMF_SystemFiles'): os.makedirs(filePath+'/$PMF_SystemFiles') # 创建系统文件路径 if 'Windows' in platform.system(): win32api.SetFileAttributes(filePath+'/$PMF_SystemFiles', win32con.FILE_ATTRIBUTE_HIDDEN) # 隐藏文件夹 if os.path.exists(filePath+'/$PMF_SystemFiles'+imgName): os.remove(filePath+'/$PMF_SystemFiles'+imgName) shutil.copy(imgPath[0], filePath+'/$PMF_SystemFiles') # 复制文件到指定目录 imgRelativePath = '/data/Content/%s'%(self.datas[0]) + '/$PMF_SystemFiles/' + imgName # 重组路径,相对路径 self.imgPath = configure.getProjectPath() + imgRelativePath self.setDetail_Img(self.imgPath) # set 任务树item的缩略图 self.dataChanged(u'缩略图', imgRelativePath) elif q.text().encode("utf-8") == "清除缩略图": self.setDetail_Img() # set 任务树item的缩略图 self.dataChanged(u'缩略图', '')
def browse(): directory = '' if configure.getProjectPath() != None: if os.path.isdir(configure.getProjectPath()): directory = QtWidgets.QFileDialog.getExistingDirectory(None, "Find Dir", configure.getProjectPath()) else: directory = QtWidgets.QFileDialog.getExistingDirectory(None, "Find Dir", QtCore.QDir.currentPath()) else: directory = QtWidgets.QFileDialog.getExistingDirectory(None, "Find Dir", QtCore.QDir.currentPath()) return directory
def SetProjectPath(): directory = browse() if directory != '': configure.setProjectPath(directory) configure.createProjectConfig() elif not os.path.isdir(configure.getProjectPath()): showErrorMsg('工程目录不存在')
def __init__(self, parent=None): super(DropListWidget, self).__init__(parent) self.lastPath = configure.getProjectPath() self.datas = [] # Item 数据 self.setAcceptDrops(True) self.setDragEnabled(True) # 开启可拖放事件 self.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) # 按住CTRL可多选 # 创建右键菜单 self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self.showListRightMenu) # 双击打开文件 self.itemDoubleClicked.connect(self.openFile) # 设置鼠标跟踪为True self.setMouseTracking(True) self._path = '' # 列表显示内容所在目录 # 显示的列表 self.showSource = True self.showMesh = True self.showTex = True self.showRevisions = False self.mouseIn = False
def setData(self, value, column): # self._itemData = list(self._itemData) # 将元组转换为列表 # print(self._itemData) self._itemData[column + 4] = value # 更新数据库数据 dbKey = configure.get_DB_Struct('struct_taskInfo')[column + 3] DB.updateData(configure.getProjectPath(), 'table_taskInfo', 'id=%d' % (self._dbId), '%s="%s"' % (dbKey, value))
def updateChild(self, parent=QtCore.QModelIndex()): parentItem = self.getItem(parent) # 删除现有子项 if self.rowCount(parent) > 0: self.removeRows(0, self.rowCount(parent), parent) items = [] # 添加子项(父项为root项时) if parent == QtCore.QModelIndex(): dbdatas = DB.findDatas(configure.getProjectPath(), 'table_taskInfo', 'parentID=-1') for itemdata in dbdatas: # print(itemdata) items.append(BaseTreeItem(itemdata, parentItem)) # 添加行 childrenID = self.getChildrenIdList(parent) # 获取 childrenID 列表 # 添加子项(父项非root项时) if childrenID != None: for ci in childrenID: # if str.isdigit(i): # 判断是否为正整数 dbdatas = DB.findData(configure.getProjectPath(), 'table_taskInfo', 'id=%s' % ci) itemdata = dbdatas items.append(BaseTreeItem(itemdata, parentItem)) # 根据childrenID添加行 # 添加二级子项 for item in items: itemIndex = self.index(item.row(), 0, parent) # self.updateChild(itemIndex) # 获取 childrenID 列表 secChildrenID = self.getChildrenIdList(itemIndex) if secChildrenID != None: for sci in secChildrenID: # if str.isdigit(i): # 判断是否为正整数 dbdatas = DB.findData(configure.getProjectPath(), 'table_taskInfo', 'id=%s' % sci) itemdata = dbdatas BaseTreeItem(itemdata, item) # 根据childrenID添加行
def __init__(self, uiPath='', parent=None): super(MainWindow, self).__init__(parent) # PyQt5 加载ui文件方法 self.ui = uic.loadUi(uiPath, self) # 检查工程目录是否存在,不存在则设置工程目录 if not os.path.isdir(configure.getProjectPath()): SetProjectPath() # ---------------------------- 概览面板 ---------------------------- # self.item = QtWidgets.QListWidgetItem() # 创建QListWidgetItem对象 self.item.setSizeHint(QtCore.QSize(200, 50)) # 设置QListWidgetItem大小 self.itemWidget = loadWidgets.ListItem_General_Proj() # itemWidget self.ui.listWidget_General_Proj.addItem(self.item) # 添加item self.ui.listWidget_General_Proj.setItemWidget( self.item, self.itemWidget) # 为item设置widget # -------------------------- 详细信息面板 -------------------------- # self.detailPage_Proj_Task = loadWidgets.DetailPage() # Widget- DetailPage 详细信息面板 # ---------------------------- 项目面板 ---------------------------- # ## ------------------ 任务面板 ------------------ # ### --------------- 任务树 --------------- # self.rootItemData_Proj_Task = configure.get_DB_Struct( 'rootNode_taskInfo') self.rootNode_Proj_Task = BaseTreeItem(self.rootItemData_Proj_Task) print(self.rootNode_Proj_Task) self.ui.treeView_Proj_Task.setColumnWidth(0,200) # 不起作用!!!? # 设置 Model self.model_Proj_Task = TreeModel_Proj_Task(self.rootNode_Proj_Task) self.model_Proj_Task.func = self.currentIndexDataChanged # 数据更新时调用的函数 self.ui.treeView_Proj_Task.setModel(self.model_Proj_Task) self.detailPage_Proj_Task.model_Proj_Task = self.model_Proj_Task # 把树model传入detailPage # treeView_Proj_Task item 点击事件 self.ui.treeView_Proj_Task.clicked.connect(self.taskTreeItemClicked) # treeView_Proj_Task item 双击事件 self.ui.treeView_Proj_Task.doubleClicked.connect(self.taskTreeItemDoubleClicked) # 右键菜单(treeView_Proj_Task) self.createRightMenu_treeView_Proj_Task() # 设置 Item 部件 self.delegate = range(10) self.setDelegate() self.lastSelectIndex = None
def setDetailPageInfo(self, index): if index == QtCore.QModelIndex(): index = self.lastSelectIndex if index != None: currentItem = self.model_Proj_Task.getItem(index) self.detailPage_Proj_Task.datas = currentItem.datas() self.detailPage_Proj_Task.currentIndex = index labels = configure.get_DB_Struct("rootNode_taskInfo") # ---------- 信息 ----------- # taskName if u'任务' in labels: num = labels.index(u'任务') self.detailPage_Proj_Task.setTaskName(currentItem.datas()[num]) # type if u'类型' in labels: num = labels.index(u'类型') self.detailPage_Proj_Task.setTaskType(currentItem.datas()[num]) # state if u'状态' in labels: num = labels.index(u'状态') self.detailPage_Proj_Task.setTaskState(currentItem.datas()[num]) # treePath if u'任务' in labels: num = labels.index(u'任务') treePath = [currentItem.datas()[num]] parentItem = currentItem.parent() while parentItem != None: treePath.insert(0, parentItem.datas()[num]) parentItem = parentItem.parent() treePath = treePath[1:] self.detailPage_Proj_Task.setTreePath(treePath) # Detail_Img if u'缩略图' in labels: num = labels.index(u'缩略图') self.detailPage_Proj_Task.setDetail_Img(currentItem.datas()[num]) # FL_Info labels = configure.get_DB_Struct('rootNode_taskInfo') datas = currentItem.datas() dataTypes = configure.get_DB_Struct('dataTypes') self.detailPage_Proj_Task.setFL_Info(labels, datas, dataTypes) # ---------- 文件 ----------- # fileList_Path self.detailPage_Proj_Task.fileList._path = configure.getProjectPath() + '/data/Content/%s'%currentItem.datas()[0] self.detailPage_Proj_Task.fileList.updateList() # 更新文件列表
def data(self, index, role): if not index.isValid(): return None # item = index.internalPointer() item = self.getItem(index) # 设置行高 if role == QtCore.Qt.SizeHintRole: # 返回单元格尺寸 return QtCore.QSize(0, 40) if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole: if index.column() == 1: # 缩略图列 return '' else: return item.data(index.column()) # 设置图标 state if role == QtCore.Qt.DecorationRole: if index.column() == 0: # 设置图标 # print(item.data(2)) # print("任务") if item.data(2).encode("utf-8") == "任务": return QtGui.QIcon(QtGui.QPixmap('./UI/point_blue.png')) elif item.data(2).encode("utf-8") == "用户故事": return QtGui.QIcon(QtGui.QPixmap('./UI/point_green.png')) else: return QtGui.QIcon(QtGui.QPixmap('./UI/point_gray.png')) if index.column() == 1: # 缩略图列 imgId = configure.getIndexByLabel(u'缩略图') imgPath = configure.getProjectPath() + item.datas()[ imgId] # 获取缩略图路径 if os.path.isfile(imgPath): # 判断文件 if imgPath.endswith( ('.jpg', '.jpge', '.png', '.tga', '.gif')): return QtGui.QIcon(QtGui.QPixmap(imgPath)) return QtGui.QIcon(QtGui.QPixmap('./UI/img_loss.jpg'))
def setAllDatasByDetail(self, index, datas, role=QtCore.Qt.EditRole): if index.isValid(): item = index.internalPointer() # 获取item if role == QtCore.Qt.EditRole: # if index.column() == 1: # item._itemData = datas datas = datas[8:] x = 3 for i in datas: x += 1 # 获取数据库的数据 dbKey = configure.get_DB_Struct('struct_taskInfo')[x + 3] dbData = DB.findData(configure.getProjectPath(), 'table_taskInfo', 'id=%d' % (item._dbId), '%s' % (dbKey)) if i != dbData: # 判断数据是否有修改 # 更新树列表及数据库数据 item.setData(i, x) index_X = self.index(index.row(), x, index.parent()) self.dataChanged.emit(index_X, index_X) # 更新Model的数据 return True return False