1 from __future__
import division
, absolute_import
, unicode_literals
4 from qtpy
import QtCore
6 from qtpy
import QtWidgets
7 from qtpy
.QtCore
import Qt
12 def patch(obj
, attr
, value
):
13 if not hasattr(obj
, attr
):
14 setattr(obj
, attr
, value
)
18 patch(QtWidgets
.QGraphicsItem
, 'mapRectToScene', _map_rect_to_scene
)
19 patch(QtGui
.QKeySequence
, 'Preferences', hotkeys
.PREFERENCES
)
22 def add_search_path(prefix
, path
):
23 if hasattr(QtCore
.QDir
, 'addSearchPath'):
24 QtCore
.QDir
.addSearchPath(prefix
, path
)
27 def set_common_dock_options(window
):
28 if not hasattr(window
, 'setDockOptions'):
30 nested
= QtWidgets
.QMainWindow
.AllowNestedDocks
31 tabbed
= QtWidgets
.QMainWindow
.AllowTabbedDocks
32 animated
= QtWidgets
.QMainWindow
.AnimatedDocks
33 window
.setDockOptions(nested | tabbed | animated
)
36 def _map_rect_to_scene(self
, rect
):
37 """Only available in newer PyQt4 versions"""
38 return self
.sceneTransform().mapRect(rect
)
41 def wheel_translation(event
):
42 """Return the Tx Ty translation delta for a pan"""
46 if event
.orientation() == Qt
.Vertical
:
49 angle
= event
.angleDelta()
55 def wheel_delta(event
):
56 """Return a single wheel delta"""
60 angle
= event
.angleDelta()