# Path: gsdview/mousemanager.py
# class MouseManager(QtCore.QObject):
# 
#     #: SIGNAL: it is emitted when the mouse mode is changed
#     #:
#     #: :C++ signature: `void modeChanged(const QString&)`
#     modeChanged = QtCore.Signal(str)
# 
#     def __init__(self, parent=None, stdmodes=True, **kwargs):
#         QtCore.QObject.__init__(self, parent, **kwargs)
# 
#         self._moderegistry = []
#         self.actions = QtWidgets.QActionGroup(self)
#         self.actions.setExclusive(True)
# 
#         if stdmodes:
#             self.registerStandardModes()
# 
#     def registerStandardModes(self):
#         for mode in (PointerMode, ScrollHandMode):  # , RubberBandMode):
#             self.addMode(mode)
#         if len(self._moderegistry) and not self.actions.checkedAction():
#             self.actions.actions()[0].setChecked(True)
# 
#     def _newModeAction(self, mode, parent):
#         if isinstance(mode.icon, str):
#             if mode.icon.startswith(':'):
#                 icon = QtGui.QIcon(mode.icon)
#             else:
#                 icon = QtGui.QIcon.fromTheme(mode.icon)
#         elif isinstance(mode.icon, QtWidgets.QStyle.StandardPixmap):
#             style = QtWidgets.QApplication.style()
#             icon = style.standardIcon(mode.icon)
#         else:
#             icon = mode.icon
# 
#         action = QtWidgets.QAction(
#             icon, self.tr(mode.label), parent,
#             statusTip=self.tr(mode.label),
#             checkable=True)
#         action.triggered.connect(lambda: self.modeChanged.emit(self.mode))
#         return action
# 
#     def _getMode(self):
#         action = self.actions.checkedAction()
#         index = self.actions.actions().index(action)
#         return self._moderegistry[index].name
# 
#     def _setMode(self, name):
#         names = self.modes()
#         index = names.index(name)
#         action = self.actions.actions()[index]
#         action.setChecked(True)
# 
#     def _delMode(self, name):
#         names = [m.name for m in self._moderegistry]
#         index = names.index(name)
#         action = self.actions.actions()[index]
#         self.actions.removeAction(action)
#         del self._moderegistry[index]
#         # if action.checked() and self._moderegistry:
#         #     self.actions.actions()[0].setChecked(True)
# 
#     mode = property(_getMode, _setMode, _delMode, 'mouse mode name')
# 
#     def modes(self):
#         return tuple(m.name for m in self._moderegistry)
# 
#     def addMode(self, mode):
#         if isinstance(mode, type):
#             mode = mode(self)
# 
#         action = self._newModeAction(mode, self.actions)
#         self.actions.addAction(action)
#         self._moderegistry.append(mode)
# 
#     def getModeDescriptor(self, name=None):
#         """Return the mouse mode object"""
# 
#         try:
#             if name is None:
#                 action = self.actions.checkedAction()
#                 index = self.actions.actions().index(action)
#             else:
#                 names = self.modes()
#                 index = names.index(name)
#             return self._moderegistry[index]
#         except IndexError:
#             # @TODO: check
#             # raise ValueError('invalid mode name: "%s"' % mode)
#             return None
# 
#     def eventFilter(self, obj, event):
#         """Events dispatcher"""
# 
#         return self.getModeDescriptor().eventFilter(obj, event)
# 
#     def register(self, obj):
#         """Register a Qt graphics object to be monitored by the mouse manager.
# 
#         QGraphicsScene and QGraphicsViews (and descending classes) objects
#         can be registered to be monitored by the mouse manager.
# 
#         Scene objects associated to views (passes as argument) are
#         automatically registered.
# 
#         """
# 
#         obj.installEventFilter(self)
# 
#         try:
#             obj.verticalScrollBar().installEventFilter(self)
#         except AttributeError:
#             # it is a QGraphicsScene
#             scene = obj
#         else:
#             scene = obj.scene()
# 
#         # Avoid event filter duplication
#         scene.removeEventFilter(self)
#         scene.installEventFilter(self)
# 
#     def unregister(self, obj):
#         """Unregister monitored objects.
# 
#         If the object passed as argument is not a registered object
#         nothing happens.
# 
#         .. note:: this method never tries to unregister scene objects
#                   associated to the view passed as argument.
# 
#         """
# 
#         obj.removeEventFilter(self)


import os
import sys
    import sys
from qtpy import QtCore, QtWidgets, QtGui
from gsdview.mousemanager import MouseManager
        from gsdview.mousemanager import RubberBandMode
        icon = style.standardIcon(QtWidgets.QStyle.SP_DialogCancelButton)
        QtWidgets.QAction(icon, 'Exit', actions, triggered=self.close)

        return actions

    def _setupHelpActions(self):
        actions = QtWidgets.QActionGroup(self)

        icon = QtGui.QIcon.fromTheme('dialog-information')
        QtWidgets.QAction(icon, 'About', actions, triggered=self.about)

        icon = QtGui.QIcon(':/qtlogo-64')
        QtWidgets.QAction(icon, 'About Qt', actions,
                          triggered=QtWidgets.QApplication.aboutQt)

        return actions

    @QtCore.Slot()
    def openfile(self):
        self.scene.clear()
        self.graphicsview.setTransform(QtGui.QTransform())
        filename = QtWidgets.QFileDialog.getOpenFileName()
        if filename:
            pixmap = QtGui.QPixmap(filename)
            item = self.scene.addPixmap(pixmap)
            self.scene.setSceneRect(item.boundingRect())

    @QtCore.Slot()
    def about(self):
        title = self.tr('MouseManager Example')

# Path: gsdview/mousemanager.py
# class MouseManager(QtCore.QObject):
# 
#     #: SIGNAL: it is emitted when the mouse mode is changed
#     #:
#     #: :C++ signature: `void modeChanged(const QString&)`
#     modeChanged = QtCore.Signal(str)
# 
#     def __init__(self, parent=None, stdmodes=True, **kwargs):
#         QtCore.QObject.__init__(self, parent, **kwargs)
# 
#         self._moderegistry = []
#         self.actions = QtWidgets.QActionGroup(self)
#         self.actions.setExclusive(True)
# 
#         if stdmodes:
#             self.registerStandardModes()
# 
#     def registerStandardModes(self):
#         for mode in (PointerMode, ScrollHandMode):  # , RubberBandMode):
#             self.addMode(mode)
#         if len(self._moderegistry) and not self.actions.checkedAction():
#             self.actions.actions()[0].setChecked(True)
# 
#     def _newModeAction(self, mode, parent):
#         if isinstance(mode.icon, str):
#             if mode.icon.startswith(':'):
#                 icon = QtGui.QIcon(mode.icon)
#             else:
#                 icon = QtGui.QIcon.fromTheme(mode.icon)
#         elif isinstance(mode.icon, QtWidgets.QStyle.StandardPixmap):
#             style = QtWidgets.QApplication.style()
#             icon = style.standardIcon(mode.icon)
#         else:
#             icon = mode.icon
# 
#         action = QtWidgets.QAction(
#             icon, self.tr(mode.label), parent,
#             statusTip=self.tr(mode.label),
#             checkable=True)
#         action.triggered.connect(lambda: self.modeChanged.emit(self.mode))
#         return action
# 
#     def _getMode(self):
#         action = self.actions.checkedAction()
#         index = self.actions.actions().index(action)
#         return self._moderegistry[index].name
# 
#     def _setMode(self, name):
#         names = self.modes()
#         index = names.index(name)
#         action = self.actions.actions()[index]
#         action.setChecked(True)
# 
#     def _delMode(self, name):
#         names = [m.name for m in self._moderegistry]
#         index = names.index(name)
#         action = self.actions.actions()[index]
#         self.actions.removeAction(action)
#         del self._moderegistry[index]
#         # if action.checked() and self._moderegistry:
#         #     self.actions.actions()[0].setChecked(True)
# 
#     mode = property(_getMode, _setMode, _delMode, 'mouse mode name')
# 
#     def modes(self):
#         return tuple(m.name for m in self._moderegistry)
# 
#     def addMode(self, mode):
#         if isinstance(mode, type):
#             mode = mode(self)
# 
#         action = self._newModeAction(mode, self.actions)
#         self.actions.addAction(action)
#         self._moderegistry.append(mode)
# 
#     def getModeDescriptor(self, name=None):
#         """Return the mouse mode object"""
# 
#         try:
#             if name is None:
#                 action = self.actions.checkedAction()
#                 index = self.actions.actions().index(action)
#             else:
#                 names = self.modes()
#                 index = names.index(name)
#             return self._moderegistry[index]
#         except IndexError:
#             # @TODO: check
#             # raise ValueError('invalid mode name: "%s"' % mode)
#             return None
# 
#     def eventFilter(self, obj, event):
#         """Events dispatcher"""
# 
#         return self.getModeDescriptor().eventFilter(obj, event)
# 
#     def register(self, obj):
#         """Register a Qt graphics object to be monitored by the mouse manager.
# 
#         QGraphicsScene and QGraphicsViews (and descending classes) objects
#         can be registered to be monitored by the mouse manager.
# 
#         Scene objects associated to views (passes as argument) are
#         automatically registered.
# 
#         """
# 
#         obj.installEventFilter(self)
# 
#         try:
#             obj.verticalScrollBar().installEventFilter(self)
#         except AttributeError:
#             # it is a QGraphicsScene
#             scene = obj
#         else:
#             scene = obj.scene()
# 
#         # Avoid event filter duplication
#         scene.removeEventFilter(self)
#         scene.installEventFilter(self)
# 
#     def unregister(self, obj):
#         """Unregister monitored objects.
# 
#         If the object passed as argument is not a registered object
#         nothing happens.
# 
#         .. note:: this method never tries to unregister scene objects
#                   associated to the view passed as argument.
# 
#         """
# 
#         obj.removeEventFilter(self)


# Path: tests/test_mousemanager.py
import os
import sys
    import sys
from qtpy import QtCore, QtWidgets, QtGui
from gsdview.mousemanager import MouseManager
        from gsdview.mousemanager import RubberBandMode

        icon = style.standardIcon(QtWidgets.QStyle.SP_DialogCancelButton)
        QtWidgets.QAction(icon, 'Exit', actions, triggered=self.close)

        return actions

    def _setupHelpActions(self):
        actions = QtWidgets.QActionGroup(self)

        icon = QtGui.QIcon.fromTheme('dialog-information')
        QtWidgets.QAction(icon, 'About', actions, triggered=self.about)

        icon = QtGui.QIcon(':/qtlogo-64')
        QtWidgets.QAction(icon, 'About Qt', actions,
                          triggered=QtWidgets.QApplication.aboutQt)

        return actions

    @QtCore.Slot()
    def openfile(self):
        self.scene.clear()
        self.graphicsview.setTransform(QtGui.QTransform())
        filename = QtWidgets.QFileDialog.getOpenFileName()
        if filename:
            pixmap = QtGui.QPixmap(filename)
            item = self.scene.addPixmap(pixmap)
            self.scene.setSceneRect(item.boundingRect())

    @QtCore.Slot()
    def about(self):
        title = self.tr('MouseManager Example')

        text = [