5 from PyQt4 import QtGui
6 from PyQt4 import QtCore
9 def _radius_at(center, pos):
10 xDelta = pos.x() - center.x()
11 yDelta = pos.y() - center.y()
13 radius = math.sqrt(xDelta ** 2 + yDelta ** 2)
17 def _angle_at(center, pos):
18 xDelta = pos.x() - center.x()
19 yDelta = pos.y() - center.y()
21 radius = math.sqrt(xDelta ** 2 + yDelta ** 2)
22 angle = math.acos(xDelta / radius)
24 angle = 2*math.pi - angle
29 class QActionPieItem(object):
31 def __init__(self, action, weight = 1):
38 def setWeight(self, weight):
44 def setEnabled(self, enabled = True):
45 self._action.setEnabled(enabled)
48 return self._action.isEnabled()
51 class PieFiling(object):
53 INNER_RADIUS_DEFAULT = 32
54 OUTER_RADIUS_DEFAULT = 128
59 NULL_CENTER = QActionPieItem(QtGui.QAction(None))
62 self._innerRadius = self.INNER_RADIUS_DEFAULT
63 self._outerRadius = self.OUTER_RADIUS_DEFAULT
65 self._center = self.NULL_CENTER
67 def insertItem(self, item, index = -1):
68 self._children.insert(index, item)
70 def removeItemAt(self, index):
71 item = self._children.pop(index)
73 def set_center(self, item):
75 item = self.NULL_CENTER
84 def itemAt(self, index):
85 return self._children[index]
87 def indexAt(self, center, point):
88 return self._angle_to_index(_angle_at(center, point))
90 def innerRadius(self):
91 return self._innerRadius
93 def setInnerRadius(self, radius):
94 self._innerRadius = radius
96 def outerRadius(self):
97 return self._outerRadius
99 def setOuterRadius(self, radius):
100 self._outerRadius = radius
103 return iter(self._children)
106 return len(self._children)
108 def __getitem__(self, index):
109 return self._children[index]
111 def _index_to_angle(self, index, isShifted):
112 index = index % len(self._children)
114 totalWeight = sum(child.weight() for child in self._children)
117 baseAngle = (2 * math.pi) / totalWeight
122 angle -= (self._children[0].weight() * baseAngle) / 2
124 angle -= baseAngle / 2
128 for i, child in enumerate(self._children):
131 angle += child.weight() * baseAngle
132 while (2*math.pi) < angle:
137 def _angle_to_index(self, angle):
138 numChildren = len(self._children)
140 return self.SELECTION_CENTER
142 totalWeight = sum(child.weight() for child in self._children)
145 baseAngle = (2 * math.pi) / totalWeight
147 iterAngle = math.pi / 2 - (self.itemAt(0).weight() * baseAngle) / 2
149 iterAngle += 2 * math.pi
151 oldIterAngle = iterAngle
152 for index, child in enumerate(self._children):
153 iterAngle += child.weight() * baseAngle
154 if oldIterAngle < angle and angle <= iterAngle:
155 return index - 1 if index != 0 else numChildren - 1
156 elif oldIterAngle < (angle + 2*math.pi) and (angle + 2*math.pi <= iterAngle):
157 return index - 1 if index != 0 else numChildren - 1
158 oldIterAngle = iterAngle
161 class PieArtist(object):
163 ICON_SIZE_DEFAULT = 32
165 def __init__(self, filing):
166 self._filing = filing
168 self._cachedOuterRadius = self._filing.outerRadius()
169 self._cachedInnerRadius = self._filing.innerRadius()
170 canvasSize = self._cachedOuterRadius * 2 + 1
171 self._canvas = QtGui.QPixmap(canvasSize, canvasSize)
176 diameter = self._filing.outerRadius() * 2 + 1
177 return QtCore.QSize(diameter, diameter)
179 def centerSize(self):
180 painter = QtGui.QPainter(self._canvas)
181 text = self._filing.center().action().text()
182 fontMetrics = painter.fontMetrics()
184 textBoundingRect = fontMetrics.boundingRect(text)
186 textBoundingRect = QtCore.QRect()
187 textWidth = textBoundingRect.width()
188 textHeight = textBoundingRect.height()
191 textWidth + self.ICON_SIZE_DEFAULT,
192 max(textHeight, self.ICON_SIZE_DEFAULT),
195 def show(self, palette):
196 self.palette = palette
199 self._cachedOuterRadius != self._filing.outerRadius() or
200 self._cachedInnerRadius != self._filing.innerRadius()
202 self._cachedOuterRadius = self._filing.outerRadius()
203 self._cachedInnerRadius = self._filing.innerRadius()
204 self._canvas = self._canvas.scaled(self.pieSize())
206 if self._mask is None:
207 self._mask = QtGui.QBitmap(self._canvas.size())
208 self._mask.fill(QtCore.Qt.color0)
209 self._generate_mask(self._mask)
210 self._canvas.setMask(self._mask)
216 def paint(self, selectionIndex):
217 painter = QtGui.QPainter(self._canvas)
218 painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
220 adjustmentRect = self._canvas.rect().adjusted(0, 0, -1, -1)
222 numChildren = len(self._filing)
224 if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
225 painter.setBrush(self.palette.highlight())
227 painter.setBrush(self.palette.background())
229 painter.fillRect(self._canvas.rect(), painter.brush())
230 self._paint_center_foreground(painter, selectionIndex)
232 elif numChildren == 1:
233 if selectionIndex == 0 and self._filing[0].isEnabled():
234 painter.setBrush(self.palette.highlight())
236 painter.setBrush(self.palette.background())
238 painter.fillRect(self._canvas.rect(), painter.brush())
240 for i in xrange(len(self._filing)):
241 self._paint_slice_background(painter, adjustmentRect, i, selectionIndex)
243 self._paint_center_background(painter, adjustmentRect, selectionIndex)
244 self._paint_center_foreground(painter, selectionIndex)
246 for i in xrange(len(self._filing)):
247 self._paint_slice_foreground(painter, i, selectionIndex)
251 def _generate_mask(self, mask):
253 Specifies on the mask the shape of the pie menu
255 painter = QtGui.QPainter(mask)
256 painter.setPen(QtCore.Qt.color1)
257 painter.setBrush(QtCore.Qt.color1)
258 painter.drawEllipse(mask.rect().adjusted(0, 0, -1, -1))
260 def _paint_slice_background(self, painter, adjustmentRect, i, selectionIndex):
261 if i == selectionIndex and self._filing[i].isEnabled():
262 painter.setBrush(self.palette.highlight())
264 painter.setBrush(self.palette.background())
265 painter.setPen(self.palette.mid().color())
267 a = self._filing._index_to_angle(i, True)
268 b = self._filing._index_to_angle(i + 1, True)
275 startAngleInDeg = (a * 360 * 16) / (2*math.pi)
276 sizeInDeg = (size * 360 * 16) / (2*math.pi)
277 painter.drawPie(adjustmentRect, int(startAngleInDeg), int(sizeInDeg))
279 def _paint_slice_foreground(self, painter, i, selectionIndex):
280 child = self._filing[i]
282 a = self._filing._index_to_angle(i, True)
283 b = self._filing._index_to_angle(i + 1, True)
286 middleAngle = (a + b) / 2
287 averageRadius = (self._cachedInnerRadius + self._cachedOuterRadius) / 2
289 sliceX = averageRadius * math.cos(middleAngle)
290 sliceY = - averageRadius * math.sin(middleAngle)
292 pieX = self._canvas.rect().center().x()
293 pieY = self._canvas.rect().center().y()
295 painter, child.action(), i == selectionIndex, pieX+sliceX, pieY+sliceY
298 def _paint_label(self, painter, action, isSelected, x, y):
300 fontMetrics = painter.fontMetrics()
302 textBoundingRect = fontMetrics.boundingRect(text)
304 textBoundingRect = QtCore.QRect()
305 textWidth = textBoundingRect.width()
306 textHeight = textBoundingRect.height()
308 icon = action.icon().pixmap(
309 QtCore.QSize(self.ICON_SIZE_DEFAULT, self.ICON_SIZE_DEFAULT),
313 averageWidth = (icon.width() + textWidth)/2
314 if not icon.isNull():
315 iconRect = QtCore.QRect(
322 painter.drawPixmap(iconRect, icon)
326 if action.isEnabled():
327 pen = self.palette.highlightedText()
328 brush = self.palette.highlight()
330 pen = self.palette.mid()
331 brush = self.palette.background()
333 if action.isEnabled():
334 pen = self.palette.text()
336 pen = self.palette.mid()
337 brush = self.palette.background()
339 leftX = x - averageWidth + icon.width()
340 topY = y + textHeight/2
341 painter.setPen(pen.color())
342 painter.setBrush(brush)
343 painter.drawText(leftX, topY, text)
345 def _paint_center_background(self, painter, adjustmentRect, selectionIndex):
346 dark = self.palette.dark().color()
347 light = self.palette.light().color()
348 if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
349 background = self.palette.highlight().color()
351 background = self.palette.background().color()
353 innerRadius = self._cachedInnerRadius
354 innerRect = QtCore.QRect(
355 adjustmentRect.center().x() - innerRadius,
356 adjustmentRect.center().y() - innerRadius,
361 painter.setPen(QtCore.Qt.NoPen)
362 painter.setBrush(background)
363 painter.drawPie(innerRect, 0, 360 * 16)
365 painter.setPen(QtGui.QPen(dark, 1))
366 painter.setBrush(QtCore.Qt.NoBrush)
367 painter.drawEllipse(innerRect)
369 painter.setPen(QtGui.QPen(dark, 1))
370 painter.setBrush(QtCore.Qt.NoBrush)
371 painter.drawEllipse(adjustmentRect)
373 r = QtCore.QRect(innerRect)
374 innerRect.setLeft(r.center().x() + ((r.left() - r.center().x()) / 3) * 1)
375 innerRect.setRight(r.center().x() + ((r.right() - r.center().x()) / 3) * 1)
376 innerRect.setTop(r.center().y() + ((r.top() - r.center().y()) / 3) * 1)
377 innerRect.setBottom(r.center().y() + ((r.bottom() - r.center().y()) / 3) * 1)
379 def _paint_center_foreground(self, painter, selectionIndex):
380 pieX = self._canvas.rect().center().x()
381 pieY = self._canvas.rect().center().y()
388 self._filing.center().action(),
389 selectionIndex == PieFiling.SELECTION_CENTER,
394 class QPieDisplay(QtGui.QWidget):
396 def __init__(self, filing, parent = None, flags = 0):
397 QtGui.QWidget.__init__(self, parent, flags)
398 self._filing = filing
399 self._artist = PieArtist(self._filing)
400 self._selectionIndex = PieFiling.SELECTION_NONE
402 def popup(self, pos):
403 self._update_selection(pos)
407 return self._artist.pieSize()
409 def showEvent(self, showEvent):
410 mask = self._artist.show(self.palette())
413 QtGui.QWidget.showEvent(self, showEvent)
415 def hideEvent(self, hideEvent):
417 self._selectionIndex = PieFiling.SELECTION_NONE
418 QtGui.QWidget.hideEvent(self, hideEvent)
420 def paintEvent(self, paintEvent):
421 canvas = self._artist.paint(self._selectionIndex)
423 screen = QtGui.QPainter(self)
424 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
426 QtGui.QWidget.paintEvent(self, paintEvent)
428 def selectAt(self, index):
429 self._selectionIndex = index
433 class QPieButton(QtGui.QWidget):
435 activated = QtCore.pyqtSignal(int)
436 highlighted = QtCore.pyqtSignal(int)
437 canceled = QtCore.pyqtSignal()
438 aboutToShow = QtCore.pyqtSignal()
439 aboutToHide = QtCore.pyqtSignal()
441 def __init__(self, buttonSlice, parent = None):
442 QtGui.QWidget.__init__(self, parent)
443 self._filing = PieFiling()
444 self._display = QPieDisplay(self._filing, None, QtCore.Qt.SplashScreen)
445 self._selectionIndex = PieFiling.SELECTION_NONE
447 self._buttonFiling = PieFiling()
448 self._buttonFiling.set_center(buttonSlice)
449 self._buttonArtist = PieArtist(self._buttonFiling)
450 centerSize = self._buttonArtist.centerSize()
451 self._buttonFiling.setOuterRadius(max(centerSize.width(), centerSize.height()))
452 self._poppedUp = False
454 self._mousePosition = None
455 self.setFocusPolicy(QtCore.Qt.StrongFocus)
457 def insertItem(self, item, index = -1):
458 self._filing.insertItem(item, index)
460 def removeItemAt(self, index):
461 self._filing.removeItemAt(index)
463 def set_center(self, item):
464 self._filing.set_center(item)
466 def set_button(self, item):
472 def itemAt(self, index):
473 return self._filing.itemAt(index)
475 def indexAt(self, point):
476 return self._filing.indexAt(self.rect().center(), point)
478 def innerRadius(self):
479 return self._filing.innerRadius()
481 def setInnerRadius(self, radius):
482 self._filing.setInnerRadius(radius)
484 def outerRadius(self):
485 return self._filing.outerRadius()
487 def setOuterRadius(self, radius):
488 self._filing.setOuterRadius(radius)
491 return self._buttonArtist.pieSize()
493 def mousePressEvent(self, mouseEvent):
494 self._popup_child(mouseEvent.globalPos())
495 lastSelection = self._selectionIndex
497 lastMousePos = mouseEvent.pos()
498 self._mousePosition = lastMousePos
499 self._update_selection(self.rect().center())
501 if lastSelection != self._selectionIndex:
502 self.highlighted.emit(self._selectionIndex)
503 self._display.selectAt(self._selectionIndex)
505 def mouseMoveEvent(self, mouseEvent):
506 lastSelection = self._selectionIndex
508 lastMousePos = mouseEvent.pos()
509 if self._mousePosition is None:
511 self._update_selection(lastMousePos)
514 self._update_selection(self.rect().center() + (lastMousePos - self._mousePosition))
516 if lastSelection != self._selectionIndex:
517 self.highlighted.emit(self._selectionIndex)
518 self._display.selectAt(self._selectionIndex)
520 def mouseReleaseEvent(self, mouseEvent):
521 lastSelection = self._selectionIndex
523 lastMousePos = mouseEvent.pos()
524 if self._mousePosition is None:
526 self._update_selection(lastMousePos)
529 self._update_selection(self.rect().center() + (lastMousePos - self._mousePosition))
530 self._mousePosition = None
532 self._activate_at(self._selectionIndex)
535 def keyPressEvent(self, keyEvent):
536 if keyEvent.key() in [QtCore.Qt.Key_Right, QtCore.Qt.Key_Down, QtCore.Qt.Key_Tab]:
537 self._popup_child(QtGui.QCursor.pos())
538 if self._selectionIndex != len(self._filing) - 1:
539 nextSelection = self._selectionIndex + 1
542 self._select_at(nextSelection)
543 self._display.selectAt(self._selectionIndex)
544 elif keyEvent.key() in [QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Backtab]:
545 self._popup_child(QtGui.QCursor.pos())
546 if 0 < self._selectionIndex:
547 nextSelection = self._selectionIndex - 1
549 nextSelection = len(self._filing) - 1
550 self._select_at(nextSelection)
551 self._display.selectAt(self._selectionIndex)
552 elif keyEvent.key() in [QtCore.Qt.Key_Space]:
553 self._popup_child(QtGui.QCursor.pos())
554 self._select_at(PieFiling.SELECTION_CENTER)
555 self._display.selectAt(self._selectionIndex)
556 elif keyEvent.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space]:
557 self._activate_at(self._selectionIndex)
559 elif keyEvent.key() in [QtCore.Qt.Key_Escape, QtCore.Qt.Key_Backspace]:
560 self._activate_at(PieFiling.SELECTION_NONE)
563 QtGui.QWidget.keyPressEvent(self, keyEvent)
565 def showEvent(self, showEvent):
566 self._buttonArtist.show(self.palette())
568 QtGui.QWidget.showEvent(self, showEvent)
570 def hideEvent(self, hideEvent):
572 self._select_at(PieFiling.SELECTION_NONE)
573 QtGui.QWidget.hideEvent(self, hideEvent)
575 def paintEvent(self, paintEvent):
577 canvas = self._buttonArtist.paint(PieFiling.SELECTION_CENTER)
579 canvas = self._buttonArtist.paint(PieFiling.SELECTION_NONE)
581 screen = QtGui.QPainter(self)
582 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
584 QtGui.QWidget.paintEvent(self, paintEvent)
586 def _popup_child(self, position):
587 self._poppedUp = True
588 self.aboutToShow.emit()
590 position = position - QtCore.QPoint(self._filing.outerRadius(), self._filing.outerRadius())
591 self._display.move(position)
596 def _hide_child(self):
597 self._poppedUp = False
598 self.aboutToHide.emit()
602 def _select_at(self, index):
603 self._selectionIndex = index
605 def _update_selection(self, lastMousePos):
606 radius = _radius_at(self.rect().center(), lastMousePos)
607 if radius < self._filing.innerRadius():
608 self._select_at(PieFiling.SELECTION_CENTER)
609 elif radius <= self._filing.outerRadius():
610 self._select_at(self.indexAt(lastMousePos))
612 self._select_at(PieFiling.SELECTION_NONE)
614 def _activate_at(self, index):
615 if index == PieFiling.SELECTION_NONE:
618 elif index == PieFiling.SELECTION_CENTER:
619 child = self._filing.center()
621 child = self.itemAt(index)
623 if child.action().isEnabled():
624 child.action().trigger()
625 self.activated.emit(index)
630 class QPieMenu(QtGui.QWidget):
632 activated = QtCore.pyqtSignal(int)
633 highlighted = QtCore.pyqtSignal(int)
634 canceled = QtCore.pyqtSignal()
635 aboutToShow = QtCore.pyqtSignal()
636 aboutToHide = QtCore.pyqtSignal()
638 def __init__(self, parent = None):
639 QtGui.QWidget.__init__(self, parent)
640 self._filing = PieFiling()
641 self._artist = PieArtist(self._filing)
642 self._selectionIndex = PieFiling.SELECTION_NONE
644 self._mousePosition = ()
645 self.setFocusPolicy(QtCore.Qt.StrongFocus)
647 def popup(self, pos):
648 self._update_selection(pos)
651 def insertItem(self, item, index = -1):
652 self._filing.insertItem(item, index)
655 def removeItemAt(self, index):
656 self._filing.removeItemAt(index)
659 def set_center(self, item):
660 self._filing.set_center(item)
667 def itemAt(self, index):
668 return self._filing.itemAt(index)
670 def indexAt(self, point):
671 return self._filing.indexAt(self.rect().center(), point)
673 def innerRadius(self):
674 return self._filing.innerRadius()
676 def setInnerRadius(self, radius):
677 self._filing.setInnerRadius(radius)
680 def outerRadius(self):
681 return self._filing.outerRadius()
683 def setOuterRadius(self, radius):
684 self._filing.setOuterRadius(radius)
688 return self._artist.pieSize()
690 def mousePressEvent(self, mouseEvent):
691 lastSelection = self._selectionIndex
693 lastMousePos = mouseEvent.pos()
694 self._update_selection(lastMousePos)
695 self._mousePosition = lastMousePos
697 if lastSelection != self._selectionIndex:
698 self.highlighted.emit(self._selectionIndex)
701 def mouseMoveEvent(self, mouseEvent):
702 lastSelection = self._selectionIndex
704 lastMousePos = mouseEvent.pos()
705 self._update_selection(lastMousePos)
707 if lastSelection != self._selectionIndex:
708 self.highlighted.emit(self._selectionIndex)
711 def mouseReleaseEvent(self, mouseEvent):
712 lastSelection = self._selectionIndex
714 lastMousePos = mouseEvent.pos()
715 self._update_selection(lastMousePos)
716 self._mousePosition = ()
718 self._activate_at(self._selectionIndex)
721 def keyPressEvent(self, keyEvent):
722 if keyEvent.key() in [QtCore.Qt.Key_Right, QtCore.Qt.Key_Down, QtCore.Qt.Key_Tab]:
723 self._select_at(self._selectionIndex + 1)
725 elif keyEvent.key() in [QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Backtab]:
726 self._select_at(self._selectionIndex - 1)
728 elif keyEvent.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space]:
729 self._activate_at(self._selectionIndex)
730 elif keyEvent.key() in [QtCore.Qt.Key_Escape, QtCore.Qt.Key_Backspace]:
731 self._activate_at(PieFiling.SELECTION_NONE)
733 QtGui.QWidget.keyPressEvent(self, keyEvent)
735 def showEvent(self, showEvent):
736 self.aboutToShow.emit()
738 mask = self._artist.show(self.palette())
741 lastMousePos = self.mapFromGlobal(QtGui.QCursor.pos())
742 self._update_selection(lastMousePos)
744 QtGui.QWidget.showEvent(self, showEvent)
746 def hideEvent(self, hideEvent):
748 self._selectionIndex = PieFiling.SELECTION_NONE
749 QtGui.QWidget.hideEvent(self, hideEvent)
751 def paintEvent(self, paintEvent):
752 canvas = self._artist.paint(self._selectionIndex)
754 screen = QtGui.QPainter(self)
755 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
757 QtGui.QWidget.paintEvent(self, paintEvent)
759 def _select_at(self, index):
760 self._selectionIndex = index
762 numChildren = len(self._filing)
763 loopDelta = max(numChildren, 1)
764 while self._selectionIndex < 0:
765 self._selectionIndex += loopDelta
766 while numChildren <= self._selectionIndex:
767 self._selectionIndex -= loopDelta
769 def _update_selection(self, lastMousePos):
770 radius = _radius_at(self.rect().center(), lastMousePos)
771 if radius < self._filing.innerRadius():
772 self._selectionIndex = PieFiling.SELECTION_CENTER
773 elif radius <= self._filing.outerRadius():
774 self._select_at(self.indexAt(lastMousePos))
776 self._selectionIndex = PieFiling.SELECTION_NONE
778 def _activate_at(self, index):
779 if index == PieFiling.SELECTION_NONE:
781 self.aboutToHide.emit()
784 elif index == PieFiling.SELECTION_CENTER:
785 child = self._filing.center()
787 child = self.itemAt(index)
789 if child.isEnabled():
790 child.action().trigger()
791 self.activated.emit(index)
794 self.aboutToHide.emit()
802 def _on_about_to_hide(app):
806 if __name__ == "__main__":
807 app = QtGui.QApplication([])
808 PieFiling.NULL_CENTER.setEnabled(False)
815 singleAction = QtGui.QAction(None)
816 singleAction.setText("Boo")
817 singleItem = QActionPieItem(singleAction)
819 spie.insertItem(singleItem)
823 oneAction = QtGui.QAction(None)
824 oneAction.setText("Chew")
825 oneItem = QActionPieItem(oneAction)
826 twoAction = QtGui.QAction(None)
827 twoAction.setText("Foo")
828 twoItem = QActionPieItem(twoAction)
829 iconTextAction = QtGui.QAction(None)
830 iconTextAction.setText("Icon")
831 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
832 iconTextItem = QActionPieItem(iconTextAction)
834 mpie.insertItem(oneItem)
835 mpie.insertItem(twoItem)
836 mpie.insertItem(oneItem)
837 mpie.insertItem(iconTextItem)
841 oneAction = QtGui.QAction(None)
842 oneAction.setText("Chew")
843 oneAction.triggered.connect(lambda: _print("Chew"))
844 oneItem = QActionPieItem(oneAction)
845 twoAction = QtGui.QAction(None)
846 twoAction.setText("Foo")
847 twoAction.triggered.connect(lambda: _print("Foo"))
848 twoItem = QActionPieItem(twoAction)
849 iconAction = QtGui.QAction(None)
850 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
851 iconAction.triggered.connect(lambda: _print("Icon"))
852 iconItem = QActionPieItem(iconAction)
853 iconTextAction = QtGui.QAction(None)
854 iconTextAction.setText("Icon")
855 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
856 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
857 iconTextItem = QActionPieItem(iconTextAction)
859 mpie.set_center(iconItem)
860 mpie.insertItem(oneItem)
861 mpie.insertItem(twoItem)
862 mpie.insertItem(oneItem)
863 mpie.insertItem(iconTextItem)
865 mpie.aboutToHide.connect(lambda: _on_about_to_hide(app))
866 mpie.canceled.connect(lambda: _print("Canceled"))
869 oneAction = QtGui.QAction(None)
870 oneAction.setText("Chew")
871 oneAction.triggered.connect(lambda: _print("Chew"))
872 oneItem = QActionPieItem(oneAction)
873 twoAction = QtGui.QAction(None)
874 twoAction.setText("Foo")
875 twoAction.triggered.connect(lambda: _print("Foo"))
876 twoItem = QActionPieItem(twoAction)
877 iconAction = QtGui.QAction(None)
878 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
879 iconAction.triggered.connect(lambda: _print("Icon"))
880 iconItem = QActionPieItem(iconAction)
881 iconTextAction = QtGui.QAction(None)
882 iconTextAction.setText("Icon")
883 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
884 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
885 iconTextItem = QActionPieItem(iconTextAction)
886 pieFiling = PieFiling()
887 pieFiling.set_center(iconItem)
888 pieFiling.insertItem(oneItem)
889 pieFiling.insertItem(twoItem)
890 pieFiling.insertItem(oneItem)
891 pieFiling.insertItem(iconTextItem)
892 mpie = QPieDisplay(pieFiling)
896 oneAction = QtGui.QAction(None)
897 oneAction.setText("Chew")
898 oneAction.triggered.connect(lambda: _print("Chew"))
899 oneItem = QActionPieItem(oneAction)
900 twoAction = QtGui.QAction(None)
901 twoAction.setText("Foo")
902 twoAction.triggered.connect(lambda: _print("Foo"))
903 twoItem = QActionPieItem(twoAction)
904 iconAction = QtGui.QAction(None)
905 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
906 iconAction.triggered.connect(lambda: _print("Icon"))
907 iconItem = QActionPieItem(iconAction)
908 iconTextAction = QtGui.QAction(None)
909 iconTextAction.setText("Icon")
910 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
911 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
912 iconTextItem = QActionPieItem(iconTextAction)
913 mpie = QPieButton(iconItem)
914 mpie.set_center(iconItem)
915 mpie.insertItem(oneItem)
916 mpie.insertItem(twoItem)
917 mpie.insertItem(oneItem)
918 mpie.insertItem(iconTextItem)
920 mpie.aboutToHide.connect(lambda: _on_about_to_hide(app))
921 mpie.canceled.connect(lambda: _print("Canceled"))