Changeset 105f1d354e0b…
Parent 26c8e6c497a0…
by
Changes to 2 files · Browse files at 105f1d354e0b Showing diff from parent 26c8e6c497a0 Diff from another changeset...
@@ -735,6 +735,69 @@
self.setLayout(box)
+class InfoBar(QFrame):
+ """Non-modal confirmation/alert (like web flash or Chrome's InfoBar)
+
+ You shouldn't reuse InfoBar object after close(). It is automatically
+ deleted.
+
+ Layout::
+
+ |widgets ... |right widgets ...|x|
+ """
+ linkActivated = pyqtSignal(unicode)
+
+ # type of InfoBar (the number denotes its priority)
+ INFO = 1
+ ERROR = 2
+
+ infobartype = INFO
+
+ _colormap = {
+ INFO: '#e7f9e0',
+ ERROR: '#f9d8d8',
+ }
+
+ def __init__(self, parent=None):
+ super(InfoBar, self).__init__(parent, frameShape=QFrame.StyledPanel,
+ frameShadow=QFrame.Plain)
+ self.setAttribute(Qt.WA_DeleteOnClose)
+
+ self.setAutoFillBackground(True)
+ p = self.palette()
+ p.setColor(QPalette.Window, QColor(self._colormap[self.infobartype]))
+ self.setPalette(p)
+
+ self.setLayout(QHBoxLayout())
+ self.layout().setContentsMargins(2, 2, 2, 2)
+
+ self.layout().addStretch()
+ self._closebutton = QPushButton(self, flat=True, autoDefault=False,
+ icon=self.style().standardIcon(QStyle.SP_DockWidgetCloseButton))
+ self._closebutton.clicked.connect(self.close)
+ self.layout().addWidget(self._closebutton)
+
+ def addWidget(self, w):
+ self.layout().insertWidget(self.layout().count() - 2, w)
+
+ def addRightWidget(self, w):
+ self.layout().insertWidget(self.layout().count() - 1, w)
+
+class CommandErrorInfoBar(InfoBar):
+ """Show command execution failure (with link to open log window)"""
+ infobartype = InfoBar.ERROR
+
+ def __init__(self, message, parent=None):
+ super(CommandErrorInfoBar, self).__init__(parent)
+
+ self._msglabel = QLabel(message, self,
+ textInteractionFlags=Qt.TextSelectableByMouse)
+ self.addWidget(self._msglabel)
+
+ self._loglabel = QLabel('<a href="log:">%s</a>' % _('Show Log'))
+ self._loglabel.linkActivated.connect(self.linkActivated)
+ self.addRightWidget(self._loglabel)
+
class WidgetGroups(object):
""" Support for bulk-updating properties of Qt widgets """
|
@@ -102,6 +102,9 @@ self.layout().setContentsMargins(0, 0, 0, 0)
self.layout().setSpacing(0)
+ self._infobarlayout = QVBoxLayout() # placeholder for InfoBar
+ self.layout().addLayout(self._infobarlayout)
+
hbox = QHBoxLayout()
hbox.setContentsMargins(0, 0, 0, 0)
hbox.setSpacing(0)
@@ -230,6 +233,7 @@ def _openLink(self, link):
link = unicode(link)
handlers = {'cset': self.goto,
+ 'log': lambda a: self.makeLogVisible.emit(True),
'subrepo': self.repoLinkClicked.emit,
'shelve' : self.shelve}
if ':' in link:
@@ -240,6 +244,25 @@
QDesktopServices.openUrl(QUrl(link))
+ def setInfoBar(self, cls, *args, **kwargs):
+ """Show the given infobar at top of RepoWidget"""
+ self.clearInfoBar()
+ w = cls(*args, **kwargs)
+ w.linkActivated.connect(self._openLink)
+ self._infobarlayout.insertWidget(0, w)
+ return w
+
+ def clearInfoBar(self):
+ """Close current infobar if available"""
+ it = self._infobarlayout.itemAt(0)
+ if it:
+ it.widget().close()
+
+ @pyqtSlot(unicode, unicode)
+ def _showOutputOnInfoBar(self, msg, label):
+ if label == 'ui.error':
+ self.setInfoBar(qtlib.CommandErrorInfoBar, unicode(msg).strip())
+
def createCommitWidget(self):
pats, opts = {}, {}
cw = CommitWidget(self.repo, pats, opts, True, self)
@@ -278,6 +301,7 @@ def createSyncWidget(self):
sw = SyncWidget(self.repo, self)
sw.output.connect(self.output)
+ sw.output.connect(self._showOutputOnInfoBar)
sw.progress.connect(self.progress)
sw.makeLogVisible.connect(self.makeLogVisible)
sw.outgoingNodes.connect(self.setOutgoingNodes)
|
Loading...