1 from qtpy
import QtCore
3 from qtpy
import QtWidgets
4 from qtpy
.QtCore
import Qt
14 def patch(obj
, attr
, value
):
15 if not hasattr(obj
, attr
):
16 setattr(obj
, attr
, value
)
20 patch(QtWidgets
.QGraphicsItem
, 'mapRectToScene', _map_rect_to_scene
)
21 patch(QtGui
.QKeySequence
, 'Preferences', hotkeys
.PREFERENCES
)
24 def add_search_path(prefix
, path
):
25 if hasattr(QtCore
.QDir
, 'addSearchPath'):
26 QtCore
.QDir
.addSearchPath(prefix
, path
)
29 def set_common_dock_options(window
):
30 if not hasattr(window
, 'setDockOptions'):
32 nested
= QtWidgets
.QMainWindow
.AllowNestedDocks
33 tabbed
= QtWidgets
.QMainWindow
.AllowTabbedDocks
34 animated
= QtWidgets
.QMainWindow
.AnimatedDocks
35 window
.setDockOptions(nested | tabbed | animated
)
38 def _map_rect_to_scene(self
, rect
):
39 """Only available in newer PyQt4 versions"""
40 return self
.sceneTransform().mapRect(rect
)
43 def wheel_translation(event
):
44 """Return the Tx Ty translation delta for a pan"""
48 if event
.orientation() == Qt
.Vertical
:
51 angle
= event
.angleDelta()
57 def wheel_delta(event
):
58 """Return a single wheel delta"""
62 angle
= event
.angleDelta()