35 from python_qt_binding.QtCore
import Signal
36 from python_qt_binding.QtWidgets
import QToolButton
39 from .util
import IconHelper
44 This is the base class for all widgets.
45 It provides state and icon switching support as well as convenience functions for creating icons.
47 :raises IndexError: if ``icons`` is not a list of lists of strings
49 :param name: name of the object
51 :param icons: A list of lists of strings to create icons for the states of this button.\
52 If only one is supplied then ok, warn, error, stale icons will be created with overlays
55 :param clicked_icons: A list of clicked state icons. len must equal icons
56 :type clicked_icons: list
57 :param suppress_overlays: if false and there is only one icon path supplied
58 :type suppress_overlays: bool
59 :param icon_paths: list of lists of package and subdirectory in the form\
60 ['package name', 'subdirectory'] example ['rqt_pr2_dashboard', 'images/svg']
62 :type icon_paths: list of lists of strings
64 state_changed = Signal(int)
66 def __init__(self, name, icons, clicked_icons=None, suppress_overlays=False, icon_paths=None):
67 super(IconToolButton, self).
__init__()
70 self.setObjectName(self.
name)
77 icon_paths = (icon_paths
if icon_paths
else []) + [[
'rqt_robot_dashboard',
'images']]
80 for path
in icon_paths:
81 paths.append(os.path.join(rp.get_path(path[0]), path[1]))
83 converted_icons = self.
icon_helper.set_icon_lists(icons, clicked_icons, suppress_overlays)
87 self.setStyleSheet(
'QToolButton {border: none;}')
94 Set the state of this button.
95 This will also update the icon for the button based on the ``self._icons`` list
97 :raises IndexError: If state is not a proper index to ``self._icons``
99 :param state: The state to set.
102 if 0 <= state
and state < len(self.
_icons):
106 raise IndexError(
"%s update_state received invalid state: %s" % (self.
name, state))
111 Read-only accessor for the widgets current state.