예제 #1
0
 def setup_sufficient_space(self):
     # TODO move into prepare.
     size = misc.install_size()
     self.db.subst('ubiquity/text/required_space', 'SIZE',
                   misc.format_size(size))
     free = self.free_space()
     self.db.subst('ubiquity/text/free_space', 'SIZE',
                   misc.format_size(free))
     required_text = self.description('ubiquity/text/required_space')
     free_text = self.description('ubiquity/text/free_space')
     self.ui.set_sufficient_space(size < free, required_text, free_text)
예제 #2
0
 def setup_sufficient_space(self):
     # TODO move into prepare.
     size = misc.install_size()
     self.db.subst(
         'ubiquity/text/required_space', 'SIZE',
         misc.format_size(size))
     free = self.free_space()
     self.db.subst(
         'ubiquity/text/free_space', 'SIZE',
         misc.format_size(free))
     required_text = self.description('ubiquity/text/required_space')
     free_text = self.description('ubiquity/text/free_space')
     self.ui.set_sufficient_space(size < free, required_text, free_text)
예제 #3
0
    def _drawLabels(self, painter, part, x, h, partColor):
        painter.setPen(QtCore.Qt.black)

        # label vertical location
        labelY = h + 8

        texts = []
        texts.append(part.name)
        texts.append(format_size(part.size))

        nameFont = QtGui.QFont("arial", 10)
        infoFont = QtGui.QFont("arial", 8)

        painter.setFont(nameFont)
        v_off = 0
        width = 0
        for text in texts:
            textSize = painter.fontMetrics().size(
                QtCore.Qt.TextSingleLine, text)
            painter.drawText(
                x + 18,
                labelY + v_off + textSize.height() / 2, text)
            v_off += textSize.height()
            painter.setFont(infoFont)
            painter.setPen(QtGui.QColor(PartitionsBar.InfoColor))
            width = max(width, textSize.width())

        self._drawPartitionFrame(painter, x, labelY - 3, 13, 13, partColor)

        return width + 40
예제 #4
0
    def _drawLabels(self, painter, part, x, h, partColor):
        painter.setPen(QtCore.Qt.black)

        # label vertical location
        labelY = h + 8

        texts = []
        texts.append(part.name)
        texts.append(format_size(part.size))

        nameFont = QtGui.QFont("arial", 10)
        infoFont = QtGui.QFont("arial", 8)

        painter.setFont(nameFont)
        v_off = 0
        width = 0
        for text in texts:
            textSize = painter.fontMetrics().size(QtCore.Qt.TextSingleLine,
                                                  text)
            painter.drawText(x + 18, labelY + v_off + textSize.height() / 2,
                             text)
            v_off += textSize.height()
            painter.setFont(infoFont)
            painter.setPen(QtGui.QColor(PartitionsBar.InfoColor))
            width = max(width, textSize.width())

        self._drawPartitionFrame(painter, x, labelY - 3, 13, 13, partColor)

        return width + 40
예제 #5
0
 def setup_sufficient_space(self):
     # TODO move into prepare.
     size = misc.install_size()
     self.db.subst('ubiquity/text/prepare_sufficient_space', 'SIZE', misc.format_size(size))
     space = self.description('ubiquity/text/prepare_sufficient_space')
     self.ui.set_sufficient_space(self.big_enough(size))
     self.ui.set_sufficient_space_text(space)
예제 #6
0
 def setup_sufficient_space(self):
     # TODO move into prepare.
     size = misc.install_size()
     self.db.subst('ubiquity/text/prepare_sufficient_space', 'SIZE',
                   misc.format_size(size))
     space = self.description('ubiquity/text/prepare_sufficient_space')
     self.ui.set_sufficient_space(self.big_enough(size))
     self.ui.set_sufficient_space_text(space)
예제 #7
0
 def set_size(self, size):
     self.size = size
     if size > 0:
         self.subtitle = format_size(self.size)
     else:
         self.subtitle = ''
예제 #8
0
 def set_size(self, size):
     self.size = size
     if size > 0:
         self.subtitle = format_size(self.size)
     else:
         self.subtitle = ''
