def add_alternative_shot(self, shot_number): """adds a new alternative to the given shot returns the alternative shot number """ # shot_number could be an int convert it to str # get the first integer as int in the string shot_number = utils.embedded_numbers(str(shot_number))[1] # get the next available alternative shot number for that shot alternative_shot_number = \ self.get_next_alternate_shot_number(shot_number) # add that alternative shot to the shot list if alternative_shot_number is not None: new_alternative_shot = Shot(self, alternative_shot_number) db.session.add(new_alternative_shot) db.session.commit() return alternative_shot_number
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)