Beispiel #1
0
    def update_content(self, versions):
        """updates the content with the given versions data
        """
        import os
        import datetime

        logger.debug('VersionsTableWidget.update_content() is started')

        self.clear()
        self.versions = versions
        self.setRowCount(len(versions))

        def set_published_font(item):
            """sets the font for the given item

            :param item: the a QTableWidgetItem
            """
            my_font = item.font()
            my_font.setBold(True)

            item.setFont(my_font)

            foreground = item.foreground()
            foreground.setColor(QtGui.QColor(0, 192, 0))
            item.setForeground(foreground)

        # update the previous versions list
        from anima import defaults
        for i, version in enumerate(versions):
            is_published = version.is_published
            absolute_full_path = os.path.normpath(
                os.path.expandvars(version.full_path)).replace('\\', '/')
            version_file_exists = os.path.exists(absolute_full_path)

            c = 0

            # ------------------------------------
            # version_number
            item = QtWidgets.QTableWidgetItem(str(version.version_number))
            # align to center and vertical center
            item.setTextAlignment(0x0004 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # created_with
            item = QtWidgets.QTableWidgetItem()
            if version.created_with:
                from anima.ui import utils as ui_utils
                item.setIcon(ui_utils.get_icon(version.created_with.lower()))

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # user.name
            created_by = ''
            if version.created_by_id:
                created_by = defaults.user_names_lut[version.created_by_id]
            item = QtWidgets.QTableWidgetItem(created_by)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # user.name
            updated_by = ''
            if version.updated_by_id:
                updated_by = defaults.user_names_lut[version.updated_by_id]
            item = QtWidgets.QTableWidgetItem(updated_by)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # file size

            # get the file size
            # file_size_format = "%.2f MB"
            file_size = -1
            if version_file_exists:
                file_size = float(
                    os.path.getsize(absolute_full_path)) / 1048576

            from anima import defaults
            item = QtWidgets.QTableWidgetItem(defaults.file_size_format %
                                              file_size)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # date

            # get the file date
            file_date = datetime.datetime.today()
            if version_file_exists:
                file_date = datetime.datetime.fromtimestamp(
                    os.path.getmtime(absolute_full_path))
            item = QtWidgets.QTableWidgetItem(
                file_date.strftime(defaults.date_time_format))

            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

            # ------------------------------------
            # description
            item = QtWidgets.QTableWidgetItem(version.description)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)

            if is_published:
                set_published_font(item)

            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))

            self.setItem(i, c, item)
            c += 1
            # ------------------------------------

        # resize the first column
        self.resizeRowsToContents()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()
        logger.debug('VersionsTableWidget.update_content() is finished')
Beispiel #2
0
    def update_content(self, versions):
        """updates the content with the given versions data
        """
        import os
        import datetime
        
        logger.debug('VersionsTableWidget.update_content() is started')
        
        self.clear()
        self.versions = versions
        self.setRowCount(len(versions))
        
        def set_published_font(item):
            """sets the font for the given item

            :param item: the a QTableWidgetItem
            """
            my_font = item.font()
            my_font.setBold(True)
            
            item.setFont(my_font)
            
            foreground = item.foreground()
            foreground.setColor(QtGui.QColor(0, 192, 0))
            item.setForeground(foreground)
        
        # update the previous versions list
        from anima import defaults
        for i, version in enumerate(versions):
            is_published = version.is_published
            absolute_full_path = os.path.normpath(
                os.path.expandvars(version.full_path)
            ).replace('\\', '/')
            version_file_exists = os.path.exists(absolute_full_path)
            
            c = 0
            
            # ------------------------------------
            # version_number
            item = QtWidgets.QTableWidgetItem(str(version.version_number))
            # align to center and vertical center
            item.setTextAlignment(0x0004 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # created_with
            item = QtWidgets.QTableWidgetItem()
            if version.created_with:
                from anima.ui import utils as ui_utils
                item.setIcon(ui_utils.get_icon(version.created_with.lower()))
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # user.name
            created_by = ''
            if version.created_by_id:
                created_by = defaults.user_names_lut[version.created_by_id]
            item = QtWidgets.QTableWidgetItem(created_by)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # user.name
            updated_by = ''
            if version.updated_by_id:
                updated_by = defaults.user_names_lut[version.updated_by_id]
            item = QtWidgets.QTableWidgetItem(updated_by)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # file size
            
            # get the file size
            # file_size_format = "%.2f MB"
            file_size = -1
            if version_file_exists:
                file_size = float(
                    os.path.getsize(absolute_full_path)) / 1048576
            
            from anima import defaults
            item = QtWidgets.QTableWidgetItem(
                defaults.file_size_format % file_size
            )
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # date
            
            # get the file date
            file_date = datetime.datetime.today()
            if version_file_exists:
                file_date = datetime.datetime.fromtimestamp(
                    os.path.getmtime(absolute_full_path)
                )
            item = QtWidgets.QTableWidgetItem(
                file_date.strftime(defaults.date_time_format)
            )
            
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
            
            # ------------------------------------
            # description
            item = QtWidgets.QTableWidgetItem(version.description)
            # align to left and vertical center
            item.setTextAlignment(0x0001 | 0x0080)
            
            if is_published:
                set_published_font(item)
            
            if not version_file_exists:
                item.setBackground(QtGui.QColor(64, 0, 0))
            
            self.setItem(i, c, item)
            c += 1
            # ------------------------------------
        
        # resize the first column
        self.resizeRowsToContents()
        self.resizeColumnsToContents()
        self.resizeRowsToContents()
        logger.debug('VersionsTableWidget.update_content() is finished')