Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 from QtGui import QMenu, QToolButton
00034 from .icon_tool_button import IconToolButton
00035 
00036 
00037 class MenuDashWidget(IconToolButton):
00038     """
00039     A widget which displays a pop-up menu when clicked
00040 
00041     :param name: The name to give this widget.
00042     :type name: str
00043     :param icon: The icon to display in this widgets button.
00044     :type icon: str
00045     """
00046     def __init__(self, name, icons=None, clicked_icons=None, icon_paths=[]):
00047         if icons == None:
00048             icons = [['ic-motors.svg']]
00049         super(MenuDashWidget, self).__init__(name, icons=icons, suppress_overlays=True, icon_paths=icon_paths)
00050         self.setStyleSheet('QToolButton::menu-indicator {image: url(none.jpg);} QToolButton {border: none;}')
00051         self.setPopupMode(QToolButton.InstantPopup)
00052         self.update_state(0)
00053 
00054         self.pressed.disconnect(self._pressed)
00055         self.released.disconnect(self._released)
00056 
00057         self._menu = QMenu()
00058         self._menu.aboutToHide.connect(self._released)
00059         self._menu.aboutToShow.connect(self._pressed)
00060 
00061         self.setMenu(self._menu)
00062 
00063     def add_separator(self):
00064         return self._menu.addSeparator()
00065 
00066     def add_action(self, name, callback):
00067         """
00068         Add an action to the menu, and return the newly created action.
00069 
00070         :param name: The name of the action.
00071         :type name: str
00072         :param callback: Function to be called when this item is pressed.
00073         :type callback: callable
00074         """
00075         return self._menu.addAction(name, callback)