Merge lp:~agateau/ubiquity/kde-partition-bar-refresh into lp:ubiquity

Proposed by Aurélien Gâteau
Status: Merged
Merged at revision: 6110
Proposed branch: lp:~agateau/ubiquity/kde-partition-bar-refresh
Merge into: lp:ubiquity
Diff against target: 375 lines (+143/-164)
3 files modified
ubiquity/frontend/kde_components/PartAuto.py (+2/-2)
ubiquity/frontend/kde_components/PartMan.py (+3/-1)
ubiquity/frontend/kde_components/PartitionBar.py (+138/-161)
To merge this branch: bzr merge lp:~agateau/ubiquity/kde-partition-bar-refresh
Reviewer Review Type Date Requested Status
Jonathan Riddell Pending
Review via email: mp+205616@code.launchpad.net

Description of the change

Refreshes the appearance of partitions in KDE PartMan:

- Cycle through a set of colors instead of assigning colors based on the file system to ensure colors from adjacent partitions always differ.

- Simpler borders to help makes bars more readable and avoid color overflow

- Revamped text labels: show file system between parenthesis, remove size percentage

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubiquity/frontend/kde_components/PartAuto.py'
2--- ubiquity/frontend/kde_components/PartAuto.py 2013-04-24 10:40:17 +0000
3+++ ubiquity/frontend/kde_components/PartAuto.py 2014-02-10 16:15:03 +0000
4@@ -161,8 +161,8 @@
5 disks.append((text, bar_frame))
6
7 dev = self.diskLayout[path.rsplit('/', 1)[1]]
8- before_bar = PartitionsBar()
9- after_bar = PartitionsBar()
10+ before_bar = PartitionsBar(controller=self.controller)
11+ after_bar = PartitionsBar(controller=self.controller)
12
13 for p in dev:
14 before_bar.addPartition(p.device, int(p.size), p.filesystem)
15
16=== modified file 'ubiquity/frontend/kde_components/PartMan.py'
17--- ubiquity/frontend/kde_components/PartMan.py 2013-09-18 09:20:35 +0000
18+++ ubiquity/frontend/kde_components/PartMan.py 2014-02-10 16:15:03 +0000
19@@ -64,7 +64,9 @@
20 if item in disk_cache:
21 # the item is a disk
22 indexCount += 1
23- partition_bar = PartitionsBar(self.part_advanced_bar_frame)
24+ partition_bar = PartitionsBar(
25+ self.part_advanced_bar_frame,
26+ controller=self.ctrlr)
27 self.part_advanced_bar_frame.layout().addWidget(partition_bar)
28
29 #hide all the other bars at first
30
31=== modified file 'ubiquity/frontend/kde_components/PartitionBar.py'
32--- ubiquity/frontend/kde_components/PartitionBar.py 2013-02-19 11:33:07 +0000
33+++ ubiquity/frontend/kde_components/PartitionBar.py 2014-02-10 16:15:03 +0000
34@@ -27,23 +27,15 @@
35 from ubiquity.misc import find_in_os_prober, format_size
36
37
38-def name_from_path(path):
39- return find_in_os_prober(path) or path.replace('/dev/', '')
40-
41-
42 class Partition:
43- # colors used to render partition types
44- # 'auto' is used to represent the results of automatic partitioning.
45- filesystemColours = {'auto': '#509DE8',
46- 'ext2': '#418DD4',
47- 'ext3': '#418DD4',
48- 'ext4': '#418DD4',
49- 'btrfs': '#418DD4',
50- 'free': '#FFFFFF',
51- 'linux-swap': '#FF80E0',
52- 'fat32': '#C0DAFF',
53- 'fat16': '#C0DAFF',
54- 'ntfs': '#888786'}
55+ Colors = [
56+ '#448eca',
57+ '#a5cc42',
58+ '#d87e30',
59+ '#ffbdbd',
60+ ]
61+
62+ FreeColor = '#777777'
63
64 def __init__(self, path, size, fs, name=None):
65 self.size = size
66@@ -52,15 +44,18 @@
67 self.index = None
68 self.path = path
69
70- if name is None:
71- if fs == 'free':
72- self.name = 'free space'
73- elif fs == 'swap':
74- self.name = 'swap'
75- else:
76- self.name = name_from_path(path)
77- else:
78+ if name is not None:
79 self.name = name
80+ return
81+
82+ if self.fs != 'linux-swap':
83+ # Do not go through find_in_os_prober() for swap: it returns
84+ # 'swap', which is not helpful since we show the filesystem anyway.
85+ # Better continue to the fallback of showing the partition name.
86+ name = find_in_os_prober(path)
87+ if not name:
88+ name = path.replace('/dev/', '')
89+ self.name = '%s (%s)' % (name, fs)
90
91
92 class PartitionsBar(QtGui.QWidget):
93@@ -69,9 +64,10 @@
94 ## signals
95 partitionResized = QtCore.pyqtSignal(['PyQt_PyObject', 'PyQt_PyObject'])
96
97- def __init__(self, parent=None):
98+ def __init__(self, parent=None, controller=None):
99 """ a widget to graphically show disk partitions. """
100 QtGui.QWidget.__init__(self, parent)
101+ self.controller = controller
102 self.partitions = []
103 self.bar_height = 20 # should be a multiple of 2
104 self.diskSize = 0
105@@ -89,154 +85,135 @@
106
107 def paintEvent(self, qPaintEvent):
108 painter = QtGui.QPainter(self)
109-
110- # used for drawing sunken frame
111- sunkenFrameStyle = QtGui.QStyleOptionFrame()
112- sunkenFrameStyle.state = QtGui.QStyle.State_Sunken
113-
114 h = self.bar_height
115 effective_width = self.width() - 1
116
117- path = QtGui.QPainterPath()
118- path.addRoundedRect(
119- 1, 1, self.width() - 2, h - 2, self.radius, self.radius)
120-
121- part_offset = 0
122- label_offset = 0
123- trunc_pix = 0
124+ part_x = 0
125+ label_x = 0
126+ trunc_width = 0
127 resize_handle_x = None
128- for p in self.partitions:
129- painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
130-
131- # this is done so that even after resizing, other partitions
132- # draw in the same places
133- trunc_pix += (effective_width * float(p.size) / self.diskSize)
134- pix_size = int(round(trunc_pix))
135- trunc_pix -= pix_size
136-
137- # use the right color for the filesystem
138- if p.fs in Partition.filesystemColours:
139- pColor = QtGui.QColor(Partition.filesystemColours[p.fs])
140- else:
141- pColor = QtGui.QColor(Partition.filesystemColours['free'])
142-
143- pal = QtGui.QPalette(pColor)
144- dark = pal.color(QtGui.QPalette.Dark)
145- mid = pColor.darker(125)
146- midl = mid.lighter(125)
147-
148- grad = QtGui.QLinearGradient(
149- QtCore.QPointF(0, 0), QtCore.QPointF(0, h))
150-
151- if p.fs == "free":
152- grad.setColorAt(.25, mid)
153- grad.setColorAt(1, midl)
154- else:
155- grad.setColorAt(0, midl)
156- grad.setColorAt(.75, mid)
157-
158- painter.setPen(QtCore.Qt.NoPen)
159- painter.setBrush(QtGui.QBrush(grad))
160- painter.setClipRect(part_offset, 0, pix_size, h * 2)
161- painter.drawPath(path)
162-
163- if part_offset > 0:
164- painter.setPen(dark)
165- painter.drawLine(part_offset, 3, part_offset, h - 3)
166-
167+ for idx, part in enumerate(self.partitions):
168+ # this is done so that even after resizing a partition, the
169+ # partitions after it are still drawn draw in the same places
170+ trunc_width += (effective_width * float(part.size) / self.diskSize)
171+ part_width = int(round(trunc_width))
172+ trunc_width -= part_width
173+
174+ grad, color = self._createGradient(idx, part, h)
175+
176+ painter.setClipRect(part_x, 0, part_width + 1, self.height())
177+ self._drawPartitionFrame(painter, 0, 0, self.width(), h, grad)
178 painter.setClipping(False)
179
180- draw_labels = True
181- if draw_labels:
182- # draw the labels
183- painter.setPen(QtCore.Qt.black)
184-
185- # label vertical location
186- labelY = h + 8
187-
188- texts = []
189- texts.append(p.name)
190- texts.append("%.01f%% (%s)" % (
191- float(p.size) / self.diskSize * 100, format_size(p.size)))
192-
193- nameFont = QtGui.QFont("arial", 10)
194- infoFont = QtGui.QFont("arial", 8)
195-
196- painter.setFont(nameFont)
197- v_off = 0
198- width = 0
199- for text in texts:
200- textSize = painter.fontMetrics().size(
201- QtCore.Qt.TextSingleLine, text)
202- painter.drawText(
203- label_offset + 20,
204- labelY + v_off + textSize.height() / 2, text)
205- v_off += textSize.height()
206- painter.setFont(infoFont)
207- painter.setPen(QtGui.QColor(PartitionsBar.InfoColor))
208- width = max(width, textSize.width())
209-
210- painter.setPen(QtCore.Qt.NoPen)
211- painter.setBrush(mid)
212- labelRect = QtGui.QPainterPath()
213- labelRect.addRoundedRect(
214- label_offset + 1, labelY - 3, 13, 13, 4, 4)
215- painter.drawPath(labelRect)
216-
217- sunkenFrameStyle.rect = QtCore.QRect(
218- label_offset, labelY - 4, 15, 15)
219- self.style().drawPrimitive(
220- QtGui.QStyle.PE_Frame, sunkenFrameStyle, painter, self)
221- self.style().drawPrimitive(
222- QtGui.QStyle.PE_Frame, sunkenFrameStyle, painter, self)
223-
224- label_offset += width + 40
225+ if idx > 0:
226+ # Draw vertical separator between partitions
227+ painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
228+ painter.drawLine(part_x, 0, part_x, h - 1)
229+
230+ label_x += self._drawLabels(painter, part, label_x, h, color)
231
232 # set the handle location for drawing later
233- if self.resize_part and p == self.resize_part.next:
234- resize_handle_x = part_offset
235-
236- # increment the partition offset
237- part_offset += pix_size
238-
239- sunkenFrameStyle.rect = QtCore.QRect(0, 0, self.width(), h)
240- self.style().drawPrimitive(
241- QtGui.QStyle.PE_Frame, sunkenFrameStyle, painter, self)
242+ if self.resize_part and part == self.resize_part.next:
243+ resize_handle_x = part_x
244+
245+ part_x += part_width
246
247 if self.resize_part and resize_handle_x:
248- # draw a resize handle
249- part = self.resize_part
250- xloc = resize_handle_x
251- self.resize_loc = xloc
252-
253- painter.setPen(QtCore.Qt.NoPen)
254- painter.setBrush(QtCore.Qt.black)
255-
256- painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
257- # move out so not created every time
258- arrow_offsets = (
259- (0, h / 2 - 1), (4, h / 2 - 1), (4, h / 2 - 3), (8, h / 2),
260- (4, h / 2 + 3), (4, h / 2 + 1), (0, h / 2 + 1))
261-
262- p1 = arrow_offsets[0]
263- if part.size > part.minsize:
264- arrow = QtGui.QPainterPath(
265- QtCore.QPointF(xloc + -1 * p1[0], p1[1]))
266- for p in arrow_offsets:
267- arrow.lineTo(xloc + -1 * p[0] + 1, p[1])
268- painter.drawPath(arrow)
269-
270- if part.size < part.maxsize:
271- arrow = QtGui.QPainterPath(QtCore.QPointF(xloc + p1[0], p1[1]))
272- for p in arrow_offsets:
273- arrow.lineTo(xloc + p[0], p[1])
274- painter.drawPath(arrow)
275-
276- painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
277- painter.setPen(QtCore.Qt.black)
278- painter.drawLine(xloc, 0, xloc, h)
279+ self._drawResizeHandle(
280+ painter, self.resize_part, resize_handle_x, h)
281+
282+ painter.setPen(QtCore.Qt.red)
283+
284+ def _createGradient(self, idx, part, h):
285+ # use the right color for the filesystem
286+ if part.fs == "free":
287+ color = Partition.FreeColor
288+ else:
289+ color = Partition.Colors[idx % len(Partition.Colors)]
290+ color = QtGui.QColor(color)
291+
292+ grad = QtGui.QLinearGradient(
293+ QtCore.QPointF(0, 0), QtCore.QPointF(0, h))
294+
295+ if part.fs == "free":
296+ grad.setColorAt(0, color.darker(150))
297+ grad.setColorAt(0.25, color)
298+ else:
299+ grad.setColorAt(0, color)
300+ grad.setColorAt(.75, color.darker(125))
301+ return grad, color
302+
303+ def _drawLabels(self, painter, part, x, h, partColor):
304+ painter.setPen(QtCore.Qt.black)
305+
306+ # label vertical location
307+ labelY = h + 8
308+
309+ texts = []
310+ texts.append(part.name)
311+ texts.append(format_size(part.size))
312+
313+ nameFont = QtGui.QFont("arial", 10)
314+ infoFont = QtGui.QFont("arial", 8)
315+
316+ painter.setFont(nameFont)
317+ v_off = 0
318+ width = 0
319+ for text in texts:
320+ textSize = painter.fontMetrics().size(
321+ QtCore.Qt.TextSingleLine, text)
322+ painter.drawText(
323+ x + 18,
324+ labelY + v_off + textSize.height() / 2, text)
325+ v_off += textSize.height()
326+ painter.setFont(infoFont)
327+ painter.setPen(QtGui.QColor(PartitionsBar.InfoColor))
328+ width = max(width, textSize.width())
329+
330+ self._drawPartitionFrame(painter, x, labelY - 3, 13, 13, partColor)
331+
332+ return width + 40
333+
334+ def _drawResizeHandle(self, painter, part, xloc, h):
335+ self.resize_loc = xloc
336+
337+ painter.setPen(QtCore.Qt.NoPen)
338+ painter.setBrush(QtCore.Qt.black)
339+
340+ painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
341+ arrow_offsets = (
342+ (0, h / 2 - 1), (4, h / 2 - 1), (4, h / 2 - 3), (8, h / 2),
343+ (4, h / 2 + 3), (4, h / 2 + 1), (0, h / 2 + 1))
344+
345+ p1 = arrow_offsets[0]
346+ if part.size > part.minsize:
347+ arrow = QtGui.QPainterPath(
348+ QtCore.QPointF(xloc + -1 * p1[0], p1[1]))
349+ for p in arrow_offsets:
350+ arrow.lineTo(xloc + -1 * p[0] + 1, p[1])
351+ painter.drawPath(arrow)
352+
353+ if part.size < part.maxsize:
354+ arrow = QtGui.QPainterPath(QtCore.QPointF(xloc + p1[0], p1[1]))
355+ for p in arrow_offsets:
356+ arrow.lineTo(xloc + p[0], p[1])
357+ painter.drawPath(arrow)
358+
359+ painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
360+ painter.setPen(QtCore.Qt.black)
361+ painter.drawLine(xloc, 0, xloc, h - 1)
362+
363+ def _drawPartitionFrame(self, painter, x, y, w, h, brush):
364+ painter.fillRect(x + 1, y + 1, w - 2, h - 2, brush)
365+ painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
366+ painter.setPen(self.palette().shadow().color())
367+ painter.translate(0.5, 0.5)
368+ painter.drawRoundedRect(x, y, w - 1, h - 1, 2, 2)
369+ painter.translate(-0.5, -0.5)
370
371 def addPartition(self, path, size, fs, name=None):
372+ if name is None and fs == 'free' and self.controller:
373+ name = self.controller.get_string('partition_free_space')
374 partition = Partition(path, size, fs, name=name)
375 self.diskSize += size
376

Subscribers

People subscribed via source and target branches

to status/vote changes: