1 from __future__
import absolute_import
, division
, print_function
, unicode_literals
3 from qtpy
import QtCore
5 from qtpy
import QtWidgets
6 from qtpy
.QtCore
import Qt
15 def patch(obj
, attr
, value
):
16 if not hasattr(obj
, attr
):
17 setattr(obj
, attr
, value
)
21 patch(QtWidgets
.QGraphicsItem
, 'mapRectToScene', _map_rect_to_scene
)
22 patch(QtGui
.QKeySequence
, 'Preferences', hotkeys
.PREFERENCES
)
25 def add_search_path(prefix
, path
):
26 if hasattr(QtCore
.QDir
, 'addSearchPath'):
27 QtCore
.QDir
.addSearchPath(prefix
, path
)
30 def set_common_dock_options(window
):
31 if not hasattr(window
, 'setDockOptions'):
33 nested
= QtWidgets
.QMainWindow
.AllowNestedDocks
34 tabbed
= QtWidgets
.QMainWindow
.AllowTabbedDocks
35 animated
= QtWidgets
.QMainWindow
.AnimatedDocks
36 window
.setDockOptions(nested | tabbed | animated
)
39 def _map_rect_to_scene(self
, rect
):
40 """Only available in newer PyQt4 versions"""
41 return self
.sceneTransform().mapRect(rect
)
44 def wheel_translation(event
):
45 """Return the Tx Ty translation delta for a pan"""
49 if event
.orientation() == Qt
.Vertical
:
52 angle
= event
.angleDelta()
58 def wheel_delta(event
):
59 """Return a single wheel delta"""
63 angle
= event
.angleDelta()