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
.QWidget
):
19 def __init__(self
, context
, parent
):
20 QtWidgets
.QWidget
.__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
, self
.tree
.refresh_command
)
46 qtutils
.connect_button(self
.open_parent_button
,
47 cmds
.run(cmds
.OpenParentRepo
, context
))
50 class SubmodulesTreeWidget(standard
.TreeWidget
):
53 def __init__(self
, context
, parent
=None):
54 standard
.TreeWidget
.__init
__(self
, parent
=parent
)
56 self
.context
= context
57 self
.main_model
= model
= context
.model
59 self
.setSelectionMode(QtWidgets
.QAbstractItemView
.SingleSelection
)
60 self
.setHeaderHidden(True)
62 self
.updated
.connect(self
.refresh
, type=Qt
.QueuedConnection
)
63 model
.add_observer(model
.message_updated
, self
.updated
.emit
)
66 self
.list_helper
= BuildItem()
67 self
.itemDoubleClicked
.connect(self
.tree_double_clicked
)
69 def refresh_command(self
):
70 # TODO how to monitor changes of submodules?
71 self
.main_model
._update
_submodules
_list
()
78 items
= [self
.list_helper
.get(entry
) for entry
in
79 self
.main_model
.submodules_list
]
81 self
.addTopLevelItems(items
)
83 def showEvent(self
, event
):
84 """Defer updating widgets until the widget is visible"""
88 return super(SubmodulesTreeWidget
, self
).showEvent(event
)
90 def tree_double_clicked(self
, item
, _column
):
91 path
= core
.abspath(item
.path
)
92 cmds
.do(cmds
.OpenRepo
, self
.context
, path
)
95 class BuildItem(object):
98 self
.state_folder_map
= {}
99 self
.state_folder_map
[''] = icons
.folder()
100 self
.state_folder_map
['+'] = icons
.staged()
101 self
.state_folder_map
['-'] = icons
.modified()
102 self
.state_folder_map
['U'] = icons
.merge()
104 def get(self
, entry
):
105 """entry: same as returned from list_submodule"""
109 tip
= path
+ '\n' + entry
[1]
111 tip
+= '\n({0})'.format(entry
[3])
112 icon
= self
.state_folder_map
[entry
[0]]
113 return SubmodulesTreeWidgetItem(name
, path
, tip
, icon
)
116 class SubmodulesTreeWidgetItem(QtWidgets
.QTreeWidgetItem
):
118 def __init__(self
, name
, path
, tip
, icon
):
119 QtWidgets
.QTreeWidgetItem
.__init
__(self
)
122 self
.setIcon(0, icon
)
123 self
.setText(0, name
)
124 self
.setToolTip(0, tip
)