1 """Provides widgets related to submodules"""
2 from __future__
import absolute_import
4 from qtpy
import QtWidgets
5 from qtpy
.QtCore
import Qt
6 from qtpy
.QtCore
import Signal
10 from .. import qtutils
13 from ..widgets
import defs
14 from ..widgets
import standard
17 class SubmodulesWidget(QtWidgets
.QFrame
):
19 def __init__(self
, context
, parent
):
20 QtWidgets
.QFrame
.__init
__(self
, parent
)
21 self
.setToolTip(N_('Submodules'))
23 self
.tree
= SubmodulesTreeWidget(context
, parent
=self
)
24 self
.setFocusProxy(self
.tree
)
26 self
.main_layout
= qtutils
.vbox(defs
.no_margin
, defs
.spacing
, self
.tree
)
27 self
.setLayout(self
.main_layout
)
30 self
.refresh_button
= qtutils
.create_action_button(
31 tooltip
=N_('Refresh'), icon
=icons
.sync())
33 self
.open_parent_button
= qtutils
.create_action_button(
34 tooltip
=N_('Open Parent'), icon
=icons
.repo())
36 self
.button_layout
= qtutils
.hbox(defs
.no_margin
, defs
.spacing
,
37 self
.open_parent_button
,
39 self
.corner_widget
= QtWidgets
.QWidget(self
)
40 self
.corner_widget
.setLayout(self
.button_layout
)
41 titlebar
= parent
.titleBarWidget()
42 titlebar
.add_corner_widget(self
.corner_widget
)
45 qtutils
.connect_button(self
.refresh_button
,
46 context
.model
.update_submodules_list
)
47 qtutils
.connect_button(self
.open_parent_button
,
48 cmds
.run(cmds
.OpenParentRepo
, context
))
51 class SubmodulesTreeWidget(standard
.TreeWidget
):
54 def __init__(self
, context
, parent
=None):
55 standard
.TreeWidget
.__init
__(self
, parent
=parent
)
57 self
.context
= context
58 self
.main_model
= model
= context
.model
60 self
.setSelectionMode(QtWidgets
.QAbstractItemView
.SingleSelection
)
61 self
.setHeaderHidden(True)
64 self
.list_helper
= BuildItem()
65 self
.itemDoubleClicked
.connect(self
.tree_double_clicked
)
67 self
.updated
.connect(self
.refresh
, type=Qt
.QueuedConnection
)
68 model
.add_observer(model
.message_submodules_changed
,
75 items
= [self
.list_helper
.get(entry
) for entry
in
76 self
.main_model
.submodules_list
]
78 self
.addTopLevelItems(items
)
80 def showEvent(self
, event
):
81 """Defer updating widgets until the widget is visible"""
85 return super(SubmodulesTreeWidget
, self
).showEvent(event
)
87 def tree_double_clicked(self
, item
, _column
):
88 path
= core
.abspath(item
.path
)
89 cmds
.do(cmds
.OpenRepo
, self
.context
, path
)
92 class BuildItem(object):
95 self
.state_folder_map
= {}
96 self
.state_folder_map
[''] = icons
.folder()
97 self
.state_folder_map
['+'] = icons
.staged()
98 self
.state_folder_map
['-'] = icons
.modified()
99 self
.state_folder_map
['U'] = icons
.merge()
101 def get(self
, entry
):
102 """entry: same as returned from list_submodule"""
106 tip
= path
+ '\n' + entry
[1]
108 tip
+= '\n({0})'.format(entry
[3])
109 icon
= self
.state_folder_map
[entry
[0]]
110 return SubmodulesTreeWidgetItem(name
, path
, tip
, icon
)
113 class SubmodulesTreeWidgetItem(QtWidgets
.QTreeWidgetItem
):
115 def __init__(self
, name
, path
, tip
, icon
):
116 QtWidgets
.QTreeWidgetItem
.__init
__(self
)
119 self
.setIcon(0, icon
)
120 self
.setText(0, name
)
121 self
.setToolTip(0, tip
)