5 from PyQt4 import QtGui
6 from PyQt4 import QtCore
12 def _radius_at(center, pos):
17 radius = math.sqrt(xDelta ** 2 + yDelta ** 2)
21 def _angle_at(center, pos):
26 radius = math.sqrt(xDelta ** 2 + yDelta ** 2)
27 angle = math.acos(xDelta / radius)
29 angle = _TWOPI - angle
34 class QActionPieItem(object):
36 def __init__(self, action, weight = 1):
43 def setWeight(self, weight):
49 def setEnabled(self, enabled = True):
50 self._action.setEnabled(enabled)
53 return self._action.isEnabled()
56 class PieFiling(object):
58 INNER_RADIUS_DEFAULT = 32
59 OUTER_RADIUS_DEFAULT = 128
64 NULL_CENTER = QActionPieItem(QtGui.QAction(None))
67 self._innerRadius = self.INNER_RADIUS_DEFAULT
68 self._outerRadius = self.OUTER_RADIUS_DEFAULT
70 self._center = self.NULL_CENTER
72 self._cacheIndexToAngle = {}
73 self._cacheTotalWeight = 0
75 def insertItem(self, item, index = -1):
76 self._children.insert(index, item)
77 self._invalidate_cache()
79 def removeItemAt(self, index):
80 item = self._children.pop(index)
81 self._invalidate_cache()
83 def set_center(self, item):
85 item = self.NULL_CENTER
93 self._center = self.NULL_CENTER
94 self._invalidate_cache()
96 def itemAt(self, index):
97 return self._children[index]
99 def indexAt(self, center, point):
100 return self._angle_to_index(_angle_at(center, point))
102 def innerRadius(self):
103 return self._innerRadius
105 def setInnerRadius(self, radius):
106 self._innerRadius = radius
108 def outerRadius(self):
109 return self._outerRadius
111 def setOuterRadius(self, radius):
112 self._outerRadius = radius
115 return iter(self._children)
118 return len(self._children)
120 def __getitem__(self, index):
121 return self._children[index]
123 def _invalidate_cache(self):
124 self._cacheIndexToAngle.clear()
125 self._cacheTotalWeight = sum(child.weight() for child in self._children)
126 if self._cacheTotalWeight == 0:
127 self._cacheTotalWeight = 1
129 def _index_to_angle(self, index, isShifted):
130 key = index, isShifted
131 if key in self._cacheIndexToAngle:
132 return self._cacheIndexToAngle[key]
133 index = index % len(self._children)
135 baseAngle = _TWOPI / self._cacheTotalWeight
140 angle -= (self._children[0].weight() * baseAngle) / 2
142 angle -= baseAngle / 2
146 for i, child in enumerate(self._children):
149 angle += child.weight() * baseAngle
150 while _TWOPI < angle:
153 self._cacheIndexToAngle[key] = angle
156 def _angle_to_index(self, angle):
157 numChildren = len(self._children)
159 return self.SELECTION_CENTER
161 baseAngle = _TWOPI / self._cacheTotalWeight
163 iterAngle = math.pi / 2 - (self.itemAt(0).weight() * baseAngle) / 2
167 oldIterAngle = iterAngle
168 for index, child in enumerate(self._children):
169 iterAngle += child.weight() * baseAngle
170 if oldIterAngle < angle and angle <= iterAngle:
171 return index - 1 if index != 0 else numChildren - 1
172 elif oldIterAngle < (angle + _TWOPI) and (angle + _TWOPI <= iterAngle):
173 return index - 1 if index != 0 else numChildren - 1
174 oldIterAngle = iterAngle
177 class PieArtist(object):
179 ICON_SIZE_DEFAULT = 32
181 def __init__(self, filing):
182 self._filing = filing
184 self._cachedOuterRadius = self._filing.outerRadius()
185 self._cachedInnerRadius = self._filing.innerRadius()
186 canvasSize = self._cachedOuterRadius * 2 + 1
187 self._canvas = QtGui.QPixmap(canvasSize, canvasSize)
192 diameter = self._filing.outerRadius() * 2 + 1
193 return QtCore.QSize(diameter, diameter)
195 def centerSize(self):
196 painter = QtGui.QPainter(self._canvas)
197 text = self._filing.center().action().text()
198 fontMetrics = painter.fontMetrics()
200 textBoundingRect = fontMetrics.boundingRect(text)
202 textBoundingRect = QtCore.QRect()
203 textWidth = textBoundingRect.width()
204 textHeight = textBoundingRect.height()
207 textWidth + self.ICON_SIZE_DEFAULT,
208 max(textHeight, self.ICON_SIZE_DEFAULT),
211 def show(self, palette):
212 self.palette = palette
215 self._cachedOuterRadius != self._filing.outerRadius() or
216 self._cachedInnerRadius != self._filing.innerRadius()
218 self._cachedOuterRadius = self._filing.outerRadius()
219 self._cachedInnerRadius = self._filing.innerRadius()
220 self._canvas = self._canvas.scaled(self.pieSize())
222 if self._mask is None:
223 self._mask = QtGui.QBitmap(self._canvas.size())
224 self._mask.fill(QtCore.Qt.color0)
225 self._generate_mask(self._mask)
226 self._canvas.setMask(self._mask)
232 def paint(self, selectionIndex):
233 painter = QtGui.QPainter(self._canvas)
234 painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
236 adjustmentRect = self._canvas.rect().adjusted(0, 0, -1, -1)
238 numChildren = len(self._filing)
240 if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
241 painter.setBrush(self.palette.highlight())
243 painter.setBrush(self.palette.background())
245 painter.fillRect(self._canvas.rect(), painter.brush())
246 self._paint_center_foreground(painter, selectionIndex)
248 elif numChildren == 1:
249 if selectionIndex == 0 and self._filing[0].isEnabled():
250 painter.setBrush(self.palette.highlight())
252 painter.setBrush(self.palette.background())
254 painter.fillRect(self._canvas.rect(), painter.brush())
256 for i in xrange(len(self._filing)):
257 self._paint_slice_background(painter, adjustmentRect, i, selectionIndex)
259 self._paint_center_background(painter, adjustmentRect, selectionIndex)
260 self._paint_center_foreground(painter, selectionIndex)
262 for i in xrange(len(self._filing)):
263 self._paint_slice_foreground(painter, i, selectionIndex)
267 def _generate_mask(self, mask):
269 Specifies on the mask the shape of the pie menu
271 painter = QtGui.QPainter(mask)
272 painter.setPen(QtCore.Qt.color1)
273 painter.setBrush(QtCore.Qt.color1)
274 painter.drawEllipse(mask.rect().adjusted(0, 0, -1, -1))
276 def _paint_slice_background(self, painter, adjustmentRect, i, selectionIndex):
277 if i == selectionIndex and self._filing[i].isEnabled():
278 painter.setBrush(self.palette.highlight())
280 painter.setBrush(self.palette.background())
281 painter.setPen(self.palette.mid().color())
283 a = self._filing._index_to_angle(i, True)
284 b = self._filing._index_to_angle(i + 1, True)
291 startAngleInDeg = (a * 360 * 16) / _TWOPI
292 sizeInDeg = (size * 360 * 16) / _TWOPI
293 painter.drawPie(adjustmentRect, int(startAngleInDeg), int(sizeInDeg))
295 def _paint_slice_foreground(self, painter, i, selectionIndex):
296 child = self._filing[i]
298 a = self._filing._index_to_angle(i, True)
299 b = self._filing._index_to_angle(i + 1, True)
302 middleAngle = (a + b) / 2
303 averageRadius = (self._cachedInnerRadius + self._cachedOuterRadius) / 2
305 sliceX = averageRadius * math.cos(middleAngle)
306 sliceY = - averageRadius * math.sin(middleAngle)
308 piePos = self._canvas.rect().center()
312 painter, child.action(), i == selectionIndex, pieX+sliceX, pieY+sliceY
315 def _paint_label(self, painter, action, isSelected, x, y):
317 fontMetrics = painter.fontMetrics()
319 textBoundingRect = fontMetrics.boundingRect(text)
321 textBoundingRect = QtCore.QRect()
322 textWidth = textBoundingRect.width()
323 textHeight = textBoundingRect.height()
325 icon = action.icon().pixmap(
326 QtCore.QSize(self.ICON_SIZE_DEFAULT, self.ICON_SIZE_DEFAULT),
330 iconWidth = icon.width()
331 iconHeight = icon.width()
332 averageWidth = (iconWidth + textWidth)/2
333 if not icon.isNull():
334 iconRect = QtCore.QRect(
341 painter.drawPixmap(iconRect, icon)
345 if action.isEnabled():
346 pen = self.palette.highlightedText()
347 brush = self.palette.highlight()
349 pen = self.palette.mid()
350 brush = self.palette.background()
352 if action.isEnabled():
353 pen = self.palette.text()
355 pen = self.palette.mid()
356 brush = self.palette.background()
358 leftX = x - averageWidth + iconWidth
359 topY = y + textHeight/2
360 painter.setPen(pen.color())
361 painter.setBrush(brush)
362 painter.drawText(leftX, topY, text)
364 def _paint_center_background(self, painter, adjustmentRect, selectionIndex):
365 dark = self.palette.dark().color()
366 light = self.palette.light().color()
367 if selectionIndex == PieFiling.SELECTION_CENTER and self._filing.center().isEnabled():
368 background = self.palette.highlight().color()
370 background = self.palette.background().color()
372 innerRadius = self._cachedInnerRadius
373 adjustmentCenterPos = adjustmentRect.center()
374 innerRect = QtCore.QRect(
375 adjustmentCenterPos.x() - innerRadius,
376 adjustmentCenterPos.y() - innerRadius,
381 painter.setPen(QtCore.Qt.NoPen)
382 painter.setBrush(background)
383 painter.drawPie(innerRect, 0, 360 * 16)
385 painter.setPen(QtGui.QPen(dark, 1))
386 painter.setBrush(QtCore.Qt.NoBrush)
387 painter.drawEllipse(innerRect)
389 painter.setPen(QtGui.QPen(dark, 1))
390 painter.setBrush(QtCore.Qt.NoBrush)
391 painter.drawEllipse(adjustmentRect)
393 r = QtCore.QRect(innerRect)
394 innerCenter = r.center()
395 innerRect.setLeft(innerCenter.x() + ((r.left() - innerCenter.x()) / 3) * 1)
396 innerRect.setRight(innerCenter.x() + ((r.right() - innerCenter.x()) / 3) * 1)
397 innerRect.setTop(innerCenter.y() + ((r.top() - innerCenter.y()) / 3) * 1)
398 innerRect.setBottom(innerCenter.y() + ((r.bottom() - innerCenter.y()) / 3) * 1)
400 def _paint_center_foreground(self, painter, selectionIndex):
401 centerPos = self._canvas.rect().center()
410 self._filing.center().action(),
411 selectionIndex == PieFiling.SELECTION_CENTER,
416 class QPieDisplay(QtGui.QWidget):
418 def __init__(self, filing, parent = None, flags = QtCore.Qt.Window):
419 QtGui.QWidget.__init__(self, parent, flags)
420 self._filing = filing
421 self._artist = PieArtist(self._filing)
422 self._selectionIndex = PieFiling.SELECTION_NONE
424 def popup(self, pos):
425 self._update_selection(pos)
429 return self._artist.pieSize()
431 def showEvent(self, showEvent):
432 mask = self._artist.show(self.palette())
435 QtGui.QWidget.showEvent(self, showEvent)
437 def hideEvent(self, hideEvent):
439 self._selectionIndex = PieFiling.SELECTION_NONE
440 QtGui.QWidget.hideEvent(self, hideEvent)
442 def paintEvent(self, paintEvent):
443 canvas = self._artist.paint(self._selectionIndex)
445 screen = QtGui.QPainter(self)
446 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
448 QtGui.QWidget.paintEvent(self, paintEvent)
450 def selectAt(self, index):
451 self._selectionIndex = index
455 class QPieButton(QtGui.QWidget):
457 activated = QtCore.pyqtSignal(int)
458 highlighted = QtCore.pyqtSignal(int)
459 canceled = QtCore.pyqtSignal()
460 aboutToShow = QtCore.pyqtSignal()
461 aboutToHide = QtCore.pyqtSignal()
463 def __init__(self, buttonSlice, parent = None):
464 QtGui.QWidget.__init__(self, parent)
465 self._cachedCenterPosition = self.rect().center()
467 self._filing = PieFiling()
468 self._display = QPieDisplay(self._filing, None, QtCore.Qt.SplashScreen)
469 self._selectionIndex = PieFiling.SELECTION_NONE
471 self._buttonFiling = PieFiling()
472 self._buttonFiling.set_center(buttonSlice)
473 self._buttonArtist = PieArtist(self._buttonFiling)
474 centerSize = self._buttonArtist.centerSize()
475 self._buttonFiling.setOuterRadius(max(centerSize.width(), centerSize.height()))
476 self._poppedUp = False
478 self._mousePosition = None
479 self.setFocusPolicy(QtCore.Qt.StrongFocus)
481 def insertItem(self, item, index = -1):
482 self._filing.insertItem(item, index)
484 def removeItemAt(self, index):
485 self._filing.removeItemAt(index)
487 def set_center(self, item):
488 self._filing.set_center(item)
490 def set_button(self, item):
496 def itemAt(self, index):
497 return self._filing.itemAt(index)
499 def indexAt(self, point):
500 return self._filing.indexAt(self._cachedCenterPosition, point)
502 def innerRadius(self):
503 return self._filing.innerRadius()
505 def setInnerRadius(self, radius):
506 self._filing.setInnerRadius(radius)
508 def outerRadius(self):
509 return self._filing.outerRadius()
511 def setOuterRadius(self, radius):
512 self._filing.setOuterRadius(radius)
515 return self._buttonArtist.pieSize()
517 def mousePressEvent(self, mouseEvent):
518 self._popup_child(mouseEvent.globalPos())
519 lastSelection = self._selectionIndex
521 lastMousePos = mouseEvent.pos()
522 self._mousePosition = lastMousePos
523 self._update_selection(self._cachedCenterPosition)
525 if lastSelection != self._selectionIndex:
526 self.highlighted.emit(self._selectionIndex)
527 self._display.selectAt(self._selectionIndex)
529 def mouseMoveEvent(self, mouseEvent):
530 lastSelection = self._selectionIndex
532 lastMousePos = mouseEvent.pos()
533 if self._mousePosition is None:
535 self._update_selection(lastMousePos)
538 self._update_selection(self._cachedCenterPosition + (lastMousePos - self._mousePosition))
540 if lastSelection != self._selectionIndex:
541 self.highlighted.emit(self._selectionIndex)
542 self._display.selectAt(self._selectionIndex)
544 def mouseReleaseEvent(self, mouseEvent):
545 lastSelection = self._selectionIndex
547 lastMousePos = mouseEvent.pos()
548 if self._mousePosition is None:
550 self._update_selection(lastMousePos)
553 self._update_selection(self._cachedCenterPosition + (lastMousePos - self._mousePosition))
554 self._mousePosition = None
556 self._activate_at(self._selectionIndex)
559 def keyPressEvent(self, keyEvent):
560 if keyEvent.key() in [QtCore.Qt.Key_Right, QtCore.Qt.Key_Down, QtCore.Qt.Key_Tab]:
561 self._popup_child(QtGui.QCursor.pos())
562 if self._selectionIndex != len(self._filing) - 1:
563 nextSelection = self._selectionIndex + 1
566 self._select_at(nextSelection)
567 self._display.selectAt(self._selectionIndex)
568 elif keyEvent.key() in [QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Backtab]:
569 self._popup_child(QtGui.QCursor.pos())
570 if 0 < self._selectionIndex:
571 nextSelection = self._selectionIndex - 1
573 nextSelection = len(self._filing) - 1
574 self._select_at(nextSelection)
575 self._display.selectAt(self._selectionIndex)
576 elif keyEvent.key() in [QtCore.Qt.Key_Space]:
577 self._popup_child(QtGui.QCursor.pos())
578 self._select_at(PieFiling.SELECTION_CENTER)
579 self._display.selectAt(self._selectionIndex)
580 elif keyEvent.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space]:
581 self._activate_at(self._selectionIndex)
583 elif keyEvent.key() in [QtCore.Qt.Key_Escape, QtCore.Qt.Key_Backspace]:
584 self._activate_at(PieFiling.SELECTION_NONE)
587 QtGui.QWidget.keyPressEvent(self, keyEvent)
589 def showEvent(self, showEvent):
590 self._buttonArtist.show(self.palette())
591 self._cachedCenterPosition = self.rect().center()
593 QtGui.QWidget.showEvent(self, showEvent)
595 def hideEvent(self, hideEvent):
597 self._select_at(PieFiling.SELECTION_NONE)
598 QtGui.QWidget.hideEvent(self, hideEvent)
600 def paintEvent(self, paintEvent):
602 canvas = self._buttonArtist.paint(PieFiling.SELECTION_CENTER)
604 canvas = self._buttonArtist.paint(PieFiling.SELECTION_NONE)
606 screen = QtGui.QPainter(self)
607 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
609 QtGui.QWidget.paintEvent(self, paintEvent)
611 def _popup_child(self, position):
612 self._poppedUp = True
613 self.aboutToShow.emit()
615 position = position - QtCore.QPoint(self._filing.outerRadius(), self._filing.outerRadius())
616 self._display.move(position)
621 def _hide_child(self):
622 self._poppedUp = False
623 self.aboutToHide.emit()
627 def _select_at(self, index):
628 self._selectionIndex = index
630 def _update_selection(self, lastMousePos):
631 radius = _radius_at(self._cachedCenterPosition, lastMousePos)
632 if radius < self._filing.innerRadius():
633 self._select_at(PieFiling.SELECTION_CENTER)
634 elif radius <= self._filing.outerRadius():
635 self._select_at(self.indexAt(lastMousePos))
637 self._select_at(PieFiling.SELECTION_NONE)
639 def _activate_at(self, index):
640 if index == PieFiling.SELECTION_NONE:
643 elif index == PieFiling.SELECTION_CENTER:
644 child = self._filing.center()
646 child = self.itemAt(index)
648 if child.action().isEnabled():
649 child.action().trigger()
650 self.activated.emit(index)
655 class QPieMenu(QtGui.QWidget):
657 activated = QtCore.pyqtSignal(int)
658 highlighted = QtCore.pyqtSignal(int)
659 canceled = QtCore.pyqtSignal()
660 aboutToShow = QtCore.pyqtSignal()
661 aboutToHide = QtCore.pyqtSignal()
663 def __init__(self, parent = None):
664 QtGui.QWidget.__init__(self, parent)
665 self._cachedCenterPosition = self.rect().center()
667 self._filing = PieFiling()
668 self._artist = PieArtist(self._filing)
669 self._selectionIndex = PieFiling.SELECTION_NONE
671 self._mousePosition = ()
672 self.setFocusPolicy(QtCore.Qt.StrongFocus)
674 def popup(self, pos):
675 self._update_selection(pos)
678 def insertItem(self, item, index = -1):
679 self._filing.insertItem(item, index)
682 def removeItemAt(self, index):
683 self._filing.removeItemAt(index)
686 def set_center(self, item):
687 self._filing.set_center(item)
694 def itemAt(self, index):
695 return self._filing.itemAt(index)
697 def indexAt(self, point):
698 return self._filing.indexAt(self._cachedCenterPosition, point)
700 def innerRadius(self):
701 return self._filing.innerRadius()
703 def setInnerRadius(self, radius):
704 self._filing.setInnerRadius(radius)
707 def outerRadius(self):
708 return self._filing.outerRadius()
710 def setOuterRadius(self, radius):
711 self._filing.setOuterRadius(radius)
715 return self._artist.pieSize()
717 def mousePressEvent(self, mouseEvent):
718 lastSelection = self._selectionIndex
720 lastMousePos = mouseEvent.pos()
721 self._update_selection(lastMousePos)
722 self._mousePosition = lastMousePos
724 if lastSelection != self._selectionIndex:
725 self.highlighted.emit(self._selectionIndex)
728 def mouseMoveEvent(self, mouseEvent):
729 lastSelection = self._selectionIndex
731 lastMousePos = mouseEvent.pos()
732 self._update_selection(lastMousePos)
734 if lastSelection != self._selectionIndex:
735 self.highlighted.emit(self._selectionIndex)
738 def mouseReleaseEvent(self, mouseEvent):
739 lastSelection = self._selectionIndex
741 lastMousePos = mouseEvent.pos()
742 self._update_selection(lastMousePos)
743 self._mousePosition = ()
745 self._activate_at(self._selectionIndex)
748 def keyPressEvent(self, keyEvent):
749 if keyEvent.key() in [QtCore.Qt.Key_Right, QtCore.Qt.Key_Down, QtCore.Qt.Key_Tab]:
750 if self._selectionIndex != len(self._filing) - 1:
751 nextSelection = self._selectionIndex + 1
754 self._select_at(nextSelection)
756 elif keyEvent.key() in [QtCore.Qt.Key_Left, QtCore.Qt.Key_Up, QtCore.Qt.Key_Backtab]:
757 if 0 < self._selectionIndex:
758 nextSelection = self._selectionIndex - 1
760 nextSelection = len(self._filing) - 1
761 self._select_at(nextSelection)
763 elif keyEvent.key() in [QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter, QtCore.Qt.Key_Space]:
764 self._activate_at(self._selectionIndex)
765 elif keyEvent.key() in [QtCore.Qt.Key_Escape, QtCore.Qt.Key_Backspace]:
766 self._activate_at(PieFiling.SELECTION_NONE)
768 QtGui.QWidget.keyPressEvent(self, keyEvent)
770 def showEvent(self, showEvent):
771 self.aboutToShow.emit()
772 self._cachedCenterPosition = self.rect().center()
774 mask = self._artist.show(self.palette())
777 lastMousePos = self.mapFromGlobal(QtGui.QCursor.pos())
778 self._update_selection(lastMousePos)
780 QtGui.QWidget.showEvent(self, showEvent)
782 def hideEvent(self, hideEvent):
784 self._selectionIndex = PieFiling.SELECTION_NONE
785 QtGui.QWidget.hideEvent(self, hideEvent)
787 def paintEvent(self, paintEvent):
788 canvas = self._artist.paint(self._selectionIndex)
790 screen = QtGui.QPainter(self)
791 screen.drawPixmap(QtCore.QPoint(0, 0), canvas)
793 QtGui.QWidget.paintEvent(self, paintEvent)
795 def _select_at(self, index):
796 self._selectionIndex = index
798 def _update_selection(self, lastMousePos):
799 radius = _radius_at(self._cachedCenterPosition, lastMousePos)
800 if radius < self._filing.innerRadius():
801 self._selectionIndex = PieFiling.SELECTION_CENTER
802 elif radius <= self._filing.outerRadius():
803 self._select_at(self.indexAt(lastMousePos))
805 self._selectionIndex = PieFiling.SELECTION_NONE
807 def _activate_at(self, index):
808 if index == PieFiling.SELECTION_NONE:
810 self.aboutToHide.emit()
813 elif index == PieFiling.SELECTION_CENTER:
814 child = self._filing.center()
816 child = self.itemAt(index)
818 if child.isEnabled():
819 child.action().trigger()
820 self.activated.emit(index)
823 self.aboutToHide.emit()
831 def _on_about_to_hide(app):
835 if __name__ == "__main__":
836 app = QtGui.QApplication([])
837 PieFiling.NULL_CENTER.setEnabled(False)
844 singleAction = QtGui.QAction(None)
845 singleAction.setText("Boo")
846 singleItem = QActionPieItem(singleAction)
848 spie.insertItem(singleItem)
852 oneAction = QtGui.QAction(None)
853 oneAction.setText("Chew")
854 oneItem = QActionPieItem(oneAction)
855 twoAction = QtGui.QAction(None)
856 twoAction.setText("Foo")
857 twoItem = QActionPieItem(twoAction)
858 iconTextAction = QtGui.QAction(None)
859 iconTextAction.setText("Icon")
860 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
861 iconTextItem = QActionPieItem(iconTextAction)
863 mpie.insertItem(oneItem)
864 mpie.insertItem(twoItem)
865 mpie.insertItem(oneItem)
866 mpie.insertItem(iconTextItem)
870 oneAction = QtGui.QAction(None)
871 oneAction.setText("Chew")
872 oneAction.triggered.connect(lambda: _print("Chew"))
873 oneItem = QActionPieItem(oneAction)
874 twoAction = QtGui.QAction(None)
875 twoAction.setText("Foo")
876 twoAction.triggered.connect(lambda: _print("Foo"))
877 twoItem = QActionPieItem(twoAction)
878 iconAction = QtGui.QAction(None)
879 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
880 iconAction.triggered.connect(lambda: _print("Icon"))
881 iconItem = QActionPieItem(iconAction)
882 iconTextAction = QtGui.QAction(None)
883 iconTextAction.setText("Icon")
884 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
885 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
886 iconTextItem = QActionPieItem(iconTextAction)
888 mpie.set_center(iconItem)
889 mpie.insertItem(oneItem)
890 mpie.insertItem(twoItem)
891 mpie.insertItem(oneItem)
892 mpie.insertItem(iconTextItem)
894 mpie.aboutToHide.connect(lambda: _on_about_to_hide(app))
895 mpie.canceled.connect(lambda: _print("Canceled"))
898 oneAction = QtGui.QAction(None)
899 oneAction.setText("Chew")
900 oneAction.triggered.connect(lambda: _print("Chew"))
901 oneItem = QActionPieItem(oneAction)
902 twoAction = QtGui.QAction(None)
903 twoAction.setText("Foo")
904 twoAction.triggered.connect(lambda: _print("Foo"))
905 twoItem = QActionPieItem(twoAction)
906 iconAction = QtGui.QAction(None)
907 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
908 iconAction.triggered.connect(lambda: _print("Icon"))
909 iconItem = QActionPieItem(iconAction)
910 iconTextAction = QtGui.QAction(None)
911 iconTextAction.setText("Icon")
912 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
913 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
914 iconTextItem = QActionPieItem(iconTextAction)
915 pieFiling = PieFiling()
916 pieFiling.set_center(iconItem)
917 pieFiling.insertItem(oneItem)
918 pieFiling.insertItem(twoItem)
919 pieFiling.insertItem(oneItem)
920 pieFiling.insertItem(iconTextItem)
921 mpie = QPieDisplay(pieFiling)
925 oneAction = QtGui.QAction(None)
926 oneAction.setText("Chew")
927 oneAction.triggered.connect(lambda: _print("Chew"))
928 oneItem = QActionPieItem(oneAction)
929 twoAction = QtGui.QAction(None)
930 twoAction.setText("Foo")
931 twoAction.triggered.connect(lambda: _print("Foo"))
932 twoItem = QActionPieItem(twoAction)
933 iconAction = QtGui.QAction(None)
934 iconAction.setIcon(QtGui.QIcon.fromTheme("gtk-open"))
935 iconAction.triggered.connect(lambda: _print("Icon"))
936 iconItem = QActionPieItem(iconAction)
937 iconTextAction = QtGui.QAction(None)
938 iconTextAction.setText("Icon")
939 iconTextAction.setIcon(QtGui.QIcon.fromTheme("gtk-close"))
940 iconTextAction.triggered.connect(lambda: _print("Icon and text"))
941 iconTextItem = QActionPieItem(iconTextAction)
942 mpie = QPieButton(iconItem)
943 mpie.set_center(iconItem)
944 mpie.insertItem(oneItem)
945 mpie.insertItem(twoItem)
946 mpie.insertItem(oneItem)
947 mpie.insertItem(iconTextItem)
949 mpie.aboutToHide.connect(lambda: _on_about_to_hide(app))
950 mpie.canceled.connect(lambda: _print("Canceled"))