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
16 def patch(obj
, attr
, value
):
17 if not hasattr(obj
, attr
):
18 setattr(obj
, attr
, value
)
22 patch(QtWidgets
.QGraphicsItem
, 'mapRectToScene', _map_rect_to_scene
)
23 patch(QtGui
.QKeySequence
, 'Preferences', hotkeys
.PREFERENCES
)
26 def add_search_path(prefix
, path
):
27 if hasattr(QtCore
.QDir
, 'addSearchPath'):
28 QtCore
.QDir
.addSearchPath(prefix
, path
)
31 def set_common_dock_options(window
):
32 if not hasattr(window
, 'setDockOptions'):
34 nested
= QtWidgets
.QMainWindow
.AllowNestedDocks
35 tabbed
= QtWidgets
.QMainWindow
.AllowTabbedDocks
36 animated
= QtWidgets
.QMainWindow
.AnimatedDocks
37 window
.setDockOptions(nested | tabbed | animated
)
40 def _map_rect_to_scene(self
, rect
):
41 """Only available in newer PyQt4 versions"""
42 return self
.sceneTransform().mapRect(rect
)
45 def wheel_translation(event
):
46 """Return the Tx Ty translation delta for a pan"""
50 if event
.orientation() == Qt
.Vertical
:
53 angle
= event
.angleDelta()
59 def wheel_delta(event
):
60 """Return a single wheel delta"""
64 angle
= event
.angleDelta()