예제 #9
0
    def paintEvent(self, qPaintEvent):
        painter = QPainter(self)

        #used for drawing sunken frame
        sunkenFrameStyle = QStyleOptionFrame()
        sunkenFrameStyle.state = QStyle.State_Sunken

        h = self.bar_height
        h_2 = self.bar_height/2
        effective_width = self.width() - 1

        path = QPainterPath()
        path.addRoundedRect(1, 1, self.width()-2, h-2, self.radius, self.radius)

        part_offset = 0
        label_offset = 0
        trunc_pix = 0
        resize_handle_x = None
        for p in self.partitions:
            painter.setRenderHint(QPainter.Antialiasing, True)

            #this is done so that even after resizing, other partitions draw in the same places
            trunc_pix += (effective_width * float(p.size) / self.diskSize)
            pix_size = int(round(trunc_pix))
            trunc_pix -= pix_size

            #use the right color for the filesystem
            if Partition.filesystemColours.has_key(p.fs):
                pColor = QColor(Partition.filesystemColours[p.fs])
            else:
                pColor = QColor(Partition.filesystemColours['free'])

            pal = QPalette(pColor)
            dark = pal.color(QPalette.Dark)
            mid = pColor.darker(125)
            midl = mid.lighter(125)

            grad = QLinearGradient(QPointF(0, 0), QPointF(0, h))

            if p.fs == "free":
                grad.setColorAt(.25, mid)
                grad.setColorAt(1, midl)
            else:
                grad.setColorAt(0, midl)
                grad.setColorAt(.75, mid)

            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(grad))
            painter.setClipRect(part_offset, 0, pix_size, h*2)
            painter.drawPath(path)

            if part_offset > 0:
                painter.setPen(dark)
                painter.drawLine(part_offset, 3, part_offset, h - 3)

            painter.setClipping(False)

            draw_labels = True
            if draw_labels:
                #draw the labels
                painter.setPen(Qt.black)

                #name is the path by default, or free space if unpartitioned
                name = p.name
                if name == None:
                    if p.fs == 'free':
                        name = 'free space'
                    elif p.fs == 'swap':
                        name = 'swap'
                    else:
                        name = p.path

                #label vertical location
                labelY = h + 8

                texts = []
                texts.append(name)
                texts.append("%.01f%% (%s)" % (float(p.size) / self.diskSize * 100, format_size(p.size)))

                nameFont = QFont("arial", 10)
                infoFont = QFont("arial", 8)

                painter.setFont(nameFont)
                v_off = 0
                width = 0
                for text in texts:
                    textSize = painter.fontMetrics().size(Qt.TextSingleLine, text)
                    painter.drawText(label_offset + 20, labelY + v_off + textSize.height()/2, text)
                    v_off += textSize.height()
                    painter.setFont(infoFont)
                    painter.setPen(QColor(PartitionsBar.InfoColor))
                    width = max(width, textSize.width())

                painter.setPen(Qt.NoPen)
                painter.setBrush(mid)
                labelRect = QPainterPath()
                labelRect.addRoundedRect(label_offset+1, labelY - 3, 13, 13, 4, 4)
                painter.drawPath(labelRect)

                sunkenFrameStyle.rect = QRect(label_offset, labelY-4, 15, 15)
                self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)
                self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)

                label_offset += width + 40

            #set the handle location for drawing later
            if self.resize_part and p == self.resize_part.next:
                resize_handle_x = part_offset

            #increment the partition offset
            part_offset += pix_size

        sunkenFrameStyle.rect = QRect(0, 0, self.width(), h)
        self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)

        if self.resize_part and resize_handle_x:
            # draw a resize handle
            part = self.resize_part
            xloc = resize_handle_x
            self.resize_loc = xloc
            side = 1
            arr_dist = 5

            painter.setPen(Qt.NoPen)
            painter.setBrush(Qt.black)

            painter.setRenderHint(QPainter.Antialiasing, True)
            #move out so not created every time
            arrow_offsets = (
                (0, h/2-1), (4, h/2-1), (4, h/2-3), (8, h/2),
                (4, h/2+3), (4, h/2+1), (0, h/2+1))

            p1 = arrow_offsets[0]
            if part.size > part.minsize:
                arrow = QPainterPath(QPointF(xloc + -1 * p1[0], p1[1]))
                for p in arrow_offsets:
                    arrow.lineTo(xloc + -1 * p[0] + 1, p[1])
                painter.drawPath(arrow)

            if part.size < part.maxsize:
                arrow = QPainterPath(QPointF(xloc + p1[0], p1[1]))
                for p in arrow_offsets:
                    arrow.lineTo(xloc + p[0], p[1])
                painter.drawPath(arrow)

            painter.setRenderHint(QPainter.Antialiasing, False)
            painter.setPen(Qt.black)
            painter.drawLine(xloc, 0, xloc, h)
예제 #10
0
 def set_size(self, size):
     size = misc.format_size(size)
     self.size.set_markup('<span size="x-large">%s</span>' % size)
예제 #11
0
    def paintEvent(self, qPaintEvent):
        painter = QPainter(self)

        #used for drawing sunken frame
        sunkenFrameStyle = QStyleOptionFrame()
        sunkenFrameStyle.state = QStyle.State_Sunken

        h = self.bar_height
        h_2 = self.bar_height/2
        effective_width = self.width() - 1

        path = QPainterPath()
        path.addRoundedRect(1, 1, self.width()-2, h-2, self.radius, self.radius)

        part_offset = 0
        label_offset = 0
        trunc_pix = 0
        resize_handle_x = None
        for p in self.partitions:
            painter.setRenderHint(QPainter.Antialiasing, True)

            #this is done so that even after resizing, other partitions draw in the same places
            trunc_pix += (effective_width * float(p.size) / self.diskSize)
            pix_size = int(round(trunc_pix))
            trunc_pix -= pix_size

            #use the right color for the filesystem
            if Partition.filesystemColours.has_key(p.fs):
                pColor = QColor(Partition.filesystemColours[p.fs])
            else:
                pColor = QColor(Partition.filesystemColours['free'])

            pal = QPalette(pColor)
            dark = pal.color(QPalette.Dark)
            mid = pColor.darker(125)
            midl = mid.lighter(125)

            grad = QLinearGradient(QPointF(0, 0), QPointF(0, h))

            if p.fs == "free":
                grad.setColorAt(.25, mid)
                grad.setColorAt(1, midl)
            else:
                grad.setColorAt(0, midl)
                grad.setColorAt(.75, mid)

            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(grad))
            painter.setClipRect(part_offset, 0, pix_size, h*2)
            painter.drawPath(path)

            if part_offset > 0:
                painter.setPen(dark)
                painter.drawLine(part_offset, 3, part_offset, h - 3)

            painter.setClipping(False)

            draw_labels = True
            if draw_labels:
                #draw the labels
                painter.setPen(Qt.black)

                #name is the path by default, or free space if unpartitioned
                name = p.name
                if name == None:
                    if p.fs == 'free':
                        name = 'free space'
                    elif p.fs == 'swap':
                        name = 'swap'
                    else:
                        name = p.path

                #label vertical location
                labelY = h + 8

                texts = []
                texts.append(name)
                texts.append("%.01f%% (%s)" % (float(p.size) / self.diskSize * 100, format_size(p.size)))

                nameFont = QFont("arial", 10)
                infoFont = QFont("arial", 8)

                painter.setFont(nameFont)
                v_off = 0
                width = 0
                for text in texts:
                    textSize = painter.fontMetrics().size(Qt.TextSingleLine, text)
                    painter.drawText(label_offset + 20, labelY + v_off + textSize.height()/2, text)
                    v_off += textSize.height()
                    painter.setFont(infoFont)
                    painter.setPen(QColor(PartitionsBar.InfoColor))
                    width = max(width, textSize.width())

                painter.setPen(Qt.NoPen)
                painter.setBrush(mid)
                labelRect = QPainterPath()
                labelRect.addRoundedRect(label_offset+1, labelY - 3, 13, 13, 4, 4)
                painter.drawPath(labelRect)

                sunkenFrameStyle.rect = QRect(label_offset, labelY-4, 15, 15)
                self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)
                self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)

                label_offset += width + 40

            #set the handle location for drawing later
            if self.resize_part and p == self.resize_part.next:
                resize_handle_x = part_offset

            #increment the partition offset
            part_offset += pix_size

        sunkenFrameStyle.rect = QRect(0, 0, self.width(), h)
        self.style().drawPrimitive(QStyle.PE_Frame, sunkenFrameStyle, painter, self)

        if self.resize_part and resize_handle_x:
            # draw a resize handle
            part = self.resize_part
            xloc = resize_handle_x
            self.resize_loc = xloc
            side = 1
            arr_dist = 5

            painter.setPen(Qt.NoPen)
            painter.setBrush(Qt.black)

            painter.setRenderHint(QPainter.Antialiasing, True)
            #move out so not created every time
            arrow_offsets = (
                (0, h/2-1), (4, h/2-1), (4, h/2-3), (8, h/2),
                (4, h/2+3), (4, h/2+1), (0, h/2+1))

            p1 = arrow_offsets[0]
            if part.size > part.minsize:
                arrow = QPainterPath(QPointF(xloc + -1 * p1[0], p1[1]))
                for p in arrow_offsets:
                    arrow.lineTo(xloc + -1 * p[0] + 1, p[1])
                painter.drawPath(arrow)

            if part.size < part.maxsize:
                arrow = QPainterPath(QPointF(xloc + p1[0], p1[1]))
                for p in arrow_offsets:
                    arrow.lineTo(xloc + p[0], p[1])
                painter.drawPath(arrow)

            painter.setRenderHint(QPainter.Antialiasing, False)
            painter.setPen(Qt.black)
            painter.drawLine(xloc, 0, xloc, h)
예제 #12
0
 def test_format_size(self):
     self.assertEqual(misc.format_size(4 * 1000**0), '4.0 B')
     self.assertEqual(misc.format_size(4 * 1000**1), '4.0 kB')
     self.assertEqual(misc.format_size(4 * 1000**2), '4.0 MB')
     self.assertEqual(misc.format_size(4 * 1000**3), '4.0 GB')
     self.assertEqual(misc.format_size(4 * 1000**4), '4.0 TB')
예제 #13
0
파일: test_misc.py 프로젝트: swem/ubiquity
 def test_format_size(self):
     self.assertEqual(misc.format_size(4 * 1000 ** 0), '4.0 B')
     self.assertEqual(misc.format_size(4 * 1000 ** 1), '4.0 kB')
     self.assertEqual(misc.format_size(4 * 1000 ** 2), '4.0 MB')
     self.assertEqual(misc.format_size(4 * 1000 ** 3), '4.0 GB')
     self.assertEqual(misc.format_size(4 * 1000 ** 4), '4.0 TB')
예제 #14
0
 def set_size(self, size):
     size = misc.format_size(size)
     self.size.set_markup('<span size="x-large">%s</span>' % size)