1 from __future__
import division
, absolute_import
, unicode_literals
3 from PyQt4
import QtGui
4 from PyQt4
import QtCore
6 from cola
import hotkeys
9 def patch(obj
, attr
, value
):
10 if not hasattr(obj
, attr
):
11 setattr(obj
, attr
, value
)
15 set_contents_margins
= lambda self
, *args
: self
.setMargin(max(args
))
16 patch(QtGui
.QHBoxLayout
, 'setContentsMargins', set_contents_margins
)
17 patch(QtGui
.QVBoxLayout
, 'setContentsMargins', set_contents_margins
)
19 set_margin
= lambda self
, x
: self
.setContentsMargins(x
, x
, x
, x
)
20 patch(QtGui
.QHBoxLayout
, 'setMargin', set_margin
)
21 patch(QtGui
.QVBoxLayout
, 'setMargin', set_margin
)
23 patch(QtGui
.QKeySequence
, 'Preferences', hotkeys
.PREFERENCES
)
24 patch(QtGui
.QGraphicsItem
, 'mapRectToScene', _map_rect_to_scene
)
27 def add_search_path(prefix
, path
):
28 if hasattr(QtCore
.QDir
, 'addSearchPath'):
29 QtCore
.QDir
.addSearchPath(prefix
, path
)
32 def set_common_dock_options(window
):
33 if not hasattr(window
, 'setDockOptions'):
35 nested
= QtGui
.QMainWindow
.AllowNestedDocks
36 tabbed
= QtGui
.QMainWindow
.AllowTabbedDocks
37 animated
= QtGui
.QMainWindow
.AnimatedDocks
38 window
.setDockOptions(nested | tabbed | animated
)
41 def _map_rect_to_scene(self
, rect
):
42 """Only available in newer PyQt4 versions"""
43 return self
.sceneTransform().mapRect(rect
)