def get_version_from_full_path(self, full_path): """Finds the Version instance from the given full_path value. Finds and returns a :class:`~oyProjectManager.models.version.Version` instance from the given full_path value. Returns None if it can't find any matching. :param full_path: The full_path of the desired :class:`~oyProjectManager.models.version.Version` instance. :return: :class:`~oyProjectManager.models.version.Version` """ path, filename = os.path.split(full_path) path = self.trim_server_path(path) logger.debug('path: %s' % path) # try to get a version with that info version = Version.query()\ .filter(Version.path==path)\ .filter(Version.filename==filename)\ .first() return version
def get_versions_from_path(self, path): """Finds Version instances from the given path value. Finds and returns the :class:`~oyProjectManager.models.version.Version` instances from the given path value. Returns an empth list if it can't find any matching. This method is different than :meth:`~oyProjectManager.models.entity.EnvironmentBase.get_version_from_full_path` because it returns a list of :class:`~oyProjectManager.models.version.Version` instances which are residing in that path. The list is ordered by the ``id``\ s of the instances. :param path: A path which has possible :class:`~oyProjectManager.models.version.Version` instances. :return: A list of :class:`~oyProjectManager.models.version.Version` instances. """ if path is None or path == "": return None # get the path by trimming the server_path path = path.replace('\\', '/') path = self.trim_server_path(path) # get all the version instance at that path return Version.query()\ .filter(Version.path.startswith(path))\ .order_by(Version.id.desc())\ .all()
def fill_shots_tableWidget(self): """fills the shots_tableWidget """ # TODO: merge cells of the same shot, or at least paint them in some other color # clear the tableWidget self.shots_tableWidget.clear() shot_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Shot')\ .order_by(VersionType.name)\ .all() shot_vtype_codes = map(lambda x: x.code, shot_vtypes) labels = ['Thumbnail', 'Sequence', 'Number', 'Take'] labels.extend(map(lambda x: x.code, shot_vtypes)) #logger.debug('shot_tableWidget.labels: %s' % labels) self.shots_tableWidget.setColumnCount(len(labels)) self.shots_tableWidget.setHorizontalHeaderLabels(labels) # get the project project = self.get_current_project() if project is None: return # get all the shots for the sequence sequences = Sequence.query()\ .filter(Sequence.project==project)\ .order_by(Sequence.name)\ .all() shot_count = db.query(func.count(Shot.id))\ .join(Sequence)\ .filter(Sequence.id==Shot.sequence_id)\ .filter(Sequence.project==project)\ .all()[0][0] # set the row count for all shots in that sequence self.shots_tableWidget.setRowCount(shot_count) items = [] row = 0 column = 0 for sequence in sequences: shots = Shot.query()\ .filter(Shot.sequence==sequence)\ .order_by(Shot.number)\ .all() # sort according to numbers shots.sort(key=lambda x: utils.embedded_numbers(x.number)) #logger.debug('shots of sequence %s is %s' % (sequence.name, shots)) # feed the shots to the list previous_shot = None for shot in shots: take_names = map( lambda x: x[0], db.query(distinct(Version.take_name)) .filter(Version.version_of==shot) .all() ) if not len(take_names): take_names = ['-'] for take_name in take_names: # add the seq name to the first column column = 0 item = QtGui.QTableWidgetItem() item.setTextAlignment(0x0004 | 0x0080) #set the thumbnail if os.path.exists(shot.thumbnail_full_path): thumbnail_full_path = shot.thumbnail_full_path pixmap = QtGui.QPixmap(thumbnail_full_path) pixmap = pixmap.scaled( conf.thumbnail_size[0] / 2, conf.thumbnail_size[1] / 2, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation ) brush = QtGui.QBrush(pixmap) item.has_thumbnail = True item.setBackground(brush) else: item.has_thumbnail = False items.append(item) column = 1 item = QtGui.QTableWidgetItem(sequence.name) item.setTextAlignment(0x0004 | 0x0080) #self.shots_tableWidget.setItem(row, column, item) items.append(item) # add the shot code to the second column column = 2 item = QtGui.QTableWidgetItem(shot.code) item.setTextAlignment(0x0004 | 0x0080) #self.shots_tableWidget.setItem(row, column, item) items.append(item) # add the take name to the third column column = 3 item = QtGui.QTableWidgetItem(take_name) item.setTextAlignment(0x0004 | 0x0080) #self.assets_tableWidget.setItem(row, column, item) items.append(item) for type_code in shot_vtype_codes: column += 1 # get the latest version of that type and take version = Version.query()\ .join(VersionType)\ .filter(Version.version_of==shot)\ .filter(Version.type_id==VersionType.id)\ .filter(VersionType.code==type_code)\ .filter(Version.take_name==take_name)\ .order_by(Version.version_number.desc())\ .first() if version: # mark the status of that type in that take item = QtGui.QTableWidgetItem( version.status + '\n' + version.created_by.name ) item.setTextAlignment(0x0004 | 0x0080) # set the color according to status index = conf.status_list.index(version.status) bgcolor = conf.status_bg_colors[index] fgcolor = conf.status_fg_colors[index] bg = item.background() bg.setColor(QtGui.QColor(*bgcolor)) item.setBackground(bg) fg = item.foreground() fg.setColor(QtGui.QColor(*fgcolor)) item.setForeground(fg) try: item.setBackgroundColor(QtGui.QColor(*bgcolor)) except AttributeError: # for PySide pass # set this version to the item item.version = version else: # set the background color to black item = QtGui.QTableWidgetItem('-') item.setTextAlignment(0x0004 | 0x0080) bg = item.background() bg.setColor(QtGui.QColor(0, 0, 0)) item.setBackground(bg) try: item.setBackgroundColor(QtGui.QColor(0, 0, 0)) except AttributeError: # for PySide pass # set the version to None for this item item.version = None items.append(item) row += 1 self.shots_tableWidget.setRowCount(row) item_index = 0 for r in range(row): for c in range(column + 1): item = items[item_index] self.shots_tableWidget.setItem(r, c, item) item_index += 1 # adjust the row heights accordingly self.shots_tableWidget.resizeRowsToContents() # need to pass over the first rows again # to resize the thumbnail cell for r in range(row): item_index = r * (column + 1) item = items[item_index] if item.has_thumbnail: # scale the row height self.shots_tableWidget.setRowHeight( r, conf.thumbnail_size[1] / 2 ) # resize columns to fit the content self.shots_tableWidget.resizeColumnsToContents() # set the column width self.shots_tableWidget.setColumnWidth(0, conf.thumbnail_size[0] / 2)
def fill_assets_tableWidget(self): """fills the asset_tableWidget """ # clear the table self.assets_tableWidget.clear() asset_vtypes = VersionType.query()\ .filter(VersionType.type_for=='Asset')\ .order_by(VersionType.name)\ .all() asset_vtype_codes = map(lambda x: x.code, asset_vtypes) labels = ['Thumbnail', 'Type', 'Name', 'Take'] labels.extend(map(lambda x: x.code, asset_vtypes)) logger.debug('asset_tableWidget.labels: %s' % labels) self.assets_tableWidget.setColumnCount(len(labels)) self.assets_tableWidget.setHorizontalHeaderLabels(labels) # get the project project = self.get_current_project() if project is None: return # get all the assets for the project assets = Asset.query()\ .filter(Asset.project==project)\ .order_by(Asset.type)\ .all() # feed the assets to the list items = [] row = 0 column = 0 for asset in assets: # get the distinct take names take_names = map( lambda x: x[0], db.query(distinct(Version.take_name)) .filter(Version.version_of==asset) .all() ) if not len(take_names): take_names = ['-'] for take_name in take_names: # add the asset type to the first column column = 0 item = QtGui.QTableWidgetItem() item.setTextAlignment(0x0004 | 0x0080) # set the thumbnail if os.path.exists(asset.thumbnail_full_path): thumbnail_full_path = asset.thumbnail_full_path pixmap = QtGui.QPixmap(thumbnail_full_path) pixmap = pixmap.scaled( conf.thumbnail_size[0] / 2, conf.thumbnail_size[1] / 2, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation ) brush = QtGui.QBrush(pixmap) item.has_thumbnail = True item.setBackground(brush) else: item.has_thumbnail = False items.append(item) column = 1 item = QtGui.QTableWidgetItem(asset.type) item.setTextAlignment(0x0004 | 0x0080) items.append(item) # add the asset name to the second column column = 2 item = QtGui.QTableWidgetItem(asset.name) item.setTextAlignment(0x0004 | 0x0080) items.append(item) # add the take name to the third column column = 3 item = QtGui.QTableWidgetItem(take_name) item.setTextAlignment(0x0004 | 0x0080) #self.assets_tableWidget.setItem(row, column, item) items.append(item) for type_code in asset_vtype_codes: column += 1 # now for every asset vtype create two rows instead of one # and show the users name on the second row # get the latest version of that type and take version = Version.query()\ .join(VersionType)\ .filter(Version.version_of==asset)\ .filter(Version.type_id==VersionType.id)\ .filter(VersionType.code==type_code)\ .filter(Version.take_name==take_name)\ .order_by(Version.version_number.desc())\ .first() if version: # mark the status of that type in that take item = QtGui.QTableWidgetItem( version.status + '\n' + version.created_by.name ) item.setTextAlignment(0x0004 | 0x0080) # set the color according to status index = conf.status_list.index(version.status) bgcolor = conf.status_bg_colors[index] fgcolor = conf.status_fg_colors[index] bg = item.background() bg.setColor(QtGui.QColor(*bgcolor)) item.setBackground(bg) fg = item.foreground() fg.setColor(QtGui.QColor(*fgcolor)) item.setForeground(fg) try: item.setBackgroundColor(QtGui.QColor(*bgcolor)) except AttributeError: # gives errpor with PySide pass # add this version to the item item.version = version else: # set the background color to black item = QtGui.QTableWidgetItem('-') item.setTextAlignment(0x0004 | 0x0080) bg = item.background() bg.setColor(QtGui.QColor(0, 0, 0)) item.setBackground(bg) try: item.setBackgroundColor(QtGui.QColor(0, 0, 0)) except AttributeError: # gives error with PySide pass # set the related version to None item.version = None items.append(item) row += 1 self.assets_tableWidget.setRowCount(row) item_index = 0 for r in range(row): for c in range(column + 1): item = items[item_index] self.assets_tableWidget.setItem(r, c, item) item_index += 1 # adjust the row heights accordingly self.assets_tableWidget.resizeRowsToContents() # need to pass over the first rows again # to resize the thumbnail cell for r in range(row): item_index = r * (column + 1) item = items[item_index] if item.has_thumbnail: # scale the row height self.assets_tableWidget.setRowHeight( r, conf.thumbnail_size[1] / 2 ) # resize columns to fit the content self.assets_tableWidget.resizeColumnsToContents() # set column width self.assets_tableWidget.setColumnWidth(0, conf.thumbnail_size[0] / 2